MesHelper.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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=10.8.0.34/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 Code16 = "";
  392. string Code17 = "";
  393. string Code18 = "";
  394. string Code19 = "";
  395. string Code20 = "";
  396. string Code21 = "";
  397. string Code22 = "";
  398. string Code23 = "";
  399. string Code24 = "";
  400. string Code25 = "";
  401. string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15, Code16, Code17, Code18, Code19, Code20, Code21, Code22, Code23, Code24, Code25 };
  402. 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", "v_i_code16", "v_i_code17", "v_i_code18", "v_i_code19", "v_i_code20", "v_i_code21", "v_i_code22", "v_i_code23", "v_i_code24", "v_i_code25" };
  403. CallProcedure("GetMobileAllInfo_NEW", ParamName, ref param);
  404. for (int i = 1; i < param.Length; i++)
  405. {
  406. //获取出来的参数使用^分割
  407. if (param[i] != "" && param[i] != "null" && param[i] != null)
  408. {
  409. oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
  410. }
  411. }
  412. oJson = jss.Serialize(oInfo);
  413. oErrMessage = "";
  414. return true;
  415. }
  416. else
  417. {
  418. oErrMessage = "序列号" + iSN + "不存在";
  419. return false;
  420. }
  421. }
  422. else
  423. {
  424. oErrMessage = "序列号" + iSN + "不存在";
  425. return false;
  426. }
  427. }
  428. /// <summary>
  429. /// 记录操作日志
  430. /// </summary>
  431. /// <param name="iSnCode"></param>
  432. /// <param name="iMakeCode"></param>
  433. /// <param name="iMPKind"></param>
  434. /// <param name="result"></param>
  435. /// <param name="iUserCode"></param>
  436. private void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string result, string iUserCode)
  437. {
  438. string CurrentStep = "";
  439. string LineCode = "";
  440. string CurrentStepName = "";
  441. GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
  442. sql.Length = 0;
  443. sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
  444. 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)");
  445. sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,'" + CurrentStep + "','" + CurrentStepName + "',");
  446. sql.Append("ma_craftcode,ma_craftname,'" + iMPKind + "','" + result + "',sysdate,'" + iUserCode + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
  447. 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 ");
  448. sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and st_code='" + CurrentStep + "'");
  449. ExecuteSql(sql.ToString(), "insert");
  450. }
  451. /// <summary>
  452. /// 保存Mac地址和BT地址
  453. /// </summary>
  454. /// <param name="iSN"></param>
  455. /// <param name="iMac"></param>
  456. /// <param name="iBT"></param>
  457. /// <param name="iCode1"></param>
  458. /// <param name="iCode2"></param>
  459. /// <param name="iCode3"></param>
  460. /// <param name="oErrMessage"></param>
  461. /// <returns></returns>
  462. [Description("写入SN的Wifi,BT信息")]
  463. public bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrMessage)
  464. {
  465. if (iSN == "")
  466. {
  467. oErrMessage = "SN不能为空";
  468. return false;
  469. }
  470. oErrMessage = "";
  471. string[] param = new string[] { iSN, iMac, iBT, iCode1, iCode2, iCode3, oErrMessage };
  472. 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" };
  473. CallProcedure("CS_SETADDRESSINFO", ParamName, ref param);
  474. oErrMessage = param[6];
  475. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  476. return true;
  477. else
  478. return false;
  479. }
  480. [Description("序列号跳到下一 步")]
  481. public bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
  482. {
  483. if (iSN == "")
  484. {
  485. oErrMessage = "SN不能为空";
  486. return false;
  487. }
  488. oErrMessage = "";
  489. string StepCode = getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
  490. string CurrentStep = GetStepCodeBySource(iSourceCode);
  491. string BgCode = getFieldDataByCondition("step", "st_badgroupcode", "st_code='" + CurrentStep + "'").ToString();
  492. switch (iResult)
  493. {
  494. case "OK":
  495. break;
  496. case "NG":
  497. if (iErrCode == "")
  498. {
  499. oErrMessage = "测试结果为NG时必须传递不良代码";
  500. return false;
  501. }
  502. else
  503. {
  504. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
  505. string[] BadCode = iErrCode.Split(',');
  506. sql.Length = 0;
  507. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  508. sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
  509. sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
  510. sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  511. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  512. List<string> InsertSQL = new List<string>();
  513. for (int i = 0; i < BadCode.Length; i++)
  514. {
  515. InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
  516. }
  517. ExecuteSQLTran(InsertSQL.ToArray());
  518. //将不良的序列号的状态码设为3
  519. ExecuteSql("update makeserial set ms_status='3' where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'", "update");
  520. }
  521. break;
  522. default:
  523. oErrMessage = "测试结果必须为NG或者OK";
  524. return false;
  525. }
  526. //不良采集为良品是更新
  527. if (StepCode == CurrentStep && iResult == "OK")
  528. {
  529. DataTable dt = getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_craftcode", "ms_prodcode" }, "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  530. if (dt.Rows.Count > 0)
  531. {
  532. string ms_status = dt.Rows[0]["ms_status"].ToString();
  533. string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  534. string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  535. if (ms_status == "3")
  536. {
  537. 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();
  538. UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  539. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "'");
  540. }
  541. }
  542. }
  543. return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
  544. }
  545. /// <summary>
  546. /// 设置测试结果
  547. /// </summary>
  548. /// <param name="iMakeCode"></param>
  549. /// <param name="iSourceCode"></param>
  550. /// <param name="iSN"></param>
  551. /// <param name="iOperater"></param>
  552. /// <param name="iResult"></param>
  553. /// <param name="iUserCode"></param>
  554. /// <param name="oErrorMessage"></param>
  555. /// <returns></returns>
  556. [Description("设置测试结果,结果必须为NG或者OK")]
  557. public bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperater, string iResult, string iErrCode, string flag, out string oErrorMessage)
  558. {
  559. oErrorMessage = "";
  560. if (iTSN == "") { oErrorMessage = "TSN不能为空"; return false; }
  561. if (iSN == "") { oErrorMessage = "SN不能为空"; return false; }
  562. string[] param = new string[] { iTSN, iSN, iSourceCode, iOperater, iResult, iErrCode, oErrorMessage };
  563. 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" };
  564. CallProcedure("CS_DLLSNCHANGE", ParamName, ref param);
  565. oErrorMessage = param[6];
  566. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  567. return true;
  568. else
  569. return false;
  570. }
  571. private bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
  572. {
  573. if (iSN == "")
  574. {
  575. oErrMessage = "SN不能为空";
  576. return false;
  577. }
  578. oErrMessage = "";
  579. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
  580. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
  581. CallProcedure("CS_SETSTEPRESULT", ParamName, ref param);
  582. oErrMessage = param[5];
  583. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  584. return true;
  585. else
  586. return false;
  587. }
  588. /// <summary>
  589. /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
  590. /// </summary>
  591. /// <param name="iSN">序列号</param>
  592. /// <param name="iClass"></param>
  593. /// <param name="iSubClass1"></param>
  594. /// <param name="iSubClass2"></param>
  595. /// <param name="iSubClass3"></param>
  596. /// <param name="iMaxValue"></param>
  597. /// <param name="iMinValue"></param>
  598. /// <param name="iActualValue"></param>
  599. /// <param name="iValue1"></param>
  600. /// <param name="iValue2"></param>
  601. /// <param name="iValue3"></param>
  602. /// <param name="iTestResult"></param>
  603. /// <param name="oErrMessage"></param>
  604. /// <returns></returns>
  605. [Description("设置测试结果")]
  606. public bool SetTestDetail(string iSN, string iClass, string iResCode, string[,] iTestDetail, out string oErrMessage)
  607. {
  608. if (iSN == "" || iSN == null)
  609. {
  610. oErrMessage = "SN不能为空";
  611. return false;
  612. }
  613. oErrMessage = "";
  614. string omakeCode = "";
  615. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  616. sql.Clear();
  617. sql.Append("begin ");
  618. bool needBreak = false;
  619. for (int i = 0; i < iTestDetail.Length / 200; i++)
  620. {
  621. string DataField = "Insert into MES_TEST(STD_ID,STD_SN,STD_MAKECODE,STD_CLASS,STD_TESTDATE,";
  622. string ValueField = ")values(MES_TEST_SEQ.nextval,'" + iSN + "','" + omakeCode + "','" + iClass + "',sysdate,";
  623. for (int j = 0; j < 200; j++)
  624. {
  625. if (j == 0)
  626. {
  627. DataField += "STD_ITEMNAME,";
  628. //如果传递的参数没有测试名称则中断插入
  629. if (iTestDetail[i, j] == "" || iTestDetail[i, j] == null)
  630. {
  631. //外层循环也需要中断
  632. needBreak = true;
  633. break;
  634. }
  635. }
  636. else
  637. {
  638. DataField += "STD_ITEM" + j + " ,";
  639. }
  640. ValueField += "'" + iTestDetail[i, j] + "',";
  641. }
  642. if (needBreak)
  643. break;
  644. sql.Append(DataField.Substring(0, DataField.Length - 1) + ValueField.Substring(0, ValueField.Length - 1) + ");");
  645. }
  646. sql.Append("end;");
  647. ExecuteSql(sql.ToString(), "insert");
  648. return true;
  649. }
  650. /// <summary>
  651. /// 作业调用该方法将确认接收SN对应的IMEI及附属信息。
  652. /// </summary>
  653. /// <param name="iSN"></param>
  654. /// <param name="iMO"></param>
  655. /// <param name="iIMEI1"></param>
  656. /// <param name="iIMEI2"></param>
  657. /// <param name="iIMEI3"></param>
  658. /// <param name="iMEID"></param>
  659. /// <param name="iNetCode"></param>
  660. /// <param name="iPSN"></param>
  661. /// <param name="iID1"></param>
  662. /// <param name="iBT"></param>
  663. /// <param name="iID1"></param>
  664. /// <param name="iID2"></param>
  665. /// <param name="iID3"></param>
  666. /// <param name="oErrorMessage"></param>
  667. /// <returns></returns>
  668. [Description("设置IMEI信息")]
  669. public bool SetIMEIInfo(string iSN, string iIMEI1, out string oErrMessage)
  670. {
  671. if (iSN == "")
  672. {
  673. oErrMessage = "SN不能为空";
  674. return false;
  675. }
  676. oErrMessage = "";
  677. string[] param = new string[] { iSN, iIMEI1, "", "", "", "", "", "", "", "", oErrMessage };
  678. 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" };
  679. CallProcedure("CS_SETIMEIINFO", ParamName, ref param);
  680. oErrMessage = param[10];
  681. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  682. return true;
  683. else
  684. return false;
  685. }
  686. /// <summary>
  687. ///
  688. /// </summary>
  689. /// <param name="iSN"></param>
  690. /// <param name="iResCode"></param>
  691. /// <param name="iOperator"></param>
  692. /// <param name="iResult"></param>
  693. /// <param name="iErrCode"></param>
  694. /// <param name="oErrMessage"></param>
  695. /// <returns></returns>
  696. [Description("设置测试结果")]
  697. public bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage)
  698. {
  699. if (iSN == "")
  700. {
  701. oErrMessage = "SN不能为空";
  702. return false;
  703. }
  704. oErrMessage = "";
  705. string oMakeCode = "";
  706. GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
  707. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  708. return SetStepFinish(oMakeCode, iResCode, iSN, "", iResult, iOperator, iErrCode, out oErrMessage);
  709. else
  710. return false;
  711. }
  712. /// <summary>
  713. /// 序列号归属工单
  714. /// </summary>
  715. /// <param name="iMO"></param>
  716. /// <param name="iSN"></param>
  717. /// <param name="iResCode"></param>
  718. /// <param name="oErrMessage"></param>
  719. /// <returns></returns>
  720. [Description("序列号归属工单")]
  721. public bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage)
  722. {
  723. if (iSN == "")
  724. {
  725. oErrMessage = "SN不能为空";
  726. return false;
  727. }
  728. oErrMessage = "";
  729. string[] param = new string[] { iMO, iResCode, iSN, "", "", "", oErrMessage };
  730. 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" };
  731. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  732. oErrMessage = param[6];
  733. 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");
  734. string ms_status = "";
  735. string ms_stepcode = "";
  736. string ms_nextstepcode = "";
  737. if (dt.Rows.Count > 0)
  738. {
  739. ms_status = dt.Rows[0]["ms_status"].ToString();
  740. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  741. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  742. }
  743. string stepcode = GetStepCodeBySource(iResCode);
  744. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && ms_stepcode == stepcode))
  745. {
  746. if (ms_status == "3")
  747. {
  748. oErrMessage = "";
  749. }
  750. return true;
  751. }
  752. else
  753. return false;
  754. }
  755. /// <summary>
  756. /// 获取执行步骤代码,名称和线别
  757. /// </summary>
  758. /// <param name="Source"></param>
  759. /// <param name="StepCode"></param>
  760. /// <param name="StepName"></param>
  761. /// <param name="LineCode"></param>
  762. private void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
  763. {
  764. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  765. if (dt.Rows.Count > 0)
  766. {
  767. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  768. StepName = dt.Rows[0]["sc_stepname"].ToString();
  769. LineCode = dt.Rows[0]["sc_linecode"].ToString();
  770. }
  771. }
  772. /// <summary>
  773. /// 获取步骤代码和名称
  774. /// </summary>
  775. /// <param name="Source"></param>
  776. /// <param name="StepCode"></param>
  777. /// <param name="StepName"></param>
  778. private void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  779. {
  780. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  781. if (dt.Rows.Count > 0)
  782. {
  783. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  784. StepName = dt.Rows[0]["sc_stepname"].ToString();
  785. }
  786. }
  787. /// <summary>
  788. /// 获取步骤代码
  789. /// </summary>
  790. /// <param name="Source"></param>
  791. /// <returns></returns>
  792. private string GetStepCodeBySource(string Source)
  793. {
  794. return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  795. }
  796. /// <summary>
  797. /// 获取步骤代码
  798. /// </summary>
  799. /// <param name="Source"></param>
  800. /// <returns></returns>
  801. private string GetStepName(string st_code)
  802. {
  803. return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
  804. }
  805. /// <summary>
  806. /// 获取第一行第一列的信息
  807. /// </summary>
  808. private object getFieldDataByCondition(string TableName, string Field, string Condition)
  809. {
  810. DataTable dt = new DataTable();
  811. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  812. command = new OracleCommand(sql, connection);
  813. Reconnect(command);
  814. OracleDataAdapter ad = new OracleDataAdapter();
  815. ad.SelectCommand = command;
  816. try
  817. {
  818. ad.Fill(dt);
  819. }
  820. catch (Exception)
  821. {
  822. connection = new OracleConnection(ConnectionStrings);
  823. connection.Open();
  824. command = new OracleCommand(sql, connection);
  825. ad = new OracleDataAdapter();
  826. ad.SelectCommand = command;
  827. ad.Fill(dt);
  828. }
  829. ad.Dispose();
  830. command.Dispose();
  831. if (dt.Rows.Count > 0)
  832. {
  833. return dt.Rows[0][0];
  834. }
  835. else
  836. {
  837. return "";
  838. }
  839. }
  840. /// <summary>
  841. /// 通过表名和获取单行的记录
  842. /// </summary>
  843. private DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  844. {
  845. DataTable dt = new DataTable();
  846. string sql = "select ";
  847. sql += AddField(Fields);
  848. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  849. command = new OracleCommand(sql, connection);
  850. Reconnect(command);
  851. OracleDataAdapter ad = new OracleDataAdapter(command);
  852. try
  853. {
  854. ad.Fill(dt);
  855. }
  856. catch (Exception)
  857. {
  858. connection = new OracleConnection(ConnectionStrings);
  859. connection.Open();
  860. command = new OracleCommand(sql, connection);
  861. ad = new OracleDataAdapter();
  862. ad.SelectCommand = command;
  863. ad.Fill(dt);
  864. }
  865. ad.Dispose();
  866. command.Dispose();
  867. return dt;
  868. }
  869. /// <summary>
  870. /// 通过表名,字段和条件获取DataTable类型的数据
  871. /// </summary>
  872. private DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  873. {
  874. DataTable dt = new DataTable();
  875. string sql = "select ";
  876. sql += AddField(Fields);
  877. sql += " from " + TableName + " where " + Condition;
  878. command = new OracleCommand(sql, connection);
  879. Reconnect(command);
  880. OracleDataAdapter ad = new OracleDataAdapter(command);
  881. try
  882. {
  883. ad.Fill(dt);
  884. }
  885. catch (Exception)
  886. {
  887. connection = new OracleConnection(ConnectionStrings);
  888. connection.Open();
  889. command = new OracleCommand(sql, connection);
  890. ad = new OracleDataAdapter();
  891. ad.SelectCommand = command;
  892. ad.Fill(dt);
  893. }
  894. ad.Dispose();
  895. command.Dispose();
  896. return dt;
  897. }
  898. /// <summary>
  899. /// 通过表名,字段获取DataTable类型的数据
  900. /// </summary>
  901. private DataTable getFieldsDatas(string TableName, string Fields)
  902. {
  903. DataTable dt = new DataTable();
  904. string sql = "select ";
  905. sql += Fields;
  906. sql += " from " + TableName;
  907. command = new OracleCommand(sql, connection);
  908. Reconnect(command);
  909. OracleDataAdapter ad = new OracleDataAdapter(command);
  910. ad.SelectCommand = command;
  911. try
  912. {
  913. ad.Fill(dt);
  914. }
  915. catch (Exception)
  916. {
  917. connection = new OracleConnection(ConnectionStrings);
  918. connection.Open();
  919. command = new OracleCommand(sql, connection);
  920. ad = new OracleDataAdapter();
  921. ad.SelectCommand = command;
  922. ad.Fill(dt);
  923. }
  924. ad.Dispose();
  925. command.Dispose();
  926. return dt;
  927. }
  928. /// <summary>
  929. /// 检测内容是否存在
  930. /// </summary>
  931. /// <param name="TableName"></param>
  932. /// <param name="Condition"></param>
  933. /// <returns></returns>
  934. private bool CheckExist(string TableName, string Condition)
  935. {
  936. string sql = "select count(1) from " + TableName + " where " + Condition;
  937. command = new OracleCommand(sql, connection);
  938. Reconnect(command);
  939. OracleDataAdapter ad = new OracleDataAdapter(command);
  940. DataTable dt = new DataTable();
  941. ad.Fill(dt);
  942. ad.Dispose();
  943. command.Dispose();
  944. return int.Parse(dt.Rows[0][0].ToString()) > 0;
  945. }
  946. /// <summary>
  947. /// 直接执行SQL,同时传入SQL的类型
  948. /// </summary>
  949. /// <param name="SQL"></param>
  950. /// <param name="Type"></param>
  951. /// <returns></returns>
  952. private object ExecuteSql(string SQL, string Type, params object[] names)
  953. {
  954. object result = null;
  955. command = new OracleCommand(SQL, connection);
  956. Reconnect(command);
  957. //用来拼接参数的
  958. if (names.Length > 0)
  959. {
  960. string[] par = SQL.Split(':');
  961. //用来存参数的数组
  962. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  963. for (int i = 0; i < par.Length - 1; i++)
  964. {
  965. //新建一个char类型的数组用来存储每个字节的变量
  966. char[] c = par[i + 1].ToCharArray();
  967. addpar[i] = new StringBuilder();
  968. for (int j = 0; j < c.Length; j++)
  969. {
  970. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  971. {
  972. addpar[i].Append(c[j]);
  973. }
  974. else
  975. {
  976. break;
  977. }
  978. }
  979. }
  980. for (int i = 0; i < addpar.Length; i++)
  981. {
  982. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
  983. }
  984. }
  985. switch (Type.ToUpper())
  986. {
  987. case "SELECT":
  988. OracleDataAdapter ad = new OracleDataAdapter(command);
  989. result = new DataTable();
  990. try
  991. {
  992. ad.Fill((DataTable)result);
  993. }
  994. catch (Exception)
  995. {
  996. connection = new OracleConnection(ConnectionStrings);
  997. connection.Open();
  998. command = new OracleCommand(SQL, connection);
  999. ad = new OracleDataAdapter();
  1000. ad.SelectCommand = command;
  1001. ad.Fill((DataTable)result);
  1002. }
  1003. break;
  1004. case "DELETE":
  1005. try
  1006. {
  1007. result = command.ExecuteNonQuery();
  1008. }
  1009. catch (Exception)
  1010. {
  1011. command.Connection = new OracleConnection(ConnectionStrings);
  1012. command.Connection.Open();
  1013. result = command.ExecuteNonQuery();
  1014. }
  1015. break;
  1016. case "UPDATE":
  1017. try
  1018. {
  1019. result = command.ExecuteNonQuery();
  1020. }
  1021. catch (Exception)
  1022. {
  1023. command.Connection = new OracleConnection(ConnectionStrings);
  1024. command.Connection.Open();
  1025. result = command.ExecuteNonQuery();
  1026. }
  1027. break;
  1028. case "INSERT":
  1029. try
  1030. {
  1031. result = command.ExecuteNonQuery();
  1032. }
  1033. catch (Exception)
  1034. {
  1035. command.Connection = new OracleConnection(ConnectionStrings);
  1036. command.Connection.Open();
  1037. result = command.ExecuteNonQuery();
  1038. }
  1039. break;
  1040. }
  1041. command.Dispose();
  1042. return result;
  1043. }
  1044. /// <summary>
  1045. /// 出现异常进行回滚的执行方法
  1046. /// </summary>
  1047. /// <param name="SQL"></param>
  1048. private void ExecuteSQLTran(params string[] SQL)
  1049. {
  1050. command = new OracleCommand();
  1051. command.Connection = new OracleConnection(ConnectionStrings);
  1052. command.Connection.Open();
  1053. Reconnect(command);
  1054. OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
  1055. command.Transaction = tx;
  1056. try
  1057. {
  1058. foreach (string sql in SQL)
  1059. {
  1060. if (!string.IsNullOrEmpty(sql))
  1061. {
  1062. command.CommandText = sql;
  1063. command.ExecuteNonQuery();
  1064. }
  1065. }
  1066. tx.Commit();
  1067. }
  1068. catch (OracleException E)
  1069. {
  1070. tx.Rollback();
  1071. throw new Exception(E.Message);
  1072. }
  1073. command.Dispose();
  1074. }
  1075. private string UpdateByCondition(string TableName, string update, string condition)
  1076. {
  1077. string sql = "update " + TableName + " set " + update + " where " + condition;
  1078. command = new OracleCommand(sql, connection);
  1079. Reconnect(command);
  1080. try
  1081. {
  1082. command.ExecuteNonQuery();
  1083. }
  1084. catch (Exception)
  1085. {
  1086. command.Connection = new OracleConnection(ConnectionStrings);
  1087. command.Connection.Open();
  1088. command.ExecuteNonQuery();
  1089. }
  1090. command.Dispose();
  1091. return sql;
  1092. }
  1093. private void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
  1094. {
  1095. command = new OracleCommand(ProcedureName);
  1096. command.Connection = connection;
  1097. Reconnect(command);
  1098. command.CommandText = ProcedureName;
  1099. command.CommandType = CommandType.StoredProcedure;
  1100. for (int i = 0; i < param.Length; i++)
  1101. {
  1102. command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1103. //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
  1104. }
  1105. try
  1106. {
  1107. command.ExecuteNonQuery();
  1108. }
  1109. catch (Exception)
  1110. {
  1111. command.Connection = new OracleConnection(ConnectionStrings);
  1112. command.Connection.Open();
  1113. command.ExecuteNonQuery();
  1114. }
  1115. for (int i = 0; i < command.Parameters.Count; i++)
  1116. param[i] = command.Parameters[i].Value.ToString();
  1117. command.Dispose();
  1118. }
  1119. private string AddField(string[] Fields)
  1120. {
  1121. string sql = " ";
  1122. foreach (string field in Fields)
  1123. {
  1124. sql += field + ",";
  1125. }
  1126. return sql.Substring(0, sql.Length - 1);
  1127. }
  1128. private string[] GetField(string field)
  1129. {
  1130. string[] fields = field.Split(',');
  1131. for (int i = 0; i < fields.Length; i++)
  1132. {
  1133. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1134. }
  1135. return fields;
  1136. }
  1137. private void Reconnect(OracleCommand cmd)
  1138. {
  1139. if (cmd.Connection.State == ConnectionState.Closed)
  1140. {
  1141. cmd.Connection.Open();
  1142. }
  1143. }
  1144. }
  1145. }