MesHelper.cs 65 KB

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