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 ( ) ;
_ComboBoxLanguageTextList = this . GetInfoLanguageText ( GlobalHelper . LanguageCode , "KryptonComboBox" ) ;
_InfoLanguageTextList = this . GetInfoLanguageText ( GlobalHelper . LanguageCode ) ;
}
private DataTable _ComboBoxLanguageTextList ;
private DataTable _InfoLanguageTextList ;
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 ( ) ;
this . SetFormControlText ( GlobalHelper . LanguageCode ) ;
if ( GlobalHelper . LanguageCode = = "English" )
{
kcmb_WarningType . Items . Clear ( ) ;
foreach ( DataRow item in _ComboBoxLanguageTextList . GetComBoboxItemArr ( kcmb_WarningType . Name , "KryptonComboBox" ) )
{
kcmb_WarningType . Items . Add ( item [ "CONTROL_NAME" ] . ToString ( ) ) ;
}
}
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 )
{
KryptonMessageBox . Show ( _InfoLanguageTextList . GetInfoText ( "编辑基础报警数据界面加载异常" , "LoadEditFrmExp" ) + $":【{ex.Message}】!" ) ;
}
}
private void btnAdd_Click ( object sender , EventArgs e )
{
try
{
if ( string . IsNullOrEmpty ( txtWarningCode . Text ) )
{
//KryptonMessageBox.Show("请输入报警条码!");
KryptonMessageBox . Show ( _InfoLanguageTextList . GetInfoText ( "请输入报警条码!" , "EnterWarningCodeInfo" ) ) ;
return ;
}
if ( string . IsNullOrEmpty ( txtWarningName . Text ) )
{
//KryptonMessageBox.Show("请输入报警名称!");
KryptonMessageBox . Show ( _InfoLanguageTextList . GetInfoText ( "请输入报警名称!" , "EnterWarningNameInfo" ) ) ;
return ;
}
if ( kcmb_WarningType . SelectedIndex = = 0 )
{
//KryptonMessageBox.Show("请选择报警类型!");
KryptonMessageBox . Show ( _InfoLanguageTextList . GetInfoText ( "请选择报警类型!" , "SelectWarningTypeInfo" ) ) ;
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("修改基础报警数据成功!");
KryptonMessageBox . Show ( _InfoLanguageTextList . 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("修改基础报警数据失败!");
KryptonMessageBox . Show ( _InfoLanguageTextList . GetInfoText ( "修改基础报警数据失败!" , "EditFailInfo" ) ) ;
}
}
catch ( Exception ex )
{
KryptonMessageBox . Show ( _InfoLanguageTextList . GetInfoText ( "编辑基础报警数据发生异常" , "EditWarningDataExp" ) + $":【{ex.Message}】!" ) ;
}
}
private void btnEdit_Click ( object sender , EventArgs e )
{
this . Close ( ) ;
}
}
}