From 4e536ec720e7b98c0a8ac935df166da7edb4bdf8 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Tue, 3 Dec 2024 15:25:34 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E7=89=A9=E6=96=99=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E6=A1=86=E6=9E=B6=E5=BC=80=E5=8F=91=E5=AE=8C?= =?UTF-8?q?=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ZxMaterialService.cs | 16 ++- .../MaterialAddForm.Designer.cs | 2 + .../MaterialConfigPages/MaterialAddForm.cs | 2 +- .../MaterialConfigPage.Designer.cs | 117 +++++++++++------- .../MaterialConfigPages/MaterialConfigPage.cs | 58 ++++++++- .../MaterialUpdateForm.Designer.cs | 1 + .../MaterialConfigPages/MaterialUpdateForm.cs | 93 ++++++++++++++ 7 files changed, 239 insertions(+), 50 deletions(-) diff --git a/HighWayIot.Repository/service/ZxMaterialService.cs b/HighWayIot.Repository/service/ZxMaterialService.cs index 321f173..a7efb70 100644 --- a/HighWayIot.Repository/service/ZxMaterialService.cs +++ b/HighWayIot.Repository/service/ZxMaterialService.cs @@ -28,8 +28,13 @@ namespace HighWayIot.Repository.service /// /// 查询所有物料信息 /// + /// 物料名 + /// 类型 + /// 子类型 + /// 是否按是否使用查询 + /// 是否使用 /// - public List GetMaterialInfos(string materialName = null, string materialType = null, string childType = null) + public List GetMaterialInfos(string materialName = null, string materialType = null, string childType = null, bool isAvaliableUse = false, bool isUse = false) { try { @@ -43,14 +48,19 @@ namespace HighWayIot.Repository.service { if(!string.IsNullOrEmpty(childType)) { - entity.Where(x => x.MaterialType == materialType && x.ChildType == childType).ToList(); + entity = entity.Where(x => x.MaterialType == materialType && x.ChildType == childType).ToList(); } else { - entity.Where(x => x.MaterialType == materialType).ToList(); + entity = entity.Where(x => x.MaterialType == materialType).ToList(); } } + if(isAvaliableUse == true) + { + entity = entity.Where(x => x.IsUse == isUse).ToList(); + } + return entity; } catch (Exception ex) diff --git a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.Designer.cs b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.Designer.cs index 281f9f7..e5f252d 100644 --- a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.Designer.cs @@ -130,6 +130,8 @@ // IsUseCheckBox // this.IsUseCheckBox.AutoSize = true; + this.IsUseCheckBox.Checked = true; + this.IsUseCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; this.IsUseCheckBox.Location = new System.Drawing.Point(128, 133); this.IsUseCheckBox.Name = "IsUseCheckBox"; this.IsUseCheckBox.Size = new System.Drawing.Size(72, 16); diff --git a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.cs b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.cs index 869b313..522ac11 100644 --- a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.cs +++ b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialAddForm.cs @@ -76,7 +76,7 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages if (!zxMaterialService.InsertMaterialInfo(entity)) { - MessageBox.Show("物料信息添加失败,请尝试重新添加。"); + MessageBox.Show("物料信息添加失败,请检查物料编号是否重复或为空!"); return; } diff --git a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.Designer.cs b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.Designer.cs index 2448d61..aacdb8c 100644 --- a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.Designer.cs @@ -32,11 +32,6 @@ namespace HighWayIot.Winform.UserControlPages private void InitializeComponent() { this.MaterialDataGridView = new System.Windows.Forms.DataGridView(); - this.MaterialCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.MaterialName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.MaterialType = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ChildType = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.IsUse = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.AddMaterial = new System.Windows.Forms.Button(); this.ButtonPanel = new System.Windows.Forms.Panel(); this.MaterialNameTextbox = new System.Windows.Forms.TextBox(); @@ -48,6 +43,13 @@ namespace HighWayIot.Winform.UserControlPages this.MaterialTypeComboBox = new System.Windows.Forms.ComboBox(); this.ChildComboBox = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); + this.MaterialCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.MaterialName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.MaterialType = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ChildType = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.IsUse = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.IsAvailableUseCheckBox = new System.Windows.Forms.CheckBox(); + this.IsUseCheckBox = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.MaterialDataGridView)).BeginInit(); this.ButtonPanel.SuspendLayout(); this.SuspendLayout(); @@ -73,40 +75,6 @@ namespace HighWayIot.Winform.UserControlPages this.MaterialDataGridView.TabIndex = 0; this.MaterialDataGridView.Tag = ""; // - // MaterialCode - // - this.MaterialCode.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.MaterialCode.DataPropertyName = "MaterialCode"; - this.MaterialCode.HeaderText = "物料编码"; - this.MaterialCode.Name = "MaterialCode"; - // - // MaterialName - // - this.MaterialName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.MaterialName.DataPropertyName = "MaterialName"; - this.MaterialName.HeaderText = "物料名称"; - this.MaterialName.Name = "MaterialName"; - // - // MaterialType - // - this.MaterialType.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.MaterialType.DataPropertyName = "MaterialType"; - this.MaterialType.HeaderText = "物料类型"; - this.MaterialType.Name = "MaterialType"; - // - // ChildType - // - this.ChildType.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ChildType.DataPropertyName = "ChildType"; - this.ChildType.HeaderText = "物料子类型"; - this.ChildType.Name = "ChildType"; - // - // IsUse - // - this.IsUse.DataPropertyName = "IsUse"; - this.IsUse.HeaderText = "是否启用"; - this.IsUse.Name = "IsUse"; - // // AddMaterial // this.AddMaterial.Location = new System.Drawing.Point(11, 11); @@ -122,6 +90,8 @@ namespace HighWayIot.Winform.UserControlPages // this.ButtonPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonPanel.Controls.Add(this.IsUseCheckBox); + this.ButtonPanel.Controls.Add(this.IsAvailableUseCheckBox); this.ButtonPanel.Controls.Add(this.ChildComboBox); this.ButtonPanel.Controls.Add(this.label3); this.ButtonPanel.Controls.Add(this.MaterialTypeComboBox); @@ -203,6 +173,7 @@ namespace HighWayIot.Winform.UserControlPages this.MaterialTypeComboBox.Name = "MaterialTypeComboBox"; this.MaterialTypeComboBox.Size = new System.Drawing.Size(124, 20); this.MaterialTypeComboBox.TabIndex = 8; + this.MaterialTypeComboBox.SelectedIndexChanged += new System.EventHandler(this.MaterialTypeComboBox_SelectedIndexChanged); // // ChildComboBox // @@ -221,6 +192,62 @@ namespace HighWayIot.Winform.UserControlPages this.label3.TabIndex = 9; this.label3.Text = "子类型:"; // + // MaterialCode + // + this.MaterialCode.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.MaterialCode.DataPropertyName = "MaterialCode"; + this.MaterialCode.HeaderText = "物料编码"; + this.MaterialCode.Name = "MaterialCode"; + // + // MaterialName + // + this.MaterialName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.MaterialName.DataPropertyName = "MaterialName"; + this.MaterialName.HeaderText = "物料名称"; + this.MaterialName.Name = "MaterialName"; + // + // MaterialType + // + this.MaterialType.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.MaterialType.DataPropertyName = "MaterialType"; + this.MaterialType.HeaderText = "物料类型"; + this.MaterialType.Name = "MaterialType"; + // + // ChildType + // + this.ChildType.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ChildType.DataPropertyName = "ChildType"; + this.ChildType.HeaderText = "物料子类型"; + this.ChildType.Name = "ChildType"; + // + // IsUse + // + this.IsUse.DataPropertyName = "IsUse"; + this.IsUse.HeaderText = "是否启用"; + this.IsUse.Name = "IsUse"; + this.IsUse.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.IsUse.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + // + // IsAvailableUseCheckBox + // + this.IsAvailableUseCheckBox.AutoSize = true; + this.IsAvailableUseCheckBox.Location = new System.Drawing.Point(1079, 11); + this.IsAvailableUseCheckBox.Name = "IsAvailableUseCheckBox"; + this.IsAvailableUseCheckBox.Size = new System.Drawing.Size(120, 16); + this.IsAvailableUseCheckBox.TabIndex = 11; + this.IsAvailableUseCheckBox.Text = "是否查询启用状态"; + this.IsAvailableUseCheckBox.UseVisualStyleBackColor = true; + // + // IsUseCheckBox + // + this.IsUseCheckBox.AutoSize = true; + this.IsUseCheckBox.Location = new System.Drawing.Point(1079, 34); + this.IsUseCheckBox.Name = "IsUseCheckBox"; + this.IsUseCheckBox.Size = new System.Drawing.Size(72, 16); + this.IsUseCheckBox.TabIndex = 12; + this.IsUseCheckBox.Text = "是否启用"; + this.IsUseCheckBox.UseVisualStyleBackColor = true; + // // MaterialConfigPage // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -248,14 +275,16 @@ namespace HighWayIot.Winform.UserControlPages private Button SelectMaterial; private TextBox MaterialNameTextbox; private Label label1; - private DataGridViewTextBoxColumn MaterialCode; - private DataGridViewTextBoxColumn MaterialName; - private DataGridViewTextBoxColumn MaterialType; - private DataGridViewTextBoxColumn ChildType; - private DataGridViewTextBoxColumn IsUse; private ComboBox ChildComboBox; private Label label3; private ComboBox MaterialTypeComboBox; private Label label2; + private DataGridViewTextBoxColumn MaterialCode; + private DataGridViewTextBoxColumn MaterialName; + private DataGridViewTextBoxColumn MaterialType; + private DataGridViewTextBoxColumn ChildType; + private DataGridViewCheckBoxColumn IsUse; + private CheckBox IsUseCheckBox; + private CheckBox IsAvailableUseCheckBox; } } diff --git a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.cs b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.cs index 9bd1c89..00819f3 100644 --- a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.cs +++ b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialConfigPage.cs @@ -16,6 +16,26 @@ namespace HighWayIot.Winform.UserControlPages { public partial class MaterialConfigPage : UserControl { + /// + /// 物料子类型服务类实例 + /// + ZxMaterialChildTypeService zxMaterialChildTypeService = ZxMaterialChildTypeService.Instance; + + /// + /// 物料子类型数组 + /// + string[] MaterialChildTypeArray; + + /// + /// 物料类型服务类实例 + /// + ZxMaterialTypeService zxMaterialTypeService = ZxMaterialTypeService.Instance; + + /// + /// 物料类型数组 + /// + string[] MaterialTypeArray; + /// /// 物料信息服务类实例 /// @@ -36,7 +56,13 @@ namespace HighWayIot.Winform.UserControlPages { MaterialDataGridView.AutoGenerateColumns = false; - + //绑定物料类型 + MaterialTypeArray = zxMaterialTypeService.GetMaterialTypeInfos().Select(x => x.MaterialTypeName).ToArray(); + Array.Resize(ref MaterialTypeArray, MaterialTypeArray.Length + 1); + Array.Copy(MaterialTypeArray, 0, MaterialTypeArray, 1, MaterialTypeArray.Length - 1); + MaterialTypeArray[0] = string.Empty; + + MaterialTypeComboBox.DataSource = MaterialTypeArray; Lists = zxMaterialService.GetMaterialInfos(); @@ -88,6 +114,19 @@ namespace HighWayIot.Winform.UserControlPages /// private void DeleteMaterial_Click(object sender, EventArgs e) { + int a = MaterialDataGridView.CurrentRow.Index; + string s = MaterialDataGridView.Rows[a].Cells["MaterialCode"].Value.ToString(); + + if(MessageBox.Show($"是否要删除编号为{s}的物料?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) + { + return; + } + + if (!zxMaterialService.DeleteMaterialInfoByMaterialCode(s)) + { + MessageBox.Show($"编号为{s}的物料删除失败" ,"提示"); + } + Lists = zxMaterialService.GetMaterialInfos(); MaterialDataGridView.DataSource = null; MaterialDataGridView.DataSource = Lists; @@ -100,9 +139,24 @@ namespace HighWayIot.Winform.UserControlPages /// private void SelectMaterial_Click(object sender, EventArgs e) { - Lists = zxMaterialService.GetMaterialInfos(MaterialNameTextbox.Text.Trim(), MaterialTypeComboBox.Text.Trim(), ChildComboBox.Text.Trim()); + Lists = zxMaterialService.GetMaterialInfos(MaterialNameTextbox.Text.Trim(), MaterialTypeComboBox.Text.Trim(), ChildComboBox.Text.Trim(), IsAvailableUseCheckBox.Checked, IsUseCheckBox.Checked); MaterialDataGridView.DataSource = null; MaterialDataGridView.DataSource = Lists; } + + /// + /// 物料类型更改事件 + /// + /// + /// + private void MaterialTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + MaterialChildTypeArray = zxMaterialChildTypeService.GetMaterialChildTypeInfos(x => x.MaterialTypeName == MaterialTypeComboBox.Text).Select(x => x.MaterialChlidTypeName).ToArray(); + Array.Resize(ref MaterialChildTypeArray, MaterialChildTypeArray.Length + 1); + Array.Copy(MaterialChildTypeArray, 0, MaterialChildTypeArray, 1, MaterialChildTypeArray.Length - 1); + MaterialChildTypeArray[0] = string.Empty; + + ChildComboBox.DataSource = MaterialChildTypeArray; + } } } diff --git a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.Designer.cs b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.Designer.cs index 70bc4c9..4aaed6a 100644 --- a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.Designer.cs @@ -85,6 +85,7 @@ this.MaterialTypeComboBox.Name = "MaterialTypeComboBox"; this.MaterialTypeComboBox.Size = new System.Drawing.Size(136, 20); this.MaterialTypeComboBox.TabIndex = 19; + this.MaterialTypeComboBox.SelectedIndexChanged += new System.EventHandler(this.MaterialTypeComboBox_SelectedIndexChanged); // // label4 // diff --git a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.cs b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.cs index 7e786d8..9ce809d 100644 --- a/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.cs +++ b/HighWayIot.Winform/UserControlPages/MaterialConfigPages/MaterialUpdateForm.cs @@ -10,11 +10,32 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace HighWayIot.Winform.UserControlPages.SysConfigPages { public partial class MaterialUpdateForm : Form { + /// + /// 物料子类型服务类实例 + /// + ZxMaterialChildTypeService zxMaterialChildTypeService = ZxMaterialChildTypeService.Instance; + + /// + /// 物料子类型数组 + /// + string[] MaterialChildTypeArray; + + /// + /// 物料类型服务类实例 + /// + ZxMaterialTypeService zxMaterialTypeService = ZxMaterialTypeService.Instance; + + /// + /// 物料类型数组 + /// + string[] MaterialTypeArray; + /// /// 物料数据库业务实例 /// @@ -29,6 +50,41 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages { InitializeComponent(); _entity = entity; + + Init(); + } + + //初始化选择 + private void Init() + { + MaterialNameTextBox.Text = _entity.MaterialName; + MaterialCodeTextBox.Text = _entity.MaterialCode; + + //绑定物料类型 + MaterialTypeArray = zxMaterialTypeService.GetMaterialTypeInfos().Select(x => x.MaterialTypeName).ToArray(); + Array.Resize(ref MaterialTypeArray, MaterialTypeArray.Length + 1); + Array.Copy(MaterialTypeArray, 0, MaterialTypeArray, 1, MaterialTypeArray.Length - 1); + MaterialTypeArray[0] = string.Empty; + + MaterialTypeComboBox.DataSource = MaterialTypeArray; + + for (int i = 0; i < MaterialTypeComboBox.Items.Count; i++) + { + if (MaterialTypeComboBox.GetItemText(MaterialTypeComboBox.Items[i]) == _entity.MaterialType) + { + MaterialTypeComboBox.SelectedIndex = i; + } + } + + for (int i = 0; i < ChildComboBox.Items.Count; i++) + { + if (ChildComboBox.GetItemText(ChildComboBox.Items[i]) == _entity.ChildType) + { + ChildComboBox.SelectedIndex = i; + } + } + + IsUseCheckBox.Checked = _entity.IsUse.Value; } /// @@ -38,7 +94,44 @@ namespace HighWayIot.Winform.UserControlPages.SysConfigPages /// private void ConfrimAddButton_Click(object sender, EventArgs e) { + ZxMaterialEntity entity = new ZxMaterialEntity() + { + MaterialName = MaterialNameTextBox.Text.Trim(), + MaterialCode = MaterialCodeTextBox.Text.Trim(), + MaterialType = MaterialTypeComboBox.Text.Trim(), + ChildType = ChildComboBox.Text.Trim(), + IsUse = IsUseCheckBox.Checked, + IsDeleted = _entity.IsDeleted.Value, + }; + + if (zxMaterialService.UpdateMaterialInfo(entity)) + { + MessageBox.Show("物料信息修改成功!", "提示"); + } + else + { + MessageBox.Show("物料信息修改失败!请检查物料编号是否重复或为空!", "提示"); + return; + } + + + this.Close(); + this.Dispose(); + } + + /// + /// 物料类型选择事件 + /// + /// + /// + private void MaterialTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + MaterialChildTypeArray = zxMaterialChildTypeService.GetMaterialChildTypeInfos(x => x.MaterialTypeName == MaterialTypeComboBox.Text).Select(x => x.MaterialChlidTypeName).ToArray(); + Array.Resize(ref MaterialChildTypeArray, MaterialChildTypeArray.Length + 1); + Array.Copy(MaterialChildTypeArray, 0, MaterialChildTypeArray, 1, MaterialChildTypeArray.Length - 1); + MaterialChildTypeArray[0] = string.Empty; + ChildComboBox.DataSource = MaterialChildTypeArray; } } }