MesHelper.cs 52 KB

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