Browse Source

设备总控模块

Linsk 3 months ago
parent
commit
f1ca9c47bf

+ 8 - 0
Helper/SystemEnums.cs

@@ -17,5 +17,13 @@ namespace Helper
             黑体,
             黑体,
             楷体
             楷体
         }
         }
+
+        public enum UserRole
+        {
+            管理员,
+            工程师,
+            操作员,
+            访客
+        }
     }
     }
 }
 }

+ 27 - 0
Model/Entity/AuthEntity.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+
+namespace Model
+{
+    [SugarTable("auth")]
+    public class AuthEntity : BaseEntity
+    {
+        [SugarColumn(ColumnDataType = "Nvarchar(255)", IsNullable = false)]
+
+        public string Role { get; set; } = "管理员";
+        public bool ControlModule { get; set; }
+        public bool MonitorModule { get; set; }
+        public bool RecipeModule { get; set; }
+        public bool LogModule { get; set; }
+        public bool ReportModule { get; set; }
+        public bool ChartModule { get; set; }
+        public bool ParamModule { get; set; }
+        //管理员特有
+        //public bool AuthModule { get; set; }
+        public bool UserModule { get; set; }
+    }
+}

+ 14 - 0
Model/Entity/BaseEntity.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+    public class BaseEntity
+    {
+        [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+        public int Id { get; set; }
+    }
+}

+ 35 - 0
Model/Entity/DataEntity.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+
+namespace Model
+{
+    [SugarTable("data")]
+    public class DataEntity : BaseEntity
+    {
+
+        public DateTime InsertTime { get; set; }
+
+        public string? 脱脂喷淋泵压力值 { get; set; }
+
+        public string? 脱脂pH值 { get; set; }
+        public string? 陶化pH值 { get; set; }
+
+        public string? 粗洗喷淋泵压力值 { get; set; }
+
+        public string? 陶化喷淋泵压力值 { get; set; }
+
+        public string? 精洗喷淋泵压力值 { get; set; }
+
+        public string? 水分炉测量温度 { get; set; }
+
+        public string? 固化炉测量温度 { get; set; }
+
+        public string? 厂内温度 { get; set; }
+
+        public string? 厂内湿度 { get; set; }
+    }
+}

+ 44 - 0
Model/Entity/RecipeEntity.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+
+namespace Model
+{
+    [SugarTable("recipe")]
+    public class RecipeEntity : BaseEntity
+    {
+        [SugarColumn(ColumnDataType = "Nvarchar(255)", IsNullable = false)]
+        public string 产品类型 { get; set; }
+
+        public string 脱脂设定压力上限值 { get; set; } = string.Empty;
+        public string 脱脂设定压力下限值 { get; set; } = string.Empty;
+
+        public string 粗洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 粗洗液位下限值 { get; set; } = string.Empty;
+
+        public string 陶化喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗喷淋泵过载上限值 { get; set; } = string.Empty;
+
+        public string 精洗液位下限值 { get; set; } = string.Empty;
+
+
+        public string 水分炉温度上限值 { get; set; } = string.Empty;
+
+        public string 水分炉温度下限值 { get; set; } = string.Empty;
+
+        public string 冷却室离心风机过载上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度上限值 { get; set; } = string.Empty;
+
+        public string 固化炉温度下限值 { get; set; } = string.Empty;
+
+        public string 输送机设定速度 { get; set; } = string.Empty;
+
+        public string 输送机设定频率 { get; set; } = string.Empty;
+    }
+}

+ 17 - 0
Model/Entity/UserEntity.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+
+namespace Model
+{
+    [SugarTable("user")]
+    public class UserEntity : BaseEntity
+    {
+        public string UserName { get; set; }
+        public string UserPassword { get; set; }
+        public string Role { get; set; }
+    }
+}

+ 2 - 0
Scada/FormMain.Designer.cs

@@ -561,6 +561,8 @@
             AllowShowTitle = false;
             AllowShowTitle = false;
             AutoScaleMode = AutoScaleMode.None;
             AutoScaleMode = AutoScaleMode.None;
             ClientSize = new Size(1280, 720);
             ClientSize = new Size(1280, 720);
