From 980b78709fef23248956382fe72571e431c4d289 Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期二, 06 一月 2026 10:46:05 +0800
Subject: [PATCH] 单品过站同步插件增加打印生产质量汇报单单号日志

---
 WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs |  647 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 491 insertions(+), 156 deletions(-)

diff --git a/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs b/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs
index 1767412..549b2e0 100644
--- a/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs
+++ b/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs
@@ -33,20 +33,27 @@
             this.btnSave.Enabled = false;
             this.txtHMaterNumber.ReadOnly = true;
             //this.btnRest.Enabled = false;
+            //鍒跺崟缂栫爜鍙
+            this.txtHMakerNumber.ReadOnly = true;
+            //鍒跺崟浜烘彁绀�
+            this.txtHMaker.ForeColor = Color.LightGray;
+            this.txtHMaker.Text = "璇疯緭鍏ョ敤鎴风紪鐮�!";
+
             bindCbox();
-          
+
         }
 
-        private  void btnBegin_Click(object sender, EventArgs e)
+        private void btnBegin_Click(object sender, EventArgs e)
         {
             if (this.txtHBathNo.Text == "" || this.txtHBathNo.ReadOnly == false)
+            //if (false)
             {
                 MessageBox.Show("璇疯緭鍏ユ壒娆″彿杩涜纭!");
             }
             else
             {
                 this.txtBegin.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-                //this.txtBegin.Text = "2024-09-06 10:52:39";
+                //this.txtBegin.Text = "2024-11-21 13:40:27";
                 this.btnBegin.Enabled = false;
                 if (cmbEquipFile.SelectedIndex == 1)
                 {
@@ -65,7 +72,7 @@
             else
             {
                 this.txtEnd.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-                //this.txtEnd.Text = "2024-09-06 11:20:39";
+                //this.txtEnd.Text = "2024-09-24 09:52:39";
                 this.btnEnd.Enabled = false;
 
                 if (cmbEquipFile.SelectedIndex == 1)
@@ -112,7 +119,7 @@
                                     ",鏈夋棤铻虹墮妫�娴嬬粨鏋�:" + dt.Rows[i]["DetectionResult"].ToString() +
                                 ",鏃堕棿:" + dt.Rows[i]["HDate"].ToString());
                             }
-                           
+
                         }
                     }
                 }
@@ -168,7 +175,8 @@
                     for (int j = 0; j < 2; j++)
                     {
                         DateTime Now = DateTime.Parse(dt2.Rows[i][dt2.Columns[6]].ToString() + " " + dt2.Rows[i][dt2.Columns[7]].ToString());
-                        if (Now >= HBegin && Now <= HEnd) {
+                        if (Now >= HBegin && Now <= HEnd)
+                        {
                             DataRow dr = dt.NewRow();
                             dr["BottomHoleDiameter"] = dt2.Rows[i][dt2.Columns[j]].ToString();
                             dr["TestingData"] = dt2.Rows[i][dt2.Columns[j + 2]].ToString();
@@ -200,13 +208,22 @@
         {
             if (e.KeyCode == Keys.Enter)
             {
+                if (this.txtHMakerNumber.Text == "")
+                {
+                    MessageBox.Show("璇疯緭鍏ュ埗鍗曚汉淇℃伅!");
+                }
+                else
+                {
+                    Get_DisplayBard();
+                }
                 //this.txtHBathNo.ReadOnly = true;
-                Get_DisplayBard();
+
             }
         }
 
         //鏌ヨ鏉$爜鏁版嵁
-        public void Get_DisplayBard() {
+        public void Get_DisplayBard()
+        {
             string HBarCode = this.txtHBathNo.Text;
             DataSet ds = oCN.RunProcReturn("select HBatchNo,m.HNumber,a.HMaterID from Gy_BarCodeBill a left join Gy_Material m on a.HMaterID = m.HItemID where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill");
 
@@ -214,7 +231,8 @@
             {
                 MessageBox.Show("鏉$爜鏌ユ棤鏁版嵁!");
             }
-            else {
+            else
+            {
                 this.txtHBathNo.Text = ds.Tables[0].Rows[0]["HBatchNo"].ToString();
                 this.txtHMaterNumber.Text = ds.Tables[0].Rows[0]["HNumber"].ToString();
                 this.HMaterID.Text = ds.Tables[0].Rows[0]["HMaterID"].ToString();
@@ -248,9 +266,11 @@
         {
             DialogResult dr = MessageBox.Show("纭淇濆瓨?", "鎻愮ず", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
 
-            if (dr == DialogResult.Yes) {
+            if (dr == DialogResult.Yes)
+            {
 
                 string Url = DBHelper.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sUrl");
+                //閫氳繃鎺ュ彛 鑾峰彇token
                 JsonResult jsonResult = await FindAccessToken(Url);
 
                 string EquipFile = this.cmbEquipFile.Text;
@@ -272,11 +292,13 @@
         }
 
         //铻烘瘝鍏ㄦ淇濆瓨
-        public async void SaveFullInspectionOfNuts(string token,string url) {
+        public async void SaveFullInspectionOfNuts(string token, string url)
+        {
             try
             {
-               
-                JsonEquipmentData jsonResult =await FindDeviceList(url, token);
+
+                //鑾峰彇鎵�鏈夎澶囨暟鎹�
+                JsonEquipmentData jsonResult = await FindDeviceList(url, token);
 
                 if (jsonResult.code != "0")
                 {
@@ -286,7 +308,7 @@
                 else
                 {
                     string nos = "";
-                    //鑾峰彇鍘昏澶囩紪鐮�
+                    //鑾峰彇璁惧缂栫爜
                     for (int i = 0; i < jsonResult.data.Count; i++)
                     {
                         if (jsonResult.data[i].no == this.cmbEquipFile.SelectedValue.ToString())
@@ -294,15 +316,19 @@
                             nos = jsonResult.data[i].no;
                         }
                     }
+                    //寮�濮嬫椂闂�
                     string HBegin = this.txtBegin.Text;
+                    //缁撴潫鏃堕棿
                     string HEnd = this.txtEnd.Text;
+                    //鑾峰彇涓嶈壇鏁帮紝鍚堟暟鏁帮紝鍙枒鏁� 鎬绘暟
                     jsonResult = await FindDevicePropCalc(url, token, nos, HBegin, HEnd);
                     if (jsonResult.code != "0")
                     {
                         this.btnSave.Enabled = true;
                         MessageBox.Show("鏁伴噺鑾峰彇鎶ラ敊:" + jsonResult.message);
                     }
-                    else {
+                    else
+                    {
                         double HInSpectQty = 0;//妫�楠屾暟閲�
                         double HRightQty = 0;//鍚堟牸
                         double HUnRightQty = 0;//涓嶅悎鏍�
@@ -310,15 +336,15 @@
 
                         for (int i = 0; i < jsonResult.data.Count; i++)
                         {
-                            if (jsonResult.data[i].propId == 467)
+                            if (jsonResult.data[i].propId == 173)
                             {
-                                HInSpectQty = jsonResult.data[i].sum;
+                                //HInSpectQty = jsonResult.data[i].sum;
                             }
                             else if (jsonResult.data[i].propId == 469)
                             {
                                 HRightQty = jsonResult.data[i].sum;
                             }
-                            else if (jsonResult.data[i].propId == 466)
+                            else if (jsonResult.data[i].propId == 606)
                             {
                                 HUnKnowQty = jsonResult.data[i].sum;
                             }
@@ -327,8 +353,10 @@
                                 HUnRightQty = jsonResult.data[i].sum;
                             }
                         }
+                        //閫氳繃鍙屾柟璁ㄨ 鏈�缁堥噰绾� 妫�楠屾暟閲�=鍚堟牸+涓嶅悎鏍�+鍙枒
+                        HInSpectQty = HRightQty + HUnKnowQty + HUnRightQty;
 
-                      
+
                         string HNumber = "";
                         int HSourceID = 0;
                         string HSourceNumber = "";
@@ -352,7 +380,8 @@
                             this.btnSave.Enabled = true;
                             MessageBox.Show("鐢熶骇璧勬簮鏌ユ棤鏁版嵁!");
                         }
-                        else {
+                        else
+                        {
 
                             HSourceID = int.Parse(dsSouce.Tables[0].Rows[0]["HItemID"].ToString());
 
@@ -389,9 +418,12 @@
                                         decimal HUpLimit = 0;
                                         decimal HDownLimit = 0;
 
+                                        //鍒嗘瀽鏂规硶 涓哄畾閲忓垎鏋�
                                         if (HAnalysisMethod == "2")
                                         {
+                                            //鑾峰彇涓婇檺
                                             HUpLimit = decimal.Parse(dataSet.Tables[0].Rows[i]["HTargetVal"].ToString()) + decimal.Parse(dataSet.Tables[0].Rows[i]["HUpLimit"].ToString());
+                                            //鑾峰彇涓嬮檺
                                             HDownLimit = decimal.Parse(dataSet.Tables[0].Rows[i]["HTargetVal"].ToString()) + decimal.Parse(dataSet.Tables[0].Rows[i]["HDownLimit"].ToString());
                                         }
 
@@ -413,16 +445,19 @@
                                                     break;
                                             }
                                             //SRM@101.2@VEN00005@CGDD000167@1.02.002.002@20231129@1000
+                                            //鍒ゆ柇妫�楠岄」鐩殑浠g爜 璺熷垪鍚嶆槸鍚︿竴鑷�
                                             if (dataSet.Tables[0].Rows[i]["HQCCheckItemNumber"].ToString().Contains(HQCCheckItemName))
                                             {
                                                 for (int k = 0; k < dt.Rows.Count; k++)
                                                 {
-
+                                                    //鍙彇鏃堕棿鑼冨洿鍐呯殑鏁版嵁
                                                     if (DateTime.Parse(dt.Rows[k]["HDate"].ToString()) >= DateTime.Parse(HBegin) && DateTime.Parse(dt.Rows[k]["HDate"].ToString()) <= DateTime.Parse(HEnd))
                                                     {
+                                                        //鑾峰彇妫�楠屽��
                                                         decimal HInSpectValue = decimal.Parse(dt.Rows[k][dt.Columns[j].ColumnName].ToString());
-
+                                                        //榛樿鍊肩粨璁轰负鍚堟牸
                                                         int HInSpectResult = 1;
+                                                        //瀹氶噺鍒嗘瀽 杩涜鍒ゆ柇鏄惁婊¤冻涓婁笅闄�
                                                         if (HAnalysisMethod == "2")
                                                         {
                                                             HInSpectResult = (HInSpectValue > HUpLimit || HDownLimit > HInSpectValue) ? 0 : 1;
@@ -432,7 +467,7 @@
                                                             HInSpectResult = int.Parse(HInSpectValue.ToString());
                                                         }
 
-
+                                                        //濡傛灉褰撳墠缁撹涓哄悎鏍� 骞朵笖鍘嗗彶缁撹涔熸槸鍚堟牸 鍒欑户缁繚鎸佸悎鏍�
                                                         if (HInSpectResult == 1 && HLastResult != 0)
                                                         {
                                                             HLastResult = 1;
@@ -470,7 +505,7 @@
                         ",0,0,'',0,'','" + dataSet.Tables[0].Rows[i]["HTargetVal"].ToString() + "'" +
                         ",'" + dataSet.Tables[0].Rows[i]["HUpLimit"].ToString() + "','" + dataSet.Tables[0].Rows[i]["HDownLimit"].ToString() + "','','',0,'" + HAnalysisMethod + "'," + dataSet.Tables[0].Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" +
                         ") ");
-
+                                        //濡傛灉褰撳墠缁撹涓哄悎鏍� 骞朵笖鍘嗗彶缁撹涔熸槸鍚堟牸 鍒欑户缁繚鎸佸悎鏍�
                                         if (HLastResult == 1 && HLastResults != 0)
                                         {
                                             HLastResults = 1;
@@ -490,12 +525,12 @@
                                         ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HShiftsID,HErrTreatment" +
                                         ",HProcID,HBatchNo,HInSpectQty ,HRightQty ,HUnRightQty ,HUnKnowQty " +
                                         ") " +
-                                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,getdate(),'',getdate()" +
+                                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,getdate(),'" + this.txtHMaker.Text + "',getdate()" +
                                         "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                                         "," + HSourceID + ",0,'',0,0,0" +
-                                        ",'',0," + HMaterID + ",'', " + HLastResults +
+                                        ",'',0," + HMaterID + ",'" + this.labHMakerID.Text + "', " + HLastResults +
                                         ",0,0,'','',0," + HQCSchemeID + ",0,''" +
-                                        "," + HProcID + ",'" + HBatchNo + "',"+ HInSpectQty + ","+ HRightQty + ", "+ HUnRightQty + ", " + HUnKnowQty + ") ");
+                                        "," + HProcID + ",'" + HBatchNo + "'," + HInSpectQty + "," + HRightQty + ", " + HUnRightQty + ", " + HUnKnowQty + ") ");
 
 
                                     oCN.Commit();
@@ -554,13 +589,13 @@
             }
         }
 
-      /// <summary>
-      /// 鑾峰彇璁惧鍒楄〃
-      /// </summary>
-      /// <param name="url"></param>
-      /// <param name="postData"></param>
-      /// <returns></returns>
-        public async Task<JsonEquipmentData> EquipmentList(string url, StringContent postData,string Type)
+        /// <summary>
+        /// 鑾峰彇璁惧鍒楄〃
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <returns></returns>
+        public async Task<JsonEquipmentData> EquipmentList(string url, StringContent postData, string Type)
         {
 
             // 鍒涘缓 HttpClient 瀹炰緥
@@ -579,8 +614,8 @@
                         // 鍙戣捣 get 璇锋眰
                         response = await client.GetAsync(url);
                     }
-                  
-                  
+
+
                     // 纭繚璇锋眰鎴愬姛
                     if (response.IsSuccessStatusCode)
                     {
@@ -590,7 +625,7 @@
                     }
                     else
                     {
-                        MessageBox.Show($"璇锋眰澶辫触锛�: {response.StatusCode}");
+                        MessageBox.Show($"璇锋眰澶辫触锛歿response.StatusCode} - {url} - 褰撳墠鏃堕棿锛歿DateTime.Now:yyyy-MM-dd HH:mm:ss}");
                     }
 
                 }
@@ -602,6 +637,49 @@
             }
         }
 
+        public async Task<JsonResult> EquipResultList(string url, StringContent postData, string Type)
+        {
+
+            // 鍒涘缓 HttpClient 瀹炰緥
+            using (HttpClient client = new HttpClient())
+            {
+                JsonResult jsonResult = new JsonResult();
+                try
+                {
+                    HttpResponseMessage response;
+                    if (Type == "POST")
+                    {  // 鍙戣捣 POST 璇锋眰
+                        response = await client.PostAsync(url, postData);
+                    }
+                    else
+                    {
+                        // 鍙戣捣 get 璇锋眰
+                        response = await client.GetAsync(url);
+                    }
+
+
+                    // 纭繚璇锋眰鎴愬姛
+                    if (response.IsSuccessStatusCode)
+                    {
+                        // 璇诲彇鍝嶅簲鍐呭
+                        string responseBody = await response.Content.ReadAsStringAsync();
+                        jsonResult = JsonConvert.DeserializeObject<JsonResult>(responseBody);
+                    }
+                    else
+                    {
+                        MessageBox.Show($"璇锋眰澶辫触锛歿response.StatusCode} - {url} - 褰撳墠鏃堕棿锛歿DateTime.Now:yyyy-MM-dd HH:mm:ss}");
+                    }
+
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show("璇锋眰鎶ラ敊:" + ex.Message);
+                }
+                return jsonResult;
+            }
+        }
+
+
         //鑾峰彇ID
         public async Task<JsonResult> FindAccessToken(string url)
         {
@@ -609,8 +687,8 @@
             // 鍑嗗瑕佸彂閫佺殑琛ㄥ崟鏁版嵁
             var formData = new FormUrlEncodedContent(new[]
             {
-                    new KeyValuePair<string, string>("userName", "admin"),
-                    new KeyValuePair<string, string>("password", "admin")
+                    new KeyValuePair<string, string>("userName", "mes"),
+                    new KeyValuePair<string, string>("password", "MesApi123")
                     // 娣诲姞鏇村閿�煎锛屾牴鎹偍鐨勯渶瑕�
                 });
             JsonResult jsonResult = await getUrl(urls, formData);
@@ -618,7 +696,8 @@
         }
 
         //鑾峰彇璁惧鍒楄〃
-        public async Task<JsonEquipmentData> FindDeviceList(string url,string token) {
+        public async Task<JsonEquipmentData> FindDeviceList(string url, string token)
+        {
             //璁惧鍒楄〃鎺ュ彛
             string urls = url + EquipmentType.Two;
             // 鍑嗗瑕佸彂閫佺殑琛ㄥ崟鏁版嵁
@@ -628,12 +707,16 @@
         }
 
         //鑾峰彇鑹搧銆佷笉鑹搧鏄庣粏
-        public async Task<JsonEquipmentData> FindAllDevicePropsDetailByTimeRange(string url, string token,string nos, string HBegin, string HEnd)
+        public async Task<JsonEquipmentData> FindAllDevicePropsDetailByTimeRange(string url, string token, string nos, string HBegin, string HEnd)
         {
+            string basePropIds = DBHelper.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "basePropIds");
+            basePropIds = "[" + basePropIds + "]";
             nos = nos.Replace(",", "\",\"");
-            string stringJson = "{\"token\":\"" + token + "\",\"deviceNos\":[\"" + nos + "\"],\"startTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\",\"basePropIds\":[473,474,489,508, 562, 563, 564, 565, 566, 567, 568, 569, 570,571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 597, 600, 601, 602, 603, 604, 605, 593, 594, 595]}";
+            string stringJson = "{\"token\":\"" + token + "\",\"deviceNos\":[\"" + nos + "\"],\"startTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\",\"basePropIds\":" + basePropIds + "}";
             //璁惧鍒楄〃鎺ュ彛
             string urls = url + EquipmentType.Nine;
+
+            CustomWriteLog("宸ヨ壓鍙傛暟鎺ュ彛锛�'" + urls + "' 鍙傛暟鍊硷細 '" + stringJson + "'", DateTime.Now.ToString("yyyy-MM-dd"));
 
             // 鍑嗗瑕佸彂閫佺殑琛ㄥ崟鏁版嵁
             var postData = new StringContent(stringJson, System.Text.Encoding.UTF8, "application/json");
@@ -642,11 +725,12 @@
         }
 
         //鑾峰彇涓嶈壇鏁帮紝鍚堟暟鏁帮紝鍙枒鏁� 鎬绘暟
-        public async Task<JsonEquipmentData> FindDevicePropCalc(string url, string token,string nos,string HBegin,string HEnd)
+        public async Task<JsonEquipmentData> FindDevicePropCalc(string url, string token, string nos, string HBegin, string HEnd)
         {
-            string stringJson = "{\"token\":\"" + token + "\",\"deviceNo\":\"" + nos + "\",\"propIds\":[466,467,469,470],\"beginTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\"}";
+            string stringJson = "{\"token\":\"" + token + "\",\"deviceNo\":\"" + nos + "\",\"propIds\":[606,173,469,470],\"beginTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\"}";
             var postData = new StringContent(stringJson, System.Text.Encoding.UTF8, "application/json");
             string urls = url + EquipmentType.Seven;
+            CustomWriteLog("鑾峰彇涓嶈壇鏁帮紝鍚堟暟鏁帮紝鍙枒鏁� 鎬绘暟锛�'" + urls + "' 鍙傛暟鍊硷細 '" + stringJson + "'", DateTime.Now.ToString("yyyy-MM-dd"));
             JsonEquipmentData jsonResult = await EquipmentList(urls, postData, "POST");
             return jsonResult;
         }
@@ -660,6 +744,7 @@
             string stringJson = "{\"token\":\"" + token + "\",\"nos\":[" + nos + "]}";
             var postData = new StringContent(stringJson, System.Text.Encoding.UTF8, "application/json");
             string urls = url + EquipmentType.Three;
+            CustomWriteLog("璁惧杩愯鐘舵�侊細'" + urls + "' 鍙傛暟鍊硷細 '" + stringJson + "'", DateTime.Now.ToString("yyyy-MM-dd"));
             JsonEquipmentData jsonResult = await EquipmentList(urls, postData, "POST");
             return jsonResult;
         }
@@ -672,16 +757,44 @@
             string stringJson = "{\"token\":\"" + token + "\",\"nos\":[" + nos + "],\"startTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\"}";
             var postData = new StringContent(stringJson, System.Text.Encoding.UTF8, "application/json");
             string urls = url + EquipmentType.Four;
+            CustomWriteLog("璁惧鏃堕棿娈典骇閲忥細'" + urls + "' 鍙傛暟鍊硷細 '" + stringJson + "'", DateTime.Now.ToString("yyyy-MM-dd"));
             JsonEquipmentData jsonResult = await EquipmentList(urls, postData, "POST");
             return jsonResult;
         }
+
+        //鑾峰彇璁惧杩愯鏃堕棿 寮�鏈� 鍋滄満 寰呮満  鍏虫満
+        public async Task<JsonResult> FindDeviceStatusTimeByNo(string url, string token, string nos, string HBegin, string HEnd)
+        {
+            nos = nos.Replace(",", "\",\"");
+            nos = "\"" + nos + "\"";
+            string stringJson = "{\"token\":\"" + token + "\",\"no\":" + nos + ",\"startTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\"}";
+            var postData = new StringContent(stringJson, System.Text.Encoding.UTF8, "application/json");
+            string urls = url + EquipmentType.Five;
+            CustomWriteLog("璁惧杩愯鏃堕棿鎺ュ彛锛�'" + urls + "' 鍙傛暟鍊硷細 '" + stringJson + "'", DateTime.Now.ToString("yyyy-MM-dd"));
+            JsonResult jsonResult = await EquipResultList(urls, postData, "POST");
+            return jsonResult;
+        }
+
+        //鑾峰彇娉ㄥ鏈虹殑 寮�鏈�
+        public async Task<JsonResult> FindDeviceStatusTimeByNosAndOperationMode(string url, string token, string nos, string HBegin, string HEnd)
+        {
+            nos = nos.Replace(",", "\",\"");
+            nos = "\"" + nos + "\"";
+            string stringJson = "{\"token\":\"" + token + "\",\"no\":" + nos + ",\"startTime\":\"" + HBegin + "\",\"endTime\":\"" + HEnd + "\"}";
+            var postData = new StringContent(stringJson, System.Text.Encoding.UTF8, "application/json");
+            string urls = url + EquipmentType.Ten;
+            CustomWriteLog("娉ㄥ鏈虹殑 寮�鏈烘帴鍙o細'" + urls + "' 鍙傛暟鍊硷細 '" + stringJson + "'", DateTime.Now.ToString("yyyy-MM-dd"));
+            JsonResult jsonResult = await EquipResultList(urls, postData, "POST");
+            return jsonResult;
+        }
+
 
         //涓嬫媺妗嗙粦瀹氭暟鎹�
         private void bindCbox()
         {
             IList<Info> infoList = new List<Info>();
-            Info info1 = new Info() { Id = "CMR_QC_SE_001", Name = "铻烘瘝鍏ㄦ" }; 
-            Info info2 = new Info() { Id = "CMR_ZZ_SE_001", Name = "铻烘瘝鍘嬭" };
+            Info info1 = new Info() { Id = "CMR-QC-SE-001", Name = "铻烘瘝鍏ㄦ" };
+            Info info2 = new Info() { Id = "CMR-ZZ-SE-001", Name = "铻烘瘝鍘嬭" };
             Info info3 = new Info() { Id = "ZSJ07", Name = "娉ㄥ鏈�#07" };
             //Info info3 = new Info() { Id = "3", Name = "鐜嬩簲" };
             infoList.Add(info1);
@@ -702,7 +815,7 @@
                 this.btnLj.Enabled = true;
                 this.timer.Enabled = false;
             }
-            else 
+            else
             {
                 this.btnLj.Enabled = false;
                 DialogResult dr = MessageBox.Show("鏄惁纭寮�濮嬮噰闆�?", "鎻愮ず", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
@@ -710,7 +823,8 @@
                 if (dr == DialogResult.Yes)
                 {
                     this.txtHBathNo.ReadOnly = true;
-                    this.txtBegin.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                    this.txtBegin.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
+                    //this.txtBegin.Text = "2024-11-21 13:40:27";
                     this.btnBegin.Enabled = false;
                     this.timer.Enabled = true;
                     this.Time_CLHB.Enabled = true;
@@ -721,17 +835,20 @@
         //瀹氭椂鑾峰彇鏁版嵁
         private async void timer_Tick(object sender, EventArgs e)
         {
+            //娴嬭瘯鍏ㄦ
+            //this.timer.Enabled = false;
+
             string Url = DBHelper.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sUrl");
             string urls = Url + EquipmentType.One;
             // 鍑嗗瑕佸彂閫佺殑琛ㄥ崟鏁版嵁
             var formData = new FormUrlEncodedContent(new[]
             {
-                    new KeyValuePair<string, string>("userName", "admin"),
-                    new KeyValuePair<string, string>("password", "admin")
+                    new KeyValuePair<string, string>("userName", "mes"),
+                    new KeyValuePair<string, string>("password", "MesApi123")
                     // 娣诲姞鏇村閿�煎锛屾牴鎹偍鐨勯渶瑕�
                 });
             JsonResult jsonResult = await getUrl(urls, formData);
-            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
 
             if (cmbEquipFile.SelectedIndex == 1)
             {
@@ -746,7 +863,8 @@
         }
 
         //铻烘瘝鍘嬭閲囬泦鏁版嵁 淇濆瓨
-        public async void SaveNutPressFit(string Url , string token, string time) {
+        public async void SaveNutPressFit(string Url, string token, string time)
+        {
             if (TimeDate == "")
             {
                 TimeDate = this.txtBegin.Text;
@@ -760,11 +878,11 @@
             }
             else
             {
-                 string nos = "";
+                string nos = "";
                 //鑾峰彇鍘昏澶囩紪鐮�
                 for (int i = 0; i < jsonResult.data.Count; i++)
                 {
-                    if (jsonResult.data[i].no.Contains("CMR_ZZ_SE_001"))
+                    if (jsonResult.data[i].no.Contains("CMR-ZZ-SE-001"))
                     {
                         nos += jsonResult.data[i].no + ",";
                     }
@@ -802,8 +920,8 @@
                     //鍚堟牸鏁�
                     if (jsonEquipment.data[i].propId == 469)
                     {
-                        JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鑹搧鏁癨",\"HResult\":\"OK\",\"HCount\":" + jsonEquipment.data[i].sum + ",\"HSourceCode\":\""+ nos + "\"},";
-                    }   
+                        JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鑹搧鏁癨",\"HResult\":\"OK\",\"HCount\":" + jsonEquipment.data[i].sum + ",\"HSourceCode\":\"" + nos + "\"},";
+                    }
                     //涓嶈壇鏁�
                     else if (jsonEquipment.data[i].propId == 470)
                     {
@@ -822,104 +940,185 @@
         }
 
         //娉ㄥ鏈洪噰闆嗘暟鎹� 淇濆瓨
-        public async void SaveInjectionMoldingMachine(string token, string Url,  string time)
+        public async void SaveInjectionMoldingMachine(string token, string Url, string time)
         {
             ListData.Items.Clear();
             if (TimeDate == "")
             {
                 TimeDate = this.txtBegin.Text;
             }
-            //this.timer.Enabled = false;
-
-            //TimeDate = "2024-08-19 19:38:14.540";
-            //time = "2024-08-19 19:39:14.540";
-
+           
+            //鑾峰彇鎵�鏈夎澶囨暟鎹�
             JsonEquipmentData jsonResult = await FindDeviceList(Url, token);
             if (jsonResult.code != "0")
             {
                 MessageBox.Show("璁惧鍒楄〃鎶ラ敊:" + jsonResult.message);
             }
-            else {
+            else
+            {
 
                 string nos = "";
-                //鑾峰彇鍘昏澶囩紪鐮�
+                //鑾峰彇璁惧缂栫爜
                 for (int i = 0; i < jsonResult.data.Count; i++)
                 {
-                    if (jsonResult.data[i].no.Contains("CMR-ZS-SE"))
-                    {
-                        nos += jsonResult.data[i].no + ",";
-                    }
-                    else if (jsonResult.data[i].no.Contains("CMR_ZZ_SE_"))
-                    {
-                        nos += jsonResult.data[i].no + ",";
-                    }
+                    nos += jsonResult.data[i].no + ",";
+                    //if (jsonResult.data[i].no.Contains("CMR-ZS-SE"))
+                    //{
+                    //    nos += jsonResult.data[i].no + ",";
+                    //}
+                    //else if (jsonResult.data[i].no.Contains("CMR_ZZ_SE_"))
+                    //{
+                    //    nos += jsonResult.data[i].no + ",";
+                    //}
                 }
                 nos = nos.Substring(0, nos.Length - 1);
-
+                //鑾峰彇鍙傛暟 鑾峰彇姣忎釜璁惧瀵瑰簲鐨勬墍鏈夊弬鏁�
                 JsonEquipmentData jsonEquipment = await FindAllDevicePropsDetailByTimeRange(Url, token, nos, TimeDate, time);
-
                 var JsonData = "{\"data\":[";
 
-                for (int i = 0; i < jsonEquipment.data.Count; i++)
+                if (jsonEquipment == null)
                 {
-                    if (jsonEquipment.data[i].deviceNo.Contains("CMR_ZZ_SE_"))
-                    {
-                        for (int j = 0; j < jsonEquipment.data[i].props.Count; j++)
-                        {
-                            for (int k = 0; k < jsonEquipment.data[i].props[j].datas.Count; k++)
-                            {
-                                valueData value = JsonConvert.DeserializeObject<valueData>(jsonEquipment.data[i].props[j].datas[k].value);
-                                if (value.type == "鑹搧")
-                                {
-                                    JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"铻烘瘝鏄惁鍑稿嚭\",\"HResult\":\"OK\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                                }
-                                else
-                                {
-                                    JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"铻烘瘝鏄惁鍑稿嚭\",\"HResult\":\"NG\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                                }
-                                JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"鐢熶骇鍛ㄦ湡\",\"HResult\":\"" + value.beat + "\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                            }
-                        }
-
-                        JsonEquipmentData data = await FindDevicePropCalc(Url, token, jsonEquipment.data[i].deviceNo, TimeDate, time);
-
-                        for (int j = 0; j < data.data.Count; j++)
-                        {
-                            //鍚堟牸鏁�
-                            if (data.data[j].propId == 469)
-                            {
-                                JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鑹搧鏁癨",\"HResult\":\"OK\",\"HCount\":" + data.data[j].sum + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                            }
-                            //涓嶈壇鏁�
-                            else if (data.data[j].propId == 470)
-                            {
-                                JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"NG鏁伴噺\",\"HResult\":\"NG\",\"HCount\":" + data.data[j].sum + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                            }
-                        }
-                    }
-                    else {
-                        for (int j = 0; j < jsonEquipment.data[i].props.Count; j++)
-                        {
-                            for (int k = 0; k < jsonEquipment.data[i].props[j].datas.Count; k++)
-                            {
-                                JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"" + jsonEquipment.data[i].props[j].propName + "\",\"HResult\":\""+ jsonEquipment.data[i].props[j].datas[k].value + "\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                            }
-                        }
-
-                        JsonEquipmentData data = await FindProdByNosAndTime(Url, token, jsonEquipment.data[i].deviceNo, TimeDate, time);
-
-                        for (int j = 0; j < data.data.Count; j++)
-                        {
-
-                            JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鐢熶骇鏁伴噺\",\"HResult\":\"OK\",\"HCount\":" + data.data[j].prod + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
-                        }
-                    }
+                    CustomWriteLog("jsonEquipment瀵硅薄涓虹┖", DateTime.Now.ToString("yyyy-MM-dd"));
                 }
 
-                var  EquipmentStaus = await FindDeviceStatusByNos(Url, token, nos);
+                if (jsonEquipment.data == null)
+                {
+                    CustomWriteLog("jsonEquipment.data灞炴�т负绌�", DateTime.Now.ToString("yyyy-MM-dd"));
+                }
+                else
+                {
+                    CustomWriteLog("寮�濮嬪惊鐜伐鑹哄弬鏁版�绘暟涓猴細锛�'" + jsonEquipment.data.Count + "'", DateTime.Now.ToString("yyyy-MM-dd"));
+
+                    //閫氳繃姣忎釜璁惧杩涜寰幆璧嬪��
+                    for (int i = 0; i < jsonEquipment.data.Count; i++)
+                    {
+                        CustomWriteLog("褰撳墠寰幆 绗�  '" + i + "'  娆�", DateTime.Now.ToString("yyyy-MM-dd"));
+                        //鑾峰彇璁惧瀵瑰簲鐨勭紪鐮� 鍒ゆ柇缂栫爜鏄惁婊¤冻涓鸿灪姣嶅帇瑁呰澶�
+                        if (jsonEquipment.data[i].deviceNo.Contains("CMR-ZZ-SE-"))
+                        {
+                            //寰幆 铻烘瘝鍘嬭璁惧瀵瑰簲鐨勬墍鏈夊伐鑹哄弬鏁�
+                            for (int j = 0; j < jsonEquipment.data[i].props.Count; j++)
+                            {
+                                //寰幆 姣忎釜鍙傛暟瀵瑰簲鐨勬墍鏈夋暟鎹�
+                                for (int k = 0; k < jsonEquipment.data[i].props[j].datas.Count; k++)
+                                {
+                                    //鏃ュ織
+                                    CustomWriteLog("1-" + k + ":" + jsonEquipment.data[i].props[j].datas[k].value, DateTime.Now.ToString("yyyy-MM-dd"));
+
+                                    //鑾峰彇鍙傛暟鐨勭被鍨�
+                                    valueData value = JsonConvert.DeserializeObject<valueData>(jsonEquipment.data[i].props[j].datas[k].value);
+
+                                    //鏃ュ織
+                                    CustomWriteLog("2", DateTime.Now.ToString("yyyy-MM-dd"));
+
+                                    if (value.type == "鑹搧")
+                                    {
+                                        JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"铻烘瘝鏄惁鍑稿嚭\",\"HResult\":\"OK\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                    }
+                                    else
+                                    {
+                                        JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"铻烘瘝鏄惁鍑稿嚭\",\"HResult\":\"NG\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                    }
+                                    JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"鐢熶骇鍛ㄦ湡\",\"HResult\":\"" + value.beat + "\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                }
+                            }
+
+                            JsonEquipmentData data = await FindDevicePropCalc(Url, token, jsonEquipment.data[i].deviceNo, TimeDate, time);
+
+                            await Task.Delay(200);
+
+                            for (int j = 0; j < data.data.Count; j++)
+                            {
+                                //鍚堟牸鏁�
+                                if (data.data[j].propId == 469)
+                                {
+                                    JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鑹搧鏁癨",\"HResult\":\"OK\",\"HCount\":" + data.data[j].sum + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                }
+                                //涓嶈壇鏁�
+                                else if (data.data[j].propId == 470)
+                                {
+                                    JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"NG鏁伴噺\",\"HResult\":\"NG\",\"HCount\":" + data.data[j].sum + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                }
+                            }
+                        }
+                        else
+                        {
+                            //寰幆 铻烘瘝鍘嬭浠ュ鐨勮澶囧搴旂殑鎵�鏈夊伐鑹哄弬鏁�
+                            for (int j = 0; j < jsonEquipment.data[i].props.Count; j++)
+                            {
+                                //寰幆 姣忎釜鍙傛暟瀵瑰簲鐨勬墍鏈夋暟鎹�
+                                for (int k = 0; k < jsonEquipment.data[i].props[j].datas.Count; k++)
+                                {
+                                    JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"" + jsonEquipment.data[i].props[j].propName + "\",\"HResult\":\"" + jsonEquipment.data[i].props[j].datas[k].value + "\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                    //CustomWriteLog("宸ヨ壓鍙傛暟鍏蜂綋鍊硷細{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"" + jsonEquipment.data[i].props[j].propName + "\",\"HResult\":\"" + jsonEquipment.data[i].props[j].datas[k].value + "\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"}", DateTime.Now.ToString("yyyy-MM-dd"));
+                                }
+                            }
+
+                            //鑾峰彇璁惧鏃堕棿娈典骇閲�
+                            JsonEquipmentData data = await FindProdByNosAndTime(Url, token, jsonEquipment.data[i].deviceNo, TimeDate, time);
+                            for (int j = 0; j < data.data.Count; j++)
+                            {
+
+                                JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鐢熶骇鏁伴噺\",\"HResult\":\"OK\",\"HCount\":" + data.data[j].prod + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
+                                //CustomWriteLog("璁惧浜ч噺鍊硷細{\"HDate\":\"" + time + "\",\"HTechParamName\":\"鐢熶骇鏁伴噺\",\"HResult\":\"OK\",\"HCount\":" + data.data[j].prod + ",\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"}", DateTime.Now.ToString("yyyy-MM-dd"));
+                            }
+                        }
+                    }
+
+                    CustomWriteLog("宸ヨ壓鍙傛暟涓庝骇閲忓惊鐜粨鏉�", DateTime.Now.ToString("yyyy-MM-dd"));
+                }
+
+                CustomWriteLog("1", DateTime.Now.ToString("yyyy-MM-dd"));
+
+
+                //鑾峰彇璁惧杩愯鐘舵��
+                var EquipmentStaus = await FindDeviceStatusByNos(Url, token, nos);
 
                 for (int i = 0; i < EquipmentStaus.data.Count; i++)
                 {
+                    //鍗风粫  娉ㄥ  娴告笉  缁勮  鐨勮澶囪繍琛� 寮�鍏冲仠鏈烘椂闂�
+                    if (EquipmentStaus.data[i].no.Contains("CMR-JR-SD-") || EquipmentStaus.data[i].no.Contains("CMR-JZ-SD-") || EquipmentStaus.data[i].no.Contains("CMR-HX-SD-")
+                        || EquipmentStaus.data[i].no.Contains("CMR-ZD-SD") || EquipmentStaus.data[i].no.Contains("CMR-ZS-SE-"))
+                    {
+                        string HBegDate = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
+                        string HEndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
+
+                        if (DateTime.Parse(HEndDate).AddMinutes(1).ToString("yyyy-MM-dd") != DateTime.Parse(HEndDate).ToString("yyyy-MM-dd"))
+                        {
+                            HEndDate = DateTime.Parse(HEndDate).AddMinutes(1).ToString("yyyy-MM-dd HH:mm:00");
+                        }
+
+                        JsonResult HEqDate = await FindDeviceStatusTimeByNo(Url, token, EquipmentStaus.data[i].no, HBegDate, HEndDate);
+                        if (HEqDate != null && HEqDate.data != null)
+                        {
+
+                            // 璁板綍寮�鏈烘椂闀�
+                            CustomWriteLog("璁惧寮�鏈烘椂闀�: 寮�鏈烘椂闀�" + ((float)(HEqDate.data.onlineTime / 60 / 60)).ToString("0.00") + "  " + EquipmentStaus.data[i].no + "",
+                                            DateTime.Now.ToString("yyyy-MM-dd"));
+
+                            // 璁板綍鍏虫満鏃堕暱
+                            CustomWriteLog("璁惧鍏虫満鏃堕暱: 鍏虫満鏃堕暱" + ((float)(HEqDate.data.offlineTime / 60 / 60)).ToString("0.00") + "  " + EquipmentStaus.data[i].no + "",
+                                            DateTime.Now.ToString("yyyy-MM-dd"));
+
+                            // 璁板綍鍋滄満鏃堕暱
+                            CustomWriteLog("璁惧鍋滄満鏃堕暱: 鍋滄満鏃堕暱" + ((float)(HEqDate.data.standbyTime / 60 / 60)).ToString("0.00") + "  " + EquipmentStaus.data[i].no + "",
+                                            DateTime.Now.ToString("yyyy-MM-dd"));
+
+                            // 璁板綍杩愯鏃堕暱
+                            CustomWriteLog("璁惧杩愯鏃堕暱: 杩愯鏃堕暱" + ((float)(HEqDate.data.runTime / 60 / 60)).ToString("0.00") + "  " + EquipmentStaus.data[i].no + "",
+                                            DateTime.Now.ToString("yyyy-MM-dd"));
+
+                            JsonData += "{\"HDate\":\"" + HEndDate + "\",\"HTechParamName\":\"寮�鏈烘椂闀縗",\"HResult\":\"" + ((float)(HEqDate.data.onlineTime / 60 / 60)).ToString("0.00") + "\",\"HCount\":1,\"HSourceCode\":\"" + EquipmentStaus.data[i].no + "\"},";
+                            JsonData += "{\"HDate\":\"" + HEndDate + "\",\"HTechParamName\":\"鍏虫満鏃堕暱\",\"HResult\":\"" + ((float)(HEqDate.data.offlineTime / 60 / 60)).ToString("0.00") + "\",\"HCount\":1,\"HSourceCode\":\"" + EquipmentStaus.data[i].no + "\"},";
+                            JsonData += "{\"HDate\":\"" + HEndDate + "\",\"HTechParamName\":\"鍋滄満鏃堕暱\",\"HResult\":\"" + ((float)(HEqDate.data.standbyTime / 60 / 60)).ToString("0.00") + "\",\"HCount\":1,\"HSourceCode\":\"" + EquipmentStaus.data[i].no + "\"},";
+                            JsonData += "{\"HDate\":\"" + HEndDate + "\",\"HTechParamName\":\"杩愯鏃堕暱\",\"HResult\":\"" + ((float)(HEqDate.data.runTime / 60 / 60)).ToString("0.00") + "\",\"HCount\":1,\"HSourceCode\":\"" + EquipmentStaus.data[i].no + "\"},";
+                        }
+                        else
+                        {
+                            // 璁板綍杩愯鏃堕暱
+                            CustomWriteLog("璁惧寮�鍋滄満鏃堕暱涓虹┖ HEqDate锛�" + HEqDate + " , HEqDate.data " + HEqDate.data + "", DateTime.Now.ToString("yyyy-MM-dd"));
+                        }
+                    }
                     string staus = "";
                     switch (EquipmentStaus.data[i].status)
                     {
@@ -940,7 +1139,11 @@
                             staus = "鍛婅";
                             break;
                     }
-                    if (jsonEquipment.data.Count > 0)
+                    if (jsonEquipment == null || jsonEquipment.data == null)
+                    {
+                        JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"寮�鍏虫満鐘舵�乗",\"HResult\":\"" + staus + "\",\"HCount\":0,\"HSourceCode\":\"" + EquipmentStaus.data[i].no + "\"},";
+                    }
+                    else if (jsonEquipment.data.Count > 0)
                     {
                         JsonData += "{\"HDate\":\"" + time + "\",\"HTechParamName\":\"寮�鍏虫満鐘舵�乗",\"HResult\":\"" + staus + "\",\"HCount\":1,\"HSourceCode\":\"" + EquipmentStaus.data[i].no + "\"},";
                     }
@@ -950,54 +1153,70 @@
                     }
                 }
 
+                //鏌ヨ褰撳墠寮�宸ョ殑璁惧 鑾峰彇瀵瑰簲鐨勭墿鏂欎俊鎭�
+                DataSet datable = oCN.RunProcReturn(@"select m.HNumber,eq.HEquipFileNo from Sc_ICMOBillStatus_Tmp a
+                                            inner join Gy_EquipFileBillMain eq on a.HSourceID = eq.HSourceID
+                                            inner join Gy_Material m on a.HMaterID = m.HItemID
+                                            where a.HICMOStatus = '1' ", "Sc_ICMOBillStatus_Tmp");
+
+                if (datable.Tables[0].Rows.Count > 0)
+                {
+                    for (int i = 0; i < datable.Tables[0].Rows.Count; i++)
+                    {
+                        string HSourceCode = datable.Tables[0].Rows[i]["HEquipFileNo"].ToString();
+                        string HNumber = datable.Tables[0].Rows[i]["HNumber"].ToString();
+
+                        JsonData += "{\"HDate\":\"" + DateTime.Now.ToString() + "\",\"HTechParamName\":\"鐗╂枡浠g爜\",\"HResult\":\"" + HNumber + "\",\"HCount\":1,\"HSourceCode\":\"" + HSourceCode + "\"},";
+                    }
+                }
+
+                CustomWriteLog("缁撴潫鎵�鏈�", DateTime.Now.ToString("yyyy-MM-dd"));
+
                 JsonData = JsonData.Substring(0, JsonData.Length - 1);
                 JsonData += "]}";
+
+                //淇濆瓨鏁版嵁
                 DataSave(JsonData);
                 if (TimeDate != "")
                 {
                     TimeDate = time;
                 }
             }
-
-         
-
-         
-
-           
         }
 
         //鏁版嵁淇濆瓨
-        public void DataSave(string JsonData) {
-            JsonEquipmentData  data  = JsonConvert.DeserializeObject<JsonEquipmentData>(JsonData);
+        public void DataSave(string JsonData)
+        {
+            JsonEquipmentData data = JsonConvert.DeserializeObject<JsonEquipmentData>(JsonData);
 
             for (int i = 0; i < data.data.Count; i++)
             {
                 oCN.RunProc(@"insert into Sb_EquipMentCollectionTechParam_Temp(HDate,HSourceCode,HTechParamID,HTechParamName,HCount
 ,HCreateTime,HResult,HProcNumber,HFlag)
-values(getdate(),'"+ data.data[i].HSourceCode + "',0,'" + data.data[i].HTechParamName + "'," + data.data[i].HCount
+values(getdate(),'" + data.data[i].HSourceCode + "',0,'" + data.data[i].HTechParamName + "'," + data.data[i].HCount
 + ",'" + data.data[i].HDate + "','" + data.data[i].HResult + "','" + data.data[i].HProcNumber + "',0)");
-
-                ListData.Items.Add("鏃堕棿:" + data.data[i].HDate +
-                                  ",宸ヨ壓鍙傛暟:" + data.data[i].HTechParamName +
-                                  ",宸ヨ壓鍙傛暟鍊�:" + data.data[i].HResult);
             }
+            ListData.Items.Add($"鏃堕棿: {DateTime.Now:yyyy-MM-dd HH:mm:ss}锛屽姞杞芥垚鍔�");
         }
 
         //瀹氭椂鐢熸垚浜ч噺姹囨姤鍗�
         private async void Time_CLHB_Tick(object sender, EventArgs e)
         {
+            //this.Time_CLHB.Enabled = false;
             string Url = DBHelper.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "Config/SQLAPI.config", "sUrl");
             string urls = Url + EquipmentType.One;
             // 鍑嗗瑕佸彂閫佺殑琛ㄥ崟鏁版嵁
             var formData = new FormUrlEncodedContent(new[]
             {
-                    new KeyValuePair<string, string>("userName", "admin"),
-                    new KeyValuePair<string, string>("password", "admin")
+                    new KeyValuePair<string, string>("userName", "mes"),
+                    new KeyValuePair<string, string>("password", "MesApi123")
                     // 娣诲姞鏇村閿�煎锛屾牴鎹偍鐨勯渶瑕�
                 });
             JsonResult jsonResult = await getUrl(urls, formData);
             string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             string token = jsonResult.data.token;
+
+            //鑾峰彇鎵�鏈夌殑璁惧鏁版嵁
             JsonEquipmentData jsonEquipment = await FindDeviceList(Url, token);
 
             if (jsonEquipment.code != "0")
@@ -1014,7 +1233,7 @@
                     {
                         nos += "''" + jsonEquipment.data[i].no + "'',";
                     }
-                    else if (jsonEquipment.data[i].no.Contains("CMR_ZZ_SE_"))
+                    else if (jsonEquipment.data[i].no.Contains("CMR-ZZ-SE-"))
                     {
                         nos += "''" + jsonEquipment.data[i].no + "'',";
                     }
@@ -1022,11 +1241,13 @@
                 nos = nos.Substring(0, nos.Length - 1);
 
                 //this.Time_CLHB.Enabled = false;
-
+                CustomWriteLog("浜ч噺姹囨姤鍗曪紝璁惧缂栫爜锛�'" + nos + "'", DateTime.Now.ToString("yyyy-MM-dd"));
+                //鏌ヨ寮�宸ョ殑璁惧淇℃伅 浠ュ強 鏌ヨ褰撳ぉ璁惧瀵瑰簲鐨勫紑宸ユ椂闂� 鍜屽畬宸ユ椂闂�
                 DataSet ds = oCN.RunProcReturn("exec h_p_Sc_TimeICMOReporList '" + nos + "'", "h_p_Sc_TimeICMOReporList");
-               
+
                 if (ds.Tables[0].Rows.Count > 0)
                 {
+                    //鏍规嵁褰撳ぉ鍙紑宸ユ病鏈夊畬宸ュ搴旂殑浜ч噺鏁版嵁 鐢熸垚浜ч噺姹囨姤鍗�
                     DataTable dt = ds.Tables[0];
                     for (int i = 0; i < dt.Rows.Count; i++)
                     {
@@ -1035,13 +1256,17 @@
                         string HBegDate = DateTime.Parse(dt.Rows[i]["鏃ユ湡"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                         string HEndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                         jsonEquipment = await FindProdByNosAndTime(Url, token, nos, HBegDate, HEndDate);
-                        if (decimal.Parse(jsonEquipment.data[0].prod) > 0) {
-                            oCN.RunProc("exec h_p_Sc_AddTimeICMORepor " + HICMInterID + "," + jsonEquipment.data[0].prod+",'"+ HEndDate + "'");
+                        if (decimal.Parse(jsonEquipment.data[0].prod) > 0)
+                        {
+                            //鐢熸垚浜ч噺姹囨姤鍗�
+                            oCN.RunProc("exec h_p_Sc_AddTimeICMORepor " + HICMInterID + "," + jsonEquipment.data[0].prod + ",'" + HEndDate + "'");
+                            CustomWriteLog("鐢熸垚浜ч噺姹囨姤鍗�1锛�'exec h_p_Sc_AddTimeICMORepor " + HICMInterID + "," + jsonEquipment.data[0].prod + ",'" + HEndDate + "''", DateTime.Now.ToString("yyyy-MM-dd"));
                         }
                     }
                 }
                 if (ds.Tables[1].Rows.Count > 0)
                 {
+                    //鏍规嵁褰撳ぉ寮�宸ュ苟涓斿畬宸ュ搴旂殑浜ч噺鏁版嵁 鐢熸垚浜ч噺姹囨姤鍗�
                     DataTable dt = ds.Tables[1];
                     for (int i = 0; i < dt.Rows.Count; i++)
                     {
@@ -1052,7 +1277,9 @@
                         jsonEquipment = await FindProdByNosAndTime(Url, token, nos, HBegDate, HEndDate);
                         if (decimal.Parse(jsonEquipment.data[0].prod) > 0)
                         {
+                            //鐢熸垚浜ч噺姹囨姤鍗�
                             oCN.RunProc("exec h_p_Sc_AddTimeICMORepor " + HICMInterID + "," + jsonEquipment.data[0].prod + ",'" + HEndDate + "'");
+                            CustomWriteLog("鐢熸垚浜ч噺姹囨姤鍗�2锛�'exec h_p_Sc_AddTimeICMORepor " + HICMInterID + "," + jsonEquipment.data[0].prod + ",'" + HEndDate + "''", DateTime.Now.ToString("yyyy-MM-dd"));
                         }
                     }
                 }
@@ -1067,10 +1294,113 @@
                 e.Cancel = true;
             }
         }
+
+        private void txtHMaker_Leave(object sender, EventArgs e)
+        {
+            if (string.IsNullOrWhiteSpace(txtHMaker.Text))
+            {
+                this.txtHMaker.ForeColor = Color.LightGray;
+                txtHMaker.Text = "璇疯緭鍏ョ敤鎴风紪鐮�!";
+            }
+        }
+
+        private void txtHMaker_Enter(object sender, EventArgs e)
+        {
+            if (txtHMaker.Text.Trim() == "璇疯緭鍏ョ敤鎴风紪鐮�!")
+            {
+                txtHMaker.Text = "";
+                this.txtHMaker.ForeColor = Color.Black;
+            }
+        }
+
+        private void txtHMaker_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.KeyCode == Keys.Enter)
+            {
+                SelectHMaker(this.txtHMaker.Text);
+            }
+        }
+
+
+        //鏌ヨ鑱屽憳淇℃伅
+        public void SelectHMaker(string txtHMaker)
+        {
+            try
+            {
+                DataSet ds = oCN.RunProcReturn("select  HItemID,HName,HNumber from Gy_Employee where HNumber='" + txtHMaker + "' or HName ='" + txtHMaker + "'", "Gy_Employee");
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    string HName = ds.Tables[0].Rows[0]["HName"].ToString();
+                    string HMakerID = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                    string HNumber = ds.Tables[0].Rows[0]["HNumber"].ToString();
+                    this.txtHMaker.Text = HName;
+                    this.txtHMakerNumber.Text = HNumber;
+                    this.labHMakerID.Text = HMakerID;
+                    this.txtHMaker.ReadOnly = true;
+                }
+                else
+                {
+                    MessageBox.Show(this, "缂栫爜:" + txtHMaker + ",鏌ユ棤鏁版嵁,鍙兘鏄緭鍏ョ紪鐮佹湁璇�!", "鎻愮ず");
+                }
+            }
+            catch (Exception e)
+            {
+                MessageBox.Show(this, e.Message, "鎻愮ず");
+            }
+        }
+
+        private void EquipmentCollectionForm_Activated(object sender, EventArgs e)
+        {
+            //鍏夋爣閫変腑鍒跺崟浜�
+            this.txtHMaker.Focus();
+        }
+
+        private static readonly object lockObj = new object();
+        //鍐欐棩蹇�
+        public static void CustomWriteLog(object obj, string FileName, string filePath = "Vlog", bool isAppend = true)
+        {
+            try
+            {
+                lock (lockObj)
+                {
+                    filePath = $@"{filePath}\{FileName}.txt";
+
+                    filePath = AppDomain.CurrentDomain.BaseDirectory + filePath;
+
+                    if (!System.IO.Directory.Exists(Path.GetDirectoryName(filePath)))
+                    {
+                        System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath));
+                    }
+
+                    bool fileExists = System.IO.File.Exists(filePath);
+                    //涓嶅瓨鍦� 鍒欏垱寤鸿鏂囦欢
+                    if (!fileExists)
+                    {
+                        System.IO.File.Create(filePath).Close();
+                    }
+
+                    using (StreamWriter writer = new StreamWriter(filePath, isAppend))
+                    {
+                        //瀛樺湪鐨勬椂鍊欐墠鍐欎竴琛�
+                        if (fileExists && isAppend)
+                        {
+                            writer.WriteLine();
+                        }
+
+                        var content = obj is string ? obj : JsonConvert.SerializeObject(obj);
+                        writer.WriteLine($"{DateTime.Now} {content}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+            }
+        }
     }
 
 
-    public class JsonResult {
+    public class JsonResult
+    {
         public string code { get; set; }
         public string message { get; set; }
         public string expirationTime { get; set; }
@@ -1092,6 +1422,10 @@
 
     public class JsonData
     {
+        public double onlineTime { get; set; }
+        public double offlineTime { get; set; }
+        public double standbyTime { get; set; }
+        public double runTime { get; set; }
         public string expirationTime { get; set; }
         public string token { get; set; }
         public string deviceNo { get; set; }
@@ -1113,7 +1447,7 @@
         public double sum { get; set; }
         public string createTime { get; set; }
         public string happenTime { get; set; }
-        public string HDate{ get; set; }
+        public string HDate { get; set; }
         public string HTechParamName { get; set; }
         public string HResult { get; set; }
         public string HCount { get; set; }
@@ -1121,7 +1455,8 @@
         public string HProcNumber { get; set; }
     }
 
-    public class propsData {
+    public class propsData
+    {
         public string propName { get; set; }
         public List<JsonData> datas { get; set; }
         public string basePropId { get; set; }
@@ -1153,9 +1488,9 @@
         //涓�娈垫椂闂村唴璁惧鐘舵�佺殑鑾峰彇
         public static string Eight = "/api/third/dayDeviceStatusTimeline";
         //鑹搧 涓嶈壇鍝� 鏄庣粏 娉ㄥ鏈烘暟鎹�
-        public static string Nine = "/api/third/findAllDevicePropsDetailByTimeRange";
-        //娉ㄥ鏈烘暟鎹�
-        public static string Ten = "/api/third/findAllDevicePropsDetailByTimeRange";
+        public static string Nine = "/api/third/findAllDevicePropsDetailByTimeRange_v1";
+        //娉ㄥ鏈哄紑鏈烘椂闀� 鏍规嵁 鎿嶄綔妯″紡閲囬泦
+        public static string Ten = "/api/third/findDeviceStatusTimeByNosAndOperationMode";
         //public static string Eleven = "Monday";
         //public static string Twelve = "Monday";
     }
@@ -1165,5 +1500,5 @@
         public string Id { get; set; }
         public string Name { get; set; }
     }
-   
+
 }

--
Gitblit v1.9.1