Files
CleanMachine/CleanMachineHMI/FrmUserControl/Base/frmWarning.cs

207 lines
7.8 KiB
C#
Raw Normal View History

2021-06-05 14:17:30 +08:00
using CleanMachineHMI.Domain.Enums;
using CleanMachineHMI.frmChild;
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.FrmUserControl
{
[FormType(EnumFormType.Warning)]
public partial class frmWarning : UserControl
{
public delegate void dlgRefreshFrmHost();
public static dlgRefreshFrmHost RefreshFrmHost;
public frmWarning()
{
InitializeComponent();
}
public void Init()
{
var sql = $@"select WARNING_ID 序号,WARNING_CODE 报警编码,WARNING_NAME 报警名称,PLC_ITEM_CODE 'PLC信息',CASE WARNING_TYPE WHEN '1' THEN 'Cleaning machine alarm' ELSE 'Frequency converter alarm' END '报警类型',WARNING_MESSAGE 报警描述,CREATE_TIME 创建时间 from BAS_WARNING where DEL_FLAG=0";
if (!string.IsNullOrEmpty(ktb_WarningMsg.Text))
{
sql += $" AND (WARNING_CODE like '%{ktb_WarningMsg.Text}%' OR WARNING_NAME like '%{ktb_WarningMsg.Text}%')";
}
if (kcmb_WarningType.SelectedIndex != 0)
{
sql += $" AND WARNING_TYPE = '{kcmb_WarningType.SelectedIndex}'";
}
if (kdtp_CreateStartTime.Checked)
{
sql += $" AND CREATE_TIME >= '{kdtp_CreateStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")}'";
}
if (kdtp_CreateEndTime.Checked)
{
sql += $" AND CREATE_TIME <= '{kdtp_CreateEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss")}'";
}
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
dataGridView.Columns.Clear();
dataGridView.DataSource = dt;
2022-03-19 12:46:23 +08:00
dataGridView.SetDataViewColumnText(this.Name);
2021-06-05 14:17:30 +08:00
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
private void txt_GotFocus(object sender, EventArgs e)
{
KeyboardAutoPopUp.ShowInputPanel();
}
private void txt_LostFocus(object sender, EventArgs e)
{
KeyboardAutoPopUp.HideInputPanel();
}
private void InitControlEvent()
{
ktb_WarningMsg.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
ktb_WarningMsg.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
}
private void frmWarning_Load(object sender, EventArgs e)
{
try
{
InitControlEvent();
2022-03-18 19:06:26 +08:00
this.SetFormControlText();
2021-06-05 14:17:30 +08:00
kdtp_CreateStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
kdtp_CreateEndTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
kdtp_CreateStartTime.Checked = false;
kdtp_CreateEndTime.Checked = false;
var items = this.GetComBoboxItemArr(kcmb_WarningType.Name);
if (items != null && items.Count > 0)
2021-06-05 14:17:30 +08:00
{
kcmb_WarningType.Items.Clear();
foreach (string item in items)
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;
RefreshFrmHost = new dlgRefreshFrmHost(Init);
Init();
foreach (Control item in tableLayoutPanel2.Controls)
{
if (item.Tag == null)
{
2022-05-06 12:28:16 +08:00
item.Enabled = Global.CheckRole(this.Name, item.Name);
2022-05-06 10:36:42 +08:00
//DataRow[] drs = GlobalHelper.RoleMenuPermission.Select($" MENU_URL = '{this.Name}' AND MENU_PID = '-1'");
//DataRow[] drs1 = GlobalHelper.RoleMenuPermission.Select($" MENU_URL = '{item.Name}' AND MENU_PID = '{drs[0]["MENU_ID"]}'");
//if (drs1.Length > 0)
//{
// item.Enabled = true;
//}
//else
//{
// item.Enabled = false;
//}
2021-06-05 14:17:30 +08:00
}
}
kryptonGroupBox2.Focus();
}
catch (Exception ex)
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("加载报警信息界面发生异常", "LoadWarningMsgExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
private void kbt_Query_Click(object sender, EventArgs e)
{
try
{
Init();
}
catch (Exception ex)
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("查询报警信息数据发生异常", "QueryWarningMsgDataExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
private void kbt_Reset_Click(object sender, EventArgs e)
{
ktb_WarningMsg.Text = "";
kcmb_WarningType.SelectedIndex = 0;
kdtp_CreateStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
kdtp_CreateEndTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
kdtp_CreateStartTime.Checked = false;
kdtp_CreateEndTime.Checked = false;
}
private void kbt_Add_Click(object sender, EventArgs e)
{
frmAddWaringMsg frm = new frmAddWaringMsg();
frm.ShowDialog();
}
private void kbt_Edit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
frmEditWaringMsg frm = new frmEditWaringMsg();
frm.WarningId = dataGridView.SelectedRows[0].Cells[0].Value.ToString();
frm.ShowDialog();
}
else
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("请选择要编辑的报警信息数据行!", "SelectWantToEditRow"));
2021-06-05 14:17:30 +08:00
}
}
private void kbt_Delete_Click(object sender, EventArgs e)
{
try
{
if (dataGridView.SelectedRows.Count > 0)
{
2022-05-06 08:45:56 +08:00
DialogResult dr = KryptonMessageBox.Show(this.T("确定要删除所选的报警信息吗?", "DeleteInfo"), "Prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
2021-06-05 14:17:30 +08:00
if (dr == DialogResult.OK)
{
string WarningId = dataGridView.SelectedRows[0].Cells[0].Value.ToString();
string sql = $@"DELETE FROM BAS_WARNING WHERE WARNING_ID = '{WarningId}'";
2022-05-16 09:03:42 +08:00
int row = LeadDbHelperSQLite.Execute(sql);
2021-06-05 14:17:30 +08:00
if (row > 0)
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("删除报警数据成功!", "DeleteSuccessInfo"));
2021-06-05 14:17:30 +08:00
RefreshFrmHost();
}
else
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("删除报警数据失败!", "DeleteFailInfo"));
2021-06-05 14:17:30 +08:00
}
}
}
else
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("请选择要删除的报警数据行!", "SelectWantToDeleteRow"));
2021-06-05 14:17:30 +08:00
}
}
catch (Exception ex)
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("删除报警信息数据发生异常", "DeleteWarningMsgDataExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
}
}