+            CloseAskString = "是否关闭系统";
+            EscClose = true;
             Name = "FormMain";
             Name = "FormMain";
             Padding = new Padding(0);
             Padding = new Padding(0);
             ShowTitle = false;
             ShowTitle = false;

+ 12 - 0
Scada/FormMain.cs

@@ -27,6 +27,18 @@ namespace Scada
             InitHeaderUI();
             InitHeaderUI();
             InitConfig();
             InitConfig();
             InitPlcClient();
             InitPlcClient();
+
+            this.Closed += (s, e) =>
+            {
+                //取消令牌源
+                cts.Cancel();
+                cts.Dispose();
+                //关闭PLC客户端
+                if (Globals.SiemensClient != null)
+                {
+                    Globals.SiemensClient.Close();
+                }
+            };
             //显示默认界面
             //显示默认界面
             //Aside.SelectFirst();
             //Aside.SelectFirst();
         }
         }

+ 18 - 1
Scada/Globals.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using IoTClient;
 using IoTClient.Clients.PLC;
 using IoTClient.Clients.PLC;
 using IoTClient.Common.Enums;
 using IoTClient.Common.Enums;
 using IoTClient.Enums;
 using IoTClient.Enums;
@@ -50,6 +51,22 @@ namespace Scada
 
 
         public static string SoftwareVersion;
         public static string SoftwareVersion;
 
 
-        
+        public static bool PlcWrite(string varName,dynamic value)
+        {
+            if(SiemensClient!=null && SiemensClient.Connected)
+            {
+                var address = WriteDic[varName];
+                Result result = SiemensClient.Write(address, value);
+                if(result.IsSucceed)
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            return false;
+        }
     }
     }
 }
 }

+ 29 - 14
Scada/Page/PageTotalEquipmentControl.Designer.cs

