Files
CleanMachine/CleanMachineHMI/frmChild/frmEditWaringMsg.cs

139 lines
6.5 KiB
C#
Raw Normal View History

2021-06-05 14:17:30 +08:00
using CleanMachineHMI.forms;
using CleanMachineHMI.FrmUserControl;
using CleanMachineHMI.Utils;
2021-12-26 21:30:02 +08:00
using Krypton.Toolkit;
2021-06-05 14:17:30 +08:00
using LeadDataBaseUtility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CleanMachineHMI.frmChild
{
public partial class frmEditWaringMsg : KryptonForm
{
public frmEditWaringMsg()
{
InitializeComponent();
}
public string WarningId { get; set; }
private void txt_GotFocus(object sender, EventArgs e)
{
KeyboardAutoPopUp.ShowInputPanel();
}
private void txt_LostFocus(object sender, EventArgs e)
{
KeyboardAutoPopUp.HideInputPanel();
}
private void InitControlEvent()
{
txtWarningCode.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
txtWarningCode.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
txtWarningName.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
txtWarningName.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
txtWarningMessage.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
txtWarningMessage.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
ktb_PlcCode.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
ktb_PlcCode.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
}
private void frmEditWaringMsg_Load(object sender, EventArgs e)
{
try
{
InitControlEvent();
2022-03-18 19:06:26 +08:00
this.SetFormControlText();
2022-03-18 21:25:34 +08:00
2021-06-05 14:17:30 +08:00
{
kcmb_WarningType.Items.Clear();
2022-03-18 21:25:34 +08:00
foreach (string item in this.GetComBoboxItemArr(kcmb_WarningType.Name, "KryptonComboBox"))
2021-06-05 14:17:30 +08:00
{
2022-03-18 21:25:34 +08:00
kcmb_WarningType.Items.Add(item);
2021-06-05 14:17:30 +08:00
}
}
kcmb_WarningType.SelectedIndex = 0;
string sql1 = $@"select WARNING_ID,WARNING_CODE,WARNING_NAME,PLC_ITEM_CODE,WARNING_TYPE,WARNING_MESSAGE,CREATE_TIME from BAS_WARNING where WARNING_ID = '{WarningId}'";
DataTable dt1 = LeadDbHelperSQLite.Query(sql1).Tables[0];
if (dt1 != null && dt1.Rows.Count > 0)
{
txtWarningCode.Text = dt1.Rows[0]["WARNING_CODE"].ToString();
txtWarningCode.Enabled = false;
txtWarningName.Text = dt1.Rows[0]["WARNING_NAME"].ToString();
txtWarningMessage.Text = dt1.Rows[0]["WARNING_MESSAGE"].ToString();
ktb_PlcCode.Text = dt1.Rows[0]["PLC_ITEM_CODE"].ToString();
kcmb_WarningType.SelectedIndex = Convert.ToInt32(dt1.Rows[0]["WARNING_TYPE"]);
}
kryptonPanel1.Focus();
}
catch (Exception ex)
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("编辑基础报警数据界面加载异常", "LoadEditFrmExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtWarningCode.Text))
{
//KryptonMessageBox.Show("请输入报警条码!");
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("请输入报警条码!", "EnterWarningCodeInfo"));
2021-06-05 14:17:30 +08:00
return;
}
if (string.IsNullOrEmpty(txtWarningName.Text))
{
//KryptonMessageBox.Show("请输入报警名称!");
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("请输入报警名称!", "EnterWarningNameInfo"));
2021-06-05 14:17:30 +08:00
return;
}
if (kcmb_WarningType.SelectedIndex == 0)
{
//KryptonMessageBox.Show("请选择报警类型!");
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("请选择报警类型!", "SelectWarningTypeInfo"));
2021-06-05 14:17:30 +08:00
return;
}
string sqlIsExistCode = $@"SELECT 1 FROM BAS_WARNING WHERE WARNING_TYPE = '{kcmb_WarningType.SelectedIndex}' AND PLC_ITEM_CODE = '{ktb_PlcCode.Text}' AND WARNING_CODE = '{txtWarningCode.Text}'";
DataTable dtIsExistCode = LeadDbHelperSQLite.Query(sqlIsExistCode).Tables[0];
if (dtIsExistCode != null && dtIsExistCode.Rows.Count > 0)
{
//KryptonMessageBox.Show($"相同报警类型;【{kcmb_WarningType.Text}】,PLC条码:【{ktb_PlcCode.Text}】下的报警编码:【{txtWarningCode.Text}】已经存在,请重新输入!");
KryptonMessageBox.Show($"Same alarm type: [{kcmb_WarningType.Text}],PLC item code: [{ktb_PlcCode.Text}] alarm code: [{txtWarningCode.Text}] already exists, please re-enter!");
return;
}
2021-12-31 16:27:14 +08:00
string sql = $@"update BAS_WARNING set WARNING_NAME = '{txtWarningName.Text}',WARNING_MESSAGE = '{txtWarningMessage.Text}',PLC_ITEM_CODE = '{ktb_PlcCode.Text}',WARNING_TYPE = '{kcmb_WarningType.SelectedIndex}',UPDATE_BY = '{GlobalHelper.UserInfo.UserId}',UPDATE_TIME = datetime('now', 'localtime') where WARNING_ID = '{WarningId}'";
2021-06-05 14:17:30 +08:00
int row = LeadDbHelperSQLite.ExecuteSql(sql);
if (row > 0)
{
//KryptonMessageBox.Show("修改基础报警数据成功!");
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("修改基础报警数据成功!", "EditSuccessInfo"));
2022-01-13 11:03:20 +08:00
//frmWarning.RefreshFrmHost();
2021-06-05 14:17:30 +08:00
this.Close();
}
else
{
//KryptonMessageBox.Show("修改基础报警数据失败!");
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("修改基础报警数据失败!", "EditFailInfo"));
2021-06-05 14:17:30 +08:00
}
}
catch (Exception ex)
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("编辑基础报警数据发生异常", "EditWarningDataExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}