From 308b7041b91c664c959ec90c2b3870d4a959be1c Mon Sep 17 00:00:00 2001 From: SoulStar Date: Fri, 6 Dec 2024 18:01:27 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E6=B7=BB=E5=8A=A0=E9=85=8D=E6=96=B9?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ZxMaterialTypeService.cs | 4 +- .../service/ZxRecipeParaService.cs | 59 ++++++- HighWayIot.Winform/Business/GeneralUtils.cs | 34 ++++ .../RecipeConfigPages/RecipeConfigPage.cs | 165 ++++++++++++++++-- 4 files changed, 245 insertions(+), 17 deletions(-) diff --git a/HighWayIot.Repository/service/ZxMaterialTypeService.cs b/HighWayIot.Repository/service/ZxMaterialTypeService.cs index f0e341a..3d37cf5 100644 --- a/HighWayIot.Repository/service/ZxMaterialTypeService.cs +++ b/HighWayIot.Repository/service/ZxMaterialTypeService.cs @@ -74,7 +74,7 @@ namespace HighWayIot.Repository.service } catch (Exception ex) { - log.Error("物料信息添加异常", ex); + log.Error("物料类别信息添加异常", ex); return false; } } @@ -92,7 +92,7 @@ namespace HighWayIot.Repository.service } catch (Exception ex) { - log.Error("物料信息删除异常", ex); + log.Error("物料类别信息删除异常", ex); return false; } } diff --git a/HighWayIot.Repository/service/ZxRecipeParaService.cs b/HighWayIot.Repository/service/ZxRecipeParaService.cs index db0bf84..86ca071 100644 --- a/HighWayIot.Repository/service/ZxRecipeParaService.cs +++ b/HighWayIot.Repository/service/ZxRecipeParaService.cs @@ -43,6 +43,43 @@ namespace HighWayIot.Repository.service } } + /// + /// 查询配方字段信息 + /// + /// + public List GetRecipeParaInfoByRecipeCode() + { + try + { + List entity = _repository.GetList(x => x.IsDeleted == false); + return entity; + } + catch (Exception ex) + { + log.Error("用户信息获取异常", ex); + return null; + } + } + + /// + /// 根据配方号查询配方字段信息 + /// + /// 配方编号 + /// + public List GetRecipeParaInfoByRecipeCode(string recipeCode) + { + try + { + List entity = _repository.GetList(x => x.IsDeleted == false && x.RecipeCode == recipeCode); + return entity; + } + catch (Exception ex) + { + log.Error("用户信息获取异常", ex); + return null; + } + } + /// /// 修改配方字段信息 /// @@ -56,7 +93,7 @@ namespace HighWayIot.Repository.service } catch(Exception ex) { - log.Error("用户信息修改异常", ex); + log.Error("配方字段信息修改异常", ex); return false; } } @@ -74,7 +111,25 @@ namespace HighWayIot.Repository.service } catch (Exception ex) { - log.Error("用户信息修改异常", ex); + log.Error("配方字段信息修改异常", ex); + return false; + } + } + + /// + /// ID删除配方字段信息 + /// + /// + /// + public bool DeleteRecipeParaInfoById(int id) + { + try + { + return _repository.DeleteById(id); + } + catch (Exception ex) + { + log.Error("配方字段信息删除异常", ex); return false; } } diff --git a/HighWayIot.Winform/Business/GeneralUtils.cs b/HighWayIot.Winform/Business/GeneralUtils.cs index d580fa3..883b309 100644 --- a/HighWayIot.Winform/Business/GeneralUtils.cs +++ b/HighWayIot.Winform/Business/GeneralUtils.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,5 +20,38 @@ namespace HighWayIot.Winform.Business str[0] = string.Empty; return str; } + + /// + /// 转换string为int? + /// + /// + /// + public static int? StringNullOrToInt(string intValue) + { + if (string.IsNullOrEmpty(intValue.Trim())) + { + return null; + } + if (int.TryParse(intValue, out int result)) + { + return result; + } + else + { + return null; + } + } + + public static string IntEmptyOrToString(int? value) + { + if (value == null) + { + return string.Empty; + } + else + { + return value.ToString(); + } + } } } diff --git a/HighWayIot.Winform/UserControlPages/RecipeConfigPages/RecipeConfigPage.cs b/HighWayIot.Winform/UserControlPages/RecipeConfigPages/RecipeConfigPage.cs index 0db24a7..6e5d3f7 100644 --- a/HighWayIot.Winform/UserControlPages/RecipeConfigPages/RecipeConfigPage.cs +++ b/HighWayIot.Winform/UserControlPages/RecipeConfigPages/RecipeConfigPage.cs @@ -1,5 +1,6 @@ using HighWayIot.Repository.domain; using HighWayIot.Repository.service; +using HighWayIot.Winform.Business; using HighWayIot.Winform.UserControlPages.RecipeConfigPages; using HighWayIot.Winform.UserControlPages.SysConfigPages; using Models; @@ -38,6 +39,16 @@ namespace HighWayIot.Winform.UserControlPages /// ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance; + /// + /// 配方字段实例 + /// + ZxRecipeParaEntity zxRecipeParaEntity = new ZxRecipeParaEntity(); + + /// + /// 配方字段实例剪切板 + /// + ZxRecipeParaEntity zxRecipeParaEntityCut; + /// /// 称重DataGridView数据源 /// @@ -96,10 +107,10 @@ namespace HighWayIot.Winform.UserControlPages string s = RecipeDataGridView.Rows[a].Cells["RecipeCode"].Value.ToString(); int id; try - { - id = int.Parse(RecipeDataGridView.Rows[a].Cells["RId"].Value.ToString()); + { + id = int.Parse(RecipeDataGridView.Rows[a].Cells["RId"].Value.ToString()); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show("ID转换发生错误"); return; @@ -149,7 +160,7 @@ namespace HighWayIot.Winform.UserControlPages { DataGridViewRow nowRow = RecipeDataGridView.CurrentRow; - if(MessageBox.Show($"确认要更改编号为 [{nowRow.Cells["RecipeCode"].Value.ToString()}] 配方的数据吗", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) + if (MessageBox.Show($"确认要更改编号为 [{nowRow.Cells["RecipeCode"].Value.ToString()}] 配方的数据吗", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } @@ -355,7 +366,52 @@ namespace HighWayIot.Winform.UserControlPages /// private void SaveParaButton_Click(object sender, EventArgs e) { + string s = RecipeDataGridView.CurrentRow.Cells["RecipeCode"].Value.ToString(); + if (MessageBox.Show($"确定要保存配方编号为 [{s}] 的配方的参数?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) + { + return; + } + + ZxRecipeParaEntity entity = GetParaValue(); + + entity.IsDeleted = false; + entity.RecipeCode = s; + + zxRecipeParaEntity = entity; + + var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(zxRecipeParaEntity.RecipeCode); + + //没有就插入 + if (paraData.Count == 0) + { + if (zxRecipeParaService.InsertRecipeParaInfo(zxRecipeParaEntity)) + { + MessageBox.Show("保存成功!"); + } + else + { + MessageBox.Show("保存失败!"); + } + } + //有就更改 + else if (paraData.Count == 1) + { + zxRecipeParaEntity.Id = paraData[0].Id; + if (zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity)) + { + MessageBox.Show("保存成功!"); + } + else + { + MessageBox.Show("保存失败!"); + } + } + else + { + MessageBox.Show("存在多条未删除的相同配方参数!请检查数据库。"); + return; + } } /// @@ -365,7 +421,8 @@ namespace HighWayIot.Winform.UserControlPages /// private void CopyParaButton_Click(object sender, EventArgs e) { - + zxRecipeParaEntityCut = GetParaValue(); + NowCopyLabel.Text = RecipeDataGridView.CurrentRow.Cells["RecipeCode"].Value.ToString(); } /// @@ -375,7 +432,11 @@ namespace HighWayIot.Winform.UserControlPages /// private void PasteParaButton_Click(object sender, EventArgs e) { - + if (zxRecipeParaEntityCut == null) + { + MessageBox.Show("剪切板为空!"); + } + SetParaValue(zxRecipeParaEntityCut); } /// @@ -385,7 +446,8 @@ namespace HighWayIot.Winform.UserControlPages /// private void ClearCutBoradButton_Click(object sender, EventArgs e) { - + zxRecipeParaEntityCut = null; + NowCopyLabel.Text = "N/A"; } /// @@ -404,6 +466,24 @@ namespace HighWayIot.Winform.UserControlPages WeightDataGridView.DataSource = null; WeightDataGridView.DataSource = weightDataSourceEntities; + + var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(s); + //没有就全0 + if (paraData.Count == 0) + { + SetParaValue(new ZxRecipeParaEntity()); + } + //有就显示 + else if (paraData.Count == 1) + { + SetParaValue(paraData[0]); + } + //有多条设为第一条 + else + { + MessageBox.Show("存在多条未删除的相同配方字段信息!将设置为第一条,请检查数据库。"); + SetParaValue(paraData[0]); + } } /// @@ -448,12 +528,71 @@ namespace HighWayIot.Winform.UserControlPages } /// - /// 所选单条Weight dataSource转为实体类 + /// 设置配方字段值 /// - //private ZxWeightEntity DataSourceToWeight() - //{ - // int a = WeightDataGridView.CurrentRow.Index; - // foreach - //} + /// + private void SetParaValue(ZxRecipeParaEntity entity) + { + zxRecipeParaEntity = entity; + E1P1TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P1); + E1P2TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P2); + E1P3TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P3); + E1P4TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P4); + E2P1TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P1); + E2P2TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P2); + E2P3TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P3); + E2P4TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P4); + E3P1TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P1); + E3P2TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P2); + E3P3TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P3); + E3P4TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P4); + E3P5CheckBox.Checked = zxRecipeParaEntity.E3P5 == 1; + E3P6TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P6); + E3P7TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P7); + E3P8TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P8); + E3P9TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P9); + E3P10TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P10); + E3P11TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P11); + E3P12TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P12); + E3P13TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P13); + E3P14TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P14); + E3P15TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P15); + } + + /// + /// 获取界面上的配方参数 + /// + /// 获取到的配方参数值 + private ZxRecipeParaEntity GetParaValue() + { + ZxRecipeParaEntity entity = new ZxRecipeParaEntity() + { + E1P1 = GeneralUtils.StringNullOrToInt(E1P1TextBox.Text), + E1P2 = GeneralUtils.StringNullOrToInt(E1P2TextBox.Text), + E1P3 = GeneralUtils.StringNullOrToInt(E1P3TextBox.Text), + E1P4 = GeneralUtils.StringNullOrToInt(E1P4TextBox.Text), + E2P1 = GeneralUtils.StringNullOrToInt(E2P1TextBox.Text), + E2P2 = GeneralUtils.StringNullOrToInt(E2P2TextBox.Text), + E2P3 = GeneralUtils.StringNullOrToInt(E2P3TextBox.Text), + E2P4 = GeneralUtils.StringNullOrToInt(E2P4TextBox.Text), + E3P1 = GeneralUtils.StringNullOrToInt(E3P1TextBox.Text), + E3P2 = GeneralUtils.StringNullOrToInt(E3P2TextBox.Text), + E3P3 = GeneralUtils.StringNullOrToInt(E3P3TextBox.Text), + E3P4 = GeneralUtils.StringNullOrToInt(E3P4TextBox.Text), + E3P5 = E3P5CheckBox.Checked ? 1 : 0, + E3P6 = GeneralUtils.StringNullOrToInt(E3P6TextBox.Text), + E3P7 = GeneralUtils.StringNullOrToInt(E3P7TextBox.Text), + E3P8 = GeneralUtils.StringNullOrToInt(E3P8TextBox.Text), + E3P9 = GeneralUtils.StringNullOrToInt(E3P9TextBox.Text), + E3P10 = GeneralUtils.StringNullOrToInt(E3P10TextBox.Text), + E3P11 = GeneralUtils.StringNullOrToInt(E3P11TextBox.Text), + E3P12 = GeneralUtils.StringNullOrToInt(E3P12TextBox.Text), + E3P13 = GeneralUtils.StringNullOrToInt(E3P13TextBox.Text), + E3P14 = GeneralUtils.StringNullOrToInt(E3P14TextBox.Text), + E3P15 = GeneralUtils.StringNullOrToInt(E3P15TextBox.Text), + }; + + return entity; + } } }