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#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.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 = 0;
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();
}
}
}