@@ -29,7 +29,7 @@
         private void InitializeComponent()
         private void InitializeComponent()
         {
         {
             uiTitlePanel1 = new Sunny.UI.UITitlePanel();
             uiTitlePanel1 = new Sunny.UI.UITitlePanel();
-            btn_DryRun = new Sunny.UI.UISymbolButton();
+            btn_DryRun = new UserCounterButton();
             btn_AlarmReset = new Sunny.UI.UISymbolButton();
             btn_AlarmReset = new Sunny.UI.UISymbolButton();
             btn_MachineReset = new Sunny.UI.UISymbolButton();
             btn_MachineReset = new Sunny.UI.UISymbolButton();
             btn_Stop = new Sunny.UI.UISymbolButton();
             btn_Stop = new Sunny.UI.UISymbolButton();
@@ -71,18 +71,21 @@
             // 
             // 
             // btn_DryRun
             // btn_DryRun
             // 
             // 
-            btn_DryRun.Font = new Font("微软雅黑", 21.75F);
-            btn_DryRun.Location = new Point(870, 68);
+            btn_DryRun.BackColor = Color.Transparent;
+            btn_DryRun.CounterButtonState = false;
+            btn_DryRun.CounterButtonSymbol = 558653;
+            btn_DryRun.FillColor = Color.Transparent;
+            btn_DryRun.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_DryRun.Location = new Point(871, 68);
             btn_DryRun.MinimumSize = new Size(1, 1);
             btn_DryRun.MinimumSize = new Size(1, 1);
             btn_DryRun.Name = "btn_DryRun";
             btn_DryRun.Name = "btn_DryRun";
-            btn_DryRun.Radius = 10;
-            btn_DryRun.Size = new Size(181, 84);
-            btn_DryRun.Symbol = 61452;
-            btn_DryRun.SymbolSize = 55;
+            btn_DryRun.RectColor = Color.FromArgb(64, 128, 204);
+            btn_DryRun.Size = new Size(184, 84);
             btn_DryRun.TabIndex = 4;
             btn_DryRun.TabIndex = 4;
-            btn_DryRun.TagString = "空运行";
-            btn_DryRun.Text = "空运行";
-            btn_DryRun.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_DryRun.Text = null;
+            btn_DryRun.TextAlignment = ContentAlignment.MiddleCenter;
+            btn_DryRun.VariableName = "空运行";
+            btn_DryRun.ClickEvent += btn_DryRun_ClickEvent;
             // 
             // 
             // btn_AlarmReset
             // btn_AlarmReset
             // 
             // 
@@ -98,6 +101,7 @@
             btn_AlarmReset.TagString = "报警复位";
             btn_AlarmReset.TagString = "报警复位";
             btn_AlarmReset.Text = "报警复位";
             btn_AlarmReset.Text = "报警复位";
             btn_AlarmReset.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_AlarmReset.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_AlarmReset.Click += btn_Start_Common_Click;
             // 
             // 
             // btn_MachineReset
             // btn_MachineReset
             // 
             // 
@@ -113,6 +117,7 @@
             btn_MachineReset.TagString = "机械复位";
             btn_MachineReset.TagString = "机械复位";
             btn_MachineReset.Text = "机械复位";
             btn_MachineReset.Text = "机械复位";
             btn_MachineReset.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_MachineReset.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_MachineReset.Click += btn_Start_Common_Click;
             // 
             // 
             // btn_Stop
             // btn_Stop
             // 
             // 
@@ -128,6 +133,7 @@
             btn_Stop.TagString = "总停止";
             btn_Stop.TagString = "总停止";
             btn_Stop.Text = "总停止";
             btn_Stop.Text = "总停止";
             btn_Stop.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_Stop.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_Stop.Click += btn_Start_Common_Click;
             // 
             // 
             // btn_Start
             // btn_Start
             // 
             // 
@@ -143,6 +149,7 @@
             btn_Start.TagString = "总启动";
             btn_Start.TagString = "总启动";
             btn_Start.Text = "总启动";
             btn_Start.Text = "总启动";
             btn_Start.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_Start.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_Start.Click += btn_Start_Common_Click;
             // 
             // 
             // uiTitlePanel2
             // uiTitlePanel2
             // 
             // 
@@ -182,24 +189,26 @@
             device_SSJ.TabIndex = 3;
             device_SSJ.TabIndex = 3;
             device_SSJ.Text = "userDeviceUnitControl1";
             device_SSJ.Text = "userDeviceUnitControl1";
             device_SSJ.TextAlignment = ContentAlignment.MiddleCenter;
             device_SSJ.TextAlignment = ContentAlignment.MiddleCenter;
+            device_SSJ.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_CX
             // device_CX
             // 
             // 
             device_CX.BackColor = Color.Transparent;
             device_CX.BackColor = Color.Transparent;
-            device_CX.CloseVariableName = "粗工位关";
-            device_CX.EquipmentUnitName = "粗工位";
+            device_CX.CloseVariableName = "粗工位关";
+            device_CX.EquipmentUnitName = "粗工位";
             device_CX.FillColor = Color.Transparent;
             device_CX.FillColor = Color.Transparent;
             device_CX.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             device_CX.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             device_CX.Location = new Point(19, 126);
             device_CX.Location = new Point(19, 126);
             device_CX.MinimumSize = new Size(1, 1);
             device_CX.MinimumSize = new Size(1, 1);
             device_CX.Name = "device_CX";
             device_CX.Name = "device_CX";
-            device_CX.OpenVariableName = "粗工位开";
+            device_CX.OpenVariableName = "粗工位开";
             device_CX.RectColor = Color.Transparent;
             device_CX.RectColor = Color.Transparent;
             device_CX.Size = new Size(253, 46);
             device_CX.Size = new Size(253, 46);
             device_CX.State = false;
             device_CX.State = false;
             device_CX.TabIndex = 1;
             device_CX.TabIndex = 1;
             device_CX.Text = "userDeviceUnitControl1";
             device_CX.Text = "userDeviceUnitControl1";
             device_CX.TextAlignment = ContentAlignment.MiddleCenter;
             device_CX.TextAlignment = ContentAlignment.MiddleCenter;
+            device_CX.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_JX
             // device_JX
             // 
             // 
@@ -218,6 +227,7 @@
             device_JX.TabIndex = 2;
             device_JX.TabIndex = 2;
             device_JX.Text = "userDeviceUnitControl1";
             device_JX.Text = "userDeviceUnitControl1";
             device_JX.TextAlignment = ContentAlignment.MiddleCenter;
             device_JX.TextAlignment = ContentAlignment.MiddleCenter;
+            device_JX.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_GHL
             // device_GHL
             // 
             // 
@@ -236,6 +246,7 @@
             device_GHL.TabIndex = 3;
             device_GHL.TabIndex = 3;
             device_GHL.Text = "userDeviceUnitControl1";
             device_GHL.Text = "userDeviceUnitControl1";
             device_GHL.TextAlignment = ContentAlignment.MiddleCenter;
             device_GHL.TextAlignment = ContentAlignment.MiddleCenter;
+            device_GHL.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_TH
             // device_TH
             // 
             // 
@@ -254,6 +265,7 @@
             device_TH.TabIndex = 2;
             device_TH.TabIndex = 2;
             device_TH.Text = "userDeviceUnitControl1";
             device_TH.Text = "userDeviceUnitControl1";
             device_TH.TextAlignment = ContentAlignment.MiddleCenter;
             device_TH.TextAlignment = ContentAlignment.MiddleCenter;
+            device_TH.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_LQS
             // device_LQS
             // 
             // 
@@ -272,6 +284,7 @@
             device_LQS.TabIndex = 3;
             device_LQS.TabIndex = 3;
             device_LQS.Text = "userDeviceUnitControl1";
             device_LQS.Text = "userDeviceUnitControl1";
             device_LQS.TextAlignment = ContentAlignment.MiddleCenter;
             device_LQS.TextAlignment = ContentAlignment.MiddleCenter;
+            device_LQS.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_SFL
             // device_SFL
             // 
             // 
@@ -290,6 +303,7 @@
             device_SFL.TabIndex = 2;
             device_SFL.TabIndex = 2;
             device_SFL.Text = "userDeviceUnitControl1";
             device_SFL.Text = "userDeviceUnitControl1";
             device_SFL.TextAlignment = ContentAlignment.MiddleCenter;
             device_SFL.TextAlignment = ContentAlignment.MiddleCenter;
+            device_SFL.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // device_TZ
             // device_TZ
             // 
             // 
@@ -308,6 +322,7 @@
             device_TZ.TabIndex = 0;
             device_TZ.TabIndex = 0;
             device_TZ.Text = "userDeviceUnitControl1";
             device_TZ.Text = "userDeviceUnitControl1";
             device_TZ.TextAlignment = ContentAlignment.MiddleCenter;
             device_TZ.TextAlignment = ContentAlignment.MiddleCenter;
+            device_TZ.ClickEvent += device_Common_ClickEvent;
             // 
             // 
             // uiTitlePanel3
             // uiTitlePanel3
             // 
             // 
@@ -357,7 +372,6 @@
 
 
         private Sunny.UI.UITitlePanel uiTitlePanel1;
         private Sunny.UI.UITitlePanel uiTitlePanel1;
         private Sunny.UI.UISymbolButton btn_Start;
         private Sunny.UI.UISymbolButton btn_Start;
-        private Sunny.UI.UISymbolButton btn_DryRun;
         private Sunny.UI.UISymbolButton btn_AlarmReset;
         private Sunny.UI.UISymbolButton btn_AlarmReset;
         private Sunny.UI.UISymbolButton btn_MachineReset;
         private Sunny.UI.UISymbolButton btn_MachineReset;
         private Sunny.UI.UISymbolButton btn_Stop;
         private Sunny.UI.UISymbolButton btn_Stop;
@@ -372,5 +386,6 @@
         private UserDeviceUnitControl device_CX;
         private UserDeviceUnitControl device_CX;
         private Sunny.UI.UITitlePanel uiTitlePanel3;
         private Sunny.UI.UITitlePanel uiTitlePanel3;
         private Sunny.UI.UITextBox txt_Log;
         private Sunny.UI.UITextBox txt_Log;
+        private UserCounterButton btn_DryRun;
     }
     }
 }
 }

