MesHelper.cs 49 KB

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