MesHelper.cs 61 KB

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