|
|
using System;
|
|
|
using System.Windows.Forms;
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.LjMaterial
|
|
|
{
|
|
|
public partial class FrmMaterial : Form
|
|
|
{
|
|
|
private MaterialInfoType _materialInfoType;
|
|
|
|
|
|
private ActionType _actionType = ActionType.Add; //操作类型,0-为添加,1-为修改
|
|
|
public FrmMaterial(ActionType actionType)
|
|
|
{
|
|
|
this._actionType = actionType;
|
|
|
InitializeComponent();
|
|
|
|
|
|
DrpmaterialType.DataSource = MaterialInfoTypeHelp.GetType();
|
|
|
DrpmaterialType.DisplayMember = "Name";
|
|
|
DrpmaterialType.ValueMember = "Id";
|
|
|
}
|
|
|
|
|
|
public FrmMaterial(ActionType actionType, MaterialInfoType materialInfoType):this(actionType)
|
|
|
{
|
|
|
_materialInfoType = materialInfoType;
|
|
|
this.MNameTB.Text = materialInfoType.MaterialName;
|
|
|
|
|
|
if (actionType == ActionType.Modify)
|
|
|
{
|
|
|
var mtypeIdById = MaterialInfoTypeHelp.GetMtypeIdById(materialInfoType.Id);
|
|
|
|
|
|
foreach (MyNameValue s in DrpmaterialType.Items)
|
|
|
{
|
|
|
if (s.Id == mtypeIdById)
|
|
|
{
|
|
|
DrpmaterialType.SelectedItem = s;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
var materialinfoTypeName = MNameTB.Text.Trim();
|
|
|
|
|
|
int mtypeId = Convert.ToInt32(DrpmaterialType.SelectedValue);
|
|
|
|
|
|
if (string.IsNullOrEmpty(materialinfoTypeName))
|
|
|
{
|
|
|
MessageBox.Show("物料名不能为空!!");
|
|
|
this.MNameTB.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var exist = MaterialInfoTypeHelp.Exist(materialinfoTypeName);
|
|
|
if (_actionType == ActionType.Add && exist>0)
|
|
|
{
|
|
|
MessageBox.Show("物料名已经存在!!");
|
|
|
this.MNameTB.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (_actionType == ActionType.Modify && exist>1)
|
|
|
{
|
|
|
MessageBox.Show("物料名已经存在!!");
|
|
|
this.MNameTB.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (_actionType == ActionType.Add)
|
|
|
{
|
|
|
MaterialInfoTypeHelp.Add(materialinfoTypeName,mtypeId);
|
|
|
}
|
|
|
|
|
|
if (_actionType == ActionType.Modify)
|
|
|
{
|
|
|
MaterialInfoTypeHelp.Update(_materialInfoType.Id,materialinfoTypeName,mtypeId);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
this.Close();
|
|
|
}
|
|
|
}
|
|
|
} |