MesHelper.cs 50 KB

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