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.
111 lines
4.2 KiB
C#
111 lines
4.2 KiB
C#
using DevExpress.XtraEditors;
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using ZJ_BYD.Common;
|
|
using ZJ_BYD.DB;
|
|
using ZJ_BYD.Model;
|
|
using ZJ_BYD.Untils;
|
|
|
|
namespace ZJ_BYD.UserControls.MachineType
|
|
{
|
|
public partial class EditMachineType : XtraForm
|
|
{
|
|
public EditMachineType(int id = 0)
|
|
{
|
|
InitializeComponent();
|
|
if (id > 0)
|
|
{
|
|
GetMachineTypeById(id);
|
|
}
|
|
}
|
|
|
|
private void GetMachineTypeById(int id)
|
|
{
|
|
var model = MachineTypeHelper.QueryActiveMachines().First(m => m.Id == id);
|
|
if (model != null)
|
|
{
|
|
this.lblId.Text = model.Id.ToString();
|
|
this.txtMachineTypeCode.Text = model.MachineTypeCode;
|
|
this.txtMachineTypeName.Text = model.MachineTypeName;
|
|
}
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
int row;
|
|
var t_MachineType = new T_MachineType();
|
|
var flag = this.RegexSave(new Control[] { txtMachineTypeCode, txtMachineTypeName }, out _);
|
|
if (!flag)
|
|
{
|
|
return;
|
|
}
|
|
splashScreenManager1.ShowWaitForm();
|
|
if (string.IsNullOrWhiteSpace(lblId.Text))
|
|
{
|
|
t_MachineType.IpcId = Program.CurrentIpcId;
|
|
t_MachineType.LineCode = Program.CurrentLineCode;
|
|
t_MachineType.MachineTypeCode = this.txtMachineTypeCode.Text.Trim();
|
|
t_MachineType.MachineTypeName = this.txtMachineTypeName.Text.Trim();
|
|
t_MachineType.CreatedBy = CurrentUser.UserName;
|
|
t_MachineType.CreatedTime = DateTime.Now;
|
|
if (CheckIsExistMachineTypeCode(t_MachineType.IpcId, t_MachineType.LineCode, t_MachineType.MachineTypeCode))
|
|
{
|
|
XtraMessageBox.Show("机型编码已存在!");
|
|
splashScreenManager1.CloseWaitForm();
|
|
return;
|
|
}
|
|
row = MachineTypeHelper.AddMachineType(t_MachineType);
|
|
}
|
|
else
|
|
{
|
|
t_MachineType.Id = int.Parse(lblId.Text);
|
|
t_MachineType.IpcId = Program.CurrentIpcId;
|
|
t_MachineType.LineCode = Program.CurrentLineCode;
|
|
t_MachineType.MachineTypeCode = this.txtMachineTypeCode.Text.Trim();
|
|
t_MachineType.MachineTypeName = this.txtMachineTypeName.Text.Trim();
|
|
t_MachineType.UpdatedBy = CurrentUser.UserName;
|
|
t_MachineType.UpdatedTime = DateTime.Now;
|
|
if (CheckIsExistMachineTypeCode(t_MachineType.IpcId, t_MachineType.LineCode, t_MachineType.MachineTypeCode, t_MachineType.Id))
|
|
{
|
|
XtraMessageBox.Show("机型编码已存在!");
|
|
splashScreenManager1.CloseWaitForm();
|
|
return;
|
|
}
|
|
row = MachineTypeHelper.UpdateMachineType(t_MachineType);
|
|
}
|
|
if (row <= 0)
|
|
{
|
|
XtraMessageBox.Show("操作失败!");
|
|
splashScreenManager1.CloseWaitForm();
|
|
return;
|
|
}
|
|
XtraMessageBox.Show("操作成功!");
|
|
DialogResult = DialogResult.OK;
|
|
splashScreenManager1.CloseWaitForm();
|
|
this.Close();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 校验机型编码是否存在
|
|
/// </summary>
|
|
/// <param name="ipcId"></param>
|
|
/// <param name="lineCode"></param>
|
|
/// <param name="machineTypeCode"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
private bool CheckIsExistMachineTypeCode(string ipcId, string lineCode, string machineTypeCode, int id = 0)
|
|
{
|
|
var model = MachineTypeHelper.QueryActiveMachines()
|
|
.Where(m => m.IpcId == ipcId && m.LineCode == lineCode && m.MachineTypeCode == machineTypeCode)
|
|
.WhereIF(id > 0, m => m.Id != id)
|
|
.First();
|
|
return model != null;
|
|
}
|
|
}
|
|
}
|