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(); } public FrmMaterial(ActionType actionType, MaterialInfoType materialInfoType):this(actionType) { _materialInfoType = materialInfoType; this.MNameTB.Text = materialInfoType.MaterialInfoTypeName; } private void btnOK_Click(object sender, EventArgs e) { var materialinfoTypeName = MNameTB.Text.Trim(); 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>0) { MessageBox.Show("物料名已经存在!!"); this.MNameTB.Focus(); return; } if (_actionType == ActionType.Add) { MaterialInfoTypeHelp.Add(materialinfoTypeName); } if (_actionType == ActionType.Modify) { MaterialInfoTypeHelp.Update(_materialInfoType.Id,materialinfoTypeName); } this.DialogResult = System.Windows.Forms.DialogResult.OK; } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } } }