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.
161 lines
6.0 KiB
C#
161 lines
6.0 KiB
C#
using DevExpress.XtraEditors;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Web.UI.WebControls;
|
|
using System.Windows.Forms;
|
|
using ZJ_BYD.Common;
|
|
using ZJ_BYD.DB;
|
|
using ZJ_BYD.Model;
|
|
using ZJ_BYD.Untils;
|
|
|
|
namespace ZJ_BYD.UserControls.AHeadPara
|
|
{
|
|
public partial class EditAheadPara : XtraForm
|
|
{
|
|
private static int _id = 0;
|
|
public EditAheadPara(int id = 0)
|
|
{
|
|
InitializeComponent();
|
|
_id = id;
|
|
BindCombox.BindMachineTypeForAhead(cmbMachineType);
|
|
if (_id > 0)
|
|
{
|
|
GetAheadParaById();
|
|
}
|
|
}
|
|
|
|
private void GetAheadParaById()
|
|
{
|
|
var model = AheadParaHelper.QueryAheadParaVM("", _id).First();
|
|
if (model != null)
|
|
{
|
|
cmbMachineType.SelectedItem = new ListItem { Text = model.MachineTypeCode, Value = $"{model.Category}_{model.MachineTypeCode}" };
|
|
cmbMachineType_SelectedValueChanged(this.cmbMachineType, new EventArgs());
|
|
cmbStation.SelectedItem = new ListItem { Text = $"{model.Category}_{model.LastStationName}({model.LastStationCode})", Value = model.LastStationCode };
|
|
txtPara.Text = model.PointCode;
|
|
txtResultColName.Text = model.ResultColName;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 机型下拉框Change事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void cmbMachineType_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
var selectedMachineType = this.cmbMachineType.SelectedItem as ListItem;
|
|
cmbStation.Properties.Items.Clear();
|
|
var category = selectedMachineType.Value.Split('_')[0];
|
|
BindCombox.BindStationByCategory(cmbStation, category);
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
int row;
|
|
var t_AheadPara = new T_AheadPara();
|
|
var flag = this.RegexSave(new Control[] { cmbMachineType, cmbStation, txtPara }, out _);
|
|
if (!flag)
|
|
{
|
|
return;
|
|
}
|
|
splashScreenManager1.ShowWaitForm();
|
|
var selectedMachineType = cmbMachineType.SelectedItem as ListItem;
|
|
var selectedStation = cmbStation.SelectedItem as ListItem;
|
|
t_AheadPara.IpcId = Program.CurrentIpcId;
|
|
t_AheadPara.LineCode = Program.CurrentLineCode;
|
|
t_AheadPara.StationCode = Program.ActiveStatinCode;
|
|
t_AheadPara.MachineTypeCode = selectedMachineType.Value.Split('_')[1];
|
|
t_AheadPara.LastStationCode = selectedStation != null ? selectedStation.Value : cmbStation.EditValue.ToString();
|
|
t_AheadPara.PointCode = txtPara.Text.Trim();
|
|
t_AheadPara.ResultColName = txtResultColName.Text.Trim();
|
|
t_AheadPara.Category = selectedStation.Text.Split('_')[0];
|
|
if (_id == 0)
|
|
{
|
|
t_AheadPara.CreatedBy = CurrentUser.UserName;
|
|
if (CheckIsExistAheadPara(t_AheadPara))
|
|
{
|
|
XtraMessageBox.Show("前置参数已存在!");
|
|
splashScreenManager1.CloseWaitForm();
|
|
return;
|
|
}
|
|
t_AheadPara.CreatedTime = DateTime.Now;
|
|
row = AheadParaHelper.AddAheadPara(t_AheadPara);
|
|
}
|
|
else
|
|
{
|
|
t_AheadPara.Id = _id;
|
|
t_AheadPara.UpdatedBy = CurrentUser.UserName;
|
|
t_AheadPara.UpdatedTime = DateTime.Now;
|
|
if (CheckIsExistAheadPara(t_AheadPara))
|
|
{
|
|
XtraMessageBox.Show("前置参数已存在!");
|
|
splashScreenManager1.CloseWaitForm();
|
|
return;
|
|
}
|
|
row = AheadParaHelper.UpdateAheadPara(t_AheadPara);
|
|
}
|
|
if (row <= 0)
|
|
{
|
|
splashScreenManager1.CloseWaitForm();
|
|
XtraMessageBox.Show("操作失败!");
|
|
return;
|
|
}
|
|
splashScreenManager1.CloseWaitForm();
|
|
XtraMessageBox.Show("操作成功!");
|
|
DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 校验前置参数是否存在
|
|
/// </summary>
|
|
/// <param name="t_AheadPara"></param>
|
|
/// <returns></returns>
|
|
private bool CheckIsExistAheadPara(T_AheadPara t_AheadPara)
|
|
{
|
|
var model = AheadParaHelper.QueryActiveAheadParas()
|
|
.Where(m => m.IpcId == t_AheadPara.IpcId && m.LineCode == t_AheadPara.LineCode && m.StationCode == Program.ActiveStatinCode)
|
|
.Where(m => m.MachineTypeCode == t_AheadPara.MachineTypeCode && m.LastStationCode == t_AheadPara.LastStationCode && m.PointCode == t_AheadPara.PointCode && m.Category == t_AheadPara.Category)
|
|
.WhereIF(t_AheadPara.Id > 0, m => m.Id != t_AheadPara.Id).First();
|
|
return model != null;
|
|
}
|
|
|
|
#region 窗体移动
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
base.WndProc(ref m);
|
|
if (m.Msg == 0x84)
|
|
{
|
|
switch (m.Result.ToInt32())
|
|
{
|
|
case 1:
|
|
m.Result = new IntPtr(2);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private Point mPoint;
|
|
private void panelControl8_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
mPoint = new Point(e.X, e.Y);
|
|
}
|
|
|
|
private void panelControl8_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|