Browse Source

设备监控模块

Linsk 3 months ago
parent
commit
94de073f6a

+ 1 - 1
BLL/Dto/UserDto/QueryUserDto.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace BLL.Dto
+namespace BLL.Dto.UserDto
 {
     public class QueryUserDto : BaseDto
     {

+ 13 - 0
BLL/Dto/UserDto/QueryUserRoleDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BLL.Dto.UserDto
+{
+    public class QueryUserRoleDto
+    {
+        public string UserName { get; set; }
+    }
+}

+ 1 - 1
BLL/Dto/UserDto/UserAddDto.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace BLL
+namespace BLL.Dto.UserDto
 {
     public class UserAddDto:BaseDto
     {

+ 1 - 1
BLL/Dto/UserDto/UserDeleteDto.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace BLL.Dto
+namespace BLL.Dto.UserDto
 {
     public class UserDeleteDto:BaseDto
     {

+ 1 - 1
BLL/Dto/UserDto/UserExistDto.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace BLL
+namespace BLL.Dto.UserDto
 {
     public class UserExistDto
     {

+ 1 - 1
BLL/Dto/UserDto/UserLoginDto.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace BLL
+namespace BLL.Dto.UserDto
 {
     public class UserLoginDto
     {

+ 1 - 1
BLL/Dto/UserDto/UserUpdateDto.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace BLL.Dto
+namespace BLL.Dto.UserDto
 {
     public class UserUpdateDto:BaseDto
     {

+ 1 - 0
BLL/Manager/UserManager.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using BLL.Dto;
+using BLL.Dto.UserDto;
 using DAL;
 using Helper;
 using HZY.Framework.DependencyInjection;

+ 4 - 0
Helper/Helper.csproj

@@ -6,4 +6,8 @@
     <Nullable>enable</Nullable>
   </PropertyGroup>
 
+  <ItemGroup>
+    <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="9.0.4" />
+  </ItemGroup>
+
 </Project>

+ 167 - 0
Helper/RuntimeStatusHelper.cs

@@ -0,0 +1,167 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Net;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Helper
+{
+    public class RuntimeStatusHelper
+    {
+        /// <summary>
+        /// 唯一实例
+        /// </summary>
+        public readonly static RuntimeStatusHelper DataManager = new RuntimeStatusHelper();
+
+        private PerformanceCounter cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");//保持一个cpu实例,避免重复创建
+
+        //定义内存的信息结构
+        [StructLayout(LayoutKind.Sequential)]
+        public struct MEMORY_INFO
+        {
+            public uint dwLength; //当前结构体大小
+            public uint dwMemoryLoad; //当前内存使用率
+            public ulong ullTotalPhys; //总计物理内存大小
+            public ulong ullAvailPhys; //可用物理内存大小
+            public ulong ullTotalPageFile; //总计交换文件大小
+            public ulong ullAvailPageFile; //总计交换文件大小
+            public ulong ullTotalVirtual; //总计虚拟内存大小
+            public ulong ullAvailVirtual; //可用虚拟内存大小
+            public ulong ullAvailExtendedVirtual; //保留 这个值始终为0
+        }
+
+        [DllImport("kernel32")]
+        [return: MarshalAs(UnmanagedType.Bool)]
+        public static extern bool GlobalMemoryStatusEx(ref MEMORY_INFO mi);//获取内存相关数据
+
+        /// <summary> 
+        /// 构造方法 
+        /// </summary>     
+        private RuntimeStatusHelper()
+        {
+            cpu.NextValue();//因为第一次获取CPU使用率总是0,所以在此获取一次CPU使用率,避免画面显示CPU为0的情况
+        }
+
+
+        /// <summary>
+        /// 获取电脑磁盘剩余空间
+        /// </summary>
+        /// <returns></returns>
+        public string GetDrivers()
+        {
+            string result = "";
+            DriveInfo[] drives = DriveInfo.GetDrives();
+            foreach (DriveInfo drive in drives)
+            {
+                if (!drive.IsReady)
+                    continue;
+                if (result.Length > 0) result += ",";
+                result += string.Format("{0}盘剩余{1}", drive.Name.Split(':')[0] + "盘剩余", FormatSize(drive.TotalFreeSpace));
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取电脑IP地址
+        /// </summary>
+        /// <returns></returns>
+        public string GetIPAddress()
+        {
+            string hostName = Dns.GetHostName();
+            IPAddress[] iPs = Dns.GetHostEntry(hostName).AddressList;
+            foreach (IPAddress ip in iPs)
+            {
+                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
+                {
+                    return ip.ToString();
+                }
+            }
+            return "";
+        }
+
+
+        /// <summary>
+        /// 获取CPU实时占用率
+        /// </summary>
+        /// <returns></returns>
+        public string GetCpuUtilization()
+        {
+            return String.Format("{0}", cpu.NextValue());
+        }
+
+        /// <summary>
+        /// 获取内存实时占用率
+        /// </summary>
+        /// <returns></returns>
+        public string GetMemoryUtilization()
+        {
+            return String.Format("{0}/{1}", FormatSize(GetUsedPhys()), FormatSize(GetTotalPhys()));
+        }
+
+        /// <summary>
+        /// 格式化容量大小
+        /// </summary>
+        /// <param name="size">容量(B)</param>
+        /// <returns>已格式化的容量</returns>
+        private string FormatSize(double size)
+        {
+            double d = (double)size;
+            int i = 0;
+            while ((d > 1024) && (i < 5))
+            {
+                d /= 1024;
+                i++;
+            }
+            string[] unit = { "B", "KB", "MB", "G", "T" };
+            return (string.Format("{0} {1}", Math.Round(d, 2), unit[i]));
+        }
+
+        /// <summary>
+        /// 获得当前内存使用情况
+        /// </summary>
+        /// <returns></returns>
+        public MEMORY_INFO GetMemoryStatus()
+        {
+            MEMORY_INFO mi = new MEMORY_INFO();
+            mi.dwLength = (uint)Marshal.SizeOf(mi);
+            GlobalMemoryStatusEx(ref mi);
+            return mi;
+        }
+
+        /// <summary>
+        /// 获得当前可用物理内存大小
+        /// </summary>
+        /// <returns>当前可用物理内存(B)</returns>
+        public ulong GetAvailPhys()
+        {
+            MEMORY_INFO mi = GetMemoryStatus();
+            return mi.ullAvailPhys;
+        }
+
+        /// <summary>
+        /// 获得当前已使用的内存大小
+        /// </summary>
+        /// <returns>已使用的内存大小(B)</returns>
+        public ulong GetUsedPhys()
+        {
+            MEMORY_INFO mi = GetMemoryStatus();
+            return (mi.ullTotalPhys - mi.ullAvailPhys);
+        }
+
+        /// <summary>
+        /// 获得当前总计物理内存大小
+        /// </summary>
+        /// <returns&amp;gt;总计物理内存大小(B)&amp;lt;/returns&amp;gt;
+        public ulong GetTotalPhys()
+        {
+            MEMORY_INFO mi = GetMemoryStatus();
+            return mi.ullTotalPhys;
+        }
+        public string GetTurnonTime()
+        {
+            return DateTime.Now.AddMilliseconds(-Environment.TickCount).ToString();
+        }
+    }
+}

+ 2 - 1
Scada/FormLogin.cs

@@ -8,6 +8,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using BLL;
+using BLL.Dto.UserDto;
 using Helper;
 using HZY.Framework.DependencyInjection;
 using Sunny.UI;
@@ -23,7 +24,7 @@ namespace Scada
             InitializeComponent();
         }
 
-        private async Task FormLogin_ButtonLoginClick(object sender, EventArgs e)
+        private async void FormLogin_ButtonLoginClick(object sender, EventArgs e)
         {
             var result = await _userManager.LoginAsync(new UserLoginDto() { UserName=this.UserName,UserPassword=this.Password});
             

+ 257 - 257
Scada/FormMain.Designer.cs

@@ -32,35 +32,35 @@
             uiPanel1 = new Sunny.UI.UIPanel();
             uiSymbolLabel2 = new Sunny.UI.UISymbolLabel();
             uiSymbolLabel1 = new Sunny.UI.UISymbolLabel();
-            uiLabel8 = new Sunny.UI.UILabel();
-            uiLabel7 = new Sunny.UI.UILabel();
-            uiLabel6 = new Sunny.UI.UILabel();
-            uiLabel5 = new Sunny.UI.UILabel();
-            uiLabel4 = new Sunny.UI.UILabel();
-            uiScrollingText1 = new Sunny.UI.UIScrollingText();
+            lbl_Time = new Sunny.UI.UILabel();
+            lbl_Humidness = new Sunny.UI.UILabel();
+            lbl_Temperature = new Sunny.UI.UILabel();
+            lb_Humidness = new Sunny.UI.UILabel();
+            lb_Temperature = new Sunny.UI.UILabel();
+            st_AlarmInfo = new Sunny.UI.UIScrollingText();
             lbl_User = new Sunny.UI.UILabel();
             pictureBox2 = new PictureBox();
             uiLabel2 = new Sunny.UI.UILabel();
             uiLabel1 = new Sunny.UI.UILabel();
             pictureBox1 = new PictureBox();
-            uiLabel9 = new Sunny.UI.UILabel();
-            uiLedLabel1 = new Sunny.UI.UILedLabel();
-            uiLedLabel2 = new Sunny.UI.UILedLabel();
-            uiLabel10 = new Sunny.UI.UILabel();
-            uiLedLabel3 = new Sunny.UI.UILedLabel();
-            uiLabel11 = new Sunny.UI.UILabel();
-            uiLedLabel4 = new Sunny.UI.UILedLabel();
-            uiLabel12 = new Sunny.UI.UILabel();
+            lb_ProducteCount = new Sunny.UI.UILabel();
+            lbl_ProducteCount = new Sunny.UI.UILedLabel();
+            lbl_BadCount = new Sunny.UI.UILedLabel();
+            lb_BadCount = new Sunny.UI.UILabel();
+            lbl_Beat = new Sunny.UI.UILedLabel();
+            lb_Beat = new Sunny.UI.UILabel();
+            lbl_TotalAlarm = new Sunny.UI.UILedLabel();
+            lb_TotalAlarm = new Sunny.UI.UILabel();
             uiLabel13 = new Sunny.UI.UILabel();
-            uiLedBulb1 = new Sunny.UI.UILedBulb();
+            led_ProducteState = new Sunny.UI.UILedBulb();
             uiLabel14 = new Sunny.UI.UILabel();
             uiLabel15 = new Sunny.UI.UILabel();
             uiLabel16 = new Sunny.UI.UILabel();
             uiLabel17 = new Sunny.UI.UILabel();
             uiLabel18 = new Sunny.UI.UILabel();
             led_PlcState = new Sunny.UI.UILedBulb();
-            uiLabel19 = new Sunny.UI.UILabel();
-            uiLabel20 = new Sunny.UI.UILabel();
+            lbl_CPUInformation = new Sunny.UI.UILabel();
+            lbl_MemoryInformation = new Sunny.UI.UILabel();
             uiLabel21 = new Sunny.UI.UILabel();
             uiLabel22 = new Sunny.UI.UILabel();
             StyleManager = new Sunny.UI.UIStyleManager(components);
@@ -75,8 +75,8 @@
             // 
             Footer.Controls.Add(uiLabel22);
             Footer.Controls.Add(uiLabel21);
-            Footer.Controls.Add(uiLabel20);
-            Footer.Controls.Add(uiLabel19);
+            Footer.Controls.Add(lbl_MemoryInformation);
+            Footer.Controls.Add(lbl_CPUInformation);
             Footer.Controls.Add(led_PlcState);
             Footer.Controls.Add(uiLabel18);
             Footer.Controls.Add(uiLabel17);
@@ -93,16 +93,16 @@
             // 
             // Header
             // 
-            Header.Controls.Add(uiLedBulb1);
+            Header.Controls.Add(led_ProducteState);
             Header.Controls.Add(uiLabel13);
-            Header.Controls.Add(uiLedLabel4);
-            Header.Controls.Add(uiLabel12);
-            Header.Controls.Add(uiLedLabel3);
-            Header.Controls.Add(uiLabel11);
-            Header.Controls.Add(uiLedLabel2);
-            Header.Controls.Add(uiLabel10);
-            Header.Controls.Add(uiLedLabel1);
-            Header.Controls.Add(uiLabel9);
+            Header.Controls.Add(lbl_TotalAlarm);
+            Header.Controls.Add(lb_TotalAlarm);
+            Header.Controls.Add(lbl_Beat);
+            Header.Controls.Add(lb_Beat);
+            Header.Controls.Add(lbl_BadCount);
+            Header.Controls.Add(lb_BadCount);
+            Header.Controls.Add(lbl_ProducteCount);
+            Header.Controls.Add(lb_ProducteCount);
             Header.Controls.Add(uiPanel1);
             Header.Location = new Point(0, 0);
             Header.NodeInterval = 0;
@@ -115,12 +115,12 @@
             uiPanel1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
             uiPanel1.Controls.Add(uiSymbolLabel2);
             uiPanel1.Controls.Add(uiSymbolLabel1);
-            uiPanel1.Controls.Add(uiLabel8);
-            uiPanel1.Controls.Add(uiLabel7);
-            uiPanel1.Controls.Add(uiLabel6);
-            uiPanel1.Controls.Add(uiLabel5);
-            uiPanel1.Controls.Add(uiLabel4);
-            uiPanel1.Controls.Add(uiScrollingText1);
+            uiPanel1.Controls.Add(lbl_Time);
+            uiPanel1.Controls.Add(lbl_Humidness);
+            uiPanel1.Controls.Add(lbl_Temperature);
+            uiPanel1.Controls.Add(lb_Humidness);
+            uiPanel1.Controls.Add(lb_Temperature);
+            uiPanel1.Controls.Add(st_AlarmInfo);
             uiPanel1.Controls.Add(lbl_User);
             uiPanel1.Controls.Add(pictureBox2);
             uiPanel1.Controls.Add(uiLabel2);
@@ -165,89 +165,89 @@
             uiSymbolLabel1.TabIndex = 10;
             uiSymbolLabel1.Click += uiSymbolLabel1_Click;
             // 
-            // uiLabel8
-            // 
-            uiLabel8.BackColor = Color.Transparent;
-            uiLabel8.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel8.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel8.Location = new Point(922, 43);
-            uiLabel8.Name = "uiLabel8";
-            uiLabel8.Size = new Size(215, 33);
-            uiLabel8.TabIndex = 9;
-            uiLabel8.Text = "2024-10-12 23:05:23";
-            uiLabel8.MouseDown += Panel_MouseDown;
-            uiLabel8.MouseMove += Panel_MouseMove;
-            // 
-            // uiLabel7
-            // 
-            uiLabel7.BackColor = Color.Transparent;
-            uiLabel7.Font = new Font("宋体", 9F);
-            uiLabel7.ForeColor = Color.Green;
-            uiLabel7.Location = new Point(1125, 16);
-            uiLabel7.Name = "uiLabel7";
-            uiLabel7.Size = new Size(44, 27);
-            uiLabel7.TabIndex = 8;
-            uiLabel7.Text = "60%";
-            uiLabel7.MouseDown += Panel_MouseDown;
-            uiLabel7.MouseMove += Panel_MouseMove;
-            // 
-            // uiLabel6
-            // 
-            uiLabel6.BackColor = Color.Transparent;
-            uiLabel6.Font = new Font("宋体", 9F);
-            uiLabel6.ForeColor = Color.Green;
-            uiLabel6.Location = new Point(985, 16);
-            uiLabel6.Name = "uiLabel6";
-            uiLabel6.Size = new Size(44, 27);
-            uiLabel6.TabIndex = 7;
-            uiLabel6.Text = "25℃";
-            uiLabel6.MouseDown += Panel_MouseDown;
-            uiLabel6.MouseMove += Panel_MouseMove;
-            // 
-            // uiLabel5
-            // 
-            uiLabel5.BackColor = Color.Transparent;
-            uiLabel5.Font = new Font("宋体", 9F);
-            uiLabel5.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel5.Image = Properties.Resources.湿度;
-            uiLabel5.ImageAlign = ContentAlignment.MiddleLeft;
-            uiLabel5.Location = new Point(1024, 9);
-            uiLabel5.Name = "uiLabel5";
-            uiLabel5.Size = new Size(95, 29);
-            uiLabel5.TabIndex = 6;
-            uiLabel5.Text = "厂房湿度";
-            uiLabel5.TextAlign = ContentAlignment.MiddleRight;
-            uiLabel5.MouseDown += Panel_MouseDown;
-            uiLabel5.MouseMove += Panel_MouseMove;
-            // 
-            // uiLabel4
-            // 
-            uiLabel4.BackColor = Color.Transparent;
-            uiLabel4.Font = new Font("宋体", 9F);
-            uiLabel4.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel4.Image = Properties.Resources.温度;
-            uiLabel4.ImageAlign = ContentAlignment.MiddleLeft;
-            uiLabel4.Location = new Point(884, 9);
-            uiLabel4.Name = "uiLabel4";
-            uiLabel4.Size = new Size(95, 29);
-            uiLabel4.TabIndex = 5;
-            uiLabel4.Text = "厂房温度";
-            uiLabel4.TextAlign = ContentAlignment.MiddleRight;
-            uiLabel4.MouseDown += Panel_MouseDown;
-            uiLabel4.MouseMove += Panel_MouseMove;
-            // 
-            // uiScrollingText1
-            // 
-            uiScrollingText1.BackColor = Color.Transparent;
-            uiScrollingText1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiScrollingText1.Location = new Point(595, 9);
-            uiScrollingText1.MinimumSize = new Size(1, 1);
-            uiScrollingText1.Name = "uiScrollingText1";
-            uiScrollingText1.Size = new Size(283, 48);
-            uiScrollingText1.TabIndex = 4;
-            uiScrollingText1.Text = "系统正常";
-            uiScrollingText1.MouseDown += Panel_MouseDown;
-            uiScrollingText1.MouseMove += Panel_MouseMove;
+            // lbl_Time
+            // 
+            lbl_Time.BackColor = Color.Transparent;
+            lbl_Time.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_Time.ForeColor = Color.FromArgb(48, 48, 48);
+            lbl_Time.Location = new Point(922, 43);
+            lbl_Time.Name = "lbl_Time";
+            lbl_Time.Size = new Size(215, 33);
+            lbl_Time.TabIndex = 9;
+            lbl_Time.Text = "2024-10-12 23:05:23";
+            lbl_Time.MouseDown += Panel_MouseDown;
+            lbl_Time.MouseMove += Panel_MouseMove;
+            // 
+            // lbl_Humidness
+            // 
+            lbl_Humidness.BackColor = Color.Transparent;
+            lbl_Humidness.Font = new Font("宋体", 9F);
+            lbl_Humidness.ForeColor = Color.Green;
+            lbl_Humidness.Location = new Point(1125, 16);
+            lbl_Humidness.Name = "lbl_Humidness";
+            lbl_Humidness.Size = new Size(44, 27);
+            lbl_Humidness.TabIndex = 8;
+            lbl_Humidness.Text = "60%";
+            lbl_Humidness.MouseDown += Panel_MouseDown;
+            lbl_Humidness.MouseMove += Panel_MouseMove;
+            // 
+            // lbl_Temperature
+            // 
+            lbl_Temperature.BackColor = Color.Transparent;
+            lbl_Temperature.Font = new Font("宋体", 9F);
+            lbl_Temperature.ForeColor = Color.Green;
+            lbl_Temperature.Location = new Point(985, 16);
+            lbl_Temperature.Name = "lbl_Temperature";
+            lbl_Temperature.Size = new Size(44, 27);
+            lbl_Temperature.TabIndex = 7;
+            lbl_Temperature.Text = "25℃";
+            lbl_Temperature.MouseDown += Panel_MouseDown;
+            lbl_Temperature.MouseMove += Panel_MouseMove;
+            // 
+            // lb_Humidness
+            // 
+            lb_Humidness.BackColor = Color.Transparent;
+            lb_Humidness.Font = new Font("宋体", 9F);
+            lb_Humidness.ForeColor = Color.FromArgb(48, 48, 48);
+            lb_Humidness.Image = Properties.Resources.湿度;
+            lb_Humidness.ImageAlign = ContentAlignment.MiddleLeft;
+            lb_Humidness.Location = new Point(1024, 9);
+            lb_Humidness.Name = "lb_Humidness";
+            lb_Humidness.Size = new Size(95, 29);
+            lb_Humidness.TabIndex = 6;
+            lb_Humidness.Text = "厂房湿度";
+            lb_Humidness.TextAlign = ContentAlignment.MiddleRight;
+            lb_Humidness.MouseDown += Panel_MouseDown;
+            lb_Humidness.MouseMove += Panel_MouseMove;
+            // 
+            // lb_Temperature
+            // 
+            lb_Temperature.BackColor = Color.Transparent;
+            lb_Temperature.Font = new Font("宋体", 9F);
+            lb_Temperature.ForeColor = Color.FromArgb(48, 48, 48);
+            lb_Temperature.Image = Properties.Resources.温度;
+            lb_Temperature.ImageAlign = ContentAlignment.MiddleLeft;
+            lb_Temperature.Location = new Point(884, 9);
+            lb_Temperature.Name = "lb_Temperature";
+            lb_Temperature.Size = new Size(95, 29);
+            lb_Temperature.TabIndex = 5;
+            lb_Temperature.Text = "厂房温度";
+            lb_Temperature.TextAlign = ContentAlignment.MiddleRight;
+            lb_Temperature.MouseDown += Panel_MouseDown;
+            lb_Temperature.MouseMove += Panel_MouseMove;
+            // 
+            // st_AlarmInfo
+            // 
+            st_AlarmInfo.BackColor = Color.Transparent;
+            st_AlarmInfo.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            st_AlarmInfo.Location = new Point(595, 9);
+            st_AlarmInfo.MinimumSize = new Size(1, 1);
+            st_AlarmInfo.Name = "st_AlarmInfo";
+            st_AlarmInfo.Size = new Size(283, 48);
+            st_AlarmInfo.TabIndex = 4;
+            st_AlarmInfo.Text = "系统正常";
+            st_AlarmInfo.MouseDown += Panel_MouseDown;
+            st_AlarmInfo.MouseMove += Panel_MouseMove;
             // 
             // lbl_User
             // 
@@ -313,105 +313,105 @@
             pictureBox1.MouseDown += Panel_MouseDown;
             pictureBox1.MouseMove += Panel_MouseMove;
             // 
-            // uiLabel9
-            // 
-            uiLabel9.BackColor = Color.Transparent;
-            uiLabel9.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel9.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel9.Image = Properties.Resources.产量;
-            uiLabel9.ImageAlign = ContentAlignment.MiddleLeft;
-            uiLabel9.Location = new Point(3, 72);
-            uiLabel9.Name = "uiLabel9";
-            uiLabel9.Size = new Size(132, 45);
-            uiLabel9.TabIndex = 1;
-            uiLabel9.Text = "生产计数";
-            uiLabel9.TextAlign = ContentAlignment.MiddleRight;
-            // 
-            // uiLedLabel1
-            // 
-            uiLedLabel1.BackColor = Color.Transparent;
-            uiLedLabel1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLedLabel1.Location = new Point(141, 72);
-            uiLedLabel1.MinimumSize = new Size(1, 1);
-            uiLedLabel1.Name = "uiLedLabel1";
-            uiLedLabel1.Size = new Size(80, 44);
-            uiLedLabel1.TabIndex = 2;
-            uiLedLabel1.Text = "5000";
-            // 
-            // uiLedLabel2
-            // 
-            uiLedLabel2.BackColor = Color.Transparent;
-            uiLedLabel2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLedLabel2.Location = new Point(365, 72);
-            uiLedLabel2.MinimumSize = new Size(1, 1);
-            uiLedLabel2.Name = "uiLedLabel2";
-            uiLedLabel2.Size = new Size(80, 44);
-            uiLedLabel2.TabIndex = 4;
-            uiLedLabel2.Text = "0067";
-            // 
-            // uiLabel10
-            // 
-            uiLabel10.BackColor = Color.Transparent;
-            uiLabel10.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel10.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel10.Image = Properties.Resources.产量;
-            uiLabel10.ImageAlign = ContentAlignment.MiddleLeft;
-            uiLabel10.Location = new Point(227, 72);
-            uiLabel10.Name = "uiLabel10";
-            uiLabel10.Size = new Size(132, 45);
-            uiLabel10.TabIndex = 3;
-            uiLabel10.Text = "不良计数";
-            uiLabel10.TextAlign = ContentAlignment.MiddleRight;
-            // 
-            // uiLedLabel3
-            // 
-            uiLedLabel3.BackColor = Color.Transparent;
-            uiLedLabel3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLedLabel3.Location = new Point(595, 72);
-            uiLedLabel3.MinimumSize = new Size(1, 1);
-            uiLedLabel3.Name = "uiLedLabel3";
-            uiLedLabel3.Size = new Size(80, 44);
-            uiLedLabel3.TabIndex = 6;
-            uiLedLabel3.Text = "060S";
-            // 
-            // uiLabel11
-            // 
-            uiLabel11.BackColor = Color.Transparent;
-            uiLabel11.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel11.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel11.Image = Properties.Resources.生产节拍;
-            uiLabel11.ImageAlign = ContentAlignment.MiddleLeft;
-            uiLabel11.Location = new Point(457, 72);
-            uiLabel11.Name = "uiLabel11";
-            uiLabel11.Size = new Size(132, 45);
-            uiLabel11.TabIndex = 5;
-            uiLabel11.Text = "生产节拍";
-            uiLabel11.TextAlign = ContentAlignment.MiddleRight;
-            // 
-            // uiLedLabel4
-            // 
-            uiLedLabel4.BackColor = Color.Transparent;
-            uiLedLabel4.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLedLabel4.Location = new Point(819, 72);
-            uiLedLabel4.MinimumSize = new Size(1, 1);
-            uiLedLabel4.Name = "uiLedLabel4";
-            uiLedLabel4.Size = new Size(80, 44);
-            uiLedLabel4.TabIndex = 8;
-            uiLedLabel4.Text = "0221";
-            // 
-            // uiLabel12
-            // 
-            uiLabel12.BackColor = Color.Transparent;
-            uiLabel12.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel12.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel12.Image = Properties.Resources.报警数;
-            uiLabel12.ImageAlign = ContentAlignment.MiddleLeft;
-            uiLabel12.Location = new Point(681, 72);
-            uiLabel12.Name = "uiLabel12";
-            uiLabel12.Size = new Size(132, 45);
-            uiLabel12.TabIndex = 7;
-            uiLabel12.Text = "累计报警";
-            uiLabel12.TextAlign = ContentAlignment.MiddleRight;
+            // lb_ProducteCount
+            // 
+            lb_ProducteCount.BackColor = Color.Transparent;
+            lb_ProducteCount.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lb_ProducteCount.ForeColor = Color.FromArgb(48, 48, 48);
+            lb_ProducteCount.Image = Properties.Resources.产量;
+            lb_ProducteCount.ImageAlign = ContentAlignment.MiddleLeft;
+            lb_ProducteCount.Location = new Point(3, 72);
+            lb_ProducteCount.Name = "lb_ProducteCount";
+            lb_ProducteCount.Size = new Size(132, 45);
+            lb_ProducteCount.TabIndex = 1;
+            lb_ProducteCount.Text = "生产计数";
+            lb_ProducteCount.TextAlign = ContentAlignment.MiddleRight;
+            // 
+            // lbl_ProducteCount
+            // 
+            lbl_ProducteCount.BackColor = Color.Transparent;
+            lbl_ProducteCount.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_ProducteCount.Location = new Point(141, 72);
+            lbl_ProducteCount.MinimumSize = new Size(1, 1);
+            lbl_ProducteCount.Name = "lbl_ProducteCount";
+            lbl_ProducteCount.Size = new Size(80, 44);
+            lbl_ProducteCount.TabIndex = 2;
+            lbl_ProducteCount.Text = "5000";
+            // 
+            // lbl_BadCount
+            // 
+            lbl_BadCount.BackColor = Color.Transparent;
+            lbl_BadCount.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_BadCount.Location = new Point(365, 72);
+            lbl_BadCount.MinimumSize = new Size(1, 1);
+            lbl_BadCount.Name = "lbl_BadCount";
+            lbl_BadCount.Size = new Size(80, 44);
+            lbl_BadCount.TabIndex = 4;
+            lbl_BadCount.Text = "0067";
+            // 
+            // lb_BadCount
+            // 
+            lb_BadCount.BackColor = Color.Transparent;
+            lb_BadCount.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lb_BadCount.ForeColor = Color.FromArgb(48, 48, 48);
+            lb_BadCount.Image = Properties.Resources.产量;
+            lb_BadCount.ImageAlign = ContentAlignment.MiddleLeft;
+            lb_BadCount.Location = new Point(227, 72);
+            lb_BadCount.Name = "lb_BadCount";
+            lb_BadCount.Size = new Size(132, 45);
+            lb_BadCount.TabIndex = 3;
+            lb_BadCount.Text = "不良计数";
+            lb_BadCount.TextAlign = ContentAlignment.MiddleRight;
+            // 
+            // lbl_Beat
+            // 
+            lbl_Beat.BackColor = Color.Transparent;
+            lbl_Beat.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_Beat.Location = new Point(595, 72);
+            lbl_Beat.MinimumSize = new Size(1, 1);
+            lbl_Beat.Name = "lbl_Beat";
+            lbl_Beat.Size = new Size(80, 44);
+            lbl_Beat.TabIndex = 6;
+            lbl_Beat.Text = "060S";
+            // 
+            // lb_Beat
+            // 
+            lb_Beat.BackColor = Color.Transparent;
+            lb_Beat.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lb_Beat.ForeColor = Color.FromArgb(48, 48, 48);
+            lb_Beat.Image = Properties.Resources.生产节拍;
+            lb_Beat.ImageAlign = ContentAlignment.MiddleLeft;
+            lb_Beat.Location = new Point(457, 72);
+            lb_Beat.Name = "lb_Beat";
+            lb_Beat.Size = new Size(132, 45);
+            lb_Beat.TabIndex = 5;
+            lb_Beat.Text = "生产节拍";
+            lb_Beat.TextAlign = ContentAlignment.MiddleRight;
+            // 
+            // lbl_TotalAlarm
+            // 
+            lbl_TotalAlarm.BackColor = Color.Transparent;
+            lbl_TotalAlarm.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_TotalAlarm.Location = new Point(819, 72);
+            lbl_TotalAlarm.MinimumSize = new Size(1, 1);
+            lbl_TotalAlarm.Name = "lbl_TotalAlarm";
+            lbl_TotalAlarm.Size = new Size(80, 44);
+            lbl_TotalAlarm.TabIndex = 8;
+            lbl_TotalAlarm.Text = "0221";
+            // 
+            // lb_TotalAlarm
+            // 
+            lb_TotalAlarm.BackColor = Color.Transparent;
+            lb_TotalAlarm.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lb_TotalAlarm.ForeColor = Color.FromArgb(48, 48, 48);
+            lb_TotalAlarm.Image = Properties.Resources.报警数;
+            lb_TotalAlarm.ImageAlign = ContentAlignment.MiddleLeft;
+            lb_TotalAlarm.Location = new Point(681, 72);
+            lb_TotalAlarm.Name = "lb_TotalAlarm";
+            lb_TotalAlarm.Size = new Size(132, 45);
+            lb_TotalAlarm.TabIndex = 7;
+            lb_TotalAlarm.Text = "累计报警";
+            lb_TotalAlarm.TextAlign = ContentAlignment.MiddleRight;
             // 
             // uiLabel13
             // 
@@ -427,13 +427,13 @@
             uiLabel13.Text = "系统状态";
             uiLabel13.TextAlign = ContentAlignment.MiddleRight;
             // 
-            // uiLedBulb1
+            // led_ProducteState
             // 
-            uiLedBulb1.Location = new Point(1043, 76);
-            uiLedBulb1.Name = "uiLedBulb1";
-            uiLedBulb1.Size = new Size(40, 40);
-            uiLedBulb1.TabIndex = 10;
-            uiLedBulb1.Text = "uiLedBulb1";
+            led_ProducteState.Location = new Point(1043, 76);
+            led_ProducteState.Name = "led_ProducteState";
+            led_ProducteState.Size = new Size(40, 40);
+            led_ProducteState.TabIndex = 10;
+            led_ProducteState.Text = "uiLedBulb1";
             // 
             // uiLabel14
             // 
@@ -513,27 +513,27 @@
             led_PlcState.TabIndex = 5;
             led_PlcState.Text = "uiLedBulb2";
             // 
-            // uiLabel19
+            // lbl_CPUInformation
             // 
-            uiLabel19.BackColor = Color.Transparent;
-            uiLabel19.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel19.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel19.Location = new Point(373, 22);
-            uiLabel19.Name = "uiLabel19";
-            uiLabel19.Size = new Size(49, 29);
-            uiLabel19.TabIndex = 6;
-            uiLabel19.Text = "60%";
+            lbl_CPUInformation.BackColor = Color.Transparent;
+            lbl_CPUInformation.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_CPUInformation.ForeColor = Color.FromArgb(48, 48, 48);
+            lbl_CPUInformation.Location = new Point(373, 22);
+            lbl_CPUInformation.Name = "lbl_CPUInformation";
+            lbl_CPUInformation.Size = new Size(49, 29);
+            lbl_CPUInformation.TabIndex = 6;
+            lbl_CPUInformation.Text = "60%";
             // 
-            // uiLabel20
+            // lbl_MemoryInformation
             // 
-            uiLabel20.BackColor = Color.Transparent;
-            uiLabel20.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel20.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel20.Location = new Point(564, 22);
-            uiLabel20.Name = "uiLabel20";
-            uiLabel20.Size = new Size(49, 29);
-            uiLabel20.TabIndex = 7;
-            uiLabel20.Text = "60%";
+            lbl_MemoryInformation.BackColor = Color.Transparent;
+            lbl_MemoryInformation.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            lbl_MemoryInformation.ForeColor = Color.FromArgb(48, 48, 48);
+            lbl_MemoryInformation.Location = new Point(564, 22);
+            lbl_MemoryInformation.Name = "lbl_MemoryInformation";
+            lbl_MemoryInformation.Size = new Size(49, 29);
+            lbl_MemoryInformation.TabIndex = 7;
+            lbl_MemoryInformation.Text = "60%";
             // 
             // uiLabel21
             // 
@@ -585,29 +585,29 @@
         private Sunny.UI.UILabel lbl_User;
         private PictureBox pictureBox2;
         private Sunny.UI.UILabel uiLabel2;
-        private Sunny.UI.UILabel uiLabel4;
-        private Sunny.UI.UIScrollingText uiScrollingText1;
-        private Sunny.UI.UILabel uiLabel7;
-        private Sunny.UI.UILabel uiLabel6;
-        private Sunny.UI.UILabel uiLabel5;
+        private Sunny.UI.UILabel lb_Temperature;
+        private Sunny.UI.UIScrollingText st_AlarmInfo;
+        private Sunny.UI.UILabel lbl_Humidness;
+        private Sunny.UI.UILabel lbl_Temperature;
+        private Sunny.UI.UILabel lb_Humidness;
         private Sunny.UI.UISymbolLabel uiSymbolLabel1;
-        private Sunny.UI.UILabel uiLabel8;
+        private Sunny.UI.UILabel lbl_Time;
         private Sunny.UI.UISymbolLabel uiSymbolLabel2;
-        private Sunny.UI.UILabel uiLabel9;
-        private Sunny.UI.UILedLabel uiLedLabel4;
-        private Sunny.UI.UILabel uiLabel12;
-        private Sunny.UI.UILedLabel uiLedLabel3;
-        private Sunny.UI.UILabel uiLabel11;
-        private Sunny.UI.UILedLabel uiLedLabel2;
-        private Sunny.UI.UILabel uiLabel10;
-        private Sunny.UI.UILedLabel uiLedLabel1;
+        private Sunny.UI.UILabel lb_ProducteCount;
+        private Sunny.UI.UILedLabel lbl_TotalAlarm;
+        private Sunny.UI.UILabel lb_TotalAlarm;
+        private Sunny.UI.UILedLabel lbl_Beat;
+        private Sunny.UI.UILabel lb_Beat;
+        private Sunny.UI.UILedLabel lbl_BadCount;
+        private Sunny.UI.UILabel lb_BadCount;
+        private Sunny.UI.UILedLabel lbl_ProducteCount;
         private Sunny.UI.UILabel uiLabel14;
-        private Sunny.UI.UILedBulb uiLedBulb1;
+        private Sunny.UI.UILedBulb led_ProducteState;
         private Sunny.UI.UILabel uiLabel13;
         private Sunny.UI.UILabel uiLabel22;
         private Sunny.UI.UILabel uiLabel21;
-        private Sunny.UI.UILabel uiLabel20;
-        private Sunny.UI.UILabel uiLabel19;
+        private Sunny.UI.UILabel lbl_MemoryInformation;
+        private Sunny.UI.UILabel lbl_CPUInformation;
         private Sunny.UI.UILedBulb led_PlcState;
         private Sunny.UI.UILabel uiLabel18;
         private Sunny.UI.UILabel uiLabel17;

+ 116 - 7
Scada/FormMain.cs

@@ -1,5 +1,7 @@
 using BLL;
 using BLL.Dto.AuthDto;
+using BLL.Dto.DataDto;
+using BLL.Dto.UserDto;
 using BLL.Manager;
 using Helper;
 using HZY.Framework.DependencyInjection;
@@ -22,6 +24,9 @@ namespace Scada
         private Point mPoint;
         private CancellationTokenSource cts = new CancellationTokenSource();
         private readonly UserManager _userManager;
+        private readonly AuthManager _authManager;
+        private readonly DataManager _dataManager;
+        private System.Timers.Timer Timer = new System.Timers.Timer(); // 定时器每秒触发一次
         private Dictionary<string, Control> pageControls = new Dictionary<string, Control>
 {
     { "控制模块", Globals.ServiceProvider.GetRequiredService<PageTotalEquipmentControl>() },
@@ -36,16 +41,21 @@ namespace Scada
     { "图表模块", Globals.ServiceProvider.GetRequiredService<PageChartManage>() },
     { "参数模块", Globals.ServiceProvider.GetRequiredService<PageSystemParameterSet>() }
 };
-        public FormMain(ILogger<FormMain> logger,UserManager userManager)
+        private List<string> AlarmList = new List<string>();
+        public FormMain(ILogger<FormMain> logger,UserManager userManager,AuthManager authManager,DataManager 
+            dataManager)
         {
             _logger = logger ?? throw new ArgumentNullException(nameof(logger));
             _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
+            _authManager = authManager ?? throw new ArgumentNullException(nameof(authManager));
+            _dataManager = dataManager ?? throw new ArgumentNullException(nameof(dataManager));
+            //初始化窗体
             InitializeComponent();
             InitAsideUI();
             InitHeaderUI();
             InitConfig();
             InitPlcClient();
-
+            InitOther();
             this.Closed += (s, e) =>
             {
                 //取消令牌源
@@ -58,7 +68,100 @@ namespace Scada
                 }
             };
             //显示默认界面
-            //Aside.SelectFirst();
+            Aside.SelectFirst();
+            Aside.BeforeExpand += Aside_BeforeExpand;
+        }
+
+        private void InitOther()
+        {
+            Timer.Interval = 1000; // 设置定时器间隔为1秒
+            Timer.Elapsed += Timer_Elapsed;
+            Timer.Start();
+        }
+
+        private void Timer_Elapsed(object? sender, EventArgs e)
+        {
+            if (plcIsConnected)
+            {
+                if (this.InvokeRequired)
+                {
+                    this.Invoke(async () =>
+                    {
+                        this.lbl_Temperature.Text = Globals.DataDic[this.lb_Temperature.TagString].ToString() + "℃";
+                        this.lbl_Humidness.Text = Globals.DataDic[this.lb_Humidness.TagString].ToString() + "%";
+
+                        this.lbl_ProducteCount.Text = Globals.DataDic[this.lb_ProducteCount.TagString].ToString();
+                        this.lbl_BadCount.Text = Globals.DataDic[this.lb_BadCount.TagString].ToString();
+                        this.lbl_Beat.Text = Globals.DataDic[this.lb_Beat.TagString].ToString();
+                        this.lbl_TotalAlarm.Text = Globals.DataDic[this.lb_TotalAlarm.TagString].ToString();
+
+
+                        //CPU和内存
+                        string CPUstr = RuntimeStatusHelper.DataManager.GetCpuUtilization();
+                        string MemoryStr = RuntimeStatusHelper.DataManager.GetMemoryUtilization().Replace("G", "");
+                        string NeiResult = (double.Parse(MemoryStr.Split('/')[0]) / double.Parse(MemoryStr.Split('/')[1]) * 100).ToString("f1") + "%";
+                        this.lbl_CPUInformation.Text = double.Parse(CPUstr).ToString("f1") + "%";
+                        this.lbl_MemoryInformation.Text = NeiResult;
+
+                        //时间
+                        this.lbl_Time.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+
+
+                        List<string> alarmInfos = CheckAlarms(AlarmList);
+
+                        string alarmInfo = string.Join(",", alarmInfos);
+
+                        if (string.IsNullOrEmpty(alarmInfo))
+                        {
+                            this.st_AlarmInfo.Text = "系统正常";
+                            this.st_AlarmInfo.ForeColor = Color.Green;
+                            this.led_ProducteState.On = true;
+                            this.led_ProducteState.Color = Color.Green;
+                            this.led_ProducteState.Blink = false;
+                        }
+                        else
+                        {
+                            this.st_AlarmInfo.Text = alarmInfo;
+                            this.st_AlarmInfo.ForeColor = Color.Red;
+                            this.led_ProducteState.BlinkInterval = 500;
+                            this.led_ProducteState.Blink = true;
+                        }
+
+
+
+
+                        //存储数据
+                        //用反射的方式将Globals.DataDic中对应Globals.SaveList名称的变量值保存到AddDataDto中,然后保存到数据库中
+                        AddDataDto addDataDto = new AddDataDto();
+                        addDataDto.InsertTime = DateTime.Now;
+                        //根据反射获取Globals.DataDic中对应Globals.SaveList名称的变量值,并赋值到addDataDto中
+                        foreach (var item in Globals.SaveList)
+                        {
+                            var type = typeof(AddDataDto).GetProperty(item).PropertyType.Name;
+                            if (type == "String")
+                            {
+                                addDataDto.GetType().GetProperty(item).SetValue(addDataDto, Globals.DataDic[item].ToString());
+                            }
+                        }
+                        //保存到数据库中
+                        await _dataManager.AddDataAsync(addDataDto);
+                    });
+                }
+            }
+        }
+
+        private List<string> CheckAlarms(List<string> alarmList)
+        {
+            List<string> alarmInfos = new List<string>();
+            foreach (var alarm in alarmList)
+            {
+                if (Globals.DataDic[alarm].ToString() == "1")
+                {
+                    //如果PLC变量值为1,则表示报警
+                    alarmInfos.Add(alarm);
+                }
+            }
+            return alarmInfos;
         }
 
         private void InitConfig()
@@ -119,6 +222,12 @@ namespace Scada
                 {
                     Globals.SaveList.Add(plcVarList[i].名称);
                 }
+                if (plcVarList[i].名称.EndsWith("报警") && !plcVarList[i].名称.Contains("累计"))
+                {
+                    //如果是报警变量,则添加到报警列表中
+                    AlarmList.Add(plcVarList[i].名称);
+                }
+                
             }
 
             _logger.LogInformation("初始化PLC客户端成功");
@@ -334,14 +443,14 @@ namespace Scada
             string moduleName = e.Node.Text;
 
             string user = this.lbl_User.Text;
-            var roleRes = await _userManager.GetUserAuthAsync(new BLL.Dto.UserDto.QueryUserRoleDto() { UserName = user });
+            var roleRes = await _userManager.GetUserAuthAsync(new QueryUserAuthDto() { UserName = user });
 
-            if (roleRes.Status == SystemEnums.Result.Success)
+            if (roleRes.Result == SystemEnums.Result.Success)
             {
                 if (roleRes.Data[0].Role != "管理员")
                 {
                     var authRes = await _authManager.GetAuthAsync(new QueryAuthDto { Role = roleRes.Data[0].Role });
-                    if (authRes.Status == SystemEnums.Result.Success)
+                    if (authRes.Result == SystemEnums.Result.Success)
                     {
                         UpdateControlAccess(moduleName, authRes.Data[0], pageControls);
                     }
@@ -363,9 +472,9 @@ namespace Scada
                     break;
 
                 case "监控模块":
-                    pageControls["监控模块"].Enabled = authDto.MonitorModule;
                     pageControls["监控模块1"].Enabled = authDto.MonitorModule;
                     pageControls["监控模块2"].Enabled = authDto.MonitorModule;
+                    pageControls["监控模块3"].Enabled = authDto.MonitorModule;
                     break;
 
                 case "配方模块":

+ 24 - 0
Scada/Globals.cs

@@ -68,5 +68,29 @@ namespace Scada
             }
             return false;
         }
+
+        #region 获取所有控件
+        // 获取指定页面的所有控件
+        public static List<Control> GetAllControls(UIPage page)
+        {
+            List<Control> allControls = new List<Control>();
+            CollectControls(page.Controls, allControls);
+            return allControls;
+        }
+
+        // 递归方法,用于收集控件
+        private static void CollectControls(Control.ControlCollection controls, List<Control> allControls)
+        {
+            foreach (Control control in controls)
+            {
+                allControls.Add(control); // 将当前控件添加到列表中
+                                          // 如果当前控件有子控件,则递归调用此方法
+                if (control.HasChildren)
+                {
+                    CollectControls(control.Controls, allControls);
+                }
+            }
+        }
+        #endregion
     }
 }

+ 9 - 6
Scada/Page/PageEquipmentMonitor1.Designer.cs

@@ -28,6 +28,7 @@
         /// </summary>
         private void InitializeComponent()
         {
+            components = new System.ComponentModel.Container();
             uiTitlePanel2 = new Sunny.UI.UITitlePanel();
             userVarCurrentValue3 = new UserVarCurrentValue();
             userAlarmState3 = new UserAlarmState();
@@ -45,6 +46,7 @@
             userVarCurrentValue1 = new UserVarCurrentValue();
             uiTitlePanel1 = new Sunny.UI.UITitlePanel();
             userVarCurrentValue2 = new UserVarCurrentValue();
+            timer1 = new System.Windows.Forms.Timer(components);
             uiTitlePanel2.SuspendLayout();
             uiTitlePanel3.SuspendLayout();
             uiTitlePanel1.SuspendLayout();
@@ -155,7 +157,7 @@
             // userVarCurrentValue5
             // 
             userVarCurrentValue5.BackColor = Color.Transparent;
-            userVarCurrentValue5.DeviceVarName = "脱脂喷淋泵压力值";
+            userVarCurrentValue5.DeviceVarName = "陶化喷淋泵压力值";
             userVarCurrentValue5.FillColor = Color.Transparent;
             userVarCurrentValue5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userVarCurrentValue5.Location = new Point(43, 116);
@@ -167,13 +169,13 @@
             userVarCurrentValue5.Text = "userVarCurrentValue5";
             userVarCurrentValue5.TextAlignment = ContentAlignment.MiddleCenter;
             userVarCurrentValue5.Unit = "Mpa";
-            userVarCurrentValue5.VariableName = "脱脂喷淋泵压力值";
+            userVarCurrentValue5.VariableName = "陶化喷淋泵压力值";
             userVarCurrentValue5.VarValue = 0F;
             // 
             // userVarCurrentValue4
             // 
             userVarCurrentValue4.BackColor = Color.Transparent;
-            userVarCurrentValue4.DeviceVarName = "脱脂PH值";
+            userVarCurrentValue4.DeviceVarName = "陶化PH值";
             userVarCurrentValue4.FillColor = Color.Transparent;
             userVarCurrentValue4.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userVarCurrentValue4.Location = new Point(576, 116);
@@ -185,7 +187,7 @@
             userVarCurrentValue4.Text = "userVarCurrentValue4";
             userVarCurrentValue4.TextAlignment = ContentAlignment.MiddleCenter;
             userVarCurrentValue4.Unit = "PH";
-            userVarCurrentValue4.VariableName = "脱脂PH值";
+            userVarCurrentValue4.VariableName = "陶化PH值";
             userVarCurrentValue4.VarValue = 7F;
             // 
             // userAlarmState4
@@ -240,7 +242,7 @@
             // userDeviceState1
             // 
             userDeviceState1.BackColor = Color.Transparent;
-            userDeviceState1.DeviceRunName = "陶化喷淋泵运行状态";
+            userDeviceState1.DeviceRunName = "脱脂喷淋泵运行状态";
             userDeviceState1.FillColor = Color.Transparent;
             userDeviceState1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userDeviceState1.Location = new Point(8, 45);
@@ -252,7 +254,7 @@
             userDeviceState1.TabIndex = 0;
             userDeviceState1.Text = "userDeviceState1";
             userDeviceState1.TextAlignment = ContentAlignment.MiddleCenter;
-            userDeviceState1.VariableName = "陶化喷淋泵运行状态";
+            userDeviceState1.VariableName = "脱脂喷淋泵运行状态";
             // 
             // userDeviceState2
             // 
@@ -375,5 +377,6 @@
         private UserAlarmState userAlarmState4;
         private UserAlarmState userAlarmState5;
         private UserDeviceState userDeviceState4;
+        private System.Windows.Forms.Timer timer1;
     }
 }

+ 30 - 0
Scada/Page/PageEquipmentMonitor1.cs

@@ -14,9 +14,39 @@ namespace Scada.Page
 {
     public partial class PageEquipmentMonitor1 : UIPage, ISingletonSelfDependency
     {
+        private List<Control> controls;
         public PageEquipmentMonitor1()
         {
             InitializeComponent();
+            controls = Globals.GetAllControls(this);
+            this.timer1.Interval = 500; // 设置定时器间隔为0.5秒
+            this.timer1.Tick += Timer1_Tick;
+            this.timer1.Start();
+        }
+
+        private void Timer1_Tick(object? sender, EventArgs e)
+        {
+            if (Globals.SiemensClient.Connected)
+            {
+                //遍历所有控件
+                foreach (Control control in controls)
+                {
+                    //分别判断是否是UserDeviceState/UserVarCurrentValue/UserAlarmState控件
+                    if (control is UserDeviceState userDeviceState)
+                    {
+                        userDeviceState.State = Globals.DataDic[userDeviceState.VariableName].ToString() == "1";
+                    }
+                    else if (control is UserVarCurrentValue userCurrentValue)
+                    {
+                        userCurrentValue.VarValue = float.Parse(Globals.DataDic[userCurrentValue.VariableName].ToString());
+
+                    }
+                    else if (control is UserAlarmState userAlarmState)
+                    {
+                        userAlarmState.State = Globals.DataDic[userAlarmState.VariableName].ToString() != "1";
+                    }
+                }
+            }
         }
 
         private void PageEquipmentMonitor_Load(object sender, EventArgs e)

+ 3 - 0
Scada/Page/PageEquipmentMonitor1.resx

@@ -117,4 +117,7 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
 </root>

+ 5 - 2
Scada/Page/PageEquipmentMonitor2.Designer.cs

@@ -28,6 +28,7 @@
         /// </summary>
         private void InitializeComponent()
         {
+            components = new System.ComponentModel.Container();
             uiTitlePanel3 = new Sunny.UI.UITitlePanel();
             userAlarmState5 = new UserAlarmState();
             userDeviceState4 = new UserDeviceState();
@@ -43,6 +44,7 @@
             userVarCurrentValue1 = new UserVarCurrentValue();
             userAlarmState1 = new UserAlarmState();
             userDeviceState1 = new UserDeviceState();
+            timer1 = new System.Windows.Forms.Timer(components);
             uiTitlePanel3.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
             uiTitlePanel1.SuspendLayout();
@@ -117,7 +119,7 @@
             // 
             // userAlarmState7
             // 
-            userAlarmState7.DeviceName = "水分炉煤气泄报警";
+            userAlarmState7.DeviceName = "水分炉煤气泄报警";
             userAlarmState7.FillColor = Color.Transparent;
             userAlarmState7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userAlarmState7.Location = new Point(704, 111);
@@ -129,7 +131,7 @@
             userAlarmState7.TabIndex = 8;
             userAlarmState7.Text = "userAlarmState7";
             userAlarmState7.TextAlignment = ContentAlignment.MiddleCenter;
-            userAlarmState7.VariableName = "水分炉煤气泄报警";
+            userAlarmState7.VariableName = "水分炉煤气泄报警";
             // 
             // userAlarmState2
             // 
@@ -331,5 +333,6 @@
         private UserDeviceState userDeviceState2;
         private UserAlarmState userAlarmState6;
         private UserAlarmState userAlarmState7;
+        private System.Windows.Forms.Timer timer1;
     }
 }

+ 32 - 0
Scada/Page/PageEquipmentMonitor2.cs

@@ -14,9 +14,41 @@ namespace Scada
 {
     public partial class PageEquipmentMonitor2 : UIPage, ISingletonSelfDependency
     {
+        private List<Control> controls;
         public PageEquipmentMonitor2()
         {
             InitializeComponent();
+            controls = Globals.GetAllControls(this);
+            this.timer1.Interval = 500;
+            this.timer1.Tick += Timer1_Tick;
+            this.timer1.Start();
+
+        }
+
+        private void Timer1_Tick(object? sender, EventArgs e)
+        {
+            if (Globals.SiemensClient.Connected)
+            {
+                //遍历所有控件
+                foreach (Control control in controls)
+                {
+                    if (control is UserDeviceState userDeviceState)
+                    {
+                        userDeviceState.State = Globals.DataDic[userDeviceState.VariableName].ToString() == "1";
+                    }
+                    else if (control is UserVarCurrentValue userCurrentValue)
+                    {
+                        userCurrentValue.VarValue = float.Parse(Globals.DataDic[userCurrentValue.VariableName].ToString());
+
+                    }
+                    else if (control is UserAlarmState userAlarmState)
+                    {
+                        userAlarmState.State = Globals.DataDic[userAlarmState.VariableName].ToString() != "1";
+                    }
+
+
+                }
+            }
         }
     }
 }

+ 3 - 0
Scada/Page/PageEquipmentMonitor2.resx

@@ -117,4 +117,7 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
 </root>

+ 5 - 2
Scada/Page/PageEquipmentMonitor3.Designer.cs

@@ -28,6 +28,7 @@
         /// </summary>
         private void InitializeComponent()
         {
+            components = new System.ComponentModel.Container();
             uiTitlePanel2 = new Sunny.UI.UITitlePanel();
             userAlarmState7 = new UserAlarmState();
             userAlarmState2 = new UserAlarmState();
@@ -40,6 +41,7 @@
             userDeviceState4 = new UserDeviceState();
             userAlarmState6 = new UserAlarmState();
             userDeviceState1 = new UserDeviceState();
+            timer1 = new System.Windows.Forms.Timer(components);
             uiTitlePanel2.SuspendLayout();
             uiTitlePanel1.SuspendLayout();
             SuspendLayout();
@@ -65,7 +67,7 @@
             // 
             // userAlarmState7
             // 
-            userAlarmState7.DeviceName = "固化炉煤气泄报警";
+            userAlarmState7.DeviceName = "固化炉煤气泄报警";
             userAlarmState7.FillColor = Color.Transparent;
             userAlarmState7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userAlarmState7.Location = new Point(704, 111);
@@ -77,7 +79,7 @@
             userAlarmState7.TabIndex = 8;
             userAlarmState7.Text = "userAlarmState7";
             userAlarmState7.TextAlignment = ContentAlignment.MiddleCenter;
-            userAlarmState7.VariableName = "固化炉煤气泄报警";
+            userAlarmState7.VariableName = "固化炉煤气泄报警";
             // 
             // userAlarmState2
             // 
@@ -273,5 +275,6 @@
         private UserDeviceState userDeviceState4;
         private UserAlarmState userAlarmState6;
         private UserDeviceState userDeviceState1;
+        private System.Windows.Forms.Timer timer1;
     }
 }

+ 31 - 0
Scada/Page/PageEquipmentMonitor3.cs

@@ -14,9 +14,40 @@ namespace Scada.Page
 {
     public partial class PageEquipmentMonitor3 : UIPage, ISingletonSelfDependency
     {
+        private List<Control> controls;
         public PageEquipmentMonitor3()
         {
             InitializeComponent();
+            controls = Globals.GetAllControls(this);
+            this.timer1.Interval = 500;
+            this.timer1.Tick += Timer1_Tick;
+            this.timer1.Start();
+        }
+
+        private void Timer1_Tick(object? sender, EventArgs e)
+        {
+
+            if (Globals.SiemensClient.Connected)
+            {
+                //遍历所有控件
+                foreach (Control control in controls)
+                {
+                    if (control is UserDeviceState userDeviceState)
+                    {
+                        userDeviceState.State = Globals.DataDic[userDeviceState.VariableName].ToString() == "1";
+                    }
+                    else if (control is UserVarCurrentValue userCurrentValue)
+                    {
+                        userCurrentValue.VarValue = float.Parse(Globals.DataDic[userCurrentValue.VariableName].ToString());
+
+                    }
+                    else if (control is UserAlarmState userAlarmState)
+                    {
+                        userAlarmState.State = Globals.DataDic[userAlarmState.VariableName].ToString() != "1";
+                    }
+
+                }
+            }
         }
     }
 }

+ 3 - 0
Scada/Page/PageEquipmentMonitor3.resx

@@ -117,4 +117,7 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
 </root>

+ 1 - 0
Scada/Page/PageUserManage.cs

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
 using System.Windows.Forms;
 using BLL;
 using BLL.Dto;
+using BLL.Dto.UserDto;
 using Helper;
 using HZY.Framework.DependencyInjection;
 using Sunny.UI;