GMethod.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using SufeiUtil;
  4. using SXLibrary;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data.SQLite;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.CompilerServices;
  11. using System.Security.Policy;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace MOKA_Factory_Tools
  16. {
  17. internal class GMethod
  18. {
  19. private static MaInfo s_maInfo = null;
  20. private static string strLastOrder = "";
  21. private static string strOrderKind = ""; // 试产 or 量产;
  22. private static Dictionary<string, string> LastKaylaOrderInfo = new Dictionary<string, string>();
  23. private static string url_MaInfo = "http://smes-prd-app01.tclking.com:9002/SAPService.asmx";
  24. private static string url_ReportKey = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/RecordKey";
  25. private static string url_getOrderProductStatus = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/getOrderProductStatus?sn=";
  26. private static string url_getMainBoardPSNWithSN = "http://smes-app-prod.tclking.com:9006/api/xm/GetXMTVParts?TVSN=";
  27. private static string url_getTVInfo = "http://smes-app-prod.tclking.com:9006/api/PE/GetTVInfo?sn=";
  28. public static void SetMexicanConfig(bool bMexican=false)
  29. {
  30. if (bMexican)
  31. {
  32. url_MaInfo = "http://SMES.TMSA.MX:9002/SAPService.asmx";
  33. url_ReportKey = "http://SMES.TMSA.MX/FireTVApi/api/SMESMX/RecordKey";
  34. url_getOrderProductStatus = "http://SMES.TMSA.MX/FireTVApi/api/SMESMX/getOrderProductStatus?sn=";
  35. url_getTVInfo = "http://SMES.TMSA.MX:9006/api/PE/GetTVInfo?sn=";
  36. }
  37. }
  38. public static bool GetMaInfo(string sn, string order, out MaInfo maInfo, SQLiteConnection errorDBNow)
  39. {
  40. if (GetMaInfoBySAP(sn, order, out maInfo, errorDBNow))
  41. {
  42. return true;
  43. }
  44. return GetMaInfoByMES(sn, order, out maInfo, errorDBNow);
  45. }
  46. public static bool GetMaInfoByMES(string sn, string order, out MaInfo maInfo, SQLiteConnection errorDBNow)
  47. {
  48. maInfo = null;
  49. if (s_maInfo != null && s_maInfo.ODF.Equals(order, StringComparison.InvariantCultureIgnoreCase))
  50. {
  51. maInfo = s_maInfo;
  52. return true;
  53. }
  54. HttpHelper http = new HttpHelper();
  55. HttpItem item = new HttpItem()
  56. {
  57. URL = url_getTVInfo + sn,
  58. Encoding = Encoding.UTF8,
  59. Method = "get",
  60. PostEncoding = Encoding.UTF8,
  61. KeepAlive = false
  62. };
  63. item.ContentType = "application/x-www-form-urlencoded";
  64. HttpResult hResult = http.GetHtml(item);
  65. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  66. {
  67. try
  68. {
  69. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  70. {
  71. JObject jObject = (JObject)JToken.ReadFrom(reader);
  72. reader.Close();
  73. maInfo.ODF = jObject["ODF"].Value<string>();
  74. maInfo.BOM = jObject["ProductCode"].Value<string>();
  75. maInfo.Model = jObject["ProductName"].Value<string>().Split('/')[1];
  76. maInfo.SIZE = maInfo.Model.Substring(0, 3);
  77. Log.WriteInfoLog("GetMaInfoByMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  78. s_maInfo = maInfo;
  79. return true;
  80. }
  81. }
  82. catch (Exception)
  83. {
  84. Log.WriteErrorLog("GetMaInfoByMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  85. }
  86. }
  87. else
  88. {
  89. Log.WriteInfoLog("GetMaInfoByMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  90. }
  91. return false;
  92. }
  93. public static bool GetMaInfoBySAP(string sn, string order, out MaInfo maInfo, SQLiteConnection errorDBNow)
  94. {
  95. string desc;
  96. maInfo = null;
  97. if (s_maInfo != null && s_maInfo.ODF.Equals(order, StringComparison.InvariantCultureIgnoreCase) )
  98. {
  99. maInfo = s_maInfo;
  100. return true;
  101. }
  102. string strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  103. "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
  104. "<soap:Body>" +
  105. "<GetMaInfo xmlns=\"http://tempuri.org/\">" +
  106. "<sn>" + sn + "</sn>" +
  107. "</GetMaInfo>" +
  108. "</soap:Body>" +
  109. "</soap:Envelope>";
  110. HttpHelper http = new HttpHelper();
  111. HttpItem item = new HttpItem()
  112. {
  113. Encoding = Encoding.UTF8,
  114. Method = "post",
  115. ContentType = "text/xml",
  116. KeepAlive = false
  117. };
  118. item.URL = url_MaInfo;
  119. item.Postdata = strPost;
  120. HttpResult result = http.GetHtml(item);
  121. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  122. {
  123. Log.WriteGetKeyLog("\r\nGetMaInfo :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  124. if (!Xmlconfig.GetMaInfoXml(result.Html, out maInfo, out desc))
  125. {
  126. Log.WriteGetKeyLog("GetMaInfo error:" + desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  127. return false;
  128. }
  129. }
  130. else
  131. {
  132. Log.WriteGetKeyLog("GetMaInfo error:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  133. return false;
  134. }
  135. s_maInfo = maInfo;
  136. return true;
  137. }
  138. /// <summary>
  139. /// 上报数据抄写结果到MES系统中;
  140. /// </summary>
  141. /// <param name="fsn"></param>
  142. /// <param name="dsn"></param>
  143. /// <param name="dateTime">抄写时间</param>
  144. /// <param name="result">抄写结果</param>
  145. /// <param name="msg">如果上报失败,此参数为失败的描述信息</param>
  146. /// <returns></returns>
  147. public static bool ReportDataBurningResultToMES(string fsn, string dsn, string result, string dateTime, SQLiteConnection errorDBNow, out string msg, out string returnObject)
  148. {
  149. msg = "";
  150. returnObject = "";
  151. string strPost = string.Format("{{\"FSN\":\"{0}\",\"DSN\":\"{1}\",\"DataCopy\":\"{2}\",\"UPDATETIME\":\"{3}\"}}", fsn, dsn, result, dateTime);
  152. HttpHelper http = new HttpHelper();
  153. HttpItem item = new HttpItem()
  154. {
  155. Encoding = Encoding.UTF8,
  156. Method = "post",
  157. ContentType = "application/json",
  158. KeepAlive = false
  159. };
  160. // 测试地址;
  161. item.URL = url_ReportKey;
  162. item.Postdata = strPost;
  163. HttpResult hResult = http.GetHtml(item);
  164. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  165. {
  166. try
  167. {
  168. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  169. {
  170. JObject jObject = (JObject)JToken.ReadFrom(reader);
  171. reader.Close();
  172. bool bResult = jObject["Result"].Value<bool>();
  173. msg = jObject["EroMsg"].Value<string>();
  174. if (jObject["returnObject"] != null)
  175. returnObject = jObject["returnObject"].ToString();
  176. Log.WriteInfoLog("nReportDataBurningResultToMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  177. return bResult;
  178. }
  179. }
  180. catch (Exception e)
  181. {
  182. msg = e.Message;
  183. Log.WriteErrorLog("ReportDataBurningResultToMES Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  184. }
  185. }
  186. else
  187. {
  188. msg = hResult.StatusDescription;
  189. Log.WriteInfoLog("ReportDataBurningResultToMES Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  190. }
  191. // 没有进行数据库查重:惹数据已添加过,同一次FSN抄写多次失败后导致多条记录。
  192. SQLiteHelper.InsertDelayErrorReport(errorDBNow, new object[] { item.URL, item.Postdata });
  193. return false;
  194. }
  195. /// <summary>
  196. /// 上传本地数据库失败的日志,重新上传;
  197. /// </summary>
  198. /// <param name="url"></param>
  199. /// <param name="strPost"></param>
  200. /// <param name="mark"></param>
  201. /// <returns></returns>
  202. public static bool ReportDataBurningResultToMES(string url, string strPost, out bool mark)
  203. {
  204. // 表示是否上传成功;
  205. mark = false;
  206. HttpHelper http = new HttpHelper();
  207. HttpItem item = new HttpItem()
  208. {
  209. Encoding = Encoding.UTF8,
  210. Method = "post",
  211. ContentType = "application/json",
  212. KeepAlive = false
  213. };
  214. item.URL = url;
  215. item.Postdata = strPost;
  216. HttpResult hResult = http.GetHtml(item);
  217. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  218. {
  219. try
  220. {
  221. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  222. {
  223. JObject jObject = (JObject)JToken.ReadFrom(reader);
  224. reader.Close();
  225. mark = jObject["Result"].Value<bool>();
  226. Log.WriteInfoLog("nReportDataBurningResultToMES:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  227. return true;
  228. }
  229. }
  230. catch (Exception)
  231. {
  232. Log.WriteErrorLog("ReportDataBurningResultToMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  233. return false;
  234. }
  235. }
  236. else
  237. {
  238. Log.WriteInfoLog("ReportDataBurningResultToMES error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  239. }
  240. return false;
  241. }
  242. /// <summary>
  243. /// 通过SN获取订单类型
  244. /// </summary>
  245. /// <param name="sn"></param>
  246. /// <returns></returns>
  247. public static bool GetOrderTypeFromSN(string sn, string order, out string result, out string msg)
  248. {
  249. msg = "";
  250. result = "";
  251. if (order.Equals(strLastOrder, StringComparison.OrdinalIgnoreCase))
  252. {
  253. if (strOrderKind.Equals("量产") || strOrderKind.Equals("试产"))
  254. {
  255. result = strOrderKind;
  256. return true;
  257. }
  258. }
  259. HttpHelper http = new HttpHelper();
  260. HttpItem item = new HttpItem()
  261. {
  262. Encoding = Encoding.UTF8,
  263. Method = "post",
  264. ContentType = "application/x-www-form-urlencoded",
  265. KeepAlive = false
  266. };
  267. // 测试地址;
  268. item.URL = url_getOrderProductStatus + sn;
  269. HttpResult hResult = http.GetHtml(item);
  270. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  271. {
  272. try
  273. {
  274. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  275. {
  276. JObject jObject = (JObject)JToken.ReadFrom(reader);
  277. reader.Close();
  278. bool bResult = jObject["Result"].Value<bool>();
  279. msg = jObject["EroMsg"].Value<string>();
  280. string returnObject = jObject["returnObject"].ToString();
  281. if (bResult)
  282. {
  283. if (returnObject.Contains("量产"))
  284. result = "量产";
  285. else if (returnObject.Contains("试产"))
  286. result = "试产";
  287. else
  288. result = "错误返回";
  289. strOrderKind = result;
  290. Log.WriteInfoLog("\r\nIsCuringBOM :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + hResult.Html);
  291. return true;
  292. }
  293. Log.WriteInfoLog("IsCuringBOM error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  294. }
  295. }
  296. catch (Exception e)
  297. {
  298. msg = e.Message;
  299. Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  300. }
  301. }
  302. else
  303. {
  304. msg = hResult.StatusDescription;
  305. Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  306. }
  307. strOrderKind = "";
  308. return false;
  309. }
  310. /// <summary>
  311. // Section1:本机信息;
  312. // Section2:SMES信息;
  313. // Section3:实际抄写Key信息;
  314. /// </summary>
  315. /// <param name="Line"></param>
  316. /// <param name="Station"></param>
  317. /// <param name="order"></param>
  318. /// <param name="sn"></param>
  319. /// <param name="StartTime"></param>
  320. /// <param name="EndOfTime"></param>
  321. /// <param name="returnObject"></param>
  322. /// <param name="key"></param>
  323. /// <param name="result"></param>
  324. /// <returns></returns>
  325. public static bool GeneratKaylaData(string Line, string Station, string order, string sn, DateTime StartTime, DateTime EndOfTime, string returnObject, KeyInfo key, bool result)
  326. {
  327. Dictionary<string, string> localInfo = new Dictionary<string, string>();
  328. // 本机信息;
  329. localInfo.Add("Item", "Value");
  330. localInfo.Add("factory_id_I", "TCL");
  331. localInfo.Add("operator_I", Line);
  332. localInfo.Add("station_I", Station);
  333. localInfo.Add("fixture_id_I", "1_1");
  334. localInfo.Add("gui_ver_I", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
  335. localInfo.Add("route_check_I", "1");
  336. // SMES信息;
  337. string strLastOrder = CommonMethod.ReadProfileString("MOKAFactoryTools", "LastOrder", "");
  338. if (!strLastOrder.Equals(order, StringComparison.OrdinalIgnoreCase))
  339. {
  340. // 请求新的订单信息;
  341. MaInfo maInfo;
  342. if (!GetMaInfo(sn, order, out maInfo, null))
  343. {
  344. Log.WriteErrorLog("Kayla GetMaInfo失败");
  345. return false;
  346. }
  347. LastKaylaOrderInfo = new Dictionary<string, string>();
  348. if (maInfo != null)
  349. {
  350. LastKaylaOrderInfo.Add("project_name_I", maInfo.project_name_I);
  351. LastKaylaOrderInfo.Add("build_I", maInfo.build_I);
  352. LastKaylaOrderInfo.Add("build_config_I", maInfo.build_config_I);
  353. LastKaylaOrderInfo.Add("diag_ver_I", maInfo.diag_ver_I);
  354. LastKaylaOrderInfo.Add("image_name_ver_I", maInfo.image_name_ver_I);
  355. LastKaylaOrderInfo.Add("soc_type", maInfo.soc_type);
  356. LastKaylaOrderInfo.Add("speaker_vender", maInfo.speaker_vender);
  357. LastKaylaOrderInfo.Add("mic_vender", maInfo.mic_vender);
  358. }
  359. }
  360. Dictionary<string, string> dic = localInfo.Union(LastKaylaOrderInfo).ToDictionary(k => k.Key, v => v.Value);
  361. dic.Add("start_time_I", StartTime.ToString());
  362. dic.Add("serial_id_I", key != null ? key.DSN : ""); // DSN;
  363. dic.Add("FSN", sn);
  364. // 耐压值;
  365. if (returnObject != null && returnObject.Length > 0 && returnObject.Contains("Hightpot"))
  366. {
  367. Log.WriteInfoLog(String.Format("returnObjec={0}", returnObject));
  368. // 删除头尾[];
  369. returnObject = returnObject.Remove(0, 1);
  370. returnObject = returnObject.Remove(returnObject.Length - 1, 1);
  371. JObject jObject = JObject.Parse(returnObject);
  372. string hightpot = CommonMethod.JSON_SeleteNode(jObject, "Hightpot");
  373. int pos = hightpot.LastIndexOf('/');
  374. if (pos != -1)
  375. {
  376. hightpot = hightpot.Substring(pos + 1);
  377. pos = hightpot.IndexOf("mA");
  378. // 使用正规去除数字+小数点以外的字符;
  379. string AC = hightpot.Substring(0, pos + 2);
  380. string DC = hightpot.Substring(pos + 2);
  381. AC = System.Text.RegularExpressions.Regex.Replace(AC, @"[^\d.]*", "");
  382. DC = System.Text.RegularExpressions.Regex.Replace(DC, @"[^\d.]*", "");
  383. dic.Add("AC_I", AC);
  384. dic.Add("DC_R", DC);
  385. }
  386. else
  387. {
  388. dic.Add("AC_I", "");
  389. dic.Add("DC_R", "");
  390. }
  391. }
  392. else
  393. {
  394. dic.Add("AC_I", "");
  395. dic.Add("DC_R", "");
  396. Log.WriteErrorLog("获取耐压值结果为空");
  397. }
  398. if (key != null)
  399. {
  400. if (key.DID.enable)
  401. {
  402. dic.Add("DID", key.DID); // 本身就是字符串;
  403. dic.Add("DID_check", key.DID.result ? "PASS" : "FAIL");
  404. }
  405. if (key.Mac.enable)
  406. {
  407. dic.Add("Mac", key.Mac);//keyInfo.Mac.data.Replace("-", ":");
  408. dic.Add("Mac_check", key.Mac.result ? "PASS" : "FAIL");
  409. }
  410. if (key.HDCP.enable)
  411. {
  412. dic.Add("HDCP", key.HDCP);
  413. dic.Add("HDCP_check", key.HDCP.result ? "PASS" : "FAIL");
  414. }
  415. if (key.HDCP22.enable)
  416. {
  417. dic.Add("HDCP22", key.HDCP22);
  418. dic.Add("HDCP22_check", key.HDCP22.result ? "PASS" : "FAIL");
  419. }
  420. if (key.ESN.enable)
  421. {
  422. dic.Add("ESN", key.ESN);
  423. dic.Add("ESN_check", key.ESN.result ? "PASS" : "FAIL");
  424. }
  425. if (key.Widevine.enable)
  426. {
  427. dic.Add("Widevine", key.Widevine);
  428. dic.Add("Widevine_check", key.Widevine.result ? "PASS" : "FAIL");
  429. }
  430. if (key.CI_plus.enable)
  431. {
  432. dic.Add("CI_plus", key.CI_plus);
  433. dic.Add("CI_plus_check", key.CI_plus.result ? "PASS" : "FAIL");
  434. }
  435. if (key.Attestation.enable)
  436. {
  437. dic.Add("Attestation", key.Attestation);
  438. dic.Add("Attestation_check", key.Attestation.result ? "PASS" : "FAIL");
  439. }
  440. if (key.MGK.enable)
  441. {
  442. dic.Add("MGK", key.MGK);
  443. dic.Add("MGK_check", key.MGK.result ? "PASS" : "FAIL");
  444. }
  445. if (key.Fairplay.enable)
  446. {
  447. dic.Add("Fairplay", key.Fairplay);
  448. dic.Add("Fairplay_check", key.Fairplay.result ? "PASS" : "FAIL");
  449. }
  450. if (key.DSN.enable)
  451. {
  452. dic.Add("DSN", key.DSN);
  453. dic.Add("DSN_check", key.DSN.result ? "PASS" : "FAIL");
  454. }
  455. if (key.WiFi_MAC.enable)
  456. {
  457. dic.Add("WiFi_MAC", key.WiFi_MAC);
  458. dic.Add("WiFi_MAC_check", key.WiFi_MAC.result ? "PASS" : "FAIL");
  459. }
  460. if (key.BT_MAC.enable)
  461. {
  462. dic.Add("BT_MAC", key.BT_MAC);
  463. dic.Add("BT_MAC_check", key.BT_MAC.result ? "PASS" : "FAIL");
  464. }
  465. if (key.LEK.enable)
  466. {
  467. dic.Add("LEK", key.LEK);
  468. dic.Add("LEK_check", key.LEK.result ? "PASS" : "FAIL");
  469. }
  470. if (key.PEK.enable)
  471. {
  472. dic.Add("PEK", key.PEK);
  473. dic.Add("PEK_check", key.PEK.result ? "PASS" : "FAIL");
  474. }
  475. if (key.Playready.enable)
  476. {
  477. dic.Add("Playready", key.Playready);
  478. dic.Add("Playready_check", key.Playready.result ? "PASS" : "FAIL");
  479. }
  480. if (key.Hashkey.enable)
  481. {
  482. dic.Add("Hashkey", key.Hashkey);
  483. dic.Add("Hashkey_check", key.Hashkey.result ? "PASS" : "FAIL");
  484. }
  485. if (key.ECP.enable)
  486. {
  487. dic.Add("ECP", key.ECP);
  488. dic.Add("ECP_check", key.ECP.result ? "PASS" : "FAIL");
  489. }
  490. if (key.YouTube_KEY.enable)
  491. {
  492. dic.Add("YouTube_KEY", key.YouTube_KEY);
  493. dic.Add("YouTube_KEY_check", key.YouTube_KEY.result ? "PASS" : "FAIL");
  494. }
  495. if ( key.FVP.enable )
  496. {
  497. dic.Add("FVP_set", key.FVP.data);
  498. dic.Add("FVP_check", key.FVP.result ? "PASS" : "FAIL");
  499. }
  500. }
  501. dic.Add("cycle_time_I", EndOfTime.Subtract(StartTime).Seconds.ToString());
  502. dic.Add("test_result_I", result ? "PASS" : "FAIL");
  503. try
  504. {
  505. // 以DSN命名文件;
  506. if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Kayla"))
  507. {
  508. Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Kayla");
  509. }
  510. string savefile = string.Format("{0}Kayla\\{1}.csv", AppDomain.CurrentDomain.BaseDirectory, sn);
  511. Log.WriteInfoLog(string.Format("Kayla: sn={0}, savefile={1}", sn, savefile));
  512. using (System.IO.StreamWriter file = new System.IO.StreamWriter(savefile, false))
  513. {
  514. foreach (KeyValuePair<string, string> kvp in dic)
  515. {
  516. file.WriteLine(string.Format("{0},{1}", kvp.Key, kvp.Value));
  517. }
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. Log.WriteErrorLog(string.Format("保存csv文件失败:{0}", ex.ToString()));
  523. return false;
  524. }
  525. CommonMethod.StartProcess(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "tcp_send.exe", sn);
  526. return true;
  527. }
  528. // 根据FSN获取服务器上与之绑定的PSN值;
  529. // 这个函数在哪里调用,被谁调用;
  530. // 成功怎么处理;失败怎么处理;
  531. public static bool GetMainBoardPSNWithSN(string FSN, out string PSN)
  532. {
  533. string msg;
  534. PSN = "";
  535. HttpHelper http = new HttpHelper();
  536. HttpItem item = new HttpItem()
  537. {
  538. Encoding = Encoding.UTF8,
  539. Method = "post",
  540. ContentType = "application/x-www-form-urlencoded",
  541. KeepAlive = false
  542. };
  543. item.URL = url_getMainBoardPSNWithSN + FSN;
  544. HttpResult hResult = http.GetHtml(item);
  545. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  546. {
  547. try
  548. {
  549. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  550. {
  551. JObject jObject = (JObject)JToken.ReadFrom(reader);
  552. reader.Close();
  553. foreach (var ss in jObject["Tvparts"]) //查找某个字段与值
  554. {
  555. //如果里面的TypeCode为MA(主板),读出他的PSN
  556. if (ss["PartTypeCode"].Value<string>().Equals("MA", StringComparison.OrdinalIgnoreCase))
  557. {
  558. PSN = ss["PartSN"].Value<string>();
  559. }
  560. }
  561. if (PSN == "" || PSN == null)
  562. {
  563. MessageBox.Show("查不到该FSN对应的主板PSN号");
  564. return false;
  565. }
  566. Log.WriteInfoLog("PartSN" + PSN);
  567. return true;
  568. }
  569. }
  570. catch (Exception e)
  571. {
  572. msg = e.Message;
  573. Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  574. }
  575. }
  576. else
  577. {
  578. msg = hResult.StatusDescription;
  579. Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  580. }
  581. return false;
  582. }
  583. }
  584. }