MesHelper.cs 62 KB

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