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 ;
2021-12-27 09:51:57 +08:00
2021-06-05 14:17:30 +08:00
using System.Windows.Forms ;
namespace CleanMachineHMI.frmChild
{
public partial class frmEditUser : KryptonForm
{
public frmEditUser ( )
{
InitializeComponent ( ) ;
}
public string UserId { 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 ( )
{
txtAccount . GotFocus + = new EventHandler ( txt_GotFocus ) ; //获取焦点前发生事件
txtAccount . LostFocus + = new EventHandler ( txt_LostFocus ) ; //失去焦点后发生事件
txtName . GotFocus + = new EventHandler ( txt_GotFocus ) ; //获取焦点前发生事件
txtName . LostFocus + = new EventHandler ( txt_LostFocus ) ; //失去焦点后发生事件
txtPS . GotFocus + = new EventHandler ( txt_GotFocus ) ; //获取焦点前发生事件
txtPS . LostFocus + = new EventHandler ( txt_LostFocus ) ; //失去焦点后发生事件
txtPS1 . GotFocus + = new EventHandler ( txt_GotFocus ) ; //获取焦点前发生事件
txtPS1 . LostFocus + = new EventHandler ( txt_LostFocus ) ; //失去焦点后发生事件
}
private void frmEditUser_Load ( object sender , EventArgs e )
{
try
{
InitControlEvent ( ) ;
2022-03-18 19:06:26 +08:00
this . SetFormControlText ( ) ;
2022-05-17 11:19:58 +08:00
var items = this . GetComBoboxItemArr ( cmbGender . Name ) ;
if ( items ! = null & & items . Count > 0 )
2021-06-05 14:17:30 +08:00
{
cmbGender . Items . Clear ( ) ;
2022-05-17 11:19:58 +08:00
foreach ( string item in items )
2021-06-05 14:17:30 +08:00
{
2022-03-18 21:25:34 +08:00
cmbGender . Items . Add ( item ) ;
2021-06-05 14:17:30 +08:00
}
}
string sql1 = $"SELECT ROLE_ID,ROLE_CODE,ROLE_NAME FROM SYS_ROLE " ;
DataTable dt1 = LeadDbHelperSQLite . Query ( sql1 ) . Tables [ 0 ] ;
if ( dt1 ! = null & & dt1 . Rows . Count > 0 )
{
kcmb_Role . Items . Clear ( ) ;
foreach ( DataRow item in dt1 . Rows )
{
kcmb_Role . Items . Add ( new ListItem
{
Value = item [ "ROLE_ID" ] . ToString ( ) ,
Text = item [ "ROLE_CODE" ] . ToString ( ) ,
} ) ;
}
}
cmbGender . SelectedIndex = 0 ;
string sql = $@"SELECT A.USER_ID,A.USER_CODE,A.USER_NAME,A.GENDER,A.ROLE_ID,B.ROLE_CODE,B.ROLE_NAME,A.PASSWORD FROM SYS_USER A LEFT JOIN SYS_ROLE B on A.ROLE_ID = B.ROLE_ID WHERE A.USER_ID = '{UserId}'" ;
DataTable dt = LeadDbHelperSQLite . Query ( sql ) . Tables [ 0 ] ;
if ( dt ! = null & & dt . Rows . Count > 0 )
{
txtAccount . Text = dt . Rows [ 0 ] [ "USER_CODE" ] . ToString ( ) ;
txtAccount . Enabled = false ;
txtName . Text = dt . Rows [ 0 ] [ "USER_NAME" ] . ToString ( ) ;
txtPS . Text = dt . Rows [ 0 ] [ "PASSWORD" ] . ToString ( ) ;
txtPS1 . Text = dt . Rows [ 0 ] [ "PASSWORD" ] . ToString ( ) ;
cmbGender . SelectedIndex = Convert . ToInt32 ( dt . Rows [ 0 ] [ "GENDER" ] ) ;
kcmb_Role . Text = dt . Rows [ 0 ] [ "ROLE_CODE" ] . ToString ( ) ;
}
kryptonPanel1 . Focus ( ) ;
}
catch ( Exception ex )
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "编辑用户数据界面加载异常" , "LoadEditFrmExp" ) + $":【{ex.Message}】!" ) ;
2021-06-05 14:17:30 +08:00
}
}
private void btnAdd_Click ( object sender , EventArgs e )
{
try
{
if ( string . IsNullOrEmpty ( txtAccount . Text ) )
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请输入用户编码!" , "EnterUserCodeInfo" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
if ( string . IsNullOrEmpty ( txtName . Text ) )
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请输入用户名称!" , "EnterUserNameInfo" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
if ( string . IsNullOrEmpty ( txtPS . Text ) )
{
//KryptonMessageBox.Show("请输入用户密码!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请输入用户密码!" , "EnterUserPasswordInfo" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
if ( string . IsNullOrEmpty ( txtPS1 . Text ) )
{
//KryptonMessageBox.Show("请确认用户密码!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请确认用户密码!" , "ConfirmUserPasswordInfo" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
if ( cmbGender . SelectedIndex = = 0 )
{
//KryptonMessageBox.Show("请选择性别!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请选择性别!" , "SelectUserGenderInfo" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
if ( txtPS1 . Text ! = txtPS . Text )
{
//KryptonMessageBox.Show("两次输入的密码不同,请重新输入!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "两次输入的密码不同,请重新输入!" , "ConfirmUserPasswordErrInfo" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
2022-05-06 12:28:16 +08:00
string sql = $@"update SYS_USER set USER_CODE = '{txtAccount.Text}',USER_NAME = '{txtName.Text}',PASSWORD = '{txtPS1.Text}',GENDER = '{cmbGender.SelectedIndex}',ROLE_ID = '{((ListItem)kcmb_Role.SelectedItem).Value}',UPDATE_BY = '{Global.UserInfo.UserId}',UPDATE_TIME = datetime('now', 'localtime') where USER_ID = '{UserId}'" ;
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 ( "修改用户数据成功!" , "EditSuccessInfo" ) ) ;
2021-06-05 14:17:30 +08:00
frmUser . RefreshFrmHost ( ) ;
this . Close ( ) ;
}
else
{
//KryptonMessageBox.Show("修改用户数据失败!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "修改用户数据失败!" , "EditFailInfo" ) ) ;
2021-06-05 14:17:30 +08:00
}
}
catch ( Exception ex )
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "编辑用户数据发生异常" , "EditUserDataExp" ) + $":【{ex.Message}】!" ) ;
2021-06-05 14:17:30 +08:00
}
}
private void btnClose_Click ( object sender , EventArgs e )
{
this . Close ( ) ;
}
}
}