MesHelper.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. using Oracle.ManagedDataAccess.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.IO;
  7. using System.Net;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Web.Script.Serialization;
  12. namespace UMESDLLService
  13. {
  14. [Guid("974DEAD2-9D4C-4728-87EA-2407752E300F")]
  15. [InterfaceType(ComInterfaceType.InterfaceIsDual)]
  16. public interface IMESHelper
  17. {
  18. [DispId(12)]
  19. bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage);
  20. bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
  21. bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
  22. bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage);
  23. bool SetAddressInfo(string iSN, string iMac, string iBT, string iNetCard, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
  24. bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[,] iTestDetail, out string oErrMessage);
  25. bool GetMEIOrNetCodeRange(string iSnCode, string iIMEI1, string iNetCode, out string oInfo, out string oErrMessage);
  26. bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iIMEI4, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage);
  27. bool GetMobileAllInfo(string iSnCode, out string oInfo, out string oErrorMessage);
  28. bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperator, string iResult, string iErrCode, string flag, out string oErrorMessage);
  29. bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage);
  30. bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage);
  31. bool GetInfoByMaterial(string iPCBA, out string oSN, out string oErrMessage);
  32. bool GetSoftVersion(string iSN, out string oSoftVersion, out string oErrMessage);
  33. }
  34. [Guid("5379A8F6-EB38-4A2B-9050-52AD9757E12D")]
  35. [ComSourceInterfaces(typeof(IMESHelper))]
  36. [ClassInterface(ClassInterfaceType.None)]
  37. [ProgId("UMES.DllService.MESHelper")]
  38. public class MESHelper : IMESHelper
  39. {
  40. //用于拼接SQL
  41. StringBuilder sql = new StringBuilder();
  42. //用于存放批量执行的SQL
  43. List<string> sqls = new List<string>();
  44. string Master = "N_MES";
  45. //系统默认的的连接字符串
  46. private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.98.0.21)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  47. //用户选择的数据库的连接字符串
  48. private OracleConnection connection;
  49. //用户选择的数据库的连接字符串
  50. private OracleCommand command = null;
  51. public MESHelper()
  52. {
  53. connection = new OracleConnection(ConnectionStrings);
  54. }
  55. public MESHelper(string IP)
  56. {
  57. connection = new OracleConnection("Data Source=" + IP + "/orcl;User ID=N_MES;PassWord=select!#%*(;");
  58. }
  59. [Description("获取工单软件版本")]
  60. public bool GetSoftVersion(string iMakeCode, out string oSoftVersion, out string oErrMessage)
  61. {
  62. string oMakeCode = "";
  63. oErrMessage = "";
  64. oSoftVersion = "";
  65. //GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
  66. if (!CheckExist("Make", "ma_Code='" + iMakeCode + "'"))
  67. {
  68. oErrMessage = "工单号" + iMakeCode + "不存在";
  69. return false;
  70. }
  71. oSoftVersion = getFieldDataByCondition("make", "ma_softversion", "ma_code='" + iMakeCode + "'").ToString();
  72. return true;
  73. }
  74. public bool GetInfoByMaterial(string iPCBA, out string oSN, out string oErrMessage)
  75. {
  76. oSN = "";
  77. oErrMessage = "";
  78. if (iPCBA == "")
  79. {
  80. oErrMessage = "主板SN不能为空";
  81. }
  82. DataTable dt = (DataTable)ExecuteSql("select ms_firstsn,ms_sncode from CRAFTMATERIAL left join make on cm_makecode=ma_code " +
  83. "left join makeserial on ms_firstsn=cm_firstsn and cm_makecode=ms_makecode where cm_barcode='" + iPCBA + "' and nvl(cm_status,0)<>-1 order by cm_id desc", "select");
  84. if (dt.Rows.Count > 0)
  85. {
  86. oSN = dt.Rows[0]["ms_sncode"].ToString();
  87. }
  88. else
  89. {
  90. oErrMessage = "主板SN未查询到关联信息";
  91. }
  92. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  93. {
  94. return true;
  95. }
  96. else
  97. return false;
  98. }
  99. /// <summary>
  100. /// 检测当前的岗位资源对应的工序
  101. /// </summary>
  102. /// <param name="iSN"></param>
  103. /// <param name="iResCode"></param>
  104. /// <param name="oErrMessage"></param>
  105. /// <returns></returns>
  106. [Description("序列号对应工序检测")]
  107. public bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage)
  108. {
  109. if (iSN == "")
  110. {
  111. oErrMessage = "SN不能为空";
  112. return false;
  113. }
  114. string SNcode = iSN;
  115. if (!GetInfoByMaterial(iSN, out iSN, out oErrMessage))
  116. {
  117. oErrMessage = "";
  118. }
  119. if (iSN == "")
  120. {
  121. iSN = SNcode;
  122. }
  123. oErrMessage = "";
  124. string[] param = new string[] { "", iResCode, iSN, "", "", "", oErrMessage };
  125. 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" };
  126. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  127. oErrMessage = param[6];
  128. 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");
  129. string ms_status = "";
  130. string ms_stepcode = "";
  131. string ms_nextstepcode = "";
  132. if (dt.Rows.Count > 0)
  133. {
  134. ms_status = dt.Rows[0]["ms_status"].ToString();
  135. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  136. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  137. }
  138. string stepcode = GetStepCodeBySource(iResCode);
  139. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  140. {
  141. oErrMessage = "当前序列号" + iSN + "下一工序" + ms_nextstepcode;
  142. return false;
  143. }
  144. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
  145. {
  146. if (ms_status == "3")
  147. {
  148. oErrMessage = "";
  149. }
  150. DataTable dt1 = (DataTable)ExecuteSql("select 1 from makebadcount where mbc_sncode='" + iSN + "' and mbc_stepcode='" + stepcode + "' and mbc_status=0", "select");
  151. int BadCount = dt1.Rows.Count;
  152. //测试不良3次不允许再测试,必须先维修
  153. if (BadCount == 3)
  154. {
  155. oErrMessage = stepcode + "连续三次测试不良,请进行维修";
  156. return false;
  157. }
  158. return true;
  159. }
  160. else
  161. return false;
  162. }
  163. /// <summary>
  164. /// 验证用户身份信息
  165. /// </summary>
  166. /// <param name="iUserCode"></param>
  167. /// <param name="oErrorMessage"></param>
  168. /// <returns></returns>
  169. private bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
  170. {
  171. oErrorMessage = "";
  172. string SQL = "select em_code from employee where em_code=:UserName and em_password =:PassWord";
  173. DataTable dt;
  174. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode, iPassWord);
  175. if (dt.Rows.Count > 0)
  176. return true;
  177. else
  178. {
  179. oErrorMessage = "用户名或者密码不正确!";
  180. return false;
  181. }
  182. }
  183. /// <summary>
  184. /// 验证用户身份信息和岗位资源
  185. /// </summary>
  186. /// <param name="iUserCode"></param>
  187. /// <param name="iResCode"></param>
  188. /// <param name="oErrMessage"></param>
  189. /// <returns></returns>
  190. [Description("验证身份信息")]
  191. public bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage)
  192. {
  193. oErrMessage = "";
  194. if (iUserCode == "" || iPassWord == "" || iResCode == "")
  195. {
  196. oErrMessage = "用户名,密码,岗位资源必须填写";
  197. return false;
  198. }
  199. if (CheckUserLogin(iUserCode, iPassWord, "N_MES", out oErrMessage))
  200. {
  201. string SQL = "select em_code,em_type,em_name from employee where em_code=:UserName ";
  202. DataTable dt;
  203. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode);
  204. if (dt.Rows.Count > 0)
  205. {
  206. string em_name = dt.Rows[0]["em_name"].ToString();
  207. string em_type = dt.Rows[0]["em_type"].ToString();
  208. if (iResCode == "")
  209. {
  210. oErrMessage = "岗位资源不允许为空";
  211. return false;
  212. }
  213. if (em_type == "admin")
  214. {
  215. if (CheckExist("Source", "sc_code='" + iResCode + "' and sc_statuscode='AUDITED'"))
  216. {
  217. return true;
  218. }
  219. else
  220. {
  221. oErrMessage = "岗位资源编号错误或者未审核!";
  222. return false;
  223. }
  224. }
  225. else
  226. {
  227. 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'");
  228. //如果存在该编号
  229. if (dt.Rows.Count > 0)
  230. {
  231. //判断如果多个岗位资源存在,用户输入的只要在其中就行
  232. for (int i = 0; i < dt.Rows.Count; i++)
  233. {
  234. if (dt.Rows[i]["ur_resourcecode"].ToString() == iResCode)
  235. return true;
  236. }
  237. oErrMessage = "用户不处于当前资源所属分组!";
  238. }
  239. else
  240. oErrMessage = "岗位资源编号错误或者未审核!";
  241. }
  242. }
  243. else
  244. oErrMessage = "用户不存在!";
  245. }
  246. return false;
  247. }
  248. /// <summary>
  249. /// 分配Mac地址和BT地址
  250. /// </summary>
  251. /// <param name="iSN"></param>
  252. /// <param name="oWIFI"></param>
  253. /// <param name="oBT"></param>
  254. /// <param name="oCode1"></param>
  255. /// <param name="oCode2"></param>
  256. /// <param name="oCdoe3"></param>
  257. /// <param name="oErrMessage"></param>
  258. /// <returns></returns>
  259. [Description("分配MAC和BT信息")]
  260. public bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage)
  261. {
  262. oInfo = "";
  263. string oWIFI = "";
  264. string oBT = "";
  265. string oNetCard = "";
  266. string oCode1 = "";
  267. string oCode2 = "";
  268. string oCdoe3 = "";
  269. if (iSN == "")
  270. {
  271. oErrMessage = "SN不能为空";
  272. return false;
  273. }
  274. oErrMessage = "";
  275. string omakeCode = "";
  276. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  277. string[] param = new string[] { iSN, omakeCode, oWIFI, oBT, oNetCard, oCode1, oCode2, oCdoe3, oErrMessage };
  278. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_netcard", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
  279. CallProcedure("CS_GETADDRESSBYMAKECODE_FIMEI", ParamName, ref param);
  280. oInfo += "MAC:" + param[2].ToString() + "^".Replace("null", "");
  281. oInfo += "BT:" + param[3].ToString() + "^".Replace("null", "");
  282. oInfo += "NETCARD:" + param[4].ToString() + "^".Replace("null", "");
  283. oInfo += "Code1:" + param[5].ToString() + "^".Replace("null", "");
  284. oInfo += "Code2:" + param[6].ToString() + "^".Replace("null", "");
  285. oInfo += "Code3:" + param[7].ToString() + "";
  286. oErrMessage = param[7];
  287. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  288. return true;
  289. else
  290. return false;
  291. }
  292. /// <summary>
  293. /// 输入的 SN 号查找在制品是否有 IMEI 信息存在,如果存在则将 IMEI 信息传出,如果没有则在该工单下未使用的 IMEI 中随机分配一组
  294. /// 如果iIMEI1、iNetCode不为空,则分别作为获取的附件加条件。
  295. /// </summary>
  296. /// <param name="iSN"></param>
  297. /// <param name="iIMEI1"></param>
  298. /// <param name="iNetCode"></param>
  299. /// <param name="oIMEI1"></param>
  300. /// <param name="oIMEI2"></param>
  301. /// <param name="oIMEI3"></param>
  302. /// <param name="oMEID"></param>
  303. /// <param name="oNetCode"></param>
  304. /// <param name="oPSN"></param>
  305. /// <param name="oID1"></param>
  306. /// <param name="oID2"></param>
  307. /// <param name="oID3"></param>
  308. /// <param name="oErrMessage"></param>
  309. /// <returns></returns>
  310. [Description("分配IMEI和NetCode信息")]
  311. public bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out string oInfo, out string oErrMessage)
  312. {
  313. oInfo = "";
  314. string oIMEI1 = "";
  315. string oIMEI2 = "";
  316. string oIMEI3 = "";
  317. string oIMEI4 = "";
  318. string oMEID = "";
  319. string oNetCode = "";
  320. string oPSN = "";
  321. string oID1 = "";
  322. string oID2 = "";
  323. string oID3 = "";
  324. if (iSN == "")
  325. {
  326. oErrMessage = "SN不能为空";
  327. return false;
  328. }
  329. oErrMessage = "";
  330. string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, oIMEI3, oIMEI4, oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
  331. 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_imei4", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
  332. CallProcedure("CS_GETIMEIORNETCODERANGE_FIMEI", ParamName, ref param);
  333. oInfo += "IMEI1:" + param[4].ToString() + "^".Replace("null", "");
  334. oInfo += "IMEI2:" + param[5].ToString() + "^".Replace("null", "");
  335. oInfo += "IMEI3:" + param[6].ToString() + "^".Replace("null", "");
  336. oInfo += "IMEI4:" + param[7].ToString() + "^".Replace("null", "");
  337. oInfo += "MEID:" + param[8].ToString() + "^".Replace("null", "");
  338. oInfo += "NETCODE:" + param[9].ToString() + "^".Replace("null", "");
  339. oInfo += "PSN:" + param[10].ToString() + "^".Replace("null", "");
  340. oInfo += "ID1:" + param[11].ToString() + "^".Replace("null", "");
  341. oInfo += "ID2:" + param[12].ToString() + "^".Replace("null", "");
  342. oInfo += "ID3:" + param[13].ToString() + "".Replace("null", "");
  343. oErrMessage = param[13];
  344. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  345. return true;
  346. else
  347. return false;
  348. }
  349. /// <summary>
  350. /// 获取工单的最近一条执行记录
  351. /// </summary>
  352. /// <param name="iSN"></param>
  353. /// <param name="oMoCode"></param>
  354. /// <param name="oErrMessage"></param>
  355. /// <returns></returns>
  356. [Description("获取序列号对应工单信息")]
  357. public bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage)
  358. {
  359. //取MakeProcess表中的执行记录ID最大的一个工单的号码
  360. oMoCode = "";
  361. if (iSN == "")
  362. {
  363. oErrMessage = "SN不能为空";
  364. return false;
  365. }
  366. oErrMessage = "";
  367. sql.Clear();
  368. sql.Append("select max(ms_id) from makeserial where ms_sncode in (select '" + iSN + "' from dual union select sn from ");
  369. sql.Append("makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' ')");
  370. DataTable dt = (DataTable)ExecuteSql(sql.ToString(), "select");
  371. string ms_id = dt.Rows[0][0].ToString();
  372. oMoCode = getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_id='" + ms_id + "'").ToString();
  373. if (oMoCode != "")
  374. return true;
  375. else
  376. {
  377. oErrMessage = "序列号:" + iSN + " 未归属工单";
  378. return false;
  379. }
  380. }
  381. /// <summary>
  382. /// 获取序列号的所有串号信息
  383. /// </summary>
  384. /// <param name="iSN"></param>
  385. /// <param name="oWIFI"></param>
  386. /// <param name="oBT"></param>
  387. /// <param name="oCode1"></param>
  388. /// <param name="oCode2"></param>
  389. /// <param name="oCode3"></param>
  390. /// <param name="oIMEI1"></param>
  391. /// <param name="oIMEI2"></param>
  392. /// <param name="oIMEI3"></param>
  393. /// <param name="oMEID"></param>
  394. /// <param name="oNetCode"></param>
  395. /// <param name="oPSN"></param>
  396. /// <param name="oID1"></param>
  397. /// <param name="oID2"></param>
  398. /// <param name="oID3"></param>
  399. /// <param name="oID4"></param>
  400. /// <param name="oID5"></param>
  401. /// <param name="oErrMessage"></param>
  402. /// <returns></returns>
  403. [Description("查询已分配的信息")]
  404. public bool GetMobileAllInfo(string iSN, out string oJson, out string oErrMessage)
  405. {
  406. JavaScriptSerializer jss = new JavaScriptSerializer();
  407. Dictionary<string, string> oInfo = new Dictionary<string, string>();
  408. oErrMessage = "";
  409. oJson = "";
  410. //if (iSN == "")
  411. //{
  412. // oErrMessage = "SN不能为空";
  413. // return false;
  414. //}
  415. //string MacInfo;
  416. //if (!GetAddressRangeByMO(iSN, out MacInfo, out oErrMessage))
  417. //{
  418. // if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  419. // return true;
  420. // else
  421. // return false;
  422. //}
  423. //string MAC = MacInfo.Split('^')[0].Replace("MAC:", "");
  424. //string BT = MacInfo.Split('^')[1].Replace("BT:", "");
  425. //string TCode1 = MacInfo.Split('^')[2].Replace("Code1:", "");
  426. //string TCode2 = MacInfo.Split('^')[3].Replace("Code2:", "");
  427. //string TCode3 = MacInfo.Split('^')[4].Replace("Code3:", "");
  428. //if (!SetAddressInfo(iSN, MAC == "null" ? "" : MAC, BT == "null" ? "" : BT, TCode1 == "null" ? "" : TCode1, TCode2 == "null" ? "" : TCode2, TCode3 == "null" ? "" : TCode3, out oErrMessage))
  429. //{
  430. // if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  431. // return true;
  432. // else
  433. // return false;
  434. //}
  435. //string ImeiInfo;
  436. //if (!GetMEIOrNetCodeRange(iSN, "", "", out ImeiInfo, out oErrMessage))
  437. //{
  438. // if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  439. // return true;
  440. // else
  441. // return false;
  442. //}
  443. //string IMEI1 = ImeiInfo.Split('^')[0].Replace("IMEI1:", "");
  444. //string IMEI2 = ImeiInfo.Split('^')[1].Replace("IMEI2:", "");
  445. //string IMEI3 = ImeiInfo.Split('^')[2].Replace("IMEI3:", "");
  446. //string MEID = ImeiInfo.Split('^')[3].Replace("MEID:", "");
  447. //string NETCODE = ImeiInfo.Split('^')[4].Replace("NETCODE:", "");
  448. //string PSN = ImeiInfo.Split('^')[5].Replace("PSN:", "");
  449. //string ID1 = ImeiInfo.Split('^')[6].Replace("ID1:", "");
  450. //string ID2 = ImeiInfo.Split('^')[7].Replace("ID2:", "");
  451. //string ID3 = ImeiInfo.Split('^')[8].Replace("ID3:", "");
  452. //if (!SetIMEIInfo(iSN, IMEI1 == "null" ? "" : IMEI1, IMEI2 == "null" ? "" : IMEI2, IMEI3 == "null" ? "" : IMEI3, MEID == "null" ? "" : MEID, NETCODE == "null" ? "" : NETCODE, ID1 == "null" ? "" : ID1, ID2 == "null" ? "" : ID2, ID3 == "null" ? "" : ID3, out oErrMessage))
  453. //{
  454. // if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  455. // return true;
  456. // else
  457. // return false;
  458. //}
  459. //通过序列号获取最近操作的工单号
  460. string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
  461. if (ms_id != "")
  462. {
  463. 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 + "'");
  464. if (dt.Rows.Count > 0)
  465. {
  466. string Code1 = "";
  467. string Code2 = "";
  468. string Code3 = "";
  469. string Code4 = "";
  470. string Code5 = "";
  471. string Code6 = "";
  472. string Code7 = "";
  473. string Code8 = "";
  474. string Code9 = "";
  475. string Code10 = "";
  476. string Code11 = "";
  477. string Code12 = "";
  478. string Code13 = "";
  479. string Code14 = "";
  480. string Code15 = "";
  481. string Code16 = "";
  482. string Code17 = "";
  483. string Code18 = "";
  484. string Code19 = "";
  485. string Code20 = "";
  486. string Code21 = "";
  487. string Code22 = "";
  488. string Code23 = "";
  489. string Code24 = "";
  490. string Code25 = "";
  491. 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 };
  492. 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" };
  493. CallProcedure("GetMobileAllInfo_NEW", ParamName, ref param);
  494. for (int i = 1; i < param.Length; i++)
  495. {
  496. //获取出来的参数使用^分割
  497. if (param[i] != "" && param[i] != "null" && param[i] != null)
  498. {
  499. oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
  500. }
  501. }
  502. oJson = jss.Serialize(oInfo);
  503. oErrMessage = "";
  504. return true;
  505. }
  506. else
  507. {
  508. oErrMessage = "序列号" + iSN + "不存在";
  509. return false;
  510. }
  511. }
  512. else
  513. {
  514. oErrMessage = "序列号" + iSN + "不存在";
  515. return false;
  516. }
  517. }
  518. /// <summary>
  519. /// 记录操作日志
  520. /// </summary>
  521. /// <param name="iSnCode"></param>
  522. /// <param name="iMakeCode"></param>
  523. /// <param name="iMPKind"></param>
  524. /// <param name="result"></param>
  525. /// <param name="iUserCode"></param>
  526. private void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string result, string iUserCode)
  527. {
  528. string CurrentStep = "";
  529. string LineCode = "";
  530. string CurrentStepName = "";
  531. GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
  532. sql.Length = 0;
  533. sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
  534. 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)");
  535. sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,'" + CurrentStep + "','" + CurrentStepName + "',");
  536. sql.Append("ma_craftcode,ma_craftname,'" + iMPKind + "','" + result + "',sysdate,'" + iUserCode + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
  537. 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 ");
  538. sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and st_code='" + CurrentStep + "'");
  539. ExecuteSql(sql.ToString(), "insert");
  540. }
  541. /// <summary>
  542. /// 保存Mac地址和BT地址
  543. /// </summary>
  544. /// <param name="iSN"></param>
  545. /// <param name="iMac"></param>
  546. /// <param name="iBT"></param>
  547. /// <param name="iCode1"></param>
  548. /// <param name="iCode2"></param>
  549. /// <param name="iCode3"></param>
  550. /// <param name="oErrMessage"></param>
  551. /// <returns></returns>
  552. [Description("写入SN的Wifi,BT信息")]
  553. public bool SetAddressInfo(string iSN, string iMac, string iBT, string iNetCard, string iCode1, string iCode2, string iCode3, out string oErrMessage)
  554. {
  555. if (iSN == "")
  556. {
  557. oErrMessage = "SN不能为空";
  558. return false;
  559. }
  560. oErrMessage = "";
  561. string[] param = new string[] { iSN, iMac, iBT, iNetCard, iCode1, iCode2, iCode3, oErrMessage };
  562. string[] ParamName = new string[] { "v_i_sncode", "v_i_mac", "v_i_bt", "v_i_netcard", "v_i_code1", "v_i_code2", "v_i_code3", "v_o_errmsg" };
  563. CallProcedure("CS_SETADDRESSINFO_FIMEI", ParamName, ref param);
  564. oErrMessage = param[6];
  565. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  566. return true;
  567. else
  568. return false;
  569. }
  570. [Description("序列号跳到下一 步")]
  571. private bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
  572. {
  573. if (iSN == "")
  574. {
  575. oErrMessage = "SN不能为空";
  576. return false;
  577. }
  578. oErrMessage = "";
  579. string StepCode = getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
  580. string CurrentStep = GetStepCodeBySource(iSourceCode);
  581. string BgCode = getFieldDataByCondition("step", "st_badgroupcode", "st_code='" + CurrentStep + "'").ToString();
  582. switch (iResult)
  583. {
  584. case "OK":
  585. break;
  586. case "NG":
  587. if (iErrCode == "")
  588. {
  589. oErrMessage = "测试结果为NG时必须传递不良代码";
  590. return false;
  591. }
  592. else
  593. {
  594. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
  595. string[] BadCode = iErrCode.Split(',');
  596. sql.Length = 0;
  597. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  598. sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
  599. sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
  600. sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  601. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  602. List<string> InsertSQL = new List<string>();
  603. for (int i = 0; i < BadCode.Length; i++)
  604. {
  605. InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
  606. }
  607. ExecuteSQLTran(InsertSQL.ToArray());
  608. //将不良的序列号的状态码设为3
  609. ExecuteSql("update makeserial set ms_status='3' where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'", "update");
  610. }
  611. break;
  612. default:
  613. oErrMessage = "测试结果必须为NG或者OK";
  614. return false;
  615. }
  616. //不良采集为良品是更新
  617. if (StepCode == CurrentStep && iResult == "OK")
  618. {
  619. DataTable dt = getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_craftcode", "ms_prodcode" }, "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  620. if (dt.Rows.Count > 0)
  621. {
  622. string ms_status = dt.Rows[0]["ms_status"].ToString();
  623. string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  624. string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  625. if (ms_status == "3")
  626. {
  627. 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();
  628. UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  629. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "'");
  630. }
  631. }
  632. }
  633. return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
  634. }
  635. /// <summary>
  636. /// 设置测试结果
  637. /// </summary>
  638. /// <param name="iMakeCode"></param>
  639. /// <param name="iSourceCode"></param>
  640. /// <param name="iSN"></param>
  641. /// <param name="iOperater"></param>
  642. /// <param name="iResult"></param>
  643. /// <param name="iUserCode"></param>
  644. /// <param name="oErrorMessage"></param>
  645. /// <returns></returns>
  646. [Description("设置测试结果,结果必须为NG或者OK")]
  647. public bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperater, string iResult, string iErrCode, string flag, out string oErrorMessage)
  648. {
  649. oErrorMessage = "";
  650. if (iTSN == "") { oErrorMessage = "TSN不能为空"; return false; }
  651. if (iSN == "") { oErrorMessage = "SN不能为空"; return false; }
  652. string[] param = new string[] { iTSN, iSN, iSourceCode, iOperater, iResult, iErrCode, oErrorMessage };
  653. 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" };
  654. CallProcedure("CS_DLLSNCHANGE_TOOL", ParamName, ref param);
  655. oErrorMessage = param[6];
  656. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  657. return true;
  658. else
  659. return false;
  660. }
  661. private bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
  662. {
  663. if (iSN == "")
  664. {
  665. oErrMessage = "SN不能为空";
  666. return false;
  667. }
  668. oErrMessage = "";
  669. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
  670. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
  671. CallProcedure("CS_SETSTEPRESULT_TOOL", ParamName, ref param);
  672. oErrMessage = param[5];
  673. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  674. return true;
  675. else
  676. return false;
  677. }
  678. /// <summary>
  679. /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
  680. /// </summary>
  681. /// <param name="iSN">序列号</param>
  682. /// <param name="iClass"></param>
  683. /// <param name="iSubClass1"></param>
  684. /// <param name="iSubClass2"></param>
  685. /// <param name="iSubClass3"></param>
  686. /// <param name="iMaxValue"></param>
  687. /// <param name="iMinValue"></param>
  688. /// <param name="iActualValue"></param>
  689. /// <param name="iValue1"></param>
  690. /// <param name="iValue2"></param>
  691. /// <param name="iValue3"></param>
  692. /// <param name="iTestResult"></param>
  693. /// <param name="oErrMessage"></param>
  694. /// <returns></returns>
  695. [Description("设置测试结果")]
  696. public bool SetTestDetail(string iSN, string iClass, string iResCode, string[,] iTestDetail, out string oErrMessage)
  697. {
  698. if (iSN == "" || iSN == null)
  699. {
  700. oErrMessage = "SN不能为空";
  701. return false;
  702. }
  703. oErrMessage = "";
  704. string omakeCode = "";
  705. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  706. sql.Clear();
  707. sql.Append("begin ");
  708. bool needBreak = false;
  709. for (int i = 0; i < iTestDetail.Length / 200; i++)
  710. {
  711. string DataField = "Insert into MES_TEST(STD_ID,STD_SN,STD_MAKECODE,STD_CLASS,STD_TESTDATE,";
  712. string ValueField = ")values(MES_TEST_SEQ.nextval,'" + iSN + "','" + omakeCode + "','" + iClass + "',sysdate,";
  713. for (int j = 0; j < 200; j++)
  714. {
  715. if (j == 0)
  716. {
  717. DataField += "STD_ITEMNAME,";
  718. //如果传递的参数没有测试名称则中断插入
  719. if (iTestDetail[i, j] == "" || iTestDetail[i, j] == null)
  720. {
  721. //外层循环也需要中断
  722. needBreak = true;
  723. break;
  724. }
  725. }
  726. else
  727. {
  728. DataField += "STD_ITEM" + j + " ,";
  729. }
  730. ValueField += "'" + iTestDetail[i, j] + "',";
  731. }
  732. if (needBreak)
  733. break;
  734. sql.Append(DataField.Substring(0, DataField.Length - 1) + ValueField.Substring(0, ValueField.Length - 1) + ");");
  735. }
  736. sql.Append("end;");
  737. ExecuteSql(sql.ToString(), "insert");
  738. return true;
  739. }
  740. /// <summary>
  741. /// 作业调用该方法将确认接收SN对应的IMEI及附属信息。
  742. /// </summary>
  743. /// <param name="iSN"></param>
  744. /// <param name="iMO"></param>
  745. /// <param name="iIMEI1"></param>
  746. /// <param name="iIMEI2"></param>
  747. /// <param name="iIMEI3"></param>
  748. /// <param name="iMEID"></param>
  749. /// <param name="iNetCode"></param>
  750. /// <param name="iPSN"></param>
  751. /// <param name="iID1"></param>
  752. /// <param name="iBT"></param>
  753. /// <param name="iID1"></param>
  754. /// <param name="iID2"></param>
  755. /// <param name="iID3"></param>
  756. /// <param name="oErrorMessage"></param>
  757. /// <returns></returns>
  758. [Description("设置IMEI信息")]
  759. public bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iIMEI4, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage)
  760. {
  761. if (iSN == "")
  762. {
  763. oErrMessage = "SN不能为空";
  764. return false;
  765. }
  766. oErrMessage = "";
  767. string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iIMEI4, iMEID, iNETCODE, "", iID1, iID2, iID3, oErrMessage };
  768. string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_imei4", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
  769. CallProcedure("CS_SETIMEIINFO_FIMEI", ParamName, ref param);
  770. oErrMessage = param[10];
  771. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  772. return true;
  773. else
  774. return false;
  775. }
  776. /// <summary>
  777. ///
  778. /// </summary>
  779. /// <param name="iSN"></param>
  780. /// <param name="iResCode"></param>
  781. /// <param name="iOperator"></param>
  782. /// <param name="iResult"></param>
  783. /// <param name="iErrCode"></param>
  784. /// <param name="oErrMessage"></param>
  785. /// <returns></returns>
  786. [Description("设置测试结果")]
  787. public bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage)
  788. {
  789. if (iSN == "")
  790. {
  791. oErrMessage = "SN不能为空";
  792. return false;
  793. }
  794. string SNcode = iSN;
  795. if (!GetInfoByMaterial(iSN, out iSN, out oErrMessage))
  796. {
  797. oErrMessage = "";
  798. }
  799. if (iSN == "")
  800. {
  801. iSN = SNcode;
  802. }
  803. oErrMessage = "";
  804. string oMakeCode = "";
  805. GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
  806. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  807. return SetStepFinish(oMakeCode, iResCode, iSN, "", iResult, iOperator, iErrCode, out oErrMessage);
  808. else
  809. return false;
  810. }
  811. /// <summary>
  812. /// 序列号归属工单
  813. /// </summary>
  814. /// <param name="iMO"></param>
  815. /// <param name="iSN"></param>
  816. /// <param name="iResCode"></param>
  817. /// <param name="oErrMessage"></param>
  818. /// <returns></returns>
  819. [Description("序列号归属工单")]
  820. public bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage)
  821. {
  822. if (iSN == "")
  823. {
  824. oErrMessage = "SN不能为空";
  825. return false;
  826. }
  827. oErrMessage = "";
  828. string[] param = new string[] { iMO, iResCode, iSN, "", "", "", oErrMessage };
  829. 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" };
  830. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  831. oErrMessage = param[6];
  832. 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");
  833. string ms_status = "";
  834. string ms_stepcode = "";
  835. string ms_nextstepcode = "";
  836. if (dt.Rows.Count > 0)
  837. {
  838. ms_status = dt.Rows[0]["ms_status"].ToString();
  839. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  840. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  841. }
  842. string stepcode = GetStepCodeBySource(iResCode);
  843. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  844. {
  845. oErrMessage = "当前序列号" + iSN + "下一工序" + ms_nextstepcode;
  846. return false;
  847. }
  848. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && ms_stepcode == stepcode))
  849. {
  850. if (ms_status == "3")
  851. {
  852. oErrMessage = "";
  853. }
  854. return true;
  855. }
  856. else
  857. return false;
  858. }
  859. /// <summary>
  860. /// 获取执行步骤代码,名称和线别
  861. /// </summary>
  862. /// <param name="Source"></param>
  863. /// <param name="StepCode"></param>
  864. /// <param name="StepName"></param>
  865. /// <param name="LineCode"></param>
  866. private void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
  867. {
  868. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  869. if (dt.Rows.Count > 0)
  870. {
  871. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  872. StepName = dt.Rows[0]["sc_stepname"].ToString();
  873. LineCode = dt.Rows[0]["sc_linecode"].ToString();
  874. }
  875. }
  876. /// <summary>
  877. /// 获取步骤代码和名称
  878. /// </summary>
  879. /// <param name="Source"></param>
  880. /// <param name="StepCode"></param>
  881. /// <param name="StepName"></param>
  882. private void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  883. {
  884. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  885. if (dt.Rows.Count > 0)
  886. {
  887. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  888. StepName = dt.Rows[0]["sc_stepname"].ToString();
  889. }
  890. }
  891. /// <summary>
  892. /// 获取步骤代码
  893. /// </summary>
  894. /// <param name="Source"></param>
  895. /// <returns></returns>
  896. private string GetStepCodeBySource(string Source)
  897. {
  898. return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  899. }
  900. /// <summary>
  901. /// 获取步骤代码
  902. /// </summary>
  903. /// <param name="Source"></param>
  904. /// <returns></returns>
  905. private string GetStepName(string st_code)
  906. {
  907. return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
  908. }
  909. /// <summary>
  910. /// 获取第一行第一列的信息
  911. /// </summary>
  912. private object getFieldDataByCondition(string TableName, string Field, string Condition)
  913. {
  914. DataTable dt = new DataTable();
  915. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  916. command = new OracleCommand(sql, connection);
  917. Reconnect(command);
  918. OracleDataAdapter ad = new OracleDataAdapter();
  919. ad.SelectCommand = command;
  920. try
  921. {
  922. ad.Fill(dt);
  923. }
  924. catch (Exception)
  925. {
  926. connection = new OracleConnection(ConnectionStrings);
  927. connection.Open();
  928. command = new OracleCommand(sql, connection);
  929. ad = new OracleDataAdapter();
  930. ad.SelectCommand = command;
  931. ad.Fill(dt);
  932. }
  933. ad.Dispose();
  934. command.Dispose();
  935. if (dt.Rows.Count > 0)
  936. {
  937. return dt.Rows[0][0];
  938. }
  939. else
  940. {
  941. return "";
  942. }
  943. }
  944. /// <summary>
  945. /// 通过表名和获取单行的记录
  946. /// </summary>
  947. private DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  948. {
  949. DataTable dt = new DataTable();
  950. string sql = "select ";
  951. sql += AddField(Fields);
  952. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  953. command = new OracleCommand(sql, connection);
  954. Reconnect(command);
  955. OracleDataAdapter ad = new OracleDataAdapter(command);
  956. try
  957. {
  958. ad.Fill(dt);
  959. }
  960. catch (Exception)
  961. {
  962. connection = new OracleConnection(ConnectionStrings);
  963. connection.Open();
  964. command = new OracleCommand(sql, connection);
  965. ad = new OracleDataAdapter();
  966. ad.SelectCommand = command;
  967. ad.Fill(dt);
  968. }
  969. ad.Dispose();
  970. command.Dispose();
  971. return dt;
  972. }
  973. /// <summary>
  974. /// 通过表名,字段和条件获取DataTable类型的数据
  975. /// </summary>
  976. private DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  977. {
  978. DataTable dt = new DataTable();
  979. string sql = "select ";
  980. sql += AddField(Fields);
  981. sql += " from " + TableName + " where " + Condition;
  982. command = new OracleCommand(sql, connection);
  983. Reconnect(command);
  984. OracleDataAdapter ad = new OracleDataAdapter(command);
  985. try
  986. {
  987. ad.Fill(dt);
  988. }
  989. catch (Exception)
  990. {
  991. connection = new OracleConnection(ConnectionStrings);
  992. connection.Open();
  993. command = new OracleCommand(sql, connection);
  994. ad = new OracleDataAdapter();
  995. ad.SelectCommand = command;
  996. ad.Fill(dt);
  997. }
  998. ad.Dispose();
  999. command.Dispose();
  1000. return dt;
  1001. }
  1002. /// <summary>
  1003. /// 通过表名,字段获取DataTable类型的数据
  1004. /// </summary>
  1005. private DataTable getFieldsDatas(string TableName, string Fields)
  1006. {
  1007. DataTable dt = new DataTable();
  1008. string sql = "select ";
  1009. sql += Fields;
  1010. sql += " from " + TableName;
  1011. command = new OracleCommand(sql, connection);
  1012. Reconnect(command);
  1013. OracleDataAdapter ad = new OracleDataAdapter(command);
  1014. ad.SelectCommand = command;
  1015. try
  1016. {
  1017. ad.Fill(dt);
  1018. }
  1019. catch (Exception)
  1020. {
  1021. connection = new OracleConnection(ConnectionStrings);
  1022. connection.Open();
  1023. command = new OracleCommand(sql, connection);
  1024. ad = new OracleDataAdapter();
  1025. ad.SelectCommand = command;
  1026. ad.Fill(dt);
  1027. }
  1028. ad.Dispose();
  1029. command.Dispose();
  1030. return dt;
  1031. }
  1032. /// <summary>
  1033. /// 检测内容是否存在
  1034. /// </summary>
  1035. /// <param name="TableName"></param>
  1036. /// <param name="Condition"></param>
  1037. /// <returns></returns>
  1038. private bool CheckExist(string TableName, string Condition)
  1039. {
  1040. string sql = "select count(1) from " + TableName + " where " + Condition;
  1041. command = new OracleCommand(sql, connection);
  1042. Reconnect(command);
  1043. OracleDataAdapter ad = new OracleDataAdapter(command);
  1044. DataTable dt = new DataTable();
  1045. ad.Fill(dt);
  1046. ad.Dispose();
  1047. command.Dispose();
  1048. return int.Parse(dt.Rows[0][0].ToString()) > 0;
  1049. }
  1050. /// <summary>
  1051. /// 直接执行SQL,同时传入SQL的类型
  1052. /// </summary>
  1053. /// <param name="SQL"></param>
  1054. /// <param name="Type"></param>
  1055. /// <returns></returns>
  1056. private object ExecuteSql(string SQL, string Type, params object[] names)
  1057. {
  1058. object result = null;
  1059. command = new OracleCommand(SQL, connection);
  1060. Reconnect(command);
  1061. //用来拼接参数的
  1062. if (names.Length > 0)
  1063. {
  1064. string[] par = SQL.Split(':');
  1065. //用来存参数的数组
  1066. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  1067. for (int i = 0; i < par.Length - 1; i++)
  1068. {
  1069. //新建一个char类型的数组用来存储每个字节的变量
  1070. char[] c = par[i + 1].ToCharArray();
  1071. addpar[i] = new StringBuilder();
  1072. for (int j = 0; j < c.Length; j++)
  1073. {
  1074. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  1075. {
  1076. addpar[i].Append(c[j]);
  1077. }
  1078. else
  1079. {
  1080. break;
  1081. }
  1082. }
  1083. }
  1084. for (int i = 0; i < addpar.Length; i++)
  1085. {
  1086. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
  1087. }
  1088. }
  1089. switch (Type.ToUpper())
  1090. {
  1091. case "SELECT":
  1092. OracleDataAdapter ad = new OracleDataAdapter(command);
  1093. result = new DataTable();
  1094. try
  1095. {
  1096. ad.Fill((DataTable)result);
  1097. }
  1098. catch (Exception)
  1099. {
  1100. connection = new OracleConnection(ConnectionStrings);
  1101. connection.Open();
  1102. command = new OracleCommand(SQL, connection);
  1103. ad = new OracleDataAdapter();
  1104. ad.SelectCommand = command;
  1105. ad.Fill((DataTable)result);
  1106. }
  1107. break;
  1108. case "DELETE":
  1109. try
  1110. {
  1111. result = command.ExecuteNonQuery();
  1112. }
  1113. catch (Exception)
  1114. {
  1115. command.Connection = new OracleConnection(ConnectionStrings);
  1116. command.Connection.Open();
  1117. result = command.ExecuteNonQuery();
  1118. }
  1119. break;
  1120. case "UPDATE":
  1121. try
  1122. {
  1123. result = command.ExecuteNonQuery();
  1124. }
  1125. catch (Exception)
  1126. {
  1127. command.Connection = new OracleConnection(ConnectionStrings);
  1128. command.Connection.Open();
  1129. result = command.ExecuteNonQuery();
  1130. }
  1131. break;
  1132. case "INSERT":
  1133. try
  1134. {
  1135. result = command.ExecuteNonQuery();
  1136. }
  1137. catch (Exception)
  1138. {
  1139. command.Connection = new OracleConnection(ConnectionStrings);
  1140. command.Connection.Open();
  1141. result = command.ExecuteNonQuery();
  1142. }
  1143. break;
  1144. }
  1145. command.Dispose();
  1146. return result;
  1147. }
  1148. /// <summary>
  1149. /// 出现异常进行回滚的执行方法
  1150. /// </summary>
  1151. /// <param name="SQL"></param>
  1152. private void ExecuteSQLTran(params string[] SQL)
  1153. {
  1154. command = new OracleCommand();
  1155. command.Connection = new OracleConnection(ConnectionStrings);
  1156. command.Connection.Open();
  1157. Reconnect(command);
  1158. OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
  1159. command.Transaction = tx;
  1160. try
  1161. {
  1162. foreach (string sql in SQL)
  1163. {
  1164. if (!string.IsNullOrEmpty(sql))
  1165. {
  1166. command.CommandText = sql;
  1167. command.ExecuteNonQuery();
  1168. }
  1169. }
  1170. tx.Commit();
  1171. }
  1172. catch (OracleException E)
  1173. {
  1174. tx.Rollback();
  1175. throw new Exception(E.Message);
  1176. }
  1177. command.Dispose();
  1178. }
  1179. private string UpdateByCondition(string TableName, string update, string condition)
  1180. {
  1181. string sql = "update " + TableName + " set " + update + " where " + condition;
  1182. command = new OracleCommand(sql, connection);
  1183. Reconnect(command);
  1184. try
  1185. {
  1186. command.ExecuteNonQuery();
  1187. }
  1188. catch (Exception)
  1189. {
  1190. command.Connection = new OracleConnection(ConnectionStrings);
  1191. command.Connection.Open();
  1192. command.ExecuteNonQuery();
  1193. }
  1194. command.Dispose();
  1195. return sql;
  1196. }
  1197. private void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
  1198. {
  1199. command = new OracleCommand(ProcedureName);
  1200. command.Connection = connection;
  1201. Reconnect(command);
  1202. command.CommandText = ProcedureName;
  1203. command.CommandType = CommandType.StoredProcedure;
  1204. for (int i = 0; i < param.Length; i++)
  1205. {
  1206. command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1207. //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
  1208. }
  1209. try
  1210. {
  1211. command.ExecuteNonQuery();
  1212. }
  1213. catch (Exception)
  1214. {
  1215. command.Connection = new OracleConnection(ConnectionStrings);
  1216. command.Connection.Open();
  1217. command.ExecuteNonQuery();
  1218. }
  1219. for (int i = 0; i < command.Parameters.Count; i++)
  1220. param[i] = command.Parameters[i].Value.ToString();
  1221. command.Dispose();
  1222. }
  1223. private string AddField(string[] Fields)
  1224. {
  1225. string sql = " ";
  1226. foreach (string field in Fields)
  1227. {
  1228. sql += field + ",";
  1229. }
  1230. return sql.Substring(0, sql.Length - 1);
  1231. }
  1232. private string[] GetField(string field)
  1233. {
  1234. string[] fields = field.Split(',');
  1235. for (int i = 0; i < fields.Length; i++)
  1236. {
  1237. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1238. }
  1239. return fields;
  1240. }
  1241. private void Reconnect(OracleCommand cmd)
  1242. {
  1243. if (cmd.Connection.State == ConnectionState.Closed)
  1244. {
  1245. cmd.Connection.Open();
  1246. }
  1247. }
  1248. /// <summary>
  1249. /// 验证用户身份信息
  1250. /// </summary>
  1251. /// <param name="iUserCode"></param>
  1252. /// <param name="oErrorMessage"></param>
  1253. /// <returns></returns>
  1254. private bool CheckUserLogin(string iUserCode, string iPassWord, string Master, out string oErrorMessage)
  1255. {
  1256. oErrorMessage = "";
  1257. try
  1258. {
  1259. string url = "http://10.98.0.21:8099/mes/mobile/login.action";//html调用的地址
  1260. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
  1261. if (webrequest == null)
  1262. {
  1263. return false;
  1264. }
  1265. webrequest.Method = "POST";
  1266. webrequest.Timeout = 1000;
  1267. webrequest.ContentType = "application/x-www-form-urlencoded";
  1268. System.Collections.Hashtable pars = new System.Collections.Hashtable();
  1269. pars.Add("username", iUserCode);
  1270. pars.Add("password", iPassWord);
  1271. pars.Add("master", Master);
  1272. string buffer = "";
  1273. //发送POST数据
  1274. if (!(pars == null || pars.Count == 0))
  1275. {
  1276. foreach (string key in pars.Keys)
  1277. {
  1278. buffer = buffer + "&" + key + "=" + pars[key].ToString();
  1279. }
  1280. byte[] data = Encoding.UTF8.GetBytes(buffer);
  1281. using (Stream stream = webrequest.GetRequestStream())
  1282. {
  1283. stream.Write(data, 0, data.Length);
  1284. }
  1285. }
  1286. string[] values = webrequest.Headers.GetValues("Content-Type");
  1287. WebResponse myResponse = webrequest.GetResponse();
  1288. using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
  1289. {
  1290. StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
  1291. string Content = newReader.ReadToEnd();
  1292. Dictionary<string, object> dic = new Dictionary<string, object>();
  1293. dic = ToDictionary(Content);
  1294. if (!dic.ContainsKey("erpaccount"))
  1295. {
  1296. oErrorMessage = dic["reason"].ToString();
  1297. return false;
  1298. }
  1299. newReader.Close();
  1300. }
  1301. }
  1302. catch (Exception ex)
  1303. {
  1304. oErrorMessage = ex.Message.ToString();
  1305. return false;
  1306. }
  1307. return true;
  1308. }
  1309. private Dictionary<string, object> ToDictionary(string JsonData)
  1310. {
  1311. object Data = null;
  1312. Dictionary<string, object> Dic = new Dictionary<string, object>();
  1313. if (JsonData.StartsWith("["))
  1314. {
  1315. //如果目标直接就为数组类型,则将会直接输出一个Key为List的List<Dictionary<string, object>>集合
  1316. //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["List"];
  1317. List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
  1318. MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
  1319. foreach (Match ListItem in ListMatch)
  1320. {
  1321. List.Add(ToDictionary(ListItem.ToString()));//递归调用
  1322. }
  1323. Data = List;
  1324. Dic.Add("List", Data);
  1325. }
  1326. else
  1327. {
  1328. MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\]|null|"".+?""|-{0,1}\d*)");//使用正则表达式匹配出JSON数据中的键与值
  1329. foreach (Match item in Match)
  1330. {
  1331. try
  1332. {
  1333. if (item.Groups[2].ToString().StartsWith("["))
  1334. {
  1335. //如果目标是数组,将会输出一个Key为当前Json的List<Dictionary<string, object>>集合
  1336. //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["Json中的Key"];
  1337. List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
  1338. MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
  1339. foreach (Match ListItem in ListMatch)
  1340. {
  1341. List.Add(ToDictionary(ListItem.ToString()));//递归调用
  1342. }
  1343. Data = List;
  1344. }
  1345. else if (item.Groups[2].ToString().ToLower() == "null") Data = null;//如果数据为null(字符串类型),直接转换成null
  1346. else Data = item.Groups[2].ToString(); //数据为数字、字符串中的一类,直接写入
  1347. Dic.Add(item.Groups[1].ToString(), Data);
  1348. }
  1349. catch { }
  1350. }
  1351. }
  1352. return Dic;
  1353. }
  1354. }
  1355. }