From 777ea5aaa3c65554315ac51ea9685e3814230da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=91=E5=8F=AB=E9=94=84=E5=A4=B4?= Date: Wed, 10 Apr 2024 09:04:35 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=E6=9F=A5=E8=AF=A2=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProductionSystem/Forms/HomeForm.cs | 84 +++++++++++++++---- ProductionSystem/Untils/Tool/UxTool.cs | 4 +- .../DbModel/T_Product_Step.cs | 6 +- .../ProductStepService.cs | 12 +++ 4 files changed, 86 insertions(+), 20 deletions(-) diff --git a/ProductionSystem/Forms/HomeForm.cs b/ProductionSystem/Forms/HomeForm.cs index 1141275..09e3ffc 100644 --- a/ProductionSystem/Forms/HomeForm.cs +++ b/ProductionSystem/Forms/HomeForm.cs @@ -32,6 +32,8 @@ using NewLife.Security; using ProductionSystem.Untils.Tool; using DevExpress.Data.Diagram.Core; using SqlSugar; +using ProductionSystem_Model.DbModel; +using NewLife.Reflection; namespace ProductionSystem.Forms { @@ -43,6 +45,7 @@ namespace ProductionSystem.Forms private readonly ProtocolConfigService _protocolConfigService = new ProtocolConfigService(); private readonly PlcPointService _plcPointService = new PlcPointService(); private readonly ProductTypeService _productTypeService = new ProductTypeService(); + private readonly ProductStepService productStepService = new ProductStepService(); private Random random = new Random(); DataProductService dataProductService = new DataProductService(); @@ -180,8 +183,8 @@ namespace ProductionSystem.Forms hslCurveHistory.RemoveAllCurve(); - - + + } @@ -746,17 +749,19 @@ namespace ProductionSystem.Forms - + ProductStepService stepService = new ProductStepService(); - var d1300Value = GetPlcValue("D1300"); + var d1300Value = GetPlcValue("D1300"); string[] str = new[] { "COM9", "COM10" }; //步骤1水泵1空载 if(Convert.ToInt32(Double.Parse(d1300Value).ToString("0")) == 0) { - + T_Product_Step step=new T_Product_Step(); - middleIsCanRound = false; + + + middleIsCanRound = false; @@ -789,7 +794,17 @@ namespace ProductionSystem.Forms var ya= uxTool.ToAction(); - + step.Id = Guid.NewGuid().ToString("N"); + step.ReturnValue = uxTool.Val; + step.WriteValue = uxTool.Write; + step.CreateTime = DateTime.Now; + step.ProductType = Program.ProductType; + step.EquipmentName = "SB1"; + step.StepName = ""; + + stepService.AddProductStep(step); + + Thread.Sleep(2000); @@ -981,6 +996,13 @@ namespace ProductionSystem.Forms GetPlc(Program.BZ5, "BZ5"); GetPlc(Program.BZ6, "BZ6"); + SetMiddleData("BZ1_DB"); + SetMiddleData("BZ2_DB"); + SetMiddleData("BZ3_DB"); + SetMiddleData("BZ4_DB"); + SetMiddleData("BZ5_DB"); + SetMiddleData("BZ6_DB"); + Thread.Sleep(Program.ReadPlcRate); } @@ -1188,6 +1210,9 @@ namespace ProductionSystem.Forms SetMiddleData(values, txt); } + + + @@ -1419,33 +1444,58 @@ namespace ProductionSystem.Forms { if (middleMyTestResultControls[j].IsHandleCreated && !middleMyTestResultControls[j].IsDisposed) { - var result = string.Empty; - var val = string.Empty; + int result = 0; + var writeVal = string.Empty; + var returnVal = string.Empty; var testResultPoint = middleMyTestResultControls[j].TestResultPLCPointCode; var testValPoint = middleMyTestResultControls[j].TestValPLCPointCode; //获取点位 var paraCode = middleMyTestResultControls[j].ParaCode; - + var step = productStepService.QueryLatestStep(paraCategory, paraCode, Program.ProductType); if (string.IsNullOrEmpty(testResultPoint) || string.IsNullOrEmpty(testValPoint)) { //进行sql 进行查询sql - val=dataProductService.QueryDataProduct(paraCategory, paraCode); + //val=dataProductService.QueryDataProduct(paraCategory, paraCode); + + } this.Invoke(new Action(() => { - if (middleMyTestResultControls[j].LblItemText == "总状态") + if (step == null) { - result = val; + middleMyTestResultControls[j].TestResultText = "空闲"; + middleMyTestResultControls[j].TestResultForeColor = Color.Gray; + middleMyTestResultControls[j].TestValText = ""; + } + else + { + writeVal = step.WriteValue; + returnVal = step.ReturnValue; + int val1 = Convert.ToInt32(writeVal); + int val2 = Convert.ToInt32(returnVal); + if (returnVal == null) + { + result = 2; + } + if (Math.Abs(val2 - val1) <= 10) + { + result = 1; + } + else + { + result = 2; + } + + middleMyTestResultControls[j].TestResultText = result == 1 ? "OK" : (result == 2 ? "NG" : ""); + middleMyTestResultControls[j].TestResultForeColor = Color.White; + middleMyTestResultControls[j].TestResultBackColor = result == 1 ? Color.Green : (result == 2 ? Color.Red : Color.Gainsboro); + middleMyTestResultControls[j].TestValText = returnVal; } - middleMyTestResultControls[j].TestResultText = result == "1.000" ? "OK" : (result == "2.000" ? "NG" : ""); - middleMyTestResultControls[j].TestResultForeColor = Color.White; - middleMyTestResultControls[j].TestResultBackColor = result == "1.000" ? Color.Green : (result == "2.000" ? Color.Red : Color.Gainsboro); - middleMyTestResultControls[j].TestValText = val; })); } } diff --git a/ProductionSystem/Untils/Tool/UxTool.cs b/ProductionSystem/Untils/Tool/UxTool.cs index a4ff2cc..3aa6a0e 100644 --- a/ProductionSystem/Untils/Tool/UxTool.cs +++ b/ProductionSystem/Untils/Tool/UxTool.cs @@ -30,11 +30,13 @@ namespace ProductionSystem.Untils.Tool public string Val { get; set; } + public string Write { get; set; } + public bool ToAction() { uint seep = uint.Parse((mo * 0.4).ToString()); - + Write = seep.ToString(); XTrace.WriteLine("真实速度:{0}", seep); MFMsgVariable me = new MFMsgVariable(8); diff --git a/ProductionSystem_Model/DbModel/T_Product_Step.cs b/ProductionSystem_Model/DbModel/T_Product_Step.cs index e61b301..a3f956b 100644 --- a/ProductionSystem_Model/DbModel/T_Product_Step.cs +++ b/ProductionSystem_Model/DbModel/T_Product_Step.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Principal; using System.Text; using System.Threading.Tasks; @@ -13,7 +14,8 @@ namespace ProductionSystem_Model.DbModel public class T_Product_Step { [SugarColumn(ColumnName = "id", IsPrimaryKey = true)] - public int Id { get; set; } + + public string Id { get; set; } [SugarColumn(ColumnName = "step_name")] public string StepName { get; set; } @@ -27,7 +29,7 @@ namespace ProductionSystem_Model.DbModel [SugarColumn(ColumnName = "return_value")] public string ReturnValue { get; set; } - [SugarColumn(ColumnName = "createdtime")] + [SugarColumn(ColumnName = "create_time")] public DateTime CreateTime { get; set; } [SugarColumn(ColumnName = "product_type")] diff --git a/ProductionSystem_Service/ProductStepService.cs b/ProductionSystem_Service/ProductStepService.cs index f3cc21f..ead2db8 100644 --- a/ProductionSystem_Service/ProductStepService.cs +++ b/ProductionSystem_Service/ProductStepService.cs @@ -26,5 +26,17 @@ namespace ProductionSystem_Service return -1; } } + + /// + /// 查询最新一条记录 + /// + /// + /// + /// + /// + public T_Product_Step QueryLatestStep(string stepName,string equipmentName,string productType) + { + return db.Queryable().Where(m => m.StepName == stepName && m.EquipmentName == equipmentName && m.ProductType == productType).First(); + } } }