Browse Source

配方管理模块

Linsk 3 months ago
parent
commit
e6dd492c17

+ 1 - 1
BLL/Dto/RecipeDto/DelRecipeDto.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 
 namespace BLL.Dto.RecipeDto
 namespace BLL.Dto.RecipeDto
 {
 {
-    public class DelRecipeDto
+    public class DelRecipeDto:BaseDto
     {
     {
     }
     }
 }
 }

+ 1 - 1
BLL/Manager/RecipeManager.cs

@@ -12,7 +12,7 @@ using Model;
 
 
 namespace BLL.Manager
 namespace BLL.Manager
 {
 {
-    internal class RecipeManager:IScopedSelfDependency
+    public class RecipeManager:IScopedSelfDependency
     {
     {
         private readonly RecipeService _recipeService;
         private readonly RecipeService _recipeService;
         public RecipeManager(RecipeService recipeService)
         public RecipeManager(RecipeService recipeService)

+ 18 - 0
Scada/Globals.cs

@@ -69,6 +69,24 @@ namespace Scada
             return false;
             return false;
         }
         }
 
 
+        public static bool PlcWrite(string varName, string value,DataTypeEnum type)
+        {
+            if (SiemensClient != null && SiemensClient.Connected)
+            {
+                var address = WriteDic[varName];
+                Result result = SiemensClient.Write(address, value, type);
+                if (result.IsSucceed)
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            return false;
+        }
+
         #region 获取所有控件
         #region 获取所有控件
         // 获取指定页面的所有控件
         // 获取指定页面的所有控件
         public static List<Control> GetAllControls(UIPage page)
         public static List<Control> GetAllControls(UIPage page)

+ 63 - 32
Scada/Page/PageRecipeManage.Designer.cs

@@ -57,8 +57,10 @@
             btn_UpdateRecipe = new Sunny.UI.UISymbolButton();
             btn_UpdateRecipe = new Sunny.UI.UISymbolButton();
             btn_DelRecipe = new Sunny.UI.UISymbolButton();
             btn_DelRecipe = new Sunny.UI.UISymbolButton();
             btn_AddRecipe = new Sunny.UI.UISymbolButton();
             btn_AddRecipe = new Sunny.UI.UISymbolButton();
-            uiTextBox1 = new Sunny.UI.UITextBox();
+            txt_ProductType = new Sunny.UI.UITextBox();
             uiLabel1 = new Sunny.UI.UILabel();
             uiLabel1 = new Sunny.UI.UILabel();
+            产品型号 = new DataGridViewTextBoxColumn();
+            Id = new DataGridViewTextBoxColumn();
             uiTitlePanel1.SuspendLayout();
             uiTitlePanel1.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)dgv_Recipe).BeginInit();
             ((System.ComponentModel.ISupportInitialize)dgv_Recipe).BeginInit();
@@ -130,7 +132,7 @@
             // userSetValue2
             // userSetValue2
             // 
             // 
             userSetValue2.DataType = Sunny.UI.UITextBox.UIEditType.Integer;
             userSetValue2.DataType = Sunny.UI.UITextBox.UIEditType.Integer;
-            userSetValue2.DeviceVarName = "水分炉温度限值";
+            userSetValue2.DeviceVarName = "水分炉温度限值";
             userSetValue2.FillColor = Color.Transparent;
             userSetValue2.FillColor = Color.Transparent;
             userSetValue2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userSetValue2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userSetValue2.Location = new Point(400, 44);
             userSetValue2.Location = new Point(400, 44);
@@ -142,7 +144,7 @@
             userSetValue2.Text = "userSetValue2";
             userSetValue2.Text = "userSetValue2";
             userSetValue2.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue2.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue2.Unit = "℃";
             userSetValue2.Unit = "℃";
-            userSetValue2.VariableName = "水分炉温度限值";
+            userSetValue2.VariableName = "水分炉温度限值";
             userSetValue2.VarValue = "0";
             userSetValue2.VarValue = "0";
             // 
             // 
             // userSetValue11
             // userSetValue11
@@ -173,7 +175,7 @@
             userSetValue12.MinimumSize = new Size(1, 1);
             userSetValue12.MinimumSize = new Size(1, 1);
             userSetValue12.Name = "userSetValue12";
             userSetValue12.Name = "userSetValue12";
             userSetValue12.RectColor = Color.Transparent;
             userSetValue12.RectColor = Color.Transparent;
-            userSetValue12.Size = new Size(382, 46);
+            userSetValue12.Size = new Size(395, 46);
             userSetValue12.TabIndex = 10;
             userSetValue12.TabIndex = 10;
             userSetValue12.Text = "userSetValue12";
             userSetValue12.Text = "userSetValue12";
             userSetValue12.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue12.TextAlignment = ContentAlignment.MiddleCenter;
@@ -184,19 +186,19 @@
             // userSetValue3
             // userSetValue3
             // 
             // 
             userSetValue3.DataType = Sunny.UI.UITextBox.UIEditType.Integer;
             userSetValue3.DataType = Sunny.UI.UITextBox.UIEditType.Integer;
-            userSetValue3.DeviceVarName = "离心风机过载上限值";
+            userSetValue3.DeviceVarName = "冷却室离心风机过载上限值";
             userSetValue3.FillColor = Color.Transparent;
             userSetValue3.FillColor = Color.Transparent;
             userSetValue3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userSetValue3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            userSetValue3.Location = new Point(400, 113);
+            userSetValue3.Location = new Point(400, 182);
             userSetValue3.MinimumSize = new Size(1, 1);
             userSetValue3.MinimumSize = new Size(1, 1);
             userSetValue3.Name = "userSetValue3";
             userSetValue3.Name = "userSetValue3";
             userSetValue3.RectColor = Color.Transparent;
             userSetValue3.RectColor = Color.Transparent;
-            userSetValue3.Size = new Size(353, 46);
+            userSetValue3.Size = new Size(353, 65);
             userSetValue3.TabIndex = 3;
             userSetValue3.TabIndex = 3;
             userSetValue3.Text = "userSetValue3";
             userSetValue3.Text = "userSetValue3";
             userSetValue3.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue3.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue3.Unit = "KW";
             userSetValue3.Unit = "KW";
-            userSetValue3.VariableName = "离心风机过载上限值";
+            userSetValue3.VariableName = "冷却室离心风机过载上限值";
             userSetValue3.VarValue = "0";
             userSetValue3.VarValue = "0";
             // 
             // 
             // userSetValue14
             // userSetValue14
@@ -209,7 +211,7 @@
             userSetValue14.MinimumSize = new Size(1, 1);
             userSetValue14.MinimumSize = new Size(1, 1);
             userSetValue14.Name = "userSetValue14";
             userSetValue14.Name = "userSetValue14";
             userSetValue14.RectColor = Color.Transparent;
             userSetValue14.RectColor = Color.Transparent;
-            userSetValue14.Size = new Size(382, 46);
+            userSetValue14.Size = new Size(395, 46);
             userSetValue14.TabIndex = 8;
             userSetValue14.TabIndex = 8;
             userSetValue14.Text = "userSetValue14";
             userSetValue14.Text = "userSetValue14";
             userSetValue14.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue14.TextAlignment = ContentAlignment.MiddleCenter;
@@ -220,10 +222,10 @@
             // userSetValue7
             // userSetValue7
             // 
             // 
             userSetValue7.DataType = Sunny.UI.UITextBox.UIEditType.Integer;
             userSetValue7.DataType = Sunny.UI.UITextBox.UIEditType.Integer;
-            userSetValue7.DeviceVarName = "固化炉温度下限值";
+            userSetValue7.DeviceVarName = "水分炉温度下限值";
             userSetValue7.FillColor = Color.Transparent;
             userSetValue7.FillColor = Color.Transparent;
             userSetValue7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             userSetValue7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            userSetValue7.Location = new Point(400, 184);
+            userSetValue7.Location = new Point(400, 113);
             userSetValue7.MinimumSize = new Size(1, 1);
             userSetValue7.MinimumSize = new Size(1, 1);
             userSetValue7.Name = "userSetValue7";
             userSetValue7.Name = "userSetValue7";
             userSetValue7.RectColor = Color.Transparent;
             userSetValue7.RectColor = Color.Transparent;
@@ -232,7 +234,7 @@
             userSetValue7.Text = "userSetValue7";
             userSetValue7.Text = "userSetValue7";
             userSetValue7.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue7.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue7.Unit = "℃";
             userSetValue7.Unit = "℃";
-            userSetValue7.VariableName = "固化炉温度下限值";
+            userSetValue7.VariableName = "水分炉温度下限值";
             userSetValue7.VarValue = "0";
             userSetValue7.VarValue = "0";
             // 
             // 
             // userSetValue6
             // userSetValue6
@@ -281,7 +283,7 @@
             userSetValue8.MinimumSize = new Size(1, 1);
             userSetValue8.MinimumSize = new Size(1, 1);
             userSetValue8.Name = "userSetValue8";
             userSetValue8.Name = "userSetValue8";
             userSetValue8.RectColor = Color.Transparent;
             userSetValue8.RectColor = Color.Transparent;
-            userSetValue8.Size = new Size(382, 46);
+            userSetValue8.Size = new Size(395, 46);
             userSetValue8.TabIndex = 4;
             userSetValue8.TabIndex = 4;
             userSetValue8.Text = "userSetValue8";
             userSetValue8.Text = "userSetValue8";
             userSetValue8.TextAlignment = ContentAlignment.MiddleCenter;
             userSetValue8.TextAlignment = ContentAlignment.MiddleCenter;
@@ -353,7 +355,7 @@
             uiTitlePanel2.Controls.Add(btn_UpdateRecipe);
             uiTitlePanel2.Controls.Add(btn_UpdateRecipe);
             uiTitlePanel2.Controls.Add(btn_DelRecipe);
             uiTitlePanel2.Controls.Add(btn_DelRecipe);
             uiTitlePanel2.Controls.Add(btn_AddRecipe);
             uiTitlePanel2.Controls.Add(btn_AddRecipe);
-            uiTitlePanel2.Controls.Add(uiTextBox1);
+            uiTitlePanel2.Controls.Add(txt_ProductType);
             uiTitlePanel2.Controls.Add(uiLabel1);
             uiTitlePanel2.Controls.Add(uiLabel1);
             uiTitlePanel2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiTitlePanel2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             uiTitlePanel2.Location = new Point(769, 0);
             uiTitlePanel2.Location = new Point(769, 0);
@@ -380,7 +382,9 @@
             dataGridViewCellStyle2.SelectionForeColor = SystemColors.HighlightText;
             dataGridViewCellStyle2.SelectionForeColor = SystemColors.HighlightText;
             dataGridViewCellStyle2.WrapMode = DataGridViewTriState.True;
             dataGridViewCellStyle2.WrapMode = DataGridViewTriState.True;
             dgv_Recipe.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
             dgv_Recipe.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
-            dgv_Recipe.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            dgv_Recipe.ColumnHeadersHeight = 32;
+            dgv_Recipe.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
+            dgv_Recipe.Columns.AddRange(new DataGridViewColumn[] { 产品型号, Id });
             dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
             dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
             dataGridViewCellStyle3.BackColor = SystemColors.Window;
             dataGridViewCellStyle3.BackColor = SystemColors.Window;
             dataGridViewCellStyle3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             dataGridViewCellStyle3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
@@ -392,7 +396,7 @@
             dgv_Recipe.EnableHeadersVisualStyles = false;
             dgv_Recipe.EnableHeadersVisualStyles = false;
             dgv_Recipe.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             dgv_Recipe.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             dgv_Recipe.GridColor = Color.FromArgb(80, 160, 255);
             dgv_Recipe.GridColor = Color.FromArgb(80, 160, 255);
-            dgv_Recipe.Location = new Point(5, 328);
+            dgv_Recipe.Location = new Point(4, 331);
             dgv_Recipe.Name = "dgv_Recipe";
             dgv_Recipe.Name = "dgv_Recipe";
             dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleLeft;
             dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleLeft;
             dataGridViewCellStyle4.BackColor = Color.FromArgb(235, 243, 255);
             dataGridViewCellStyle4.BackColor = Color.FromArgb(235, 243, 255);
@@ -407,9 +411,10 @@
             dataGridViewCellStyle5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             dataGridViewCellStyle5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             dgv_Recipe.RowsDefaultCellStyle = dataGridViewCellStyle5;
             dgv_Recipe.RowsDefaultCellStyle = dataGridViewCellStyle5;
             dgv_Recipe.SelectedIndex = -1;
             dgv_Recipe.SelectedIndex = -1;
-            dgv_Recipe.Size = new Size(284, 213);
+            dgv_Recipe.Size = new Size(287, 210);
             dgv_Recipe.StripeOddColor = Color.FromArgb(235, 243, 255);
             dgv_Recipe.StripeOddColor = Color.FromArgb(235, 243, 255);
             dgv_Recipe.TabIndex = 9;
             dgv_Recipe.TabIndex = 9;
+            dgv_Recipe.SelectIndexChange += dgv_Recipe_SelectIndexChangeAsync;
             // 
             // 
             // btn_DownloadRecipe
             // btn_DownloadRecipe
             // 
             // 
@@ -422,6 +427,7 @@
             btn_DownloadRecipe.TabIndex = 8;
             btn_DownloadRecipe.TabIndex = 8;
             btn_DownloadRecipe.Text = "下载配方";
             btn_DownloadRecipe.Text = "下载配方";
             btn_DownloadRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_DownloadRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_DownloadRecipe.Click += btn_DownloadRecipe_Click;
             // 
             // 
             // btn_ExportRecipe
             // btn_ExportRecipe
             // 
             // 
@@ -434,6 +440,7 @@
             btn_ExportRecipe.TabIndex = 7;
             btn_ExportRecipe.TabIndex = 7;
             btn_ExportRecipe.Text = "导出配方";
             btn_ExportRecipe.Text = "导出配方";
             btn_ExportRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_ExportRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_ExportRecipe.Click += btn_ExportRecipe_Click;
             // 
             // 
             // btn_ImportRecipe
             // btn_ImportRecipe
             // 
             // 
@@ -446,6 +453,7 @@
             btn_ImportRecipe.TabIndex = 6;
             btn_ImportRecipe.TabIndex = 6;
             btn_ImportRecipe.Text = "导入配方";
             btn_ImportRecipe.Text = "导入配方";
             btn_ImportRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_ImportRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_ImportRecipe.Click += btn_ImportRecipe_Click;
             // 
             // 
             // btn_QueryRecipe
             // btn_QueryRecipe
             // 
             // 
@@ -458,6 +466,7 @@
             btn_QueryRecipe.TabIndex = 5;
             btn_QueryRecipe.TabIndex = 5;
             btn_QueryRecipe.Text = "查询配方";
             btn_QueryRecipe.Text = "查询配方";
             btn_QueryRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_QueryRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_QueryRecipe.Click += btn_QueryRecipe_Click;
             // 
             // 
             // btn_UpdateRecipe
             // btn_UpdateRecipe
             // 
             // 
@@ -470,6 +479,7 @@
             btn_UpdateRecipe.TabIndex = 4;
             btn_UpdateRecipe.TabIndex = 4;
             btn_UpdateRecipe.Text = "修改配方";
             btn_UpdateRecipe.Text = "修改配方";
             btn_UpdateRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_UpdateRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_UpdateRecipe.Click += btn_UpdateRecipe_Click;
             // 
             // 
             // btn_DelRecipe
             // btn_DelRecipe
             // 
             // 
@@ -482,6 +492,7 @@
             btn_DelRecipe.TabIndex = 3;
             btn_DelRecipe.TabIndex = 3;
             btn_DelRecipe.Text = "删除配方";
             btn_DelRecipe.Text = "删除配方";
             btn_DelRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_DelRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            btn_DelRecipe.Click += btn_DelRecipe_Click;
             // 
             // 
             // btn_AddRecipe
             // btn_AddRecipe
             // 
             // 
@@ -494,20 +505,21 @@
             btn_AddRecipe.TabIndex = 1;
             btn_AddRecipe.TabIndex = 1;
             btn_AddRecipe.Text = "添加配方";
             btn_AddRecipe.Text = "添加配方";
             btn_AddRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_AddRecipe.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            // 
-            // uiTextBox1
-            // 
-            uiTextBox1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiTextBox1.Location = new Point(150, 44);
-            uiTextBox1.Margin = new Padding(4, 5, 4, 5);
-            uiTextBox1.MinimumSize = new Size(1, 16);
-            uiTextBox1.Name = "uiTextBox1";
-            uiTextBox1.Padding = new Padding(5);
-            uiTextBox1.ShowText = false;
-            uiTextBox1.Size = new Size(129, 46);
-            uiTextBox1.TabIndex = 1;
-            uiTextBox1.TextAlignment = ContentAlignment.MiddleLeft;
-            uiTextBox1.Watermark = "";
+            btn_AddRecipe.Click += btn_AddRecipe_Click;
+            // 
+            // txt_ProductType
+            // 
+            txt_ProductType.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            txt_ProductType.Location = new Point(150, 44);
+            txt_ProductType.Margin = new Padding(4, 5, 4, 5);
+            txt_ProductType.MinimumSize = new Size(1, 16);
+            txt_ProductType.Name = "txt_ProductType";
+            txt_ProductType.Padding = new Padding(5);
+            txt_ProductType.ShowText = false;
+            txt_ProductType.Size = new Size(129, 46);
+            txt_ProductType.TabIndex = 1;
+            txt_ProductType.TextAlignment = ContentAlignment.MiddleLeft;
+            txt_ProductType.Watermark = "";
             // 
             // 
             // uiLabel1
             // uiLabel1
             // 
             // 
@@ -520,6 +532,23 @@
             uiLabel1.Text = "产品型号:";
             uiLabel1.Text = "产品型号:";
             uiLabel1.TextAlign = ContentAlignment.MiddleCenter;
             uiLabel1.TextAlign = ContentAlignment.MiddleCenter;
             // 
             // 
+            // 产品型号
+            // 
+            产品型号.DataPropertyName = "产品类型";
+            产品型号.HeaderText = "产品型号";
+            产品型号.MinimumWidth = 6;
+            产品型号.Name = "产品型号";
+            产品型号.Width = 230;
+            // 
+            // Id
+            // 
+            Id.DataPropertyName = "Id";
+            Id.HeaderText = "Id";
+            Id.MinimumWidth = 6;
+            Id.Name = "Id";
+            Id.Visible = false;
+            Id.Width = 125;
+            // 
             // PageRecipeManage
             // PageRecipeManage
             // 
             // 
             AutoScaleMode = AutoScaleMode.None;
             AutoScaleMode = AutoScaleMode.None;
@@ -561,7 +590,9 @@
         private Sunny.UI.UISymbolButton btn_UpdateRecipe;
         private Sunny.UI.UISymbolButton btn_UpdateRecipe;
         private Sunny.UI.UISymbolButton btn_DelRecipe;
         private Sunny.UI.UISymbolButton btn_DelRecipe;
         private Sunny.UI.UISymbolButton btn_AddRecipe;
         private Sunny.UI.UISymbolButton btn_AddRecipe;
-        private Sunny.UI.UITextBox uiTextBox1;
+        private Sunny.UI.UITextBox txt_ProductType;
         private Sunny.UI.UILabel uiLabel1;
         private Sunny.UI.UILabel uiLabel1;
+        private DataGridViewTextBoxColumn 产品型号;
+        private DataGridViewTextBoxColumn Id;
     }
     }
 }
 }

