using Mesnac.Action.ChemicalWeighing.Entity; 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; namespace Mesnac.Action.ChemicalWeighing.BinManage { public partial class FrmBin : Form { #region 字段定义 private ActionType _actionType = ActionType.Add; //操作类型,0-为添加,1-为修改 private Pmt_Bin _bin = null; #endregion public FrmBin() { InitializeComponent(); } /// /// 构造方法 /// /// -1为修改 /// 传入的料仓信息 public FrmBin(ActionType actionType, Pmt_Bin bin) { InitializeComponent(); this._actionType = actionType; this._bin = bin; } /// /// 料仓信息 /// public Pmt_Bin Bin { get { return this._bin; } } /// /// 修改料仓信息 窗体加载时 将选中行的数据 /// /// /// private void FrmBin_Load(object sender, EventArgs e) { this.InitData(); } /// /// 初始化控件数据 /// public void InitData() { List lst = null; lst = BinHelper.GetMaterialList(); this.comboBox1.Items.Clear(); foreach (Pmt_material m in lst) { this.comboBox1.Items.Add(m); } //当操作类型为修改时,将选中行的数据填入到修改窗体的对应控件中 if (this._actionType == ActionType.Modify) { foreach (Pmt_material m in this.comboBox1.Items) { if (m.ID == this._bin.Material_ID) { this.comboBox1.SelectedItem = m; break; } } this.textBox1.Text = _bin.Bin_Serial.ToString(); } textBox1.Enabled = false; } private void btnOK_Click(object sender, EventArgs e) { //获取包含所有料仓对象的集合 List list = BinHelper.getBinList(); if (string.IsNullOrEmpty(comboBox1.Text)) { MessageBox.Show("请选择物料名!!"); this.comboBox1.Focus(); return; } Pmt_material material = (Pmt_material)comboBox1.SelectedItem; Pmt_Bin bin = new Pmt_Bin { Bin_Serial = Convert.ToInt32(textBox1.Text), Material_ID = material.ID }; //验证料仓中物料的唯一性 //当修改料仓中物料时,提交的物料ID和选中行的不一样时,需要验证唯一性 if (_actionType == ActionType.Modify && _bin.Material_ID != bin.Material_ID) { //物料唯一性验证 if (list.Exists(b => b.Material_ID == bin.Material_ID)) { MessageBox.Show("物料已存在于料仓中!!请更换物料!!"); return; } } this._bin = bin; this.DialogResult = System.Windows.Forms.DialogResult.OK; } } }