using CleanMachineHMI.forms; using CleanMachineHMI.FrmUserControl; using CleanMachineHMI.Utils; using Krypton.Toolkit; 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 frmAddUser : KryptonForm { public frmAddUser() { InitializeComponent(); } 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 frmAddUser_Load(object sender, EventArgs e) { InitControlEvent(); this.SetFormControlText(); { cmbGender.Items.Clear(); foreach (string item in this.GetComBoboxItemArr(cmbGender.Name, "KryptonComboBox")) { cmbGender.Items.Add(item); } } string sql = $"SELECT ROLE_ID,ROLE_CODE,ROLE_NAME FROM SYS_ROLE "; DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; kcmb_Role.DisplayMember = "Text"; kcmb_Role.DisplayMember = "Text"; if (dt != null && dt.Rows.Count > 0) { kcmb_Role.Items.Clear(); kcmb_Role.Items.Add(new ListItem { Value = "0", Text = "Please Select", }); foreach (DataRow item in dt.Rows) { kcmb_Role.Items.Add(new ListItem { Value = item["ROLE_ID"].ToString(), Text = item["ROLE_CODE"].ToString(), }); } } kcmb_Role.SelectedIndex = 0; cmbGender.SelectedIndex = 0; kryptonPanel1.Focus(); } private void btnAdd_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtAccount.Text)) { KryptonMessageBox.Show(this.GetInfoText("请输入用户编码!", "EnterUserCodeInfo")); return; } if (string.IsNullOrEmpty(txtName.Text)) { KryptonMessageBox.Show(this.GetInfoText("请输入用户名称!", "EnterUserNameInfo")); return; } if (string.IsNullOrEmpty(txtPS.Text)) { //KryptonMessageBox.Show("请输入用户密码!"); KryptonMessageBox.Show(this.GetInfoText("请输入用户密码!", "EnterUserPasswordInfo")); return; } if (string.IsNullOrEmpty(txtPS1.Text)) { //KryptonMessageBox.Show("请确认用户密码!"); KryptonMessageBox.Show(this.GetInfoText("请确认用户密码!", "ConfirmUserPasswordInfo")); return; } if (cmbGender.SelectedIndex == 0) { //KryptonMessageBox.Show("请选择性别!"); KryptonMessageBox.Show(this.GetInfoText("请选择性别!", "SelectUserGenderInfo")); return; } if (kcmb_Role.SelectedIndex == 0) { //KryptonMessageBox.Show("请选择所属角色!"); KryptonMessageBox.Show(this.GetInfoText("请选择所属角色!", "SelectUserRoleInfo")); return; } if (txtPS1.Text != txtPS.Text) { //KryptonMessageBox.Show("两次输入的密码不同,请重新输入!"); KryptonMessageBox.Show(this.GetInfoText("两次输入的密码不同,请重新输入!", "ConfirmUserPasswordErrInfo")); return; } string sqlIsExistCode = $@"SELECT 1 FROM SYS_USER WHERE USER_CODE = '{txtAccount.Text}'"; DataTable dtIsExistCode = LeadDbHelperSQLite.Query(sqlIsExistCode).Tables[0]; if (dtIsExistCode != null && dtIsExistCode.Rows.Count > 0) { //KryptonMessageBox.Show($"用户名:【{txtAccount.Text}】已经存在,请重新输入!"); KryptonMessageBox.Show($"User name 【{txtAccount.Text}】already exist, please re-enter!"); return; } string sql = $@" INSERT INTO SYS_USER ( USER_CODE, USER_NAME, PASSWORD, GENDER, SCHEDULE_CODE, ROLE_ID, USED_FLAG, DEL_FLAG, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, DATA_VERSION, REMARKS1, REMARKS2, REMARKS3, REMARKS4, REMARKS5 ) VALUES ( '{txtAccount.Text}', '{txtName.Text}', '{txtPS1.Text}', '{cmbGender.SelectedIndex}', '1', '{((ListItem)kcmb_Role.SelectedItem).Value}', 1, 0, '{GlobalHelper.UserInfo.UserId}', datetime('now', 'localtime'), '{GlobalHelper.UserInfo.UserId}', datetime('now', 'localtime'), 0, NULL, NULL, NULL, NULL, NULL ); "; int row = LeadDbHelperSQLite.ExecuteSql(sql); if (row > 0) { //KryptonMessageBox.Show("新增用户数据成功!"); KryptonMessageBox.Show(this.GetInfoText("新增用户数据成功!", "AddSuccessInfo")); frmUser.RefreshFrmHost(); this.Close(); } else { //KryptonMessageBox.Show("新增用户数据失败!"); KryptonMessageBox.Show(this.GetInfoText("新增用户数据失败!", "AddFailInfo")); } } catch (Exception ex) { KryptonMessageBox.Show(this.GetInfoText("新增用户数据发生异常", "AddUserDataExp") + $":【{ex.Message}】!"); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } }