You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/BinManage/FrmBin.cs

120 lines
3.6 KiB
C#

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();
}
/// <summary>
/// 构造方法
/// </summary>
/// <param name="actionType">-1为修改</param>
/// <param name="bin">传入的料仓信息</param>
public FrmBin(ActionType actionType, Pmt_Bin bin)
{
InitializeComponent();
this._actionType = actionType;
this._bin = bin;
}
/// <summary>
/// 料仓信息
/// </summary>
public Pmt_Bin Bin
{
get { return this._bin; }
}
/// <summary>
/// 修改料仓信息 窗体加载时 将选中行的数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmBin_Load(object sender, EventArgs e)
{
this.InitData();
}
/// <summary>
/// 初始化控件数据
/// </summary>
public void InitData()
{
List<Pmt_material> 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<Pmt_Bin> 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;
}
}
}