MesHelper.cs 51 KB

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