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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjMaterial/FrmMaterial.cs

94 lines
2.7 KiB
C#

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