using HighWayIot.Repository.service; using HighWayIot.Winform.Business; 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 static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace HighWayIot.Winform.UserControlPages.RecipeConfigPages { public partial class AddWeightForm : Form { /// /// 物料子类型服务类实例 /// ZxMaterialChildTypeService zxMaterialChildTypeService = ZxMaterialChildTypeService.Instance; /// /// 物料类型服务类实例 /// ZxMaterialTypeService zxMaterialTypeService = ZxMaterialTypeService.Instance; /// /// 物料服务类实例 /// ZxMaterialService zxMaterialService = ZxMaterialService.Instance; /// /// 称量服务类实例 /// ZxWeightService zxWeightService = ZxWeightService.Instance; /// /// 物料编号数组 /// string[] MaterialCodeArray; /// /// 物料名称数组 /// string[] MaterialNameArray; /// /// 物料子类型数组 /// string[] MaterialChildTypeArray; /// /// 物料类型数组 /// string[] MaterialTypeArray; /// /// 配方编号 /// string RecipeCode; public AddWeightForm(string recipeCode) { InitializeComponent(); RecipeCode = recipeCode; Init(); } private void Init() { RecipeCodeTextBox.Text = RecipeCode; //获取数据 MaterialTypeArray = zxMaterialTypeService.GetMaterialTypeInfos().Select(x => x.MaterialTypeName).ToArray(); List list = zxMaterialService.GetMaterialInfos(); MaterialCodeArray = list.Select(x => x.MaterialCode).ToArray(); MaterialNameArray = list.Select(x => x.MaterialName).ToArray(); //添加空白行 MaterialTypeArray = GeneralUtils.HeadAddEmptyString(MaterialTypeArray); MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray); MaterialNameArray = GeneralUtils.HeadAddEmptyString(MaterialNameArray); //绑定combobox数据源 MaterialTypeComboBox.DataSource = MaterialTypeArray; MaterialCodeComboBox.DataSource = MaterialCodeArray; MaterialNameComboBox.DataSource = MaterialNameArray; } private void AddButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(MaterialCodeComboBox.Text)) { MessageBox.Show("物料编号不可为空!"); return; } ZxWeightEntity zxWeightEntity = new ZxWeightEntity() { RecipeCode = this.RecipeCode, MaterialCode = MaterialCodeComboBox.Text.Trim(), IsUse = IsUseCheckBox.Checked, IsDeleted = false, }; if (!decimal.TryParse(SetThicknessTextBox.Text.Trim(), out decimal thickness)) { MessageBox.Show("厚度请填入可带小数的阿拉伯数字"); return; } zxWeightEntity.SetThickness = thickness; if (!decimal.TryParse(SetWidthTextBox.Text.Trim(), out decimal width)) { MessageBox.Show("宽度请填入可带小数的阿拉伯数字"); return; } zxWeightEntity.SetWidth = width; if (!int.TryParse(SetLayerTextBox.Text.Trim(), out int layer)) { MessageBox.Show("层数请填入整数阿拉伯数字"); return; } zxWeightEntity.SetLayer = layer; if (!decimal.TryParse(SetWeightTextBox.Text.Trim(), out decimal weight)) { MessageBox.Show("重量请填入可带小数的阿拉伯数字"); return; } zxWeightEntity.SetWeight = weight; if (!decimal.TryParse(SetErrorTextBox.Text.Trim(), out decimal error)) { MessageBox.Show("重量公差请填入可带小数的阿拉伯数字"); return; } zxWeightEntity.SetError = error; if (zxWeightService.InsertWeightInfo(zxWeightEntity)) { MessageBox.Show("称量信息添加成功!"); } else { MessageBox.Show("称量信息添加失败!请尝试重新添加"); return; } this.Close(); this.Dispose(); } /// /// 物料类型选择事件 /// /// /// private void MaterialTypeComboBox_SelectionChangeCommitted(object sender, EventArgs e) { List list = zxMaterialService.GetMaterialInfos(null, MaterialTypeComboBox.Text.Trim()); MaterialCodeArray = list.Select(x => x.MaterialCode).ToArray(); MaterialNameArray = list.Select(x => x.MaterialName).ToArray(); //添加空白行 MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray); MaterialNameArray = GeneralUtils.HeadAddEmptyString(MaterialNameArray); //绑定combobox数据源 MaterialCodeComboBox.DataSource = MaterialCodeArray; MaterialNameComboBox.DataSource = MaterialNameArray; MaterialChildTypeArray = zxMaterialChildTypeService.GetMaterialChildTypeInfos(x => x.MaterialTypeName == MaterialTypeComboBox.Text).Select(x => x.MaterialChlidTypeName).ToArray(); MaterialChildTypeArray = GeneralUtils.HeadAddEmptyString(MaterialChildTypeArray); ChildTypeComboBox.DataSource = MaterialChildTypeArray; } /// /// 物料子类型选择事件 /// /// /// private void ChildTypeComboBox_SelectionChangeCommitted(object sender, EventArgs e) { List list = zxMaterialService.GetMaterialInfos(null, MaterialTypeComboBox.Text.Trim(), ChildTypeComboBox.Text.Trim()); MaterialCodeArray = list.Select(x => x.MaterialCode).ToArray(); MaterialNameArray = list.Select(x => x.MaterialName).ToArray(); //添加空白行 MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray); MaterialNameArray = GeneralUtils.HeadAddEmptyString(MaterialNameArray); //绑定combobox数据源 MaterialCodeComboBox.DataSource = MaterialCodeArray; MaterialNameComboBox.DataSource = MaterialNameArray; } /// /// 物料编号选择事件 /// /// /// private void MaterialCodeComboBox_SelectionChangeCommitted(object sender, EventArgs e) { ZxMaterialEntity entity = zxMaterialService.GetSingleEntityByCode(MaterialCodeComboBox.Text.Trim()); if (entity == null) { return; } MaterialNameComboBox.Text = entity.MaterialName; MaterialTypeComboBox.Text = entity.MaterialType; ChildTypeComboBox.Text = entity.ChildType; } /// /// 物料名称选择事件 /// /// /// private void MaterialNameComboBox_SelectionChangeCommitted(object sender, EventArgs e) { List entitys = zxMaterialService.GetMaterialInfos(MaterialNameComboBox.Text.Trim()); if (entitys.Count == 1) { ZxMaterialEntity entity = entitys[0]; MaterialCodeComboBox.Text = entity.MaterialCode; MaterialTypeComboBox.Text = entity.MaterialType; ChildTypeComboBox.Text = entity.ChildType; } else if (entitys == null) { return; } else { MaterialCodeArray = entitys.Select(x => x.MaterialCode).ToArray(); //添加空白行 MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray); //绑定combobox数据源 MaterialCodeComboBox.DataSource = MaterialCodeArray; MaterialTypeComboBox.Text = string.Empty; ChildTypeComboBox.Text = string.Empty; } } /// /// 物料类型更改事件 /// /// /// 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); ChildTypeComboBox.DataSource = MaterialChildTypeArray; } } }