Browse Source

PLC连接

Linsk 3 months ago
parent
commit
0a6273c33d

+ 13 - 0
Helper/SystemConsts.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Helper
+{
+    public static class SystemConsts
+    {
+        public const int DefaultFontScale = 100;
+    }
+}

+ 21 - 0
Helper/SystemEnums.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Helper
+{
+    public class SystemEnums
+    {
+        public enum FontsType
+        {
+            微软雅黑,
+            新宋体,
+            仿宋,
+            宋体,
+            黑体,
+            楷体
+        }
+    }
+}

+ 18 - 0
Model/PLCVarConfigModel.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+    public class PLCVarConfigModel
+    {
+        public string 所属模块 { get; set; }
+        public string 名称 { get; set; }
+        public string PLC地址 { get; set; }
+        public string 变量类型 { get; set; }
+        public string 是否保存 { get; set; }
+
+    }
+}

+ 2 - 0
Scada/FormMain.Designer.cs

@@ -105,6 +105,8 @@
             Header.Controls.Add(uiLabel9);
             Header.Controls.Add(uiLabel9);
             Header.Controls.Add(uiPanel1);
             Header.Controls.Add(uiPanel1);
             Header.Location = new Point(0, 0);
             Header.Location = new Point(0, 0);
+            Header.NodeInterval = 0;
+            Header.NodeSize = new Size(70, 50);
             Header.Size = new Size(1280, 120);
             Header.Size = new Size(1280, 120);
             Header.MenuItemClick += Header_MenuItemClick;
             Header.MenuItemClick += Header_MenuItemClick;
             // 
             // 

+ 119 - 34
Scada/FormMain.cs