+ 253 - 2
Scada/Page/PageRecipeManage.cs

@@ -7,21 +7,272 @@ 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 BLL.Dto.RecipeDto;
+using BLL.Manager;
+using Helper;
 using HZY.Framework.DependencyInjection;
 using HZY.Framework.DependencyInjection;
+using IoTClient.Enums;
+using Mapster;
+using MiniExcelLibs;
+using SqlSugar;
 using Sunny.UI;
 using Sunny.UI;
 
 
 namespace Scada.Page
 namespace Scada.Page
 {
 {
     public partial class PageRecipeManage : UIPage, ISingletonSelfDependency
     public partial class PageRecipeManage : UIPage, ISingletonSelfDependency
     {
     {
-        public PageRecipeManage()
+        private readonly RecipeManager _recipeManager;
+        public PageRecipeManage(RecipeManager recipeManager)
         {
         {
+
             InitializeComponent();
             InitializeComponent();
+            _recipeManager = recipeManager;
+            dgv_Recipe.AutoGenerateColumns = false;
+            this.Load += PageRecipeManage_Load;
+        }
+
+        private async void PageRecipeManage_Load(object sender, EventArgs e)
+        {
+            await LoadRecipe();
+        }
+
+        private async Task LoadRecipe()
+        {
+            var res = await _recipeManager.GetRecipeListAsync();
+            if (res.Result == SystemEnums.Result.Success)
+            {
+                this.dgv_Recipe.DataSource = null;
+                this.dgv_Recipe.DataSource = res.Data;
+            }
+            else
+            {
+                LogExtension.ShowMessage(res.Msg, Microsoft.Extensions.Logging.LogLevel.Error);
+            }
+        }
+
+        private async void btn_AddRecipe_Click(object sender, EventArgs e)
+        {
+            if (this.txt_ProductType.Text.IsNullOrEmpty())
+            {
+                UIMessageTip.ShowWarning("请输入产品类型");
+                return;
+            }
+
+            AddRecipeDto addDto = new AddRecipeDto()
+            {
+                产品类型 = this.txt_ProductType.Text
+            };
+
+            foreach (var item in this.uiTitlePanel1.Controls)
+            {
+                if (item is UserSetValue usv)
+                {
+                    addDto.GetType().GetProperty(usv.VariableName).SetValue(addDto, usv.VarValue);
+                }
+            }
+
+            var res = await _recipeManager.AddRecipeAsync(addDto);
+            if (res.Result == SystemEnums.Result.Success)
+            {
+                UIMessageTip.ShowOk("添加配方成功");
+                await LoadRecipe();
+            }
+            else
+            {
+                LogExtension.ShowMessage(res.Msg, Microsoft.Extensions.Logging.LogLevel.Error);
+                UIMessageTip.ShowError(res.Msg);
+
+            }
+
+        }
+
+        private async void btn_DelRecipe_Click(object sender, EventArgs e)
+        {
+            if (this.dgv_Recipe.CurrentRow == null)
+            {
+                UIMessageTip.ShowWarning("请选择一行");
+                return;
+            }
+
+            var id = this.dgv_Recipe.CurrentRow.Cells["Id"].Value.ToString().ToInt();
+
+            var res = await _recipeManager.DeleteRecipeAsync(new DelRecipeDto() { Id = id });
+
+            if (res.Result == SystemEnums.Result.Success)
+            {
+                UIMessageTip.ShowOk("删除配方成功");
+                await LoadRecipe();
+            }
+            else
+            {
+                LogExtension.ShowMessage(res.Msg, Microsoft.Extensions.Logging.LogLevel.Error);
+                UIMessageTip.ShowError(res.Msg);
+
+            }
+        }
+
+        private async void btn_UpdateRecipe_Click(object sender, EventArgs e)
+        {
+            if (this.dgv_Recipe.CurrentRow == null)
+            {
+                UIMessageTip.ShowWarning("请选择一行");
+                return;
+            }
+            UpdateRecipeDto updateDto = new UpdateRecipeDto();
+            var id = this.dgv_Recipe.CurrentRow.Cells["Id"].Value.ToString().ToInt();
+            updateDto.Id = id;
+            updateDto.产品类型 = this.txt_ProductType.Text;
+
+            foreach (var item in this.uiTitlePanel1.Controls)
+            {
+                if (item is UserSetValue usv)
+                {
+                    updateDto.GetType().GetProperty(usv.VariableName).SetValue(updateDto, usv.VarValue);
+                }
+            }
+
+            var res = await _recipeManager.UpdateRecipeAsync(updateDto);
+            if (res.Result == SystemEnums.Result.Success)
+            {
+                UIMessageTip.ShowOk("修改配方成功");
+                await LoadRecipe();
+            }
+            else
+            {
+                UIMessageTip.ShowError(res.Msg);
+                LogExtension.ShowMessage(res.Msg, Microsoft.Extensions.Logging.LogLevel.Error);
+            }
         }
         }
 
 
-        private void PageRecipeManage_Load(object sender, EventArgs e)
+        private void btn_ExportRecipe_Click(object sender, EventArgs e)
         {
         {
+            SaveFileDialog saveFileDialog = new SaveFileDialog();
+            saveFileDialog.Filter = "Excel files(*.xlsx)|*.xlsx";
+            if (saveFileDialog.ShowDialog() == DialogResult.OK)
+            {
+                try
+                {
+                    var rows = this.dgv_Recipe.DataSource as List<QueryRecipeResultDto>;
+                    var filePath = saveFileDialog.FileName;
+                    MiniExcel.SaveAs(filePath, rows);
+                }
+                catch (Exception ex)
+                {
+                    UIMessageTip.ShowError("导出失败");
+                    LogExtension.ShowMessage(ex.Message, Microsoft.Extensions.Logging.LogLevel.Error);
+                }
+            }
+        }
+
+        private async void btn_ImportRecipe_Click(object sender, EventArgs e)
+        {
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.Filter = "Excel files(*.xlsx)|*.xlsx";
+
+            if (openFileDialog.ShowDialog() == DialogResult.OK)
+            {
+                try
+                {
+                    var fileName = openFileDialog.FileName;
+                    var rows = MiniExcel.Query<QueryRecipeResultDto>(fileName).ToList();
+                    var res = await _recipeManager.GetRecipeListAsync();
+
+                    if (res.Result == SystemEnums.Result.Success)
+                    {
+                        var existingRows = res.Data;
+                        foreach (var item in rows)
+                        {
+                            var dbRows = existingRows.FirstOrDefault(c => c.产品类型 == item.产品类型);
+                            if (dbRows != null)
+                            {
+                                var updateDto = item.Adapt<UpdateRecipeDto>();
+                                updateDto.Id = dbRows.Id;
+                                var res1 = await _recipeManager.UpdateRecipeAsync(updateDto);
+                                if (res1.Result != SystemEnums.Result.Success)
+                                {
+                                    UIMessageTip.ShowError("导入失败:" + res1.Msg);
+                                    return;
+                                }
+                            }
+                            else
+                            {
+                                //添加
+                                var addDto = item.Adapt<AddRecipeDto>();
 
 
+                                var res2 = await _recipeManager.AddRecipeAsync(addDto);
+                                if (res2.Result != SystemEnums.Result.Success)
+                                {
+                                    UIMessageTip.ShowError("导入失败:" + res2.Msg);
+                                    return;
+                                }
+                            }
+                        }
+                        UIMessageTip.ShowOk("导入成功");
+                        await LoadRecipe();
+                    }
+                    else
+                    {
+                        UIMessageTip.ShowError("导入失败:" + res.Msg);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    UIMessageTip.ShowError("导入失败");
+                }
+            }
+        }
+
+        private void btn_DownloadRecipe_Click(object sender, EventArgs e)
+        {
+            if (!Globals.SiemensClient.Connected)
+            {
+                UIMessageTip.ShowWarning("请先连接西门子客户端");
+                return;
+            }
+
+            var res = UIMessageBox.ShowAsk("是否要下载到PLC");
+            if (res)
+            {
+                foreach (var item in this.uiTitlePanel1.Controls)
+                {
+                    if (item is UserSetValue usv)
+                    {
+                        if (usv.VarValue == string.Empty)
+                        {
+                            usv.VarValue = "0";
+                        }
+                        if (!Globals.PlcWrite(usv.VariableName, usv.VarValue, DataTypeEnum.Float))
+                        {
+                            new UIMessageForm().ShowErrorDialog($"{usv.VariableName}下载失败");
+                            return;
+                        }
+                    }
+                }
+                UIMessageTip.ShowOk("下载成功");
+            }
+        }
+
+        private async void dgv_Recipe_SelectIndexChangeAsync(object sender, int index)
+        {
+            var id = this.dgv_Recipe.Rows[index].Cells["Id"].Value.ToString().ToInt();
+            var res = await _recipeManager.GetRecipeAsyncById(new GetRecipeByIdDto() { Id = id });
+            if (res.Result == SystemEnums.Result.Success)
+            {
+                foreach (var item in this.uiTitlePanel1.Controls)
+                {
+                    if (item is UserSetValue usv)
+                    {
+                        var value = res.Data[0].GetType().GetProperty(usv.VariableName).GetValue(res.Data[0]);
+                        usv.VarValue = value.ToString();
+                    }
+                }
+                this.txt_ProductType.Text = res.Data[0].产品类型;
+            }
+        }
+
+        private async void btn_QueryRecipe_Click(object sender, EventArgs e)
+        {
+            await LoadRecipe();
         }
         }
     }
     }
 }
 }

+ 6 - 0
Scada/Page/PageRecipeManage.resx

@@ -117,4 +117,10 @@
   <resheader name="writer">
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   </resheader>
+  <metadata name="产品型号.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
 </root>
 </root>