+ 91 - 1
Scada/Page/PageTotalEquipmentControl.cs

@@ -4,20 +4,110 @@ using System.ComponentModel;
 using System.Data;
 using System.Data;
 using System.Drawing;
 using System.Drawing;
 using System.Linq;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Windows.Forms;
 using HZY.Framework.DependencyInjection;
 using HZY.Framework.DependencyInjection;
+using Microsoft.Extensions.Logging;
 using Sunny.UI;
 using Sunny.UI;
+using LogLevel = Microsoft.Extensions.Logging.LogLevel;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
     public partial class PageTotalEquipmentControl : UIPage, ISingletonSelfDependency
     public partial class PageTotalEquipmentControl : UIPage, ISingletonSelfDependency
     {
     {
-        public PageTotalEquipmentControl()
+        private ILogger<PageTotalEquipmentControl> _logger;
+        public PageTotalEquipmentControl(ILogger<PageTotalEquipmentControl> logger)
         {
         {
+            _logger = logger;
             InitializeComponent();
             InitializeComponent();
         }
         }
 
 
+        private void btn_Start_Common_Click(object sender, EventArgs e)
+        {
+            UISymbolButton uISymbolButton = sender as UISymbolButton;
+            if (!Globals.SiemensClient.Connected)
+            {
+                UIMessageTip.ShowWarning("请先连接到西门子PLC");
+                return;
+            }
+            if (Globals.PlcWrite(uISymbolButton.TagString, true))
+            {
+                UIMessageTip.ShowOk("写入成功");
+                ShowLog($"{uISymbolButton.TagString} 写入成功");
+            }
+            else
+            {
+                UIMessageTip.ShowError("写入失败");
+                ShowLog($"{uISymbolButton.TagString} 写入失败", LogLevel.Warning);
+            }
+        }
+
+
+
+        private void ShowLog(string log, LogLevel logLevel = LogLevel.Information)
+        {
+            this.txt_Log.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "=>" + log + Environment.NewLine);
+
+            switch (logLevel)
+            {
+                case LogLevel.Information:
+                    _logger.LogInformation(log);
+                    break;
+                case LogLevel.Warning:
+                    _logger.LogWarning(log);
+                    break;
+                case LogLevel.Error:
+                    _logger.LogError(log);
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        private void btn_DryRun_ClickEvent(object sender, EventArgs e)
+        {
+            if (!Globals.SiemensClient.Connected)
+            {
+                UIMessageTip.ShowWarning("请先连接到西门子PLC");
+                return;
+            }
+            if (Globals.PlcWrite(this.btn_DryRun.VariableName, !this.btn_DryRun.CounterButtonState))
+            {
+                this.btn_DryRun.CounterButtonState = !this.btn_DryRun.CounterButtonState;
+                UIMessageTip.ShowOk("写入成功");
+                ShowLog($"{btn_DryRun.VariableName} 写入成功");
+
+            }
+            else
+            {
+                UIMessageTip.ShowError("写入失败");
+                ShowLog($"{btn_DryRun.VariableName} 写入失败", LogLevel.Warning);
+            }
+        }
+
+        private void device_Common_ClickEvent(object sender, EventArgs e)
+        {
+            UserDeviceUnitControl userDeviceUnit = sender as UserDeviceUnitControl;
+            if (!Globals.SiemensClient.Connected)
+            {
+                userDeviceUnit.State = false;
+                UIMessageTip.ShowWarning("请先连接到西门子PLC");
+                return;
+            }
+            bool state = userDeviceUnit.State;
+            string variableName = state ? userDeviceUnit.OpenVariableName : userDeviceUnit.CloseVariableName;
+            if (Globals.PlcWrite(variableName, state))
+            {
+                UIMessageTip.ShowOk("写入成功");
+                ShowLog($"{variableName} 写入成功");
+            }
+            else
+            {
+                UIMessageTip.ShowError("写入失败");
+                ShowLog($"{variableName} 写入失败", LogLevel.Warning);
+            }
+        }
     }
     }
 }
 }

