MesHelper.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. using Oracle.ManagedDataAccess.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. namespace UMES.DLLService
  9. {
  10. [Guid("99D0E96E-1058-415D-9874-D34537625284")]
  11. [InterfaceType(ComInterfaceType.InterfaceIsDual)]
  12. public interface IMESHelper
  13. {
  14. [DispId(12)]
  15. bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage);
  16. bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
  17. bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
  18. bool GetAddressRangeByMO(string iSN, out Dictionary<string, string> oInfo, out string oErrMessage);
  19. bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
  20. bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[,] iTestDetail, out string oErrMessage);
  21. bool GetMEIOrNetCodeRange(string iSnCode, string iIMEI1, string iNetCode, out Dictionary<string, string> oInfo, out string oErrMessage);
  22. bool SetIMEIInfo(string iSnCode, string iIMEI1, out string oErrMessage);
  23. bool GetMobileAllInfo(string iSnCode, out Dictionary<string, string> oInfo, out string oErrorMessage);
  24. bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperator, string iResult, string iErrCode, string flag, out string oErrorMessage);
  25. bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage);
  26. bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage);
  27. }
  28. [Guid("41EAB546-6EF4-464A-895A-9C34013A5D8C")]
  29. [ComSourceInterfaces(typeof(IMESHelper))]
  30. [ClassInterface(ClassInterfaceType.None)]
  31. [ProgId("DllService.MESHelper")]
  32. public class MESHelper : IMESHelper
  33. {
  34. //用于拼接SQL
  35. StringBuilder sql = new StringBuilder();
  36. //用于存放批量执行的SQL
  37. List<string> sqls = new List<string>();
  38. //系统默认的的连接字符串
  39. private string ConnectionStrings = "Data Source=192.168.1.23/orcl;User ID=MES;PassWord=select!#%*(;";
  40. //用户选择的数据库的连接字符串
  41. private OracleConnection connection;
  42. //用户选择的数据库的连接字符串
  43. private OracleCommand command = null;
  44. public MESHelper()
  45. {
  46. connection = new OracleConnection(ConnectionStrings);
  47. }
  48. public MESHelper(string IP)
  49. {
  50. connection = new OracleConnection("Data Source=" + IP + "/orcl;User ID=MES;PassWord=select!#%*(;");
  51. }
  52. /// <summary>
  53. /// 检测当前的岗位资源对应的工序
  54. /// </summary>
  55. /// <param name="iSN"></param>
  56. /// <param name="iResCode"></param>
  57. /// <param name="oErrMessage"></param>
  58. /// <returns></returns>
  59. [Description("序列号对应工序检测")]
  60. public bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage)
  61. {
  62. if (iSN == "")
  63. {
  64. oErrMessage = "SN不能为空";
  65. return false;
  66. }
  67. oErrMessage = "";
  68. string[] param = new string[] { "", iResCode, iSN, "", "", "", oErrMessage };
  69. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
  70. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  71. oErrMessage = param[6];
  72. DataTable dt = (DataTable)ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=( select max(ms_id) from makeserial where ms_sncode in ( select '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
  73. string ms_status = "";
  74. string ms_stepcode = "";
  75. string ms_nextstepcode = "";
  76. if (dt.Rows.Count > 0)
  77. {
  78. ms_status = dt.Rows[0]["ms_status"].ToString();
  79. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  80. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  81. }
  82. string stepcode = GetStepCodeBySource(iResCode);
  83. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  84. {
  85. oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
  86. return false;
  87. }
  88. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
  89. {
  90. if (ms_status == "3")
  91. {
  92. oErrMessage = "";
  93. }
  94. return true;
  95. }
  96. else
  97. return false;
  98. }
  99. /// <summary>
  100. /// 验证用户身份信息
  101. /// </summary>
  102. /// <param name="iUserCode"></param>
  103. /// <param name="oErrorMessage"></param>
  104. /// <returns></returns>
  105. private bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
  106. {
  107. oErrorMessage = "";
  108. string SQL = "select em_code from employee where em_code=:UserName and em_password =:PassWord";
  109. DataTable dt;
  110. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode, iPassWord);
  111. if (dt.Rows.Count > 0)
  112. return true;
  113. else
  114. {
  115. oErrorMessage = "用户名或者密码不正确!";
  116. return false;
  117. }
  118. }
  119. /// <summary>
  120. /// 验证用户身份信息和岗位资源
  121. /// </summary>
  122. /// <param name="iUserCode"></param>
  123. /// <param name="iResCode"></param>
  124. /// <param name="oErrMessage"></param>
  125. /// <returns></returns>
  126. [Description("验证身份信息")]
  127. public bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage)
  128. {
  129. oErrMessage = "";
  130. if (iUserCode == "" || iPassWord == "" || iResCode == "")
  131. {
  132. oErrMessage = "用户名,密码,岗位资源必须填写";
  133. return false;
  134. }
  135. if (CheckUserLogin(iUserCode, iPassWord, out oErrMessage))
  136. {
  137. string SQL = "select em_code,em_type,em_name from employee where em_code=:UserName ";
  138. DataTable dt;
  139. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode);
  140. if (dt.Rows.Count > 0)
  141. {
  142. string em_name = dt.Rows[0]["em_name"].ToString();
  143. string em_type = dt.Rows[0]["em_type"].ToString();
  144. if (iResCode == "")
  145. {
  146. oErrMessage = "岗位资源不允许为空";
  147. return false;
  148. }
  149. if (em_type == "admin")
  150. {
  151. if (CheckExist("Source", "sc_code='" + iResCode + "' and sc_statuscode='AUDITED'"))
  152. {
  153. return true;
  154. }
  155. else
  156. {
  157. oErrMessage = "岗位资源编号错误或者未审核!";
  158. return false;
  159. }
  160. }
  161. else
  162. {
  163. dt = getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "ur_resourcecode" }, "eg_emcode = '" + iUserCode + "' and sc_statuscode='AUDITED'");
  164. //如果存在该编号
  165. if (dt.Rows.Count > 0)
  166. {
  167. //判断如果多个岗位资源存在,用户输入的只要在其中就行
  168. for (int i = 0; i < dt.Rows.Count; i++)
  169. {
  170. if (dt.Rows[i]["ur_resourcecode"].ToString() == iResCode)
  171. return true;
  172. }
  173. oErrMessage = "用户不处于当前资源所属分组!";
  174. }
  175. else
  176. oErrMessage = "岗位资源编号错误或者未审核!";
  177. }
  178. }
  179. else
  180. oErrMessage = "用户不存在!";
  181. }
  182. return false;
  183. }
  184. /// <summary>
  185. /// 分配Mac地址和BT地址
  186. /// </summary>
  187. /// <param name="iSN"></param>
  188. /// <param name="oWIFI"></param>
  189. /// <param name="oBT"></param>
  190. /// <param name="oCode1"></param>
  191. /// <param name="oCode2"></param>
  192. /// <param name="oCdoe3"></param>
  193. /// <param name="oErrMessage"></param>
  194. /// <returns></returns>
  195. [Description("分配MAC和BT信息")]
  196. public bool GetAddressRangeByMO(string iSN, out Dictionary<string, string> oInfo, out string oErrMessage)
  197. {
  198. oInfo = new Dictionary<string, string>();
  199. string oWIFI = "";
  200. string oBT = "";
  201. string oCode1 = "";
  202. string oCode2 = "";
  203. string oCdoe3 = "";
  204. if (iSN == "")
  205. {
  206. oErrMessage = "SN不能为空";
  207. return false;
  208. }
  209. oErrMessage = "";
  210. string omakeCode = "";
  211. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  212. string[] param = new string[] { iSN, omakeCode, oWIFI, oBT, oCode1, oCode2, oCdoe3, oErrMessage };
  213. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
  214. CallProcedure("CS_GETADDRESSBYMAKECODE", ParamName, ref param);
  215. oInfo.Add("MAC", param[2]);
  216. oInfo.Add("BT", param[3]);
  217. oInfo.Add("Code1", param[4]);
  218. oInfo.Add("Code2", param[5]);
  219. oInfo.Add("Code3", param[6]);
  220. oErrMessage = param[7];
  221. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  222. return true;
  223. else
  224. return false;
  225. }
  226. /// <summary>
  227. /// 输入的 SN 号查找在制品是否有 IMEI 信息存在,如果存在则将 IMEI 信息传出,如果没有则在该工单下未使用的 IMEI 中随机分配一组
  228. /// 如果iIMEI1、iNetCode不为空,则分别作为获取的附件加条件。
  229. /// </summary>
  230. /// <param name="iSN"></param>
  231. /// <param name="iIMEI1"></param>
  232. /// <param name="iNetCode"></param>
  233. /// <param name="oIMEI1"></param>
  234. /// <param name="oIMEI2"></param>
  235. /// <param name="oIMEI3"></param>
  236. /// <param name="oMEID"></param>
  237. /// <param name="oNetCode"></param>
  238. /// <param name="oPSN"></param>
  239. /// <param name="oID1"></param>
  240. /// <param name="oID2"></param>
  241. /// <param name="oID3"></param>
  242. /// <param name="oErrMessage"></param>
  243. /// <returns></returns>
  244. [Description("分配IMEI和NetCode信息")]
  245. public bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out Dictionary<string, string> oInfo, out string oErrMessage)
  246. {
  247. oInfo = new Dictionary<string, string>();
  248. string oIMEI1 = "";
  249. string oIMEI2 = "";
  250. string oMEID = "";
  251. string oNetCode = "";
  252. string oPSN = "";
  253. string oID1 = "";
  254. string oID2 = "";
  255. string oID3 = "";
  256. if (iSN == "")
  257. {
  258. oErrMessage = "SN不能为空";
  259. return false;
  260. }
  261. oErrMessage = "";
  262. string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, "", oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
  263. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_i_imei", "v_i_netcode", "v_o_imei1", "v_o_imei2", "v_o_imei3", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
  264. CallProcedure("CS_GETIMEIORNETCODERANGE", ParamName, ref param);
  265. oInfo.Add("IMEI1", param[4]);
  266. oInfo.Add("IMEI2", param[5]);
  267. oInfo.Add("MEID", param[7]);
  268. oInfo.Add("NETCODE", param[8]);
  269. oInfo.Add("PSN", param[9]);
  270. oInfo.Add("ID1", param[10]);
  271. oInfo.Add("ID2", param[11]);
  272. oInfo.Add("ID3", param[12]);
  273. oErrMessage = param[13];
  274. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  275. return true;
  276. else
  277. return false;
  278. }
  279. /// <summary>
  280. /// 获取工单的最近一条执行记录
  281. /// </summary>
  282. /// <param name="iSN"></param>
  283. /// <param name="oMoCode"></param>
  284. /// <param name="oErrMessage"></param>
  285. /// <returns></returns>
  286. [Description("获取序列号对应工单信息")]
  287. public bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage)
  288. {
  289. //取MakeProcess表中的执行记录ID最大的一个工单的号码
  290. oMoCode = "";
  291. if (iSN == "")
  292. {
  293. oErrMessage = "SN不能为空";
  294. return false;
  295. }
  296. oErrMessage = "";
  297. sql.Clear();
  298. sql.Append("select max(ms_id) from makeserial where ms_sncode in (select '" + iSN + "' from dual union select sn from ");
  299. sql.Append("makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' ')");
  300. DataTable dt = (DataTable)ExecuteSql(sql.ToString(), "select");
  301. string ms_id = dt.Rows[0][0].ToString();
  302. oMoCode = getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_id='" + ms_id + "'").ToString();
  303. if (oMoCode != "")
  304. return true;
  305. else
  306. {
  307. oErrMessage = "序列号:" + iSN + " 未归属工单";
  308. return false;
  309. }
  310. }
  311. /// <summary>
  312. /// 获取序列号的所有串号信息
  313. /// </summary>
  314. /// <param name="iSN"></param>
  315. /// <param name="oWIFI"></param>
  316. /// <param name="oBT"></param>
  317. /// <param name="oCode1"></param>
  318. /// <param name="oCode2"></param>
  319. /// <param name="oCode3"></param>
  320. /// <param name="oIMEI1"></param>
  321. /// <param name="oIMEI2"></param>
  322. /// <param name="oIMEI3"></param>
  323. /// <param name="oMEID"></param>
  324. /// <param name="oNetCode"></param>
  325. /// <param name="oPSN"></param>
  326. /// <param name="oID1"></param>
  327. /// <param name="oID2"></param>
  328. /// <param name="oID3"></param>
  329. /// <param name="oID4"></param>
  330. /// <param name="oID5"></param>
  331. /// <param name="oErrMessage"></param>
  332. /// <returns></returns>
  333. [Description("查询已分配的信息")]
  334. public bool GetMobileAllInfo(string iSN, out Dictionary<string, string> oInfo, out string oErrMessage)
  335. {
  336. oInfo = new Dictionary<string, string>();
  337. oErrMessage = "";
  338. if (iSN == "")
  339. {
  340. oErrMessage = "SN不能为空";
  341. return false;
  342. }
  343. //通过序列号获取最近操作的工单号
  344. string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "'").ToString();
  345. if (ms_id != "")
  346. {
  347. DataTable dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
  348. if (dt.Rows.Count > 0)
  349. {
  350. string Code1 = "";
  351. string Code2 = "";
  352. string Code3 = "";
  353. string Code4 = "";
  354. string Code5 = "";
  355. string Code6 = "";
  356. string Code7 = "";
  357. string Code8 = "";
  358. string Code9 = "";
  359. string Code10 = "";
  360. string Code11 = "";
  361. string Code12 = "";
  362. string Code13 = "";
  363. string Code14 = "";
  364. string Code15 = "";
  365. string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15 };
  366. string[] ParamName = new string[] { "v_ms_id", "v_i_code1", "v_i_code2", "v_i_code3", "v_i_code4", "v_i_code5", "v_i_code6", "v_i_code7", "v_i_code8", "v_i_code9", "v_i_code10", "v_i_code11", "v_i_code12", "v_i_code13", "v_i_code14", "v_i_code15" };
  367. CallProcedure("GetMobileAllInfo", ParamName, ref param);
  368. for (int i = 1; i < param.Length; i++)
  369. {
  370. //获取出来的参数使用^分割
  371. if (param[i] != "" && param[i] != "null" && param[i] != null)
  372. {
  373. oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
  374. }
  375. }
  376. oErrMessage = "";
  377. return true;
  378. }
  379. else
  380. {
  381. oErrMessage = "序列号" + iSN + "不存在";
  382. return false;
  383. }
  384. }
  385. else
  386. {
  387. oErrMessage = "序列号" + iSN + "不存在";
  388. return false;
  389. }
  390. }
  391. /// <summary>
  392. /// 记录操作日志
  393. /// </summary>
  394. /// <param name="iSnCode"></param>
  395. /// <param name="iMakeCode"></param>
  396. /// <param name="iMPKind"></param>
  397. /// <param name="result"></param>
  398. /// <param name="iUserCode"></param>
  399. private void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string result, string iUserCode)
  400. {
  401. string CurrentStep = "";
  402. string LineCode = "";
  403. string CurrentStepName = "";
  404. GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
  405. sql.Length = 0;
  406. sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
  407. sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode,mp_snstatus,mp_sncheckno,mp_snoutboxcode)");
  408. sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,'" + CurrentStep + "','" + CurrentStepName + "',");
  409. sql.Append("ma_craftcode,ma_craftname,'" + iMPKind + "','" + result + "',sysdate,'" + iUserCode + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
  410. sql.Append("ms_status,ms_checkno,ms_outboxcode from make left join makeserial on ms_makecode=ma_code left join step on st_code=ms_stepcode ");
  411. sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and st_code='" + CurrentStep + "'");
  412. ExecuteSql(sql.ToString(), "insert");
  413. }
  414. /// <summary>
  415. /// 保存Mac地址和BT地址
  416. /// </summary>
  417. /// <param name="iSN"></param>
  418. /// <param name="iMac"></param>
  419. /// <param name="iBT"></param>
  420. /// <param name="iCode1"></param>
  421. /// <param name="iCode2"></param>
  422. /// <param name="iCode3"></param>
  423. /// <param name="oErrMessage"></param>
  424. /// <returns></returns>
  425. [Description("写入SN的Wifi,BT信息")]
  426. public bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrMessage)
  427. {
  428. if (iSN == "")
  429. {
  430. oErrMessage = "SN不能为空";
  431. return false;
  432. }
  433. oErrMessage = "";
  434. string[] param = new string[] { iSN, iMac, iBT, iCode1, iCode2, iCode3, oErrMessage };
  435. string[] ParamName = new string[] { "v_i_sncode", "v_i_mac", "v_i_bt", "v_i_code1", "v_i_code2", "v_i_code3", "v_o_errmsg" };
  436. CallProcedure("CS_SETADDRESSINFO", ParamName, ref param);
  437. oErrMessage = param[6];
  438. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  439. return true;
  440. else
  441. return false;
  442. }
  443. [Description("序列号跳到下一 步")]
  444. public bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
  445. {
  446. if (iSN == "")
  447. {
  448. oErrMessage = "SN不能为空";
  449. return false;
  450. }
  451. oErrMessage = "";
  452. string StepCode = getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
  453. string CurrentStep = GetStepCodeBySource(iSourceCode);
  454. string BgCode = getFieldDataByCondition("step", "st_badgroupcode", "st_code='" + CurrentStep + "'").ToString();
  455. switch (iResult)
  456. {
  457. case "OK":
  458. break;
  459. case "NG":
  460. if (iErrCode == "")
  461. {
  462. oErrMessage = "测试结果为NG时必须传递不良代码";
  463. return false;
  464. }
  465. else
  466. {
  467. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
  468. string[] BadCode = iErrCode.Split(',');
  469. sql.Length = 0;
  470. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  471. sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
  472. sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
  473. sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  474. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  475. List<string> InsertSQL = new List<string>();
  476. for (int i = 0; i < BadCode.Length; i++)
  477. {
  478. InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
  479. }
  480. ExecuteSQLTran(InsertSQL.ToArray());
  481. //将不良的序列号的状态码设为3
  482. ExecuteSql("update makeserial set ms_status='3' where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'", "update");
  483. }
  484. break;
  485. default:
  486. oErrMessage = "测试结果必须为NG或者OK";
  487. return false;
  488. }
  489. //不良采集为良品是更新
  490. if (StepCode == CurrentStep && iResult == "OK")
  491. {
  492. DataTable dt = getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_craftcode", "ms_prodcode" }, "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  493. if (dt.Rows.Count > 0)
  494. {
  495. string ms_status = dt.Rows[0]["ms_status"].ToString();
  496. string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  497. string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  498. if (ms_status == "3")
  499. {
  500. string nextstepcode = getFieldDataByCondition("craft left join craftdetail on cr_id=cd_crid ", "cd_nextstepcode", "cr_code='" + ms_craftcode + "' and cr_prodcode='" + ms_prodcode + "' and cd_stepcode='" + CurrentStep + "'").ToString();
  501. UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  502. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "'");
  503. }
  504. }
  505. }
  506. return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
  507. }
  508. /// <summary>
  509. /// 设置测试结果
  510. /// </summary>
  511. /// <param name="iMakeCode"></param>
  512. /// <param name="iSourceCode"></param>
  513. /// <param name="iSN"></param>
  514. /// <param name="iOperater"></param>
  515. /// <param name="iResult"></param>
  516. /// <param name="iUserCode"></param>
  517. /// <param name="oErrorMessage"></param>
  518. /// <returns></returns>
  519. [Description("设置测试结果,结果必须为NG或者OK")]
  520. public bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperater, string iResult, string iErrCode, string flag, out string oErrorMessage)
  521. {
  522. oErrorMessage = "";
  523. if (iTSN == "") { oErrorMessage = "TSN不能为空"; return false; }
  524. if (iSN == "") { oErrorMessage = "SN不能为空"; return false; }
  525. string[] param = new string[] { iTSN, iSN, iSourceCode, iOperater, iResult, iErrCode, oErrorMessage };
  526. string[] ParamName = new string[] { "v_i_tsn", "v_i_sncode", "v_i_sourcecode", "v_i_usercode", "v_i_result", "v_i_errcode", "v_o_errmsg" };
  527. CallProcedure("CS_DLLSNCHANGE", ParamName, ref param);
  528. oErrorMessage = param[6];
  529. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  530. return true;
  531. else
  532. return false;
  533. }
  534. private bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
  535. {
  536. if (iSN == "")
  537. {
  538. oErrMessage = "SN不能为空";
  539. return false;
  540. }
  541. oErrMessage = "";
  542. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
  543. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
  544. CallProcedure("CS_SETSTEPRESULT", ParamName, ref param);
  545. oErrMessage = param[5];
  546. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  547. return true;
  548. else
  549. return false;
  550. }
  551. /// <summary>
  552. /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
  553. /// </summary>
  554. /// <param name="iSN">序列号</param>
  555. /// <param name="iClass"></param>
  556. /// <param name="iSubClass1"></param>
  557. /// <param name="iSubClass2"></param>
  558. /// <param name="iSubClass3"></param>
  559. /// <param name="iMaxValue"></param>
  560. /// <param name="iMinValue"></param>
  561. /// <param name="iActualValue"></param>
  562. /// <param name="iValue1"></param>
  563. /// <param name="iValue2"></param>
  564. /// <param name="iValue3"></param>
  565. /// <param name="iTestResult"></param>
  566. /// <param name="oErrMessage"></param>
  567. /// <returns></returns>
  568. [Description("设置测试结果")]
  569. public bool SetTestDetail(string iSN, string iClass, string iResCode, string[,] iTestDetail, out string oErrMessage)
  570. {
  571. if (iSN == "" || iSN == null)
  572. {
  573. oErrMessage = "SN不能为空";
  574. return false;
  575. }
  576. oErrMessage = "";
  577. string omakeCode = "";
  578. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  579. sql.Clear();
  580. sql.Append("begin ");
  581. bool needBreak = false;
  582. for (int i = 0; i < iTestDetail.Length / 200; i++)
  583. {
  584. string DataField = "Insert into MES_TEST(STD_ID,STD_SN,STD_MAKECODE,STD_CLASS,STD_TESTDATE,";
  585. string ValueField = ")values(MES_TEST_SEQ.nextval,'" + iSN + "','" + omakeCode + "','" + iClass + "',sysdate,";
  586. for (int j = 0; j < 200; j++)
  587. {
  588. if (j == 0)
  589. {
  590. DataField += "STD_ITEMNAME,";
  591. //如果传递的参数没有测试名称则中断插入
  592. if (iTestDetail[i, j] == "" || iTestDetail[i, j] == null)
  593. {
  594. //外层循环也需要中断
  595. needBreak = true;
  596. break;
  597. }
  598. }
  599. else
  600. {
  601. DataField += "STD_ITEM" + j + " ,";
  602. }
  603. ValueField += "'" + iTestDetail[i, j] + "',";
  604. }
  605. if (needBreak)
  606. break;
  607. sql.Append(DataField.Substring(0, DataField.Length - 1) + ValueField.Substring(0, ValueField.Length - 1) + ");");
  608. }
  609. sql.Append("end;");
  610. ExecuteSql(sql.ToString(), "insert");
  611. return true;
  612. }
  613. /// <summary>
  614. /// 作业调用该方法将确认接收SN对应的IMEI及附属信息。
  615. /// </summary>
  616. /// <param name="iSN"></param>
  617. /// <param name="iMO"></param>
  618. /// <param name="iIMEI1"></param>
  619. /// <param name="iIMEI2"></param>
  620. /// <param name="iIMEI3"></param>
  621. /// <param name="iMEID"></param>
  622. /// <param name="iNetCode"></param>
  623. /// <param name="iPSN"></param>
  624. /// <param name="iID1"></param>
  625. /// <param name="iBT"></param>
  626. /// <param name="iID1"></param>
  627. /// <param name="iID2"></param>
  628. /// <param name="iID3"></param>
  629. /// <param name="oErrorMessage"></param>
  630. /// <returns></returns>
  631. [Description("设置IMEI信息")]
  632. public bool SetIMEIInfo(string iSN, string iIMEI1, out string oErrMessage)
  633. {
  634. if (iSN == "")
  635. {
  636. oErrMessage = "SN不能为空";
  637. return false;
  638. }
  639. oErrMessage = "";
  640. string[] param = new string[] { iSN, iIMEI1, "", "", "", "", "", "", "", "", oErrMessage };
  641. string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
  642. CallProcedure("CS_SETIMEIINFO", ParamName, ref param);
  643. oErrMessage = param[10];
  644. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  645. return true;
  646. else
  647. return false;
  648. }
  649. /// <summary>
  650. ///
  651. /// </summary>
  652. /// <param name="iSN"></param>
  653. /// <param name="iResCode"></param>
  654. /// <param name="iOperator"></param>
  655. /// <param name="iResult"></param>
  656. /// <param name="iErrCode"></param>
  657. /// <param name="oErrMessage"></param>
  658. /// <returns></returns>
  659. [Description("设置测试结果")]
  660. public bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage)
  661. {
  662. if (iSN == "")
  663. {
  664. oErrMessage = "SN不能为空";
  665. return false;
  666. }
  667. oErrMessage = "";
  668. string oMakeCode = "";
  669. GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
  670. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  671. return SetStepFinish(oMakeCode, iResCode, iSN, "", iResult, iOperator, iErrCode, out oErrMessage);
  672. else
  673. return false;
  674. }
  675. /// <summary>
  676. /// 序列号归属工单
  677. /// </summary>
  678. /// <param name="iMO"></param>
  679. /// <param name="iSN"></param>
  680. /// <param name="iResCode"></param>
  681. /// <param name="oErrMessage"></param>
  682. /// <returns></returns>
  683. [Description("序列号归属工单")]
  684. public bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage)
  685. {
  686. if (iSN == "")
  687. {
  688. oErrMessage = "SN不能为空";
  689. return false;
  690. }
  691. oErrMessage = "";
  692. string[] param = new string[] { iMO, iResCode, iSN, "", "", "", oErrMessage };
  693. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
  694. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  695. oErrMessage = param[6];
  696. DataTable dt = (DataTable)ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=(select max(ms_id) from makeserial where ms_sncode='" + iSN + "')", "select");
  697. string ms_status = "";
  698. string ms_stepcode = "";
  699. string ms_nextstepcode = "";
  700. if (dt.Rows.Count > 0)
  701. {
  702. ms_status = dt.Rows[0]["ms_status"].ToString();
  703. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  704. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  705. }
  706. string stepcode = GetStepCodeBySource(iResCode);
  707. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && ms_stepcode == stepcode))
  708. {
  709. if (ms_status == "3")
  710. {
  711. oErrMessage = "";
  712. }
  713. return true;
  714. }
  715. else
  716. return false;
  717. }
  718. /// <summary>
  719. /// 获取执行步骤代码,名称和线别
  720. /// </summary>
  721. /// <param name="Source"></param>
  722. /// <param name="StepCode"></param>
  723. /// <param name="StepName"></param>
  724. /// <param name="LineCode"></param>
  725. private void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
  726. {
  727. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  728. if (dt.Rows.Count > 0)
  729. {
  730. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  731. StepName = dt.Rows[0]["sc_stepname"].ToString();
  732. LineCode = dt.Rows[0]["sc_linecode"].ToString();
  733. }
  734. }
  735. /// <summary>
  736. /// 获取步骤代码和名称
  737. /// </summary>
  738. /// <param name="Source"></param>
  739. /// <param name="StepCode"></param>
  740. /// <param name="StepName"></param>
  741. private void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  742. {
  743. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  744. if (dt.Rows.Count > 0)
  745. {
  746. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  747. StepName = dt.Rows[0]["sc_stepname"].ToString();
  748. }
  749. }
  750. /// <summary>
  751. /// 获取步骤代码
  752. /// </summary>
  753. /// <param name="Source"></param>
  754. /// <returns></returns>
  755. private string GetStepCodeBySource(string Source)
  756. {
  757. return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  758. }
  759. /// <summary>
  760. /// 获取第一行第一列的信息
  761. /// </summary>
  762. private object getFieldDataByCondition(string TableName, string Field, string Condition)
  763. {
  764. DataTable dt = new DataTable();
  765. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  766. command = new OracleCommand(sql, connection);
  767. Reconnect(command);
  768. OracleDataAdapter ad = new OracleDataAdapter();
  769. ad.SelectCommand = command;
  770. try
  771. {
  772. ad.Fill(dt);
  773. }
  774. catch (Exception)
  775. {
  776. connection = new OracleConnection(ConnectionStrings);
  777. connection.Open();
  778. command = new OracleCommand(sql, connection);
  779. ad = new OracleDataAdapter();
  780. ad.SelectCommand = command;
  781. ad.Fill(dt);
  782. }
  783. ad.Dispose();
  784. command.Dispose();
  785. if (dt.Rows.Count > 0)
  786. {
  787. return dt.Rows[0][0];
  788. }
  789. else
  790. {
  791. return "";
  792. }
  793. }
  794. /// <summary>
  795. /// 通过表名和获取单行的记录
  796. /// </summary>
  797. private DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  798. {
  799. DataTable dt = new DataTable();
  800. string sql = "select ";
  801. sql += AddField(Fields);
  802. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  803. command = new OracleCommand(sql, connection);
  804. Reconnect(command);
  805. OracleDataAdapter ad = new OracleDataAdapter(command);
  806. try
  807. {
  808. ad.Fill(dt);
  809. }
  810. catch (Exception)
  811. {
  812. connection = new OracleConnection(ConnectionStrings);
  813. connection.Open();
  814. command = new OracleCommand(sql, connection);
  815. ad = new OracleDataAdapter();
  816. ad.SelectCommand = command;
  817. ad.Fill(dt);
  818. }
  819. ad.Dispose();
  820. command.Dispose();
  821. return dt;
  822. }
  823. /// <summary>
  824. /// 通过表名,字段和条件获取DataTable类型的数据
  825. /// </summary>
  826. private DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  827. {
  828. DataTable dt = new DataTable();
  829. string sql = "select ";
  830. sql += AddField(Fields);
  831. sql += " from " + TableName + " where " + Condition;
  832. command = new OracleCommand(sql, connection);
  833. Reconnect(command);
  834. OracleDataAdapter ad = new OracleDataAdapter(command);
  835. try
  836. {
  837. ad.Fill(dt);
  838. }
  839. catch (Exception)
  840. {
  841. connection = new OracleConnection(ConnectionStrings);
  842. connection.Open();
  843. command = new OracleCommand(sql, connection);
  844. ad = new OracleDataAdapter();
  845. ad.SelectCommand = command;
  846. ad.Fill(dt);
  847. }
  848. ad.Dispose();
  849. command.Dispose();
  850. return dt;
  851. }
  852. /// <summary>
  853. /// 通过表名,字段获取DataTable类型的数据
  854. /// </summary>
  855. private DataTable getFieldsDatas(string TableName, string Fields)
  856. {
  857. DataTable dt = new DataTable();
  858. string sql = "select ";
  859. sql += Fields;
  860. sql += " from " + TableName;
  861. command = new OracleCommand(sql, connection);
  862. Reconnect(command);
  863. OracleDataAdapter ad = new OracleDataAdapter(command);
  864. ad.SelectCommand = command;
  865. try
  866. {
  867. ad.Fill(dt);
  868. }
  869. catch (Exception)
  870. {
  871. connection = new OracleConnection(ConnectionStrings);
  872. connection.Open();
  873. command = new OracleCommand(sql, connection);
  874. ad = new OracleDataAdapter();
  875. ad.SelectCommand = command;
  876. ad.Fill(dt);
  877. }
  878. ad.Dispose();
  879. command.Dispose();
  880. return dt;
  881. }
  882. /// <summary>
  883. /// 检测内容是否存在
  884. /// </summary>
  885. /// <param name="TableName"></param>
  886. /// <param name="Condition"></param>
  887. /// <returns></returns>
  888. private bool CheckExist(string TableName, string Condition)
  889. {
  890. string sql = "select count(1) from " + TableName + " where " + Condition;
  891. command = new OracleCommand(sql, connection);
  892. Reconnect(command);
  893. OracleDataAdapter ad = new OracleDataAdapter(command);
  894. DataTable dt = new DataTable();
  895. ad.Fill(dt);
  896. ad.Dispose();
  897. command.Dispose();
  898. return int.Parse(dt.Rows[0][0].ToString()) > 0;
  899. }
  900. /// <summary>
  901. /// 直接执行SQL,同时传入SQL的类型
  902. /// </summary>
  903. /// <param name="SQL"></param>
  904. /// <param name="Type"></param>
  905. /// <returns></returns>
  906. private object ExecuteSql(string SQL, string Type, params object[] names)
  907. {
  908. object result = null;
  909. command = new OracleCommand(SQL, connection);
  910. Reconnect(command);
  911. //用来拼接参数的
  912. if (names.Length > 0)
  913. {
  914. string[] par = SQL.Split(':');
  915. //用来存参数的数组
  916. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  917. for (int i = 0; i < par.Length - 1; i++)
  918. {
  919. //新建一个char类型的数组用来存储每个字节的变量
  920. char[] c = par[i + 1].ToCharArray();
  921. addpar[i] = new StringBuilder();
  922. for (int j = 0; j < c.Length; j++)
  923. {
  924. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  925. {
  926. addpar[i].Append(c[j]);
  927. }
  928. else
  929. {
  930. break;
  931. }
  932. }
  933. }
  934. for (int i = 0; i < addpar.Length; i++)
  935. {
  936. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
  937. }
  938. }
  939. switch (Type.ToUpper())
  940. {
  941. case "SELECT":
  942. OracleDataAdapter ad = new OracleDataAdapter(command);
  943. result = new DataTable();
  944. try
  945. {
  946. ad.Fill((DataTable)result);
  947. }
  948. catch (Exception)
  949. {
  950. connection = new OracleConnection(ConnectionStrings);
  951. connection.Open();
  952. command = new OracleCommand(SQL, connection);
  953. ad = new OracleDataAdapter();
  954. ad.SelectCommand = command;
  955. ad.Fill((DataTable)result);
  956. }
  957. break;
  958. case "DELETE":
  959. try
  960. {
  961. result = command.ExecuteNonQuery();
  962. }
  963. catch (Exception)
  964. {
  965. command.Connection = new OracleConnection(ConnectionStrings);
  966. command.Connection.Open();
  967. result = command.ExecuteNonQuery();
  968. }
  969. break;
  970. case "UPDATE":
  971. try
  972. {
  973. result = command.ExecuteNonQuery();
  974. }
  975. catch (Exception)
  976. {
  977. command.Connection = new OracleConnection(ConnectionStrings);
  978. command.Connection.Open();
  979. result = command.ExecuteNonQuery();
  980. }
  981. break;
  982. case "INSERT":
  983. try
  984. {
  985. result = command.ExecuteNonQuery();
  986. }
  987. catch (Exception)
  988. {
  989. command.Connection = new OracleConnection(ConnectionStrings);
  990. command.Connection.Open();
  991. result = command.ExecuteNonQuery();
  992. }
  993. break;
  994. }
  995. command.Dispose();
  996. return result;
  997. }
  998. /// <summary>
  999. /// 出现异常进行回滚的执行方法
  1000. /// </summary>
  1001. /// <param name="SQL"></param>
  1002. private void ExecuteSQLTran(params string[] SQL)
  1003. {
  1004. command = new OracleCommand();
  1005. command.Connection = new OracleConnection(ConnectionStrings);
  1006. command.Connection.Open();
  1007. Reconnect(command);
  1008. OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
  1009. command.Transaction = tx;
  1010. try
  1011. {
  1012. foreach (string sql in SQL)
  1013. {
  1014. if (!string.IsNullOrEmpty(sql))
  1015. {
  1016. command.CommandText = sql;
  1017. command.ExecuteNonQuery();
  1018. }
  1019. }
  1020. tx.Commit();
  1021. }
  1022. catch (OracleException E)
  1023. {
  1024. tx.Rollback();
  1025. throw new Exception(E.Message);
  1026. }
  1027. command.Dispose();
  1028. }
  1029. private string UpdateByCondition(string TableName, string update, string condition)
  1030. {
  1031. string sql = "update " + TableName + " set " + update + " where " + condition;
  1032. command = new OracleCommand(sql, connection);
  1033. Reconnect(command);
  1034. try
  1035. {
  1036. command.ExecuteNonQuery();
  1037. }
  1038. catch (Exception)
  1039. {
  1040. command.Connection = new OracleConnection(ConnectionStrings);
  1041. command.Connection.Open();
  1042. command.ExecuteNonQuery();
  1043. }
  1044. command.Dispose();
  1045. return sql;
  1046. }
  1047. private void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
  1048. {
  1049. command = new OracleCommand(ProcedureName);
  1050. command.Connection = connection;
  1051. Reconnect(command);
  1052. command.CommandText = ProcedureName;
  1053. command.CommandType = CommandType.StoredProcedure;
  1054. for (int i = 0; i < param.Length; i++)
  1055. {
  1056. command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1057. //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
  1058. }
  1059. try
  1060. {
  1061. command.ExecuteNonQuery();
  1062. }
  1063. catch (Exception)
  1064. {
  1065. command.Connection = new OracleConnection(ConnectionStrings);
  1066. command.Connection.Open();
  1067. command.ExecuteNonQuery();
  1068. }
  1069. for (int i = 0; i < command.Parameters.Count; i++)
  1070. param[i] = command.Parameters[i].Value.ToString();
  1071. command.Dispose();
  1072. }
  1073. private string AddField(string[] Fields)
  1074. {
  1075. string sql = " ";
  1076. foreach (string field in Fields)
  1077. {
  1078. sql += field + ",";
  1079. }
  1080. return sql.Substring(0, sql.Length - 1);
  1081. }
  1082. private string[] GetField(string field)
  1083. {
  1084. string[] fields = field.Split(',');
  1085. for (int i = 0; i < fields.Length; i++)
  1086. {
  1087. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1088. }
  1089. return fields;
  1090. }
  1091. private void Reconnect(OracleCommand cmd)
  1092. {
  1093. if (cmd.Connection.State == ConnectionState.Closed)
  1094. {
  1095. cmd.Connection.Open();
  1096. }
  1097. }
  1098. }
  1099. }