using HighWayIot.Log4net; using HighWayIot.Repository.service; using HighWayIot.Winform.Business; using HighWayIot.Winform.UserControlPages.SysConfigPages; using Models; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; namespace HighWayIot.Winform.UserControlPages { public partial class MaterialConfigPage : UserControl { LogHelper logHelper = LogHelper.Instance; /// /// 物料子类型服务类实例 /// ZxMaterialChildTypeService zxMaterialChildTypeService = ZxMaterialChildTypeService.Instance; /// /// 物料子类型数组 /// string[] MaterialChildTypeArray; /// /// 物料类型服务类实例 /// ZxMaterialTypeService zxMaterialTypeService = ZxMaterialTypeService.Instance; /// /// 物料类型数组 /// string[] MaterialTypeArray; /// /// 物料信息服务类实例 /// ZxMaterialService zxMaterialService = ZxMaterialService.Instance; /// /// 物料信息列表 /// List Lists; public MaterialConfigPage() { InitializeComponent(); Init(); } private void Init() { MaterialDataGridView.AutoGenerateColumns = false; //绑定物料类型 MaterialTypeArray = zxMaterialTypeService.GetMaterialTypeInfos().Select(x => x.MaterialTypeName).ToArray(); MaterialTypeArray = GeneralUtils.HeadAddEmptyString(MaterialTypeArray); MaterialTypeComboBox.DataSource = MaterialTypeArray; Lists = zxMaterialService.GetMaterialInfos(); MaterialDataGridView.DataSource = null; MaterialDataGridView.DataSource = Lists; } /// /// 添加物料 /// /// /// private void AddMaterial_Click(object sender, EventArgs e) { MaterialAddForm form = new MaterialAddForm(); form.ShowDialog(); Lists = zxMaterialService.GetMaterialInfos(); MaterialDataGridView.DataSource = null; MaterialDataGridView.DataSource = Lists; } /// /// 更新物料 /// /// /// private void UpdateMaterial_Click(object sender, EventArgs e) { ZxMaterialEntity entity = new ZxMaterialEntity(); int a = MaterialDataGridView.CurrentRow.Index; try { entity.Id = int.Parse(MaterialDataGridView.Rows[a].Cells["Id"].Value.ToString().Trim()); } catch (Exception ex) { MessageBox.Show("物料更新ID转换发生错误"); } entity.MaterialCode = MaterialDataGridView.Rows[a].Cells["MaterialCode"].Value.ToString(); entity.MaterialName = MaterialDataGridView.Rows[a].Cells["MaterialName"].Value.ToString(); entity.MaterialType = MaterialDataGridView.Rows[a].Cells["MaterialType"].Value.ToString(); entity.ChildType = MaterialDataGridView.Rows[a].Cells["ChildType"].Value.ToString(); bool.TryParse(MaterialDataGridView.Rows[a].Cells["IsUse"].Value.ToString(), out bool b); entity.IsUse = b; entity.IsDeleted = false; MaterialUpdateForm form = new MaterialUpdateForm(entity); form.ShowDialog(); Lists = zxMaterialService.GetMaterialInfos(); MaterialDataGridView.DataSource = null; MaterialDataGridView.DataSource = Lists; } /// /// 删除物料 /// /// /// private void DeleteMaterial_Click(object sender, EventArgs e) { int a = MaterialDataGridView.CurrentRow.Index; string s = MaterialDataGridView.Rows[a].Cells["MaterialCode"].Value.ToString(); int id; try { id = int.Parse(MaterialDataGridView.Rows[a].Cells["Id"].Value.ToString()); } catch (Exception ex) { logHelper.Error("物料删除ID转换发生错误", ex); return; } if (MessageBox.Show($"是否要删除编号为{s}的物料?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } if (!zxMaterialService.DeleteMaterialInfoById(id)) { MessageBox.Show($"编号为{s}的物料删除失败", "提示"); } Lists = zxMaterialService.GetMaterialInfos(); MaterialDataGridView.DataSource = null; MaterialDataGridView.DataSource = Lists; } /// /// 查询物料 /// /// /// private void SelectMaterial_Click(object sender, EventArgs e) { 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(); MaterialChildTypeArray = GeneralUtils.HeadAddEmptyString(MaterialChildTypeArray); ChildComboBox.DataSource = MaterialChildTypeArray; } } }