Files
CleanMachine/CleanMachineHMI/frmChild/frmAddWaringMsg.cs

161 lines
6.8 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 frmAddWaringMsg : KryptonForm
{
public frmAddWaringMsg()
{
InitializeComponent();
}
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 frmAddWaringMsg_Load(object sender, EventArgs e)
{
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-19 16:14:32 +08:00
foreach (string item in this.GetComBoboxItemArr(kcmb_WarningType.Name))
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;
kryptonPanel1.Focus();
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtWarningCode.Text))
{
//KryptonMessageBox.Show("请输入报警条码!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("请输入报警条码!", "EnterWarningCodeInfo"));
2021-06-05 14:17:30 +08:00
return;
}
if (string.IsNullOrEmpty(txtWarningName.Text))
{
//KryptonMessageBox.Show("请输入报警名称!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("请输入报警名称!", "EnterWarningNameInfo"));
2021-06-05 14:17:30 +08:00
return;
}
if (kcmb_WarningType.SelectedIndex == 0)
{
//KryptonMessageBox.Show("请选择报警类型!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("请选择报警类型!", "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;
}
string sql = $@"
INSERT INTO BAS_WARNING (
WARNING_CODE,
WARNING_NAME,
2022-01-16 15:35:09 +08:00
PLC_ITEM_CODE,wq
2021-06-05 14:17:30 +08:00
WARNING_TYPE,
WARNING_MESSAGE,
USED_FLAG,
DEL_FLAG,
CREATE_BY,
CREATE_TIME,
UPDATE_BY,
UPDATE_TIME,
DATA_VERSION,
REMARKS1,
REMARKS2,
REMARKS3,
REMARKS4,
REMARKS5
)
VALUES
(
'{txtWarningCode.Text}',
'{txtWarningName.Text}',
'{ktb_PlcCode.Text}',
'{kcmb_WarningType.SelectedIndex}',
'{txtWarningMessage.Text}',
1,
0,
2022-05-06 12:28:16 +08:00
'{Global.UserInfo.UserId}',
2021-06-05 14:17:30 +08:00
datetime('now', 'localtime'),
2022-05-06 12:28:16 +08:00
'{Global.UserInfo.UserId}',
2021-06-05 14:17:30 +08:00
datetime('now', 'localtime'),
0,
NULL,
NULL,
NULL,
NULL,
NULL
);
";
2022-05-16 09:03:42 +08:00
int row = LeadDbHelperSQLite.Execute(sql);
2021-06-05 14:17:30 +08:00
if (row > 0)
{
//KryptonMessageBox.Show("新增基础报警数据成功!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("新增基础报警数据成功!", "AddSuccessInfo"));
2022-01-13 11:03:20 +08:00
// frmWarning.RefreshFrmHost();
2021-06-05 14:17:30 +08:00
this.Close();
}
else
{
//KryptonMessageBox.Show("新增基础报警数据失败!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("新增基础报警数据失败!", "AddFailInfo"));
2021-06-05 14:17:30 +08:00
}
}
catch (Exception ex)
{
//KryptonMessageBox.Show(ex.Message);
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("新增基础报警数据发生异常", "AddWarningDataExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}