ソースを参照

新增G客户抄写过程需要对PSN校验是否正确

chenjiangqun 2 年 前
コミット
ccf1772456

+ 61 - 0
FactoryTool_CShare/Business/GMethod.cs

@@ -9,6 +9,7 @@ using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Forms;
 
 namespace MOKA_Factory_Tools
 {
@@ -22,6 +23,7 @@ namespace MOKA_Factory_Tools
         private static string url_MaInfo = "http://smes-prd-app01.tclking.com:9002/SAPService.asmx";
         private static string url_ReportKey = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/RecordKey";
         private static string url_getOrderProductStatus = "http://smes-app-prod.tclking.com/FireTVApi/api/SMES/getOrderProductStatus?sn=";
+        private static string url_getMainBoardPSNWithSN = "http://smes-app-prod.tclking.com:9006/api/xm/GetXMTVParts?TVSN=";
 
         public static void SetMexicanConfig(bool bMexican=false)
         {
@@ -524,5 +526,64 @@ namespace MOKA_Factory_Tools
             return true;
         }
 
+        // 根据FSN获取服务器上与之绑定的PSN值;
+        // 这个函数在哪里调用,被谁调用;
+        // 成功怎么处理;失败怎么处理;
+        public static bool GetMainBoardPSNWithSN(string FSN, out string PSN)
+        {
+            string msg;
+            PSN = "";
+
+            HttpHelper http = new HttpHelper();
+            HttpItem item = new HttpItem()
+            {
+                Encoding = Encoding.UTF8,
+                Method = "post",
+                ContentType = "application/x-www-form-urlencoded",
+                KeepAlive = false
+            };
+            item.URL = url_getMainBoardPSNWithSN + FSN;
+            HttpResult hResult = http.GetHtml(item);
+            if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
+            {
+                try
+                {
+                    using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
+                    {
+                        JObject jObject = (JObject)JToken.ReadFrom(reader);
+                        reader.Close();
+
+                        foreach (var ss in jObject["Tvparts"])  //查找某个字段与值
+                        {
+                            //如果里面的TypeCode为MA(主板),读出他的PSN                  
+                            if (ss["PartTypeCode"].Value<string>().Equals("MA", StringComparison.OrdinalIgnoreCase))
+                            {
+                                PSN = ss["PartSN"].Value<string>();
+                            }
+                        }
+                        if (PSN == "" || PSN == null)
+                        {
+                            MessageBox.Show("查不到该FSN对应的主板PSN号");
+                            return false;
+                        }
+                        Log.WriteInfoLog("PartSN" + PSN);
+                        return true;
+                    }
+                }
+                catch (Exception e)
+                {
+                    msg = e.Message;
+                    Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
+                }
+            }
+            else
+            {
+                msg = hResult.StatusDescription;
+                Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
+            }
+            return false;
+
+        }
+
     }
 }

+ 20 - 1
FactoryTool_CShare/Views/OperationPanel.cs

@@ -1826,6 +1826,8 @@ namespace MOKA_Factory_Tools
             string ErrMsg = "";
             string psn = "";
             string devicecode = "";
+            //PSN
+            string GetPSNInFsn;
 #if !SIMULATION && !OD_VER
             //进工厂
             if (!TVPort.IsOpen)
@@ -2304,7 +2306,24 @@ namespace MOKA_Factory_Tools
                         // 读取psn的值;
                         if (SerialCMD.ReadFireTVPSN(TVPort, out result, out data, out error, SerailDelay))
                         {
-                            psn = keyInfo._PSN.data = Encoding.ASCII.GetString(data);
+                            psn = keyInfo._PSN.data = Encoding.ASCII.GetString(data);                      
+                            // 通过http获取对应fsn的psn值;
+                            if (GMethod.GetMainBoardPSNWithSN(SN, out GetPSNInFsn))
+                            {
+                                if (GetPSNInFsn != psn)
+                                {
+                                    ErrMsg = string.Format("{0} Read PSN Alignment Is Different ", SN);
+                                    Log.WriteErrorLog(ErrMsg);
+                                    goto end;
+                                }
+                            }
+                            else
+                            {
+                                ErrMsg = string.Format("{0} GetMainBoardPSNWithSN Error", SN);
+                                Log.WriteErrorLog(ErrMsg);
+                                goto end;
+                            }
+
                         }
                         else
                         {