@@ -1,70 +1,155 @@
+using Helper;
+using HZY.Framework.DependencyInjection;
+using IoTClient.Clients.PLC;
+using IoTClient.Common.Enums;
+using Microsoft.Extensions.DependencyInjection;
+using MiniExcelLibs;
+using Model;
 using Scada.Page;
 using Scada.Page;
 using Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada
 namespace Scada
 {
 {
-    public partial class FormMain : UIHeaderAsideMainFooterFrame
+    public partial class FormMain : UIHeaderAsideMainFooterFrame,IScopedSelfDependency
     {
     {
+        private bool plcIsConnected;
+
         public FormMain()
         public FormMain()
         {
         {
+            
             InitializeComponent();
             InitializeComponent();
+            InitAsideUI();
+            InitHeaderUI();
+            InitConfig();
+            InitPlcClient();
+            //显示默认界面
+            //Aside.SelectFirst();
+        }
 
 
-            //设置关联
-            Aside.TabControl = MainTabControl;
-
-            //设置初始页面索引(关联页面,唯一不重复即可)
-            int pageIndex = 1000;
+        private void InitConfig()
+        {
+            //读取PLC配置
+            Globals.IpAddress = Globals.IniFile.ReadString("PLC参数", "IP", "192.168.1.180");
+            Globals.Port = Globals.IniFile.ReadInt("PLC参数", "Port", 102);
+            Globals.CpuType = Enum.Parse<SiemensVersion>(Globals.IniFile.ReadString("PLC参数", "CpuType", SiemensVersion.S7_1200.ToString()));
+            Globals.Slot = Globals.IniFile.ReadByte("PLC参数", "Slot", 0);
+            Globals.Rack = Globals.IniFile.ReadByte("PLC参数", "Rack", 0);
+
+            Globals.ConnectTimeOut = Globals.IniFile.ReadInt("PLC参数", "ConnectTimeOut", 3000);
+            Globals.ReadTimeInterval = Globals.IniFile.ReadInt("PLC参数", "ReadTimeInterval", 300);
+            Globals.ReConnectTimeInterval = Globals.IniFile.ReadInt("PLC参数", "ReConnectTimeInterval", 3000);
+        }
 
 
-            TreeNode totalEquipment = Aside.CreateNode("总控模块", 61451, 24, pageIndex);
-            Aside.CreateChildNode(totalEquipment, AddPage(new PageTotalEquipmentControl(), ++pageIndex));
+        private void InitPlcClient()
+        {
+            Globals.PlcVarConfigPath = Globals.IniFile.ReadString("PLC参数", "变量表地址",Application.StartupPath+"\\config.ini");
+            var plcVarList = MiniExcel.Query<PLCVarConfigModel>(Globals.PlcVarConfigPath).ToList();
 
 
-            TreeNode equipmentMonitor = Aside.CreateNode("监控模块", 61451, 24, pageIndex);
-            Aside.CreateChildNode(equipmentMonitor, AddPage(new PageEquipmentMonitor1(), ++pageIndex));
-            Aside.CreateChildNode(equipmentMonitor, AddPage(new PageEquipmentMonitor2(), ++pageIndex));
-            Aside.CreateChildNode(equipmentMonitor, AddPage(new PageEquipmentMonitor3(), ++pageIndex));
+            Globals.SiemensClient = new SiemensClient(Globals.CpuType, Globals.IpAddress, Globals.Port, Globals.Slot, Globals.Rack, Globals.ConnectTimeOut);
+            var connectResult = Globals.SiemensClient.Open();
+        }
 
 
-            TreeNode recipeManage = Aside.CreateNode("配方管理", 61451, 24, pageIndex);
-            Aside.CreateChildNode(recipeManage, AddPage(new PageRecipeManage(), ++pageIndex));
+        private void InitAsideUI()
+        {
+            int pageIndex = 1000;
+            TreeNode parent0 = Aside.CreateNode("控制模块", 361461, 34, pageIndex);
+            Aside.CreateChildNode(parent0, AddPage(Globals.ServiceProvider.GetRequiredService<PageTotalEquipmentControl>(), ++pageIndex));
 
 
-            TreeNode logManage = Aside.CreateNode("日志管理", 61451, 24, pageIndex);
-            Aside.CreateChildNode(logManage, AddPage(new PageLogManage(), ++pageIndex));
+            TreeNode parent1 = Aside.CreateNode("用户模块", 61447, 34, pageIndex);
+            Aside.CreateChildNode(parent1, AddPage(Globals.ServiceProvider.GetRequiredService<PageUserManage>(), ++pageIndex));
+            Aside.CreateChildNode(parent1, AddPage(Globals.ServiceProvider.GetRequiredService<PageAuthManage>(), ++pageIndex));
 
 
-            TreeNode AuthManage = Aside.CreateNode("权限管理", 61451, 24, pageIndex);
-            Aside.CreateChildNode(AuthManage, AddPage(new PageAuthManage(), ++pageIndex));
+            TreeNode parent2 = Aside.CreateNode("监控模块", 560066, 34, pageIndex);
+            Aside.CreateChildNode(parent2, AddPage(Globals.ServiceProvider.GetRequiredService<PageEquipmentMonitor1>(), ++pageIndex));
+            Aside.CreateChildNode(parent2, AddPage(Globals.ServiceProvider.GetRequiredService<PageEquipmentMonitor2>(), ++pageIndex));
+            Aside.CreateChildNode(parent2, AddPage(Globals.ServiceProvider.GetRequiredService<PageEquipmentMonitor3>(), ++pageIndex));
 
 
-            TreeNode userManage = Aside.CreateNode("用户管理", 61451, 24, pageIndex);
-            Aside.CreateChildNode(userManage, AddPage(new PageUserManage(), ++pageIndex));
+            TreeNode parent3 = Aside.CreateNode("配方模块", 162677, 34, pageIndex);
+            Aside.CreateChildNode(parent3, AddPage(Globals.ServiceProvider.GetRequiredService<PageRecipeManage>(), ++pageIndex));
 
 
-            TreeNode reportManage = Aside.CreateNode("报表管理", 61451, 24, pageIndex);
-            Aside.CreateChildNode(reportManage, AddPage(new PageReportManage(), ++pageIndex));
+            TreeNode parent4 = Aside.CreateNode("日志模块", 57557, 34, pageIndex);
+            Aside.CreateChildNode(parent4, AddPage(Globals.ServiceProvider.GetRequiredService<PageLogManage>(), ++pageIndex));
 
 
-            TreeNode chartManage = Aside.CreateNode("图表管理", 61451, 24, pageIndex);
-            Aside.CreateChildNode(chartManage, AddPage(new PageChartManage(), ++pageIndex));
+            TreeNode parent5 = Aside.CreateNode("报表模块", 57586, 34, pageIndex);
+            Aside.CreateChildNode(parent5, AddPage(Globals.ServiceProvider.GetRequiredService<PageReportManage>(), ++pageIndex));
 
 
-            TreeNode systemParameterSet = Aside.CreateNode("系统参数", 61451, 24, pageIndex);
-            Aside.CreateChildNode(systemParameterSet, AddPage(new PageSystemParameterSet(), ++pageIndex));
+            TreeNode parent6 = Aside.CreateNode("图表模块", 61950, 34, pageIndex);
+            Aside.CreateChildNode(parent6, AddPage(Globals.ServiceProvider.GetRequiredService<PageChartManage>(), ++pageIndex));
 
 
-            //显示默认界面
-            //Aside.SelectFirst();
+            TreeNode parent7 = Aside.CreateNode("参数模块", 559576, 34, pageIndex);
+            Aside.CreateChildNode(parent7, AddPage(Globals.ServiceProvider.GetRequiredService<PageSystemParameterSet>(), ++pageIndex));
         }
         }
+        private void InitHeaderUI()
+        {
+            //设置关联
+            Header.TabControl = MainTabControl;
+
+            Header.Nodes.Add("");
+            Header.Nodes.Add("");
+            Header.Nodes.Add("");
+            Header.SetNodeSymbol(Header.Nodes[0], 558295, 34);
+            Header.SetNodeSymbol(Header.Nodes[1], 61489, 34);
+            Header.SetNodeSymbol(Header.Nodes[2], 557925, 34);
+            var styles = UIStyles.PopularStyles();
+            foreach (UIStyle style in styles)
+            {
+                Header.CreateChildNode(Header.Nodes[0], style.DisplayText(), style.Value());
+            }
 
 
+            //获取枚举FontsType的所有字体名称
+            for (int i = 0; i < Enum.GetValues(typeof(SystemEnums.FontsType)).Length; i++)
+            {
+                Header.CreateChildNode(Header.Nodes[1], Enum.GetName(typeof(SystemEnums.FontsType), i), i + 1);
+            }
+
+            //获取枚举FontSize的所有字体大小  75-125的范围 75 80 85 90 95 100 105 110 115 120 125
+            for (int i = 75; i <= 125; i += 5)
+            {
+                Header.CreateChildNode(Header.Nodes[2], i.ToString(), i);
+            }
+        }
         private void uiSymbolLabel2_Click(object sender, EventArgs e)
         private void uiSymbolLabel2_Click(object sender, EventArgs e)
         {
         {
             this.Close(); //关闭当前窗体
             this.Close(); //关闭当前窗体
         }
         }
-
         private void uiSymbolLabel1_Click(object sender, EventArgs e)
         private void uiSymbolLabel1_Click(object sender, EventArgs e)
         {
         {
             this.WindowState = FormWindowState.Minimized;
             this.WindowState = FormWindowState.Minimized;
         }
         }
-
         private void Header_MenuItemClick(string itemText, int menuIndex, int pageIndex)
         private void Header_MenuItemClick(string itemText, int menuIndex, int pageIndex)
         {
         {
-            UIStyle style = (UIStyle)pageIndex;
-            StyleManager.Style = style;
-            if (UIExtension.SetStyleManager != null)
+            switch (menuIndex)
             {
             {
-                UIExtension.SetStyleManager(StyleManager);
+                case 0:
+                    UIStyle style = (UIStyle)pageIndex;
+                    if (pageIndex < UIStyle.Colorful.Value())
+                    {
+                        StyleManager.Style = style;
+
+                        if (UIExtension.SetStyleManager != null)
+                        {
+                            UIExtension.SetStyleManager(StyleManager);
+                        }
+                    }
+                    break;
+
+                case 1:
+                    UIStyles.DPIScale = true;
+                    UIStyles.GlobalFont = true;
+                    UIStyles.GlobalFontName = itemText;
+
+                    UIStyles.GlobalFontScale = SystemConsts.DefaultFontScale;
+                    UIStyles.SetDPIScale();
+                    break;
+
+                case 2:
+                    UIStyles.GlobalFontScale = int.Parse(itemText);
+                    UIStyles.SetDPIScale();
+                    break;
+
+                default:
+
+                    break;
             }
             }
         }
         }
     }
     }

+ 43 - 0
Scada/Globals.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using IoTClient.Clients.PLC;
+using IoTClient.Common.Enums;
+using IoTClient.Enums;
+using Microsoft.Extensions.DependencyInjection;
+using Sunny.UI;
+
+namespace Scada
+{
+    public static class Globals
+    {
+        public static ServiceProvider ServiceProvider;
+
+        public static IniFile IniFile = new IniFile(Application.StartupPath+"\\config.ini");
+
+        public static string PlcVarConfigPath = string.Empty;
+
+        public static string IpAddress = string.Empty;
+
+        public static int Port;
+
+        public static SiemensVersion CpuType;
+
+        public static byte Slot;
+
+        public static byte Rack;
+
+        public static int ConnectTimeOut;
+
+        public static int ReadTimeInterval;
+
+        public static int ReConnectTimeInterval;
+
+        public static SiemensClient SiemensClient;
+        public static Dictionary<string, DataTypeEnum> ReadDic = new Dictionary<string, DataTypeEnum>();
+        public static Dictionary<string, object> DataDic = new Dictionary<string, object>();
+        public static Dictionary<string, string> WriteDic = new Dictionary<string, string>();
+    }
+}

+ 2 - 1
Scada/Page/PageAuthManage.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageAuthManage : UIPage
+    public partial class PageAuthManage : UIPage, ISingletonSelfDependency
     {
     {
         public PageAuthManage()
         public PageAuthManage()
         {
         {

+ 1 - 1
Scada/Page/PageChartManage.Designer.cs

@@ -134,7 +134,7 @@
             Controls.Add(uiSymbolLabel2);
             Controls.Add(uiSymbolLabel2);
             Controls.Add(uiSymbolLabel1);
             Controls.Add(uiSymbolLabel1);
             Name = "PageChartManage";
             Name = "PageChartManage";
-            Text = "PageChartManage";
+            Text = "图表管理";
             Load += PageChartManage_Load;
             Load += PageChartManage_Load;
             ResumeLayout(false);
             ResumeLayout(false);
         }
         }

+ 2 - 1
Scada/Page/PageChartManage.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageChartManage : UIPage
+    public partial class PageChartManage : UIPage, ISingletonSelfDependency
     {
     {
         public PageChartManage()
         public PageChartManage()
         {
         {

+ 1 - 1
Scada/Page/PageEquipmentMonitor1.Designer.cs

@@ -349,7 +349,7 @@
             Controls.Add(uiTitlePanel2);
             Controls.Add(uiTitlePanel2);
             Controls.Add(uiTitlePanel1);
             Controls.Add(uiTitlePanel1);
             Name = "PageEquipmentMonitor1";
             Name = "PageEquipmentMonitor1";
-            Text = "监控子模块1";
+            Text = "子模块1";
             Load += PageEquipmentMonitor_Load;
             Load += PageEquipmentMonitor_Load;
             uiTitlePanel2.ResumeLayout(false);
             uiTitlePanel2.ResumeLayout(false);
             uiTitlePanel3.ResumeLayout(false);
             uiTitlePanel3.ResumeLayout(false);

+ 2 - 1
Scada/Page/PageEquipmentMonitor1.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageEquipmentMonitor1 : UIPage
+    public partial class PageEquipmentMonitor1 : UIPage, ISingletonSelfDependency
     {
     {
         public PageEquipmentMonitor1()
         public PageEquipmentMonitor1()
         {
         {

+ 1 - 1
Scada/Page/PageEquipmentMonitor2.Designer.cs

@@ -307,7 +307,7 @@
             Controls.Add(uiTitlePanel2);
             Controls.Add(uiTitlePanel2);
             Controls.Add(uiTitlePanel1);
             Controls.Add(uiTitlePanel1);
             Name = "PageEquipmentMonitor2";
             Name = "PageEquipmentMonitor2";
-            Text = "监控子模块2";
+            Text = "子模块2";
             uiTitlePanel3.ResumeLayout(false);
             uiTitlePanel3.ResumeLayout(false);
             uiTitlePanel2.ResumeLayout(false);
             uiTitlePanel2.ResumeLayout(false);
             uiTitlePanel1.ResumeLayout(false);
             uiTitlePanel1.ResumeLayout(false);

+ 2 - 1
Scada/Page/PageEquipmentMonitor2.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada
 namespace Scada
 {
 {
-    public partial class PageEquipmentMonitor2 : UIPage
+    public partial class PageEquipmentMonitor2 : UIPage, ISingletonSelfDependency
     {
     {
         public PageEquipmentMonitor2()
         public PageEquipmentMonitor2()
         {
         {

+ 1 - 1
Scada/Page/PageEquipmentMonitor3.Designer.cs

@@ -253,7 +253,7 @@
             Controls.Add(uiTitlePanel1);
             Controls.Add(uiTitlePanel1);
             Controls.Add(uiTitlePanel2);
             Controls.Add(uiTitlePanel2);
             Name = "PageEquipmentMonitor3";
             Name = "PageEquipmentMonitor3";
-            Text = "监控子模块3";
+            Text = "子模块3";
             uiTitlePanel2.ResumeLayout(false);
             uiTitlePanel2.ResumeLayout(false);
             uiTitlePanel1.ResumeLayout(false);
             uiTitlePanel1.ResumeLayout(false);
             ResumeLayout(false);
             ResumeLayout(false);

+ 2 - 1
Scada/Page/PageEquipmentMonitor3.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageEquipmentMonitor3 : UIPage
+    public partial class PageEquipmentMonitor3 : UIPage, ISingletonSelfDependency
     {
     {
         public PageEquipmentMonitor3()
         public PageEquipmentMonitor3()
         {
         {

+ 2 - 1
Scada/Page/PageLogManage.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageLogManage : UIPage
+    public partial class PageLogManage : UIPage, ISingletonSelfDependency
     {
     {
         public PageLogManage()
         public PageLogManage()
         {
         {

+ 2 - 1
Scada/Page/PageRecipeManage.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageRecipeManage : UIPage
+    public partial class PageRecipeManage : UIPage, ISingletonSelfDependency
     {
     {
         public PageRecipeManage()
         public PageRecipeManage()
         {
         {

+ 2 - 1
Scada/Page/PageReportManage.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageReportManage : UIPage
+    public partial class PageReportManage : UIPage, ISingletonSelfDependency
     {
     {
         public PageReportManage()
         public PageReportManage()
         {
         {

+ 46 - 16
Scada/Page/PageSystemParameterSet.Designer.cs

@@ -56,6 +56,8 @@
             txt_SoftwareVersion = new Sunny.UI.UITextBox();
             txt_SoftwareVersion = new Sunny.UI.UITextBox();
             uiLabel10 = new Sunny.UI.UILabel();
             uiLabel10 = new Sunny.UI.UILabel();
             btn_Save = new Sunny.UI.UIButton();
             btn_Save = new Sunny.UI.UIButton();
+            uiLabel13 = new Sunny.UI.UILabel();
+            text_plcConfig = new Sunny.UI.UITextBox();
             uiTitlePanel1.SuspendLayout();
             uiTitlePanel1.SuspendLayout();
             uiTitlePanel3.SuspendLayout();
             uiTitlePanel3.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
@@ -63,6 +65,8 @@
             // 
             // 
             // uiTitlePanel1
             // uiTitlePanel1
             // 
             // 
+            uiTitlePanel1.Controls.Add(text_plcConfig);
+            uiTitlePanel1.Controls.Add(uiLabel13);
             uiTitlePanel1.Controls.Add(txt_ReConnectTimeInterval);
             uiTitlePanel1.Controls.Add(txt_ReConnectTimeInterval);
             uiTitlePanel1.Controls.Add(uiLabel8);
             uiTitlePanel1.Controls.Add(uiLabel8);
             uiTitlePanel1.Controls.Add(txt_ReadTimeInterval);
             uiTitlePanel1.Controls.Add(txt_ReadTimeInterval);
@@ -93,7 +97,7 @@
             // txt_ReConnectTimeInterval
             // txt_ReConnectTimeInterval
             // 
             // 
             txt_ReConnectTimeInterval.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_ReConnectTimeInterval.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_ReConnectTimeInterval.Location = new Point(422, 152);
+            txt_ReConnectTimeInterval.Location = new Point(422, 187);
             txt_ReConnectTimeInterval.Margin = new Padding(4, 5, 4, 5);
             txt_ReConnectTimeInterval.Margin = new Padding(4, 5, 4, 5);
             txt_ReConnectTimeInterval.MinimumSize = new Size(1, 16);
             txt_ReConnectTimeInterval.MinimumSize = new Size(1, 16);
             txt_ReConnectTimeInterval.Name = "txt_ReConnectTimeInterval";
             txt_ReConnectTimeInterval.Name = "txt_ReConnectTimeInterval";
@@ -108,7 +112,7 @@
             // 
             // 
             uiLabel8.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel8.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel8.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel8.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel8.Location = new Point(300, 159);
+            uiLabel8.Location = new Point(305, 194);
             uiLabel8.Name = "uiLabel8";
             uiLabel8.Name = "uiLabel8";
             uiLabel8.Size = new Size(102, 29);
             uiLabel8.Size = new Size(102, 29);
             uiLabel8.TabIndex = 15;
             uiLabel8.TabIndex = 15;
@@ -117,7 +121,7 @@
             // txt_ReadTimeInterval
             // txt_ReadTimeInterval
             // 
             // 
             txt_ReadTimeInterval.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_ReadTimeInterval.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_ReadTimeInterval.Location = new Point(422, 95);
+            txt_ReadTimeInterval.Location = new Point(422, 141);
             txt_ReadTimeInterval.Margin = new Padding(4, 5, 4, 5);
             txt_ReadTimeInterval.Margin = new Padding(4, 5, 4, 5);
             txt_ReadTimeInterval.MinimumSize = new Size(1, 16);
             txt_ReadTimeInterval.MinimumSize = new Size(1, 16);
             txt_ReadTimeInterval.Name = "txt_ReadTimeInterval";
             txt_ReadTimeInterval.Name = "txt_ReadTimeInterval";
@@ -132,7 +136,7 @@
             // 
             // 
             uiLabel6.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel6.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel6.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel6.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel6.Location = new Point(300, 102);
+            uiLabel6.Location = new Point(305, 148);
             uiLabel6.Name = "uiLabel6";
             uiLabel6.Name = "uiLabel6";
             uiLabel6.Size = new Size(102, 29);
             uiLabel6.Size = new Size(102, 29);
             uiLabel6.TabIndex = 13;
             uiLabel6.TabIndex = 13;
@@ -141,7 +145,7 @@
             // txt_ConnectTimeOut
             // txt_ConnectTimeOut
             // 
             // 
             txt_ConnectTimeOut.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_ConnectTimeOut.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_ConnectTimeOut.Location = new Point(422, 41);
+            txt_ConnectTimeOut.Location = new Point(422, 95);
             txt_ConnectTimeOut.Margin = new Padding(4, 5, 4, 5);
             txt_ConnectTimeOut.Margin = new Padding(4, 5, 4, 5);
             txt_ConnectTimeOut.MinimumSize = new Size(1, 16);
             txt_ConnectTimeOut.MinimumSize = new Size(1, 16);
             txt_ConnectTimeOut.Name = "txt_ConnectTimeOut";
             txt_ConnectTimeOut.Name = "txt_ConnectTimeOut";
@@ -156,7 +160,7 @@
             // 
             // 
             uiLabel7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel7.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel7.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel7.Location = new Point(300, 48);
+            uiLabel7.Location = new Point(300, 102);
             uiLabel7.Name = "uiLabel7";
             uiLabel7.Name = "uiLabel7";
             uiLabel7.Size = new Size(138, 54);
             uiLabel7.Size = new Size(138, 54);
             uiLabel7.TabIndex = 11;
             uiLabel7.TabIndex = 11;
@@ -169,7 +173,7 @@
             cb_CPUType.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             cb_CPUType.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             cb_CPUType.ItemHoverColor = Color.FromArgb(155, 200, 255);
             cb_CPUType.ItemHoverColor = Color.FromArgb(155, 200, 255);
             cb_CPUType.ItemSelectForeColor = Color.FromArgb(235, 243, 255);
             cb_CPUType.ItemSelectForeColor = Color.FromArgb(235, 243, 255);
-            cb_CPUType.Location = new Point(100, 152);
+            cb_CPUType.Location = new Point(100, 187);
             cb_CPUType.Margin = new Padding(4, 5, 4, 5);
             cb_CPUType.Margin = new Padding(4, 5, 4, 5);
             cb_CPUType.MinimumSize = new Size(63, 0);
             cb_CPUType.MinimumSize = new Size(63, 0);
             cb_CPUType.Name = "cb_CPUType";
             cb_CPUType.Name = "cb_CPUType";
@@ -183,7 +187,7 @@
             // txt_Slot
             // txt_Slot
             // 
             // 
             txt_Slot.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_Slot.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_Slot.Location = new Point(100, 262);
+            txt_Slot.Location = new Point(100, 280);
             txt_Slot.Margin = new Padding(4, 5, 4, 5);
             txt_Slot.Margin = new Padding(4, 5, 4, 5);
             txt_Slot.MinimumSize = new Size(1, 16);
             txt_Slot.MinimumSize = new Size(1, 16);
             txt_Slot.Name = "txt_Slot";
             txt_Slot.Name = "txt_Slot";
@@ -198,7 +202,7 @@
             // 
             // 
             uiLabel5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel5.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel5.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel5.Location = new Point(17, 269);
+            uiLabel5.Location = new Point(17, 287);
             uiLabel5.Name = "uiLabel5";
             uiLabel5.Name = "uiLabel5";
             uiLabel5.Size = new Size(76, 29);
             uiLabel5.Size = new Size(76, 29);
             uiLabel5.TabIndex = 8;
             uiLabel5.TabIndex = 8;
@@ -207,7 +211,7 @@
             // txt_Rack
             // txt_Rack
             // 
             // 
             txt_Rack.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_Rack.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_Rack.Location = new Point(100, 208);
+            txt_Rack.Location = new Point(100, 233);
             txt_Rack.Margin = new Padding(4, 5, 4, 5);
             txt_Rack.Margin = new Padding(4, 5, 4, 5);
             txt_Rack.MinimumSize = new Size(1, 16);
             txt_Rack.MinimumSize = new Size(1, 16);
             txt_Rack.Name = "txt_Rack";
             txt_Rack.Name = "txt_Rack";
@@ -222,7 +226,7 @@
             // 
             // 
             uiLabel4.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel4.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel4.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel4.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel4.Location = new Point(17, 215);
+            uiLabel4.Location = new Point(17, 240);
             uiLabel4.Name = "uiLabel4";
             uiLabel4.Name = "uiLabel4";
             uiLabel4.Size = new Size(76, 29);
             uiLabel4.Size = new Size(76, 29);
             uiLabel4.TabIndex = 6;
             uiLabel4.TabIndex = 6;
@@ -232,7 +236,7 @@
             // 
             // 
             uiLabel3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel3.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel3.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel3.Location = new Point(17, 159);
+            uiLabel3.Location = new Point(17, 194);
             uiLabel3.Name = "uiLabel3";
             uiLabel3.Name = "uiLabel3";
             uiLabel3.Size = new Size(88, 29);
             uiLabel3.Size = new Size(88, 29);
             uiLabel3.TabIndex = 4;
             uiLabel3.TabIndex = 4;
@@ -241,7 +245,7 @@
             // txt_Port
             // txt_Port
             // 
             // 
             txt_Port.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_Port.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_Port.Location = new Point(100, 97);
+            txt_Port.Location = new Point(100, 141);
             txt_Port.Margin = new Padding(4, 5, 4, 5);
             txt_Port.Margin = new Padding(4, 5, 4, 5);
             txt_Port.MinimumSize = new Size(1, 16);
             txt_Port.MinimumSize = new Size(1, 16);
             txt_Port.Name = "txt_Port";
             txt_Port.Name = "txt_Port";
@@ -256,7 +260,7 @@
             // 
             // 
             uiLabel2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel2.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel2.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel2.Location = new Point(17, 104);
+            uiLabel2.Location = new Point(17, 148);
             uiLabel2.Name = "uiLabel2";
             uiLabel2.Name = "uiLabel2";
             uiLabel2.Size = new Size(76, 29);
             uiLabel2.Size = new Size(76, 29);
             uiLabel2.TabIndex = 2;
             uiLabel2.TabIndex = 2;
@@ -266,7 +270,7 @@
             // 
             // 
             txt_IPAddress.FillColor2 = Color.FromArgb(235, 243, 255);
             txt_IPAddress.FillColor2 = Color.FromArgb(235, 243, 255);
             txt_IPAddress.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_IPAddress.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            txt_IPAddress.Location = new Point(100, 41);
+            txt_IPAddress.Location = new Point(100, 95);
             txt_IPAddress.Margin = new Padding(4, 5, 4, 5);
             txt_IPAddress.Margin = new Padding(4, 5, 4, 5);
             txt_IPAddress.MinimumSize = new Size(1, 1);
             txt_IPAddress.MinimumSize = new Size(1, 1);
             txt_IPAddress.Name = "txt_IPAddress";
             txt_IPAddress.Name = "txt_IPAddress";
@@ -280,7 +284,7 @@
             // 
             // 
             uiLabel1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiLabel1.ForeColor = Color.FromArgb(48, 48, 48);
             uiLabel1.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel1.Location = new Point(17, 48);
+            uiLabel1.Location = new Point(17, 102);
             uiLabel1.Name = "uiLabel1";
             uiLabel1.Name = "uiLabel1";
             uiLabel1.Size = new Size(76, 29);
             uiLabel1.Size = new Size(76, 29);
             uiLabel1.TabIndex = 0;
             uiLabel1.TabIndex = 0;
@@ -427,6 +431,30 @@
             btn_Save.Text = "保存";
             btn_Save.Text = "保存";
             btn_Save.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_Save.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             // 
             // 
+            // uiLabel13
+            // 
+            uiLabel13.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            uiLabel13.ForeColor = Color.FromArgb(48, 48, 48);
+            uiLabel13.Location = new Point(17, 56);
+            uiLabel13.Name = "uiLabel13";
+            uiLabel13.Size = new Size(209, 29);
+            uiLabel13.TabIndex = 17;
+            uiLabel13.Text = "上位机配置文件地址";
+            // 
+            // text_plcConfig
+            // 
+            text_plcConfig.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            text_plcConfig.Location = new Point(209, 49);
+            text_plcConfig.Margin = new Padding(4, 5, 4, 5);
+            text_plcConfig.MinimumSize = new Size(1, 16);
+            text_plcConfig.Name = "text_plcConfig";
+            text_plcConfig.Padding = new Padding(5);
+            text_plcConfig.ShowText = false;
+            text_plcConfig.Size = new Size(392, 36);
+            text_plcConfig.TabIndex = 18;
+            text_plcConfig.TextAlignment = ContentAlignment.MiddleLeft;
+            text_plcConfig.Watermark = "";
+            // 
             // PageSystemParameterSet
             // PageSystemParameterSet
             // 
             // 
             AutoScaleMode = AutoScaleMode.None;
             AutoScaleMode = AutoScaleMode.None;
@@ -474,5 +502,7 @@
         private Sunny.UI.UILabel uiLabel12;
         private Sunny.UI.UILabel uiLabel12;
         private Sunny.UI.UIRadioButtonGroup rbg_Save;
         private Sunny.UI.UIRadioButtonGroup rbg_Save;
         private Sunny.UI.UIButton btn_Save;
         private Sunny.UI.UIButton btn_Save;
+        private Sunny.UI.UITextBox text_plcConfig;
+        private Sunny.UI.UILabel uiLabel13;
     }
     }
 }
 }

+ 8 - 1
Scada/Page/PageSystemParameterSet.cs

@@ -7,20 +7,27 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageSystemParameterSet : UIPage
+    public partial class PageSystemParameterSet : UIPage, ISingletonSelfDependency
     {
     {
         public PageSystemParameterSet()
         public PageSystemParameterSet()
         {
         {
             InitializeComponent();
             InitializeComponent();
+            this.Load += PageSystemParameterSet_Load;
         }
         }
 
 
         private void PageSystemParameterSet_Load(object sender, EventArgs e)
         private void PageSystemParameterSet_Load(object sender, EventArgs e)
         {
         {
+            InitSystemParameter();
+        }
 
 
+        private void InitSystemParameter()
+        {
+            this.text_plcConfig.Text = Globals.PlcVarConfigPath;
         }
         }
     }
     }
 }
 }

+ 2 - 1
Scada/Page/PageTotalEquipmentControl.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageTotalEquipmentControl : UIPage
+    public partial class PageTotalEquipmentControl : UIPage, ISingletonSelfDependency
     {
     {
         public PageTotalEquipmentControl()
         public PageTotalEquipmentControl()
         {
         {

+ 2 - 1
Scada/Page/PageUserManage.cs

@@ -7,11 +7,12 @@ using System.Linq;
 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 Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
-    public partial class PageUserManage : UIPage
+    public partial class PageUserManage : UIPage, ISingletonSelfDependency
     {
     {
         public PageUserManage()
         public PageUserManage()
         {
         {

+ 23 - 6
Scada/Program.cs

@@ -1,17 +1,34 @@
+using System.Reflection;
+using HZY.Framework.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection;
+
 namespace Scada
 namespace Scada
 {
 {
     internal static class Program
     internal static class Program
     {
     {
-        /// <summary>
-        ///  The main entry point for the application.
-        /// </summary>
+        /// <summary>  
+        ///  The main entry point for the application.  
+        /// </summary>  
         [STAThread]
         [STAThread]
         static void Main()
         static void Main()
         {
         {
-            // To customize application configuration such as set high DPI settings or default font,
-            // see https://aka.ms/applicationconfiguration.
+            var services = new ServiceCollection();
+            ConfigureServices(services);
             ApplicationConfiguration.Initialize();
             ApplicationConfiguration.Initialize();
-            Application.Run(new FormMain());
+
+            var serviceProvider = services.BuildServiceProvider();
+            Globals.ServiceProvider = serviceProvider;
+            var frmMain = serviceProvider.GetRequiredService<FormMain>();
+            
+            Application.Run(frmMain);
+        }
+
+        private static void ConfigureServices(ServiceCollection services)
+        {
+            services.AddDependencyInjection(options =>
+            {
+                options.Assemblies = new[] { typeof(Program).Assembly };
+            });
         }
         }
     }
     }
 }
 }