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.

224 lines
8.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Entity.material;
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<xl_material> lst = null;
lst = BinHelper.GetXlMaterialList();
this.comboBox1.Items.Clear();
foreach (xl_material m in lst)
{
this.comboBox1.Items.Add(m);
}
//当操作类型为修改时,将选中行的数据填入到修改窗体的对应控件中
if (this._actionType == ActionType.Modify)
{
foreach (xl_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();
this.txtBinName.Text = _bin.Bin_Name.ToString();
this.txtQRCode.Text = _bin.Bin_Code.ToString();
this.textWeight_Medium.Text = _bin.Station_Weight_Medium.ToString();
this.textWeight_Low.Text = _bin.Station_Weight_Low.ToString();
this.textWeight_Advance.Text = _bin.Station_Weight_Advance.ToString();
this.textSpeed_Hight.Text = _bin.Station_Speed_Hight.ToString();
this.textSpeed_Medium.Text = _bin.Station_Speed_Medium.ToString();
this.textSpeed_Low.Text = _bin.Station_Speed_Low.ToString();
}
textBox1.Enabled = false;
txtBinName.Enabled = false;
}
private void btnOK_Click(object sender, EventArgs e)
{
//获取包含所有料仓对象的集合
List<Pmt_Bin> list = BinHelper.getBinList();
if (string.IsNullOrEmpty(txtQRCode.Text))
{
MessageBox.Show("请填写条码!!");
this.comboBox1.Focus();
return;
}
if (string.IsNullOrEmpty(comboBox1.Text))
{
MessageBox.Show("请选择物料名!!");
this.comboBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textWeight_Medium.Text))
{
MessageBox.Show("请填写中速重量!!");
this.textWeight_Medium.Focus();
return;
}
if (string.IsNullOrEmpty(textWeight_Advance.Text))
{
MessageBox.Show("请填写提前量!!");
this.comboBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textSpeed_Hight.Text))
{
MessageBox.Show("请填写高速速度!!");
this.comboBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textSpeed_Medium.Text))
{
MessageBox.Show("请填写中速速度!!");
this.comboBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textSpeed_Low.Text))
{
MessageBox.Show("请填写低速速度!!");
this.comboBox1.Focus();
return;
}
double mediumWeight = Convert.ToDouble(textWeight_Medium.Text);
if (mediumWeight < 0 || mediumWeight > 60)
{
MessageBox.Show("中速重量要大于等于0,小于等于60");
this.textWeight_Medium.Focus();
return;
}
double lowWeight = Convert.ToDouble(textWeight_Low.Text);
if (lowWeight < 0 || lowWeight > 60)
{
MessageBox.Show("低速重量要大于等于0,小于等于60");
this.textWeight_Low.Focus();
return;
}
double advWeight = Convert.ToDouble(textWeight_Advance.Text);
if (lowWeight < 0 || advWeight > 60)
{
MessageBox.Show("提前量要大于等于0,小于等于60");
this.textWeight_Advance.Focus();
return;
}
double speedHight = Convert.ToDouble(textSpeed_Hight.Text);
if (speedHight < 0 && speedHight > 50)
{
MessageBox.Show("高速速度要大于等于0,小于等于50");
this.textSpeed_Hight.Focus();
return;
}
double speedMedium = Convert.ToDouble(textSpeed_Medium.Text);
if (speedMedium < 0 || speedMedium > 50)
{
MessageBox.Show("中速速度要大于等于0,小于等于50");
this.textSpeed_Medium.Focus();
return;
}
double speedLow = Convert.ToDouble(textSpeed_Low.Text);
if (speedLow < 0 || speedLow > 50)
{
MessageBox.Show("低速速度要大于等于0,小于等于50");
this.textSpeed_Low.Focus();
return;
}
xl_material material = (xl_material)comboBox1.SelectedItem;
Pmt_Bin bin = new Pmt_Bin
{
Bin_Serial = Convert.ToInt32(textBox1.Text),
Bin_Name = txtBinName.Text,
Bin_Code= txtQRCode.Text,
Material_ID = material.ID,
Station_Weight_Medium =decimal.Parse(textWeight_Medium.Text),
Station_Weight_Low = decimal.Parse(textWeight_Low.Text),
Station_Weight_Advance = decimal.Parse(textWeight_Advance.Text),
Station_Speed_Hight = decimal.Parse(textSpeed_Hight.Text),
Station_Speed_Medium = decimal.Parse(textSpeed_Medium.Text),
Station_Speed_Low = decimal.Parse(textSpeed_Low.Text),
};
//验证料仓中物料的唯一性
//当修改料仓中物料时,提交的物料ID和选中行的不一样时需要验证唯一性
if (_actionType == ActionType.Modify && _bin.Material_ID != bin.Material_ID)
{
//物料唯一性验证
if (list.Exists(b => b.Material_ID == bin.Material_ID))
{
MessageBox.Show("物料已存在于料仓中!!请更换物料!!");
return;
}
//条码唯一性验证
if (list.Exists(b => b.Bin_Code == bin.Bin_Code && b.Bin_Serial!= bin.Bin_Serial))
{
MessageBox.Show("条码已存在于料仓中!!请更换物料!!");
return;
}
}
this._bin = bin;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
}