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.

167 lines
6.1 KiB
C#

using ICSharpCode.Core;
using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.Action.ChemicalWeighing.Technical.PmtRecipe.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.MaterialManage
{
public partial class FrmMaterial : Form
{
#region 字段定义
private ActionType _actionType = ActionType.Add; //操作类型0-为添加1-为修改
private Base_MaterialInfo _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, Base_MaterialInfo material)
{
InitializeComponent();
this._actionType = actionType;
this._material = material;
}
/// <summary>
/// 物料信息
/// </summary>
public Base_MaterialInfo 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.materialName;
this.MCodeTB.Text = _material.materialId;
}
}
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;
}
//创建对象
Base_MaterialInfo material = new Base_MaterialInfo
{
materialName = MNameTB.Text,
materialId = MCodeTB.Text
};
//获取包含所有物料对象的集合
List<Base_MaterialInfo> list = MaterialHelper.getMaterialList();
//当新增物料时
//当修改物料时 且物料名、编码都修改了 物料名和编码唯一性都需要验证
if (_actionType == ActionType.Add || (_actionType == ActionType.Modify && (_material.materialName != material.materialName && _material.materialId != material.materialId)))
{
//物料名唯一性验证
if (list.Exists(m => m.materialName == material.materialName))
{
MessageBox.Show("物料名已存在!!请更换物料名!!");
return;
}
//物料编码唯一性验证
if (list.Exists(u => u.materialId == material.materialId))
{
MessageBox.Show("物料编码已存在!!请更换物料编码!!");
return;
}
}
//修改物料时 只修改了物料名
if(_actionType == ActionType.Modify && (_material.materialName != material.materialName && _material.materialId == material.materialId))
{
//物料名唯一性验证
if (list.Exists(m => m.materialName == material.materialName))
{
MessageBox.Show("物料名已存在!!请更换物料名!!");
return;
}
}
//修改物料时 只修改了物料编码
if (_actionType == ActionType.Modify && (_material.materialName == material.materialName && _material.materialId != material.materialId))
{
//物料编码唯一性验证
if (list.Exists(u => u.materialId == material.materialId))
{
MessageBox.Show("物料编码已存在!!请更换物料编码!!");
return;
}
}
this._material = material;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}