|
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
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.XlMaterialManage
|
|
|
|
|
{
|
|
|
|
|
public partial class FrmMaterial : Form
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region 字段定义
|
|
|
|
|
|
|
|
|
|
private ActionType _actionType = ActionType.Add; //操作类型,0-为添加,1-为修改
|
|
|
|
|
private xl_material _material = null; //物料对象
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public FrmMaterial()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增物料窗体的构造方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="actionType">操作类型 0为新增</param>
|
|
|
|
|
public FrmMaterial(ActionType actionType)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this._actionType = actionType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改物料信息的构造方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="actionType">操作类型,1-为修改</param>
|
|
|
|
|
/// <param name="user">用户信息传入的</param>
|
|
|
|
|
public FrmMaterial(ActionType actionType, xl_material material)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this._actionType = actionType;
|
|
|
|
|
this._material = material;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 物料信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public xl_material Material
|
|
|
|
|
{
|
|
|
|
|
get { return this._material; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrmMaterial_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.InitUI();
|
|
|
|
|
this.InitData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化界面文本
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void InitUI()
|
|
|
|
|
{
|
|
|
|
|
if (this._actionType == ActionType.Add)
|
|
|
|
|
{
|
|
|
|
|
this.Text = StringParser.Parse(ResourceService.GetString("Menac_Action_ChemicalWeighing_MaterialManage_FrmMaterial_Text_Add")); //添加物料
|
|
|
|
|
}
|
|
|
|
|
else if (this._actionType == ActionType.Modify)
|
|
|
|
|
{
|
|
|
|
|
this.Text = StringParser.Parse(ResourceService.GetString("Menac_Action_ChemicalWeighing_MaterialManage_FrmMaterial_Text_Modify")); //修改物料信息
|
|
|
|
|
}
|
|
|
|
|
this.label1.Text = StringParser.Parse(ResourceService.GetString("Menac_Action_ChemicalWeighing_MaterialManage_FrmMaterial_label1_Text")); //物料名称:
|
|
|
|
|
this.label2.Text = StringParser.Parse(ResourceService.GetString("Menac_Action_ChemicalWeighing_MaterialManage_FrmMaterial_label2_Text")); //物料编码:
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void InitData()
|
|
|
|
|
{
|
|
|
|
|
//当操作类型为修改时,将选中行的数据填入到修改窗体的对应控件中
|
|
|
|
|
if (this._actionType == ActionType.Modify)
|
|
|
|
|
{
|
|
|
|
|
this.MNameTB.Text = _material.Material_name;
|
|
|
|
|
this.MCodeTB.Text = _material.Material_code;
|
|
|
|
|
this.chcIsEnable.Checked = _material.IsEnable=="是"?true:false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(MNameTB.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("物料名不能为空!!");
|
|
|
|
|
this.MNameTB.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(MCodeTB.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("物料编码不能为空!!");
|
|
|
|
|
this.MCodeTB.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//创建对象
|
|
|
|
|
xl_material material = new xl_material
|
|
|
|
|
{
|
|
|
|
|
Material_name = MNameTB.Text,
|
|
|
|
|
Material_code = MCodeTB.Text,
|
|
|
|
|
IsEnable=chcIsEnable.Checked==true?"是":"否",
|
|
|
|
|
ID = Guid.NewGuid().ToString("N")
|
|
|
|
|
};
|
|
|
|
|
//获取包含所有物料对象的集合
|
|
|
|
|
List<xl_material> list = MaterialHelper.getMaterialList();
|
|
|
|
|
|
|
|
|
|
//当新增物料时
|
|
|
|
|
//当修改物料时 且物料名、编码都修改了 物料名和编码唯一性都需要验证
|
|
|
|
|
if (_actionType == ActionType.Add || (_actionType == ActionType.Modify && (_material.Material_name != material.Material_name && _material.Material_code != material.Material_code)))
|
|
|
|
|
{
|
|
|
|
|
//物料名唯一性验证
|
|
|
|
|
if (list.Exists(m => m.Material_name == material.Material_name))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("物料名已存在!!请更换物料名!!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//物料编码唯一性验证
|
|
|
|
|
if (list.Exists(u => u.Material_code == material.Material_code))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("物料编码已存在!!请更换物料编码!!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//修改物料时 只修改了物料名
|
|
|
|
|
if (_actionType == ActionType.Modify && (_material.Material_name != material.Material_name && _material.Material_code == material.Material_code))
|
|
|
|
|
{
|
|
|
|
|
//物料名唯一性验证
|
|
|
|
|
if (list.Exists(m => m.Material_name == material.Material_name))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("物料名已存在!!请更换物料名!!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//修改物料时 只修改了物料编码
|
|
|
|
|
if (_actionType == ActionType.Modify && (_material.Material_name == material.Material_name && _material.Material_code != material.Material_code))
|
|
|
|
|
{
|
|
|
|
|
//物料编码唯一性验证
|
|
|
|
|
if (list.Exists(u => u.Material_code == material.Material_code))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("物料编码已存在!!请更换物料编码!!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this._material = material;
|
|
|
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|