MesHelper.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. using Oracle.ManagedDataAccess.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.IO;
  7. using System.Net;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Web.Script.Serialization;
  12. namespace UMESDLLService
  13. {
  14. [Guid("974DEAD2-9D4C-4728-87EA-2407752E300F")]
  15. [InterfaceType(ComInterfaceType.InterfaceIsDual)]
  16. public interface IMESHelper
  17. {
  18. [DispId(12)]
  19. bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage);
  20. bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
  21. bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
  22. bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage);
  23. bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
  24. bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[,] iTestDetail, out string oErrMessage);
  25. bool GetMEIOrNetCodeRange(string iSnCode, string iIMEI1, string iNetCode, out string oInfo, out string oErrMessage);
  26. bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iPSN, 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=MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11568)))(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. DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_sncode='" + iSN + "' or ms_imei1='" + iSN + "' or ms_imei2='" + iSN + "' order by ms_id desc", "select");
  116. if (dt.Rows.Count > 0)
  117. {
  118. iSN = dt.Rows[0]["ms_sncode"].ToString();
  119. }
  120. if (iSN == "")
  121. {
  122. iSN = SNcode;
  123. }
  124. oErrMessage = "";
  125. string[] param = new string[] { "", iResCode, iSN, "", "", "", oErrMessage };
  126. 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" };
  127. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  128. oErrMessage = param[6];
  129. 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");
  130. string ms_status = "";
  131. string ms_stepcode = "";
  132. string ms_nextstepcode = "";
  133. if (dt.Rows.Count > 0)
  134. {
  135. ms_status = dt.Rows[0]["ms_status"].ToString();
  136. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  137. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  138. }
  139. string stepcode = GetStepCodeBySource(iResCode);
  140. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  141. {
  142. oErrMessage = "当前序列号" + iSN + "下一工序" + ms_nextstepcode;
  143. return false;
  144. }
  145. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
  146. {
  147. if (ms_status == "3")
  148. {
  149. oErrMessage = "";
  150. }
  151. DataTable dt1 = (DataTable)ExecuteSql("select 1 from makebadcount where mbc_sncode='" + iSN + "' and mbc_stepcode='" + stepcode + "' and mbc_status=0", "select");
  152. int BadCount = dt1.Rows.Count;
  153. //测试不良3次不允许再测试,必须先维修
  154. if (BadCount == 3)
  155. {
  156. oErrMessage = stepcode + "连续三次测试不良,请进行维修";
  157. return false;
  158. }
  159. return true;
  160. }
  161. else
  162. return false;
  163. }
  164. /// <summary>
  165. /// 验证用户身份信息
  166. /// </summary>
  167. /// <param name="iUserCode"></param>
  168. /// <param name="oErrorMessage"></param>
  169. /// <returns></returns>
  170. private bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
  171. {
  172. oErrorMessage = "";
  173. string SQL = "select em_code from employee where em_code=:UserName and em_password =:PassWord";
  174. DataTable dt;
  175. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode, iPassWord);
  176. if (dt.Rows.Count > 0)
  177. return true;
  178. else
  179. {
  180. oErrorMessage = "用户名或者密码不正确!";
  181. return false;
  182. }
  183. }
  184. /// <summary>
  185. /// 验证用户身份信息和岗位资源
  186. /// </summary>
  187. /// <param name="iUserCode"></param>
  188. /// <param name="iResCode"></param>
  189. /// <param name="oErrMessage"></param>
  190. /// <returns></returns>
  191. [Description("验证身份信息")]
  192. public bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage)
  193. {
  194. oErrMessage = "";
  195. if (iUserCode == "" || iPassWord == "" || iResCode == "")
  196. {
  197. oErrMessage = "用户名,密码,岗位资源必须填写";
  198. return false;
  199. }
  200. if (CheckUserLogin(iUserCode, iPassWord, out oErrMessage))
  201. {
  202. string SQL = "select em_code,em_type,em_name from employee where em_code=:UserName ";
  203. DataTable dt;
  204. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode);
  205. if (dt.Rows.Count > 0)
  206. {
  207. string em_name = dt.Rows[0]["em_name"].ToString();
  208. string em_type = dt.Rows[0]["em_type"].ToString();
  209. if (iResCode == "")
  210. {
  211. oErrMessage = "岗位资源不允许为空";
  212. return false;
  213. }
  214. if (em_type == "admin")
  215. {
  216. if (CheckExist("Source", "sc_code='" + iResCode + "' and sc_statuscode='AUDITED'"))
  217. {
  218. return true;
  219. }
  220. else
  221. {
  222. oErrMessage = "岗位资源编号错误或者未审核!";
  223. return false;
  224. }
  225. }
  226. else
  227. {
  228. 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'");
  229. //如果存在该编号
  230. if (dt.Rows.Count > 0)
  231. {
  232. //判断如果多个岗位资源存在,用户输入的只要在其中就行
  233. for (int i = 0; i < dt.Rows.Count; i++)
  234. {
  235. if (dt.Rows[i]["ur_resourcecode"].ToString() == iResCode)
  236. return true;
  237. }
  238. oErrMessage = "用户不处于当前资源所属分组!";
  239. }
  240. else
  241. oErrMessage = "岗位资源编号错误或者未审核!";
  242. }
  243. }
  244. else
  245. oErrMessage = "用户不存在!";
  246. }
  247. return false;
  248. }
  249. /// <summary>
  250. /// 分配Mac地址和BT地址
  251. /// </summary>
  252. /// <param name="iSN"></param>
  253. /// <param name="oWIFI"></param>
  254. /// <param name="oBT"></param>
  255. /// <param name="oCode1"></param>
  256. /// <param name="oCode2"></param>
  257. /// <param name="oCdoe3"></param>
  258. /// <param name="oErrMessage"></param>
  259. /// <returns></returns>
  260. [Description("分配MAC和BT信息")]
  261. public bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage)
  262. {
  263. oInfo = "";
  264. string oWIFI = "";
  265. string oBT = "";
  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, oCode1, oCode2, oCdoe3, oErrMessage };
  278. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
  279. CallProcedure("CS_GETADDRESSBYMAKECODE", ParamName, ref param);
  280. oInfo += "MAC:" + param[2].ToString() + "^".Replace("null", "");
  281. oInfo += "BT:" + param[3].ToString() + "^".Replace("null", "");
  282. oInfo += "Code1:" + param[4].ToString() + "^".Replace("null", "");
  283. oInfo += "Code2:" + param[5].ToString() + "^".Replace("null", "");
  284. oInfo += "Code3:" + param[6].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 oMEID = "";
  316. string oNetCode = "";
  317. string oPSN = "";
  318. string oID1 = "";
  319. string oID2 = "";
  320. string oID3 = "";
  321. if (iSN == "")
  322. {
  323. oErrMessage = "SN不能为空";
  324. return false;
  325. }
  326. oErrMessage = "";
  327. string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, "", oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
  328. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_i_imei", "v_i_netcode", "v_o_imei1", "v_o_imei2", "v_o_imei3", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
  329. CallProcedure("CS_GETIMEIORNETCODERANGE", ParamName, ref param);
  330. oInfo += "IMEI1:" + param[4].ToString() + "^".Replace("null", "");
  331. oInfo += "IMEI2:" + param[5].ToString() + "^".Replace("null", "");
  332. oInfo += "MEID:" + param[7].ToString() + "^".Replace("null", "");
  333. oInfo += "NETCODE:" + param[8].ToString() + "^".Replace("null", "");
  334. oInfo += "PSN:" + param[9].ToString() + "^".Replace("null", "");
  335. oInfo += "ID1:" + param[10].ToString() + "^".Replace("null", "");
  336. oInfo += "ID2:" + param[11].ToString() + "^".Replace("null", "");
  337. oInfo += "ID3:" + param[12].ToString() + "".Replace("null", "");
  338. oErrMessage = param[13];
  339. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  340. return true;
  341. else
  342. return false;
  343. }
  344. /// <summary>
  345. /// 获取工单的最近一条执行记录
  346. /// </summary>
  347. /// <param name="iSN"></param>
  348. /// <param name="oMoCode"></param>
  349. /// <param name="oErrMessage"></param>
  350. /// <returns></returns>
  351. [Description("获取序列号对应工单信息")]
  352. public bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage)
  353. {
  354. //取MakeProcess表中的执行记录ID最大的一个工单的号码
  355. oMoCode = "";
  356. if (iSN == "")
  357. {
  358. oErrMessage = "SN不能为空";
  359. return false;
  360. }
  361. oErrMessage = "";
  362. sql.Clear();
  363. sql.Append("select max(ms_id) from makeserial where ms_sncode in (select '" + iSN + "' from dual union select sn from ");
  364. sql.Append("makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' ')");
  365. DataTable dt = (DataTable)ExecuteSql(sql.ToString(), "select");
  366. string ms_id = dt.Rows[0][0].ToString();
  367. oMoCode = getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_id='" + ms_id + "'").ToString();
  368. if (oMoCode != "")
  369. return true;
  370. else
  371. {
  372. oErrMessage = "序列号:" + iSN + " 未归属工单";
  373. return false;
  374. }
  375. }
  376. /// <summary>
  377. /// 获取序列号的所有串号信息
  378. /// </summary>
  379. /// <param name="iSN"></param>
  380. /// <param name="oWIFI"></param>
  381. /// <param name="oBT"></param>
  382. /// <param name="oCode1"></param>
  383. /// <param name="oCode2"></param>
  384. /// <param name="oCode3"></param>
  385. /// <param name="oIMEI1"></param>
  386. /// <param name="oIMEI2"></param>
  387. /// <param name="oIMEI3"></param>
  388. /// <param name="oMEID"></param>
  389. /// <param name="oNetCode"></param>
  390. /// <param name="oPSN"></param>
  391. /// <param name="oID1"></param>
  392. /// <param name="oID2"></param>
  393. /// <param name="oID3"></param>
  394. /// <param name="oID4"></param>
  395. /// <param name="oID5"></param>
  396. /// <param name="oErrMessage"></param>
  397. /// <returns></returns>
  398. [Description("查询已分配的信息")]
  399. public bool GetMobileAllInfo(string iSN, out string oJson, out string oErrMessage)
  400. {
  401. JavaScriptSerializer jss = new JavaScriptSerializer();
  402. Dictionary<string, string> oInfo = new Dictionary<string, string>();
  403. oErrMessage = "";
  404. oJson = "";
  405. if (iSN == "")
  406. {
  407. oErrMessage = "SN不能为空";
  408. return false;
  409. }
  410. DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "' or ms_imei1='" + iSN + "' or ms_imei2='" + iSN + "' order by ms_id desc", "select");
  411. if (dt.Rows.Count > 0)
  412. {
  413. iSN = dt.Rows[0]["ms_sncode"].ToString();
  414. }
  415. string MacInfo;
  416. //if (!GetAddressRangeByMO(iSN, out MacInfo, out oErrMessage))
  417. //{
  418. // if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  419. // return true;
  420. // else
  421. // return false;
  422. //}
  423. //string MAC = MacInfo.Split('^')[0].Replace("MAC:", "");
  424. //string BT = MacInfo.Split('^')[1].Replace("BT:", "");
  425. //string TCode1 = MacInfo.Split('^')[2].Replace("Code1:", "");
  426. //string TCode2 = MacInfo.Split('^')[3].Replace("Code2:", "");
  427. //string TCode3 = MacInfo.Split('^')[4].Replace("Code3:", "");
  428. //if (!SetAddressInfo(iSN, MAC == "null" ? "" : MAC, BT == "null" ? "" : BT, TCode1 == "null" ? "" : TCode1, TCode2 == "null" ? "" : TCode2, TCode3 == "null" ? "" : TCode3, out oErrMessage))
  429. //{
  430. // if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  431. // return true;
  432. // else
  433. // return false;
  434. //}
  435. string ImeiInfo;
  436. if (!GetMEIOrNetCodeRange(iSN, "", "", out ImeiInfo, out oErrMessage))
  437. {
  438. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  439. return true;
  440. else
  441. return false;
  442. }
  443. string IMEI1 = ImeiInfo.Split('^')[0].Replace("IMEI1:", "");
  444. string IMEI2 = ImeiInfo.Split('^')[1].Replace("IMEI2:", "");
  445. string MEID = ImeiInfo.Split('^')[2].Replace("MEID:", "");
  446. string NETCODE = ImeiInfo.Split('^')[3].Replace("NETCODE:", "");
  447. string PSN = ImeiInfo.Split('^')[4].Replace("PSN:", "");
  448. string ID1 = ImeiInfo.Split('^')[5].Replace("ID1:", "");
  449. string ID2 = ImeiInfo.Split('^')[6].Replace("ID2:", "");
  450. string ID3 = ImeiInfo.Split('^')[7].Replace("ID3:", "");
  451. if (!SetIMEIInfo(iSN, IMEI1 == "null" ? "" : IMEI1, IMEI2 == "null" ? "" : IMEI2, "", MEID == "null" ? "" : MEID, PSN == "null" ? "" : PSN, 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_firstsn='" + iSN + "'").ToString();
  460. if (ms_id != "")
  461. {
  462. 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_TOOL", 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_code1", "v_i_code2", "v_i_code3", "v_o_errmsg" };
  562. CallProcedure("CS_SETADDRESSINFO", 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. DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + iTSN + "' order by ms_id desc", "select");
  652. if (dt.Rows.Count > 0)
  653. {
  654. iTSN = dt.Rows[0]["ms_sncode"].ToString();
  655. }
  656. else
  657. {
  658. dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + iTSN + "' order by ms_id desc", "select");
  659. if (dt.Rows.Count > 0)
  660. {
  661. iTSN = dt.Rows[0]["ms_sncode"].ToString();
  662. }
  663. }
  664. string[] param = new string[] { iTSN, iSN, iSourceCode, iOperater, iResult, iErrCode, oErrorMessage };
  665. 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" };
  666. CallProcedure("CS_DLLSNCHANGE_TOOL", ParamName, ref param);
  667. oErrorMessage = param[6];
  668. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  669. return true;
  670. else
  671. return false;
  672. }
  673. private bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
  674. {
  675. if (iSN == "")
  676. {
  677. oErrMessage = "SN不能为空";
  678. return false;
  679. }
  680. oErrMessage = "";
  681. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
  682. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
  683. CallProcedure("CS_SETSTEPRESULT_TOOL", ParamName, ref param);
  684. oErrMessage = param[5];
  685. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  686. return true;
  687. else
  688. return false;
  689. }
  690. /// <summary>
  691. /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
  692. /// </summary>
  693. /// <param name="iSN">序列号</param>
  694. /// <param name="iClass"></param>
  695. /// <param name="iSubClass1"></param>
  696. /// <param name="iSubClass2"></param>
  697. /// <param name="iSubClass3"></param>
  698. /// <param name="iMaxValue"></param>
  699. /// <param name="iMinValue"></param>
  700. /// <param name="iActualValue"></param>
  701. /// <param name="iValue1"></param>
  702. /// <param name="iValue2"></param>
  703. /// <param name="iValue3"></param>
  704. /// <param name="iTestResult"></param>
  705. /// <param name="oErrMessage"></param>
  706. /// <returns></returns>
  707. [Description("设置测试结果")]
  708. public bool SetTestDetail(string iSN, string iClass, string iResCode, string[,] iTestDetail, out string oErrMessage)
  709. {
  710. if (iSN == "" || iSN == null)
  711. {
  712. oErrMessage = "SN不能为空";
  713. return false;
  714. }
  715. oErrMessage = "";
  716. string omakeCode = "";
  717. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  718. sql.Clear();
  719. sql.Append("begin ");
  720. bool needBreak = false;
  721. for (int i = 0; i < iTestDetail.Length / 200; i++)
  722. {
  723. string DataField = "Insert into MES_TEST(STD_ID,STD_SN,STD_MAKECODE,STD_CLASS,STD_TESTDATE,";
  724. string ValueField = ")values(MES_TEST_SEQ.nextval,'" + iSN + "','" + omakeCode + "','" + iClass + "',sysdate,";
  725. for (int j = 0; j < 200; j++)
  726. {
  727. if (j == 0)
  728. {
  729. DataField += "STD_ITEMNAME,";
  730. //如果传递的参数没有测试名称则中断插入
  731. if (iTestDetail[i, j] == "" || iTestDetail[i, j] == null)
  732. {
  733. //外层循环也需要中断
  734. needBreak = true;
  735. break;
  736. }
  737. }
  738. else
  739. {
  740. DataField += "STD_ITEM" + j + " ,";
  741. }
  742. ValueField += "'" + iTestDetail[i, j] + "',";
  743. }
  744. if (needBreak)
  745. break;
  746. sql.Append(DataField.Substring(0, DataField.Length - 1) + ValueField.Substring(0, ValueField.Length - 1) + ");");
  747. }
  748. sql.Append("end;");
  749. ExecuteSql(sql.ToString(), "insert");
  750. return true;
  751. }
  752. /// <summary>
  753. /// 作业调用该方法将确认接收SN对应的IMEI及附属信息。
  754. /// </summary>
  755. /// <param name="iSN"></param>
  756. /// <param name="iMO"></param>
  757. /// <param name="iIMEI1"></param>
  758. /// <param name="iIMEI2"></param>
  759. /// <param name="iIMEI3"></param>
  760. /// <param name="iMEID"></param>
  761. /// <param name="iNetCode"></param>
  762. /// <param name="iPSN"></param>
  763. /// <param name="iID1"></param>
  764. /// <param name="iBT"></param>
  765. /// <param name="iID1"></param>
  766. /// <param name="iID2"></param>
  767. /// <param name="iID3"></param>
  768. /// <param name="oErrorMessage"></param>
  769. /// <returns></returns>
  770. [Description("设置IMEI信息")]
  771. public bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iPSN, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage)
  772. {
  773. if (iSN == "")
  774. {
  775. oErrMessage = "SN不能为空";
  776. return false;
  777. }
  778. oErrMessage = "";
  779. string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iMEID, iNETCODE, iPSN, iID1, iID2, iID3, oErrMessage };
  780. string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
  781. CallProcedure("CS_SETIMEIINFO", ParamName, ref param);
  782. oErrMessage = param[10];
  783. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  784. return true;
  785. else
  786. return false;
  787. }
  788. /// <summary>
  789. ///
  790. /// </summary>
  791. /// <param name="iSN"></param>
  792. /// <param name="iResCode"></param>
  793. /// <param name="iOperator"></param>
  794. /// <param name="iResult"></param>
  795. /// <param name="iErrCode"></param>
  796. /// <param name="oErrMessage"></param>
  797. /// <returns></returns>
  798. [Description("设置测试结果")]
  799. public bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage)
  800. {
  801. if (iSN == "")
  802. {
  803. oErrMessage = "SN不能为空";
  804. return false;
  805. }
  806. string SNcode = iSN;
  807. //if (!GetInfoByMaterial(iSN, out iSN, out oErrMessage))
  808. //{
  809. // oErrMessage = "";
  810. //}
  811. if (iSN == "")
  812. {
  813. iSN = SNcode;
  814. }
  815. oErrMessage = "";
  816. string oMakeCode = "";
  817. GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
  818. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  819. return SetStepFinish(oMakeCode, iResCode, iSN, "", iResult, iOperator, iErrCode, out oErrMessage);
  820. else
  821. return false;
  822. }
  823. /// <summary>
  824. /// 序列号归属工单
  825. /// </summary>
  826. /// <param name="iMO"></param>
  827. /// <param name="iSN"></param>
  828. /// <param name="iResCode"></param>
  829. /// <param name="oErrMessage"></param>
  830. /// <returns></returns>
  831. [Description("序列号归属工单")]
  832. public bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage)
  833. {
  834. if (iSN == "")
  835. {
  836. oErrMessage = "SN不能为空";
  837. return false;
  838. }
  839. oErrMessage = "";
  840. string[] param = new string[] { iMO, iResCode, iSN, "", "", "", oErrMessage };
  841. 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" };
  842. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  843. oErrMessage = param[6];
  844. 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");
  845. string ms_status = "";
  846. string ms_stepcode = "";
  847. string ms_nextstepcode = "";
  848. if (dt.Rows.Count > 0)
  849. {
  850. ms_status = dt.Rows[0]["ms_status"].ToString();
  851. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  852. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  853. }
  854. string stepcode = GetStepCodeBySource(iResCode);
  855. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && ms_stepcode == stepcode))
  856. {
  857. if (ms_status == "3")
  858. {
  859. oErrMessage = "";
  860. }
  861. return true;
  862. }
  863. else
  864. return false;
  865. }
  866. /// <summary>
  867. /// 获取执行步骤代码,名称和线别
  868. /// </summary>
  869. /// <param name="Source"></param>
  870. /// <param name="StepCode"></param>
  871. /// <param name="StepName"></param>
  872. /// <param name="LineCode"></param>
  873. private void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
  874. {
  875. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  876. if (dt.Rows.Count > 0)
  877. {
  878. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  879. StepName = dt.Rows[0]["sc_stepname"].ToString();
  880. LineCode = dt.Rows[0]["sc_linecode"].ToString();
  881. }
  882. }
  883. /// <summary>
  884. /// 获取步骤代码和名称
  885. /// </summary>
  886. /// <param name="Source"></param>
  887. /// <param name="StepCode"></param>
  888. /// <param name="StepName"></param>
  889. private void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  890. {
  891. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  892. if (dt.Rows.Count > 0)
  893. {
  894. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  895. StepName = dt.Rows[0]["sc_stepname"].ToString();
  896. }
  897. }
  898. /// <summary>
  899. /// 获取步骤代码
  900. /// </summary>
  901. /// <param name="Source"></param>
  902. /// <returns></returns>
  903. private string GetStepCodeBySource(string Source)
  904. {
  905. return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  906. }
  907. /// <summary>
  908. /// 获取步骤代码
  909. /// </summary>
  910. /// <param name="Source"></param>
  911. /// <returns></returns>
  912. private string GetStepName(string st_code)
  913. {
  914. return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
  915. }
  916. /// <summary>
  917. /// 获取第一行第一列的信息
  918. /// </summary>
  919. private object getFieldDataByCondition(string TableName, string Field, string Condition)
  920. {
  921. DataTable dt = new DataTable();
  922. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  923. command = new OracleCommand(sql, connection);
  924. Reconnect(command);
  925. OracleDataAdapter ad = new OracleDataAdapter();
  926. ad.SelectCommand = command;
  927. try
  928. {
  929. ad.Fill(dt);
  930. }
  931. catch (Exception)
  932. {
  933. connection = new OracleConnection(ConnectionStrings);
  934. connection.Open();
  935. command = new OracleCommand(sql, connection);
  936. ad = new OracleDataAdapter();
  937. ad.SelectCommand = command;
  938. ad.Fill(dt);
  939. }
  940. ad.Dispose();
  941. command.Dispose();
  942. if (dt.Rows.Count > 0)
  943. {
  944. return dt.Rows[0][0];
  945. }
  946. else
  947. {
  948. return "";
  949. }
  950. }
  951. /// <summary>
  952. /// 通过表名和获取单行的记录
  953. /// </summary>
  954. private DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  955. {
  956. DataTable dt = new DataTable();
  957. string sql = "select ";
  958. sql += AddField(Fields);
  959. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  960. command = new OracleCommand(sql, connection);
  961. Reconnect(command);
  962. OracleDataAdapter ad = new OracleDataAdapter(command);
  963. try
  964. {
  965. ad.Fill(dt);
  966. }
  967. catch (Exception)
  968. {
  969. connection = new OracleConnection(ConnectionStrings);
  970. connection.Open();
  971. command = new OracleCommand(sql, connection);
  972. ad = new OracleDataAdapter();
  973. ad.SelectCommand = command;
  974. ad.Fill(dt);
  975. }
  976. ad.Dispose();
  977. command.Dispose();
  978. return dt;
  979. }
  980. /// <summary>
  981. /// 通过表名,字段和条件获取DataTable类型的数据
  982. /// </summary>
  983. private DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  984. {
  985. DataTable dt = new DataTable();
  986. string sql = "select ";
  987. sql += AddField(Fields);
  988. sql += " from " + TableName + " where " + Condition;
  989. command = new OracleCommand(sql, connection);
  990. Reconnect(command);
  991. OracleDataAdapter ad = new OracleDataAdapter(command);
  992. try
  993. {
  994. ad.Fill(dt);
  995. }
  996. catch (Exception)
  997. {
  998. connection = new OracleConnection(ConnectionStrings);
  999. connection.Open();
  1000. command = new OracleCommand(sql, connection);
  1001. ad = new OracleDataAdapter();
  1002. ad.SelectCommand = command;
  1003. ad.Fill(dt);
  1004. }
  1005. ad.Dispose();
  1006. command.Dispose();
  1007. return dt;
  1008. }
  1009. /// <summary>
  1010. /// 通过表名,字段获取DataTable类型的数据
  1011. /// </summary>
  1012. private DataTable getFieldsDatas(string TableName, string Fields)
  1013. {
  1014. DataTable dt = new DataTable();
  1015. string sql = "select ";
  1016. sql += Fields;
  1017. sql += " from " + TableName;
  1018. command = new OracleCommand(sql, connection);
  1019. Reconnect(command);
  1020. OracleDataAdapter ad = new OracleDataAdapter(command);
  1021. ad.SelectCommand = command;
  1022. try
  1023. {
  1024. ad.Fill(dt);
  1025. }
  1026. catch (Exception)
  1027. {
  1028. connection = new OracleConnection(ConnectionStrings);
  1029. connection.Open();
  1030. command = new OracleCommand(sql, connection);
  1031. ad = new OracleDataAdapter();
  1032. ad.SelectCommand = command;
  1033. ad.Fill(dt);
  1034. }
  1035. ad.Dispose();
  1036. command.Dispose();
  1037. return dt;
  1038. }
  1039. /// <summary>
  1040. /// 检测内容是否存在
  1041. /// </summary>
  1042. /// <param name="TableName"></param>
  1043. /// <param name="Condition"></param>
  1044. /// <returns></returns>
  1045. private bool CheckExist(string TableName, string Condition)
  1046. {
  1047. string sql = "select count(1) from " + TableName + " where " + Condition;
  1048. command = new OracleCommand(sql, connection);
  1049. Reconnect(command);
  1050. OracleDataAdapter ad = new OracleDataAdapter(command);
  1051. DataTable dt = new DataTable();
  1052. ad.Fill(dt);
  1053. ad.Dispose();
  1054. command.Dispose();
  1055. return int.Parse(dt.Rows[0][0].ToString()) > 0;
  1056. }
  1057. /// <summary>
  1058. /// 直接执行SQL,同时传入SQL的类型
  1059. /// </summary>
  1060. /// <param name="SQL"></param>
  1061. /// <param name="Type"></param>
  1062. /// <returns></returns>
  1063. private object ExecuteSql(string SQL, string Type, params object[] names)
  1064. {
  1065. object result = null;
  1066. command = new OracleCommand(SQL, connection);
  1067. Reconnect(command);
  1068. //用来拼接参数的
  1069. if (names.Length > 0)
  1070. {
  1071. string[] par = SQL.Split(':');
  1072. //用来存参数的数组
  1073. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  1074. for (int i = 0; i < par.Length - 1; i++)
  1075. {
  1076. //新建一个char类型的数组用来存储每个字节的变量
  1077. char[] c = par[i + 1].ToCharArray();
  1078. addpar[i] = new StringBuilder();
  1079. for (int j = 0; j < c.Length; j++)
  1080. {
  1081. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  1082. {
  1083. addpar[i].Append(c[j]);
  1084. }
  1085. else
  1086. {
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. for (int i = 0; i < addpar.Length; i++)
  1092. {
  1093. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
  1094. }
  1095. }
  1096. switch (Type.ToUpper())
  1097. {
  1098. case "SELECT":
  1099. OracleDataAdapter ad = new OracleDataAdapter(command);
  1100. result = new DataTable();
  1101. try
  1102. {
  1103. ad.Fill((DataTable)result);
  1104. }
  1105. catch (Exception)
  1106. {
  1107. connection = new OracleConnection(ConnectionStrings);
  1108. connection.Open();
  1109. command = new OracleCommand(SQL, connection);
  1110. ad = new OracleDataAdapter();
  1111. ad.SelectCommand = command;
  1112. ad.Fill((DataTable)result);
  1113. }
  1114. break;
  1115. case "DELETE":
  1116. try
  1117. {
  1118. result = command.ExecuteNonQuery();
  1119. }
  1120. catch (Exception)
  1121. {
  1122. command.Connection = new OracleConnection(ConnectionStrings);
  1123. command.Connection.Open();
  1124. result = command.ExecuteNonQuery();
  1125. }
  1126. break;
  1127. case "UPDATE":
  1128. try
  1129. {
  1130. result = command.ExecuteNonQuery();
  1131. }
  1132. catch (Exception)
  1133. {
  1134. command.Connection = new OracleConnection(ConnectionStrings);
  1135. command.Connection.Open();
  1136. result = command.ExecuteNonQuery();
  1137. }
  1138. break;
  1139. case "INSERT":
  1140. try
  1141. {
  1142. result = command.ExecuteNonQuery();
  1143. }
  1144. catch (Exception)
  1145. {
  1146. command.Connection = new OracleConnection(ConnectionStrings);
  1147. command.Connection.Open();
  1148. result = command.ExecuteNonQuery();
  1149. }
  1150. break;
  1151. }
  1152. command.Dispose();
  1153. return result;
  1154. }
  1155. /// <summary>
  1156. /// 出现异常进行回滚的执行方法
  1157. /// </summary>
  1158. /// <param name="SQL"></param>
  1159. private void ExecuteSQLTran(params string[] SQL)
  1160. {
  1161. command = new OracleCommand();
  1162. command.Connection = new OracleConnection(ConnectionStrings);
  1163. command.Connection.Open();
  1164. Reconnect(command);
  1165. OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
  1166. command.Transaction = tx;
  1167. try
  1168. {
  1169. foreach (string sql in SQL)
  1170. {
  1171. if (!string.IsNullOrEmpty(sql))
  1172. {
  1173. command.CommandText = sql;
  1174. command.ExecuteNonQuery();
  1175. }
  1176. }
  1177. tx.Commit();
  1178. }
  1179. catch (OracleException E)
  1180. {
  1181. tx.Rollback();
  1182. throw new Exception(E.Message);
  1183. }
  1184. command.Dispose();
  1185. }
  1186. private string UpdateByCondition(string TableName, string update, string condition)
  1187. {
  1188. string sql = "update " + TableName + " set " + update + " where " + condition;
  1189. command = new OracleCommand(sql, connection);
  1190. Reconnect(command);
  1191. try
  1192. {
  1193. command.ExecuteNonQuery();
  1194. }
  1195. catch (Exception)
  1196. {
  1197. command.Connection = new OracleConnection(ConnectionStrings);
  1198. command.Connection.Open();
  1199. command.ExecuteNonQuery();
  1200. }
  1201. command.Dispose();
  1202. return sql;
  1203. }
  1204. private void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
  1205. {
  1206. command = new OracleCommand(ProcedureName);
  1207. command.Connection = connection;
  1208. Reconnect(command);
  1209. command.CommandText = ProcedureName;
  1210. command.CommandType = CommandType.StoredProcedure;
  1211. for (int i = 0; i < param.Length; i++)
  1212. {
  1213. command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1214. //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
  1215. }
  1216. try
  1217. {
  1218. command.ExecuteNonQuery();
  1219. }
  1220. catch (Exception)
  1221. {
  1222. command.Connection = new OracleConnection(ConnectionStrings);
  1223. command.Connection.Open();
  1224. command.ExecuteNonQuery();
  1225. }
  1226. for (int i = 0; i < command.Parameters.Count; i++)
  1227. param[i] = command.Parameters[i].Value.ToString();
  1228. command.Dispose();
  1229. }
  1230. private string AddField(string[] Fields)
  1231. {
  1232. string sql = " ";
  1233. foreach (string field in Fields)
  1234. {
  1235. sql += field + ",";
  1236. }
  1237. return sql.Substring(0, sql.Length - 1);
  1238. }
  1239. private string[] GetField(string field)
  1240. {
  1241. string[] fields = field.Split(',');
  1242. for (int i = 0; i < fields.Length; i++)
  1243. {
  1244. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1245. }
  1246. return fields;
  1247. }
  1248. private void Reconnect(OracleCommand cmd)
  1249. {
  1250. if (cmd.Connection.State == ConnectionState.Closed)
  1251. {
  1252. cmd.Connection.Open();
  1253. }
  1254. }
  1255. /// <summary>
  1256. /// 验证用户身份信息
  1257. /// </summary>
  1258. /// <param name="iUserCode"></param>
  1259. /// <param name="oErrorMessage"></param>
  1260. /// <returns></returns>
  1261. private bool CheckUserLogin(string iUserCode, string iPassWord, string Master, out string oErrorMessage)
  1262. {
  1263. oErrorMessage = "";
  1264. try
  1265. {
  1266. string url = "http://10.98.0.21:8099/mes/mobile/login.action";//html调用的地址
  1267. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
  1268. if (webrequest == null)
  1269. {
  1270. return false;
  1271. }
  1272. webrequest.Method = "POST";
  1273. webrequest.Timeout = 1000;
  1274. webrequest.ContentType = "application/x-www-form-urlencoded";
  1275. System.Collections.Hashtable pars = new System.Collections.Hashtable();
  1276. pars.Add("username", iUserCode);
  1277. pars.Add("password", iPassWord);
  1278. pars.Add("master", Master);
  1279. string buffer = "";
  1280. //发送POST数据
  1281. if (!(pars == null || pars.Count == 0))
  1282. {
  1283. foreach (string key in pars.Keys)
  1284. {
  1285. buffer = buffer + "&" + key + "=" + pars[key].ToString();
  1286. }
  1287. byte[] data = Encoding.UTF8.GetBytes(buffer);
  1288. using (Stream stream = webrequest.GetRequestStream())
  1289. {
  1290. stream.Write(data, 0, data.Length);
  1291. }
  1292. }
  1293. string[] values = webrequest.Headers.GetValues("Content-Type");
  1294. WebResponse myResponse = webrequest.GetResponse();
  1295. using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
  1296. {
  1297. StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
  1298. string Content = newReader.ReadToEnd();
  1299. Dictionary<string, object> dic = new Dictionary<string, object>();
  1300. dic = ToDictionary(Content);
  1301. if (!dic.ContainsKey("erpaccount"))
  1302. {
  1303. oErrorMessage = dic["reason"].ToString();
  1304. return false;
  1305. }
  1306. newReader.Close();
  1307. }
  1308. }
  1309. catch (Exception ex)
  1310. {
  1311. oErrorMessage = ex.Message.ToString();
  1312. return false;
  1313. }
  1314. return true;
  1315. }
  1316. private Dictionary<string, object> ToDictionary(string JsonData)
  1317. {
  1318. object Data = null;
  1319. Dictionary<string, object> Dic = new Dictionary<string, object>();
  1320. if (JsonData.StartsWith("["))
  1321. {
  1322. //如果目标直接就为数组类型,则将会直接输出一个Key为List的List<Dictionary<string, object>>集合
  1323. //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["List"];
  1324. List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
  1325. MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
  1326. foreach (Match ListItem in ListMatch)
  1327. {
  1328. List.Add(ToDictionary(ListItem.ToString()));//递归调用
  1329. }
  1330. Data = List;
  1331. Dic.Add("List", Data);
  1332. }
  1333. else
  1334. {
  1335. MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\]|null|"".+?""|-{0,1}\d*)");//使用正则表达式匹配出JSON数据中的键与值
  1336. foreach (Match item in Match)
  1337. {
  1338. try
  1339. {
  1340. if (item.Groups[2].ToString().StartsWith("["))
  1341. {
  1342. //如果目标是数组,将会输出一个Key为当前Json的List<Dictionary<string, object>>集合
  1343. //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["Json中的Key"];
  1344. List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
  1345. MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
  1346. foreach (Match ListItem in ListMatch)
  1347. {
  1348. List.Add(ToDictionary(ListItem.ToString()));//递归调用
  1349. }
  1350. Data = List;
  1351. }
  1352. else if (item.Groups[2].ToString().ToLower() == "null") Data = null;//如果数据为null(字符串类型),直接转换成null
  1353. else Data = item.Groups[2].ToString(); //数据为数字、字符串中的一类,直接写入
  1354. Dic.Add(item.Groups[1].ToString(), Data);
  1355. }
  1356. catch { }
  1357. }
  1358. }
  1359. return Dic;
  1360. }
  1361. }
  1362. }