+ 6 - 0
Scada/Scada.csproj

@@ -33,4 +33,10 @@
     </EmbeddedResource>
     </EmbeddedResource>
   </ItemGroup>
   </ItemGroup>
 
 
+  <ItemGroup>
+    <None Update="appsettings.json">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
 </Project>
 </Project>

+ 1 - 2
Scada/UserControls/UserCounterButton.Designer.cs

@@ -38,14 +38,13 @@
             btn_Counter.Location = new Point(0, 0);
             btn_Counter.Location = new Point(0, 0);
             btn_Counter.MinimumSize = new Size(1, 1);
             btn_Counter.MinimumSize = new Size(1, 1);
             btn_Counter.Name = "btn_Counter";
             btn_Counter.Name = "btn_Counter";
-            btn_Counter.Radius = 50;
             btn_Counter.Size = new Size(190, 90);
             btn_Counter.Size = new Size(190, 90);
             btn_Counter.Symbol = 558653;
             btn_Counter.Symbol = 558653;
             btn_Counter.SymbolSize = 55;
             btn_Counter.SymbolSize = 55;
             btn_Counter.TabIndex = 0;
             btn_Counter.TabIndex = 0;
             btn_Counter.Text = "空运行";
             btn_Counter.Text = "空运行";
             btn_Counter.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_Counter.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            btn_Counter.Click += btn_Counter_Click;
+            btn_Counter.Click += UserCounterButton_Click;
             // 
             // 
             // UserCounterButton
             // UserCounterButton
             // 
             // 

+ 40 - 36
Scada/UserControls/UserCounterButton.cs

@@ -16,61 +16,75 @@ namespace Scada
         private UIStyle Style;
         private UIStyle Style;
         private Color defaultFillColor;
         private Color defaultFillColor;
         private Color defaultRectColor;
         private Color defaultRectColor;
+
         public UserCounterButton()
         public UserCounterButton()
         {
         {
             InitializeComponent();
             InitializeComponent();
             this.Load += UserCounterButton_Load;
             this.Load += UserCounterButton_Load;
         }
         }
 
 
+        // 用户按钮加载事件
         private void UserCounterButton_Load(object? sender, EventArgs e)
         private void UserCounterButton_Load(object? sender, EventArgs e)
         {
         {
-            UIExtension.SetStyleManager = SetStyle;
+            UIExtension.SetStyleManager = SetStyle; // 设置样式管理器
+                                                    //80, 160, 255
+            defaultFillColor = this.btn_Counter.FillColor;
+            defaultRectColor = this.btn_Counter.RectColor;
         }
         }
 
 
+        // 设置样式的方法
         private void SetStyle(UIStyleManager manager)
         private void SetStyle(UIStyleManager manager)
         {
         {
             this.btn_Counter.Style = manager.Style;
             this.btn_Counter.Style = manager.Style;
             Style = manager.Style;
             Style = manager.Style;
-
-            defaultFillColor = this.btn_Counter.FillColor;
-            defaultRectColor = this.btn_Counter.RectColor;
+            if (CounterButtonState)
+            {
+                this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
+                this.btn_Counter.FillColor2 = this.btn_Counter.FillPressColor;
+                this.RectColor = this.btn_Counter.RectPressColor;
+            }
         }
         }
 
 
-        private string buttonName;
-        [Browsable(true)]
-        [Category("自定义属性")]
-        [Description("按钮名称")]
-        public string ButtonName
+        // 定义一个私有变量,用于存储按钮的符号
+        private int counterButtonSymbol = 61452;
+        [Browsable(true)] // 使属性可以在属性窗口中编辑
+        [Category("自定义属性")] // 分类属性
+        [Description("取反按钮标签")] // 描述属性的用途
+        public int CounterButtonSymbol
         {
         {
-            get { return buttonName; }
-            set { this.btn_Counter.Text = value; }
+            get { return counterButtonSymbol; }
+            set
+            {
+                counterButtonSymbol = value;
+                this.btn_Counter.Symbol = counterButtonSymbol;
+            }
         }
         }
 
 
-        private int counterButtonSymbol = 61452;
+        private string variableName = "";
         [Browsable(true)]
         [Browsable(true)]
         [Category("自定义属性")]
         [Category("自定义属性")]
-        [Description("图标")]
-        public int CounterButtonSymbol
+        [Description("获取变量名称")]
+        public string VariableName
         {
         {
-            get { return counterButtonSymbol; }
-            set { this.btn_Counter.Symbol = counterButtonSymbol; }
+            get { return variableName; }
+            set { variableName = value; }
         }
         }
 
 
         private bool counterButtonState;
         private bool counterButtonState;
         [Browsable(true)]
         [Browsable(true)]
         [Category("自定义属性")]
         [Category("自定义属性")]
-        [Description("按钮状态")]
+        [Description("取反按钮状态")]
         public bool CounterButtonState
         public bool CounterButtonState
         {
         {
             get { return counterButtonState; }
             get { return counterButtonState; }
             set
             set
             {
             {
                 counterButtonState = value;
                 counterButtonState = value;
-
-                if (counterButtonState = value)
+                if (counterButtonState == true)
                 {
                 {
                     this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
                     this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
-                    this.btn_Counter.RectColor = this.btn_Counter.RectPressColor;
+                    this.btn_Counter.FillColor2 = this.btn_Counter.FillPressColor;
+                    this.RectColor = this.btn_Counter.RectPressColor;
                 }
                 }
                 else
                 else
                 {
                 {
@@ -81,31 +95,21 @@ namespace Scada
                     else
                     else
                     {
                     {
                         this.btn_Counter.FillColor = defaultFillColor;
                         this.btn_Counter.FillColor = defaultFillColor;
+                        this.btn_Counter.FillColor2 = defaultFillColor;
                         this.btn_Counter.RectColor = defaultRectColor;
                         this.btn_Counter.RectColor = defaultRectColor;
                     }
                     }
-
                 }
                 }
             }
             }
-
         }
         }
 
 
-        private string variableName = "";
-
-      
-
         [Browsable(true)]
         [Browsable(true)]
-        [Category("自定义属性")]
-        [Description("获取变量名称")]
-        public string VariableName
-        {
-            get { return variableName; }
-            set { variableName = value; }
-        }
+        [Category("自定义事件")]
+        [Description("点击事件")]
+        public event EventHandler ClickEvent;
 
 
-        public event EventHandler? CounterButtonClick;
-        private void btn_Counter_Click(object sender, EventArgs e)
+        private void UserCounterButton_Click(object sender, EventArgs e)
         {
         {
-            CounterButtonClick?.Invoke(this, e);
+            ClickEvent?.Invoke(this, e);
         }
         }
     }
     }
 }
 }

+ 36 - 0
Scada/appsettings.json

@@ -0,0 +1,36 @@
+{
+    "DbContexts": {
+        "DbType": "Sqlite",
+        "Sqlite": {
+            "ConnectionString": "Data Source=D://实战项目//Scada//Scada//bin//Debug//net8.0-windows"
+        }
+    },
+    //相对路径  可以省略前面的东西
+    // "ConnectionString": "Data Source=SprayData.db"
+    "NLog": {
+        "internalLogLevel": "Info",
+        "internalLogFile": "${currentdir}/Logs/SystemErrors.log",
+        "extensions": [
+            { "assembly": "NLog.Extensions.Logging" }
+        ],
+        "targets": {
+            "allfile": {
+                "type": "File",
+                "fileName": "${currentdir}/Logs/${shortdate}/${level}/${level}.log",
+                "layout": "${longdate}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}"
+            }
+        },
+        "rules": [
+            {
+                "logger": "*",
+                "minLevel": "Trace",
+                "writeTo": "allfile"
+            },
+            {
+                "logger": "Microsoft.*",
+                "maxLevel": "Info",
+                "final": "true"
+            }
+        ]
+    }
+}