MesHelper.cs 62 KB

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