From 871fa09fa6b84be39f7d060eb25a7159e0a2ca40 Mon Sep 17 00:00:00 2001 From: yangle <admin@YINMOU> Date: 星期二, 12 十一月 2024 16:50:28 +0800 Subject: [PATCH] 1 --- WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs | 193 +++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 172 insertions(+), 21 deletions(-) diff --git a/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs b/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs index 8b03698..9fd2537 100644 --- a/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs +++ b/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs @@ -33,6 +33,12 @@ 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(); } @@ -47,7 +53,7 @@ else { this.txtBegin.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - //this.txtBegin.Text = "2024-09-24 09:47:39"; + //this.txtBegin.Text = "2024-11-04 15:40:27"; this.btnBegin.Enabled = false; if (cmbEquipFile.SelectedIndex == 1) { @@ -201,8 +207,15 @@ { if (e.KeyCode == Keys.Enter) { + if (this.txtHMakerNumber.Text == "") + { + MessageBox.Show("璇疯緭鍏ュ埗鍗曚汉淇℃伅!"); + } + else { + Get_DisplayBard(); + } //this.txtHBathNo.ReadOnly = true; - Get_DisplayBard(); + } } @@ -491,12 +504,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(); @@ -603,6 +616,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}"); + } + + } + catch (Exception ex) + { + MessageBox.Show("璇锋眰鎶ラ敊:" + ex.Message); + } + return jsonResult; + } + } + + //鑾峰彇ID public async Task<JsonResult> FindAccessToken(string url) { @@ -631,8 +687,10 @@ //鑾峰彇鑹搧銆佷笉鑹搧鏄庣粏 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; @@ -677,12 +735,24 @@ 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; + 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); @@ -722,6 +792,9 @@ //瀹氭椂鑾峰彇鏁版嵁 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; // 鍑嗗瑕佸彂閫佺殑琛ㄥ崟鏁版嵁 @@ -765,7 +838,7 @@ //鑾峰彇鍘昏澶囩紪鐮� 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 + ","; } @@ -846,24 +919,24 @@ //鑾峰彇鍘昏澶囩紪鐮� 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.data[i].deviceNo.Contains("CMR_ZZ_SE_")) + if (jsonEquipment.data[i].deviceNo.Contains("CMR-ZZ-SE-")) { for (int j = 0; j < jsonEquipment.data[i].props.Count; j++) { @@ -921,6 +994,20 @@ for (int i = 0; i < EquipmentStaus.data.Count; i++) { + //鍗风粫鐨勮澶囪繍琛� 寮�鍏冲仠鏈烘椂闂� + if (EquipmentStaus.data[i].no.Contains("CMR-JR-SD-")) + { + string HBegDate = DateTime.Now.ToString("yyyy-MM-dd 00:00:00"); + string HEndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + JsonResult HEqDate = await FindDeviceStatusTimeByNo(Url, token, EquipmentStaus.data[i].no, HBegDate, HEndDate); + + 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 + "\"},"; + } + string staus = ""; switch (EquipmentStaus.data[i].status) { @@ -1016,7 +1103,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 + "'',"; } @@ -1069,6 +1156,66 @@ 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(); + } } @@ -1094,6 +1241,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; } @@ -1157,7 +1308,7 @@ //鑹搧 涓嶈壇鍝� 鏄庣粏 娉ㄥ鏈烘暟鎹� public static string Nine = "/api/third/findAllDevicePropsDetailByTimeRange"; //娉ㄥ鏈烘暟鎹� - public static string Ten = "/api/third/findAllDevicePropsDetailByTimeRange"; + //public static string Ten = "/api/third/findAllDevicePropsDetailByTimeRange"; //public static string Eleven = "Monday"; //public static string Twelve = "Monday"; } -- Gitblit v1.9.1