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 frmAddRole : KryptonForm { public frmAddRole() { InitializeComponent(); } private void txt_GotFocus(object sender, EventArgs e) { KeyboardAutoPopUp.ShowInputPanel(); } private void txt_LostFocus(object sender, EventArgs e) { KeyboardAutoPopUp.HideInputPanel(); } private void InitControlEvent() { txtRoleCode.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件 txtRoleCode.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件 txtRoleName.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件 txtRoleName.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件 } private void frmAddRole_Load(object sender, EventArgs e) { InitControlEvent(); this.SetFormControlText(); { kcmb_roleGrade.Items.Clear(); foreach (string item in this.GetComBoboxItemArr(kcmb_roleGrade.Name)) { kcmb_roleGrade.Items.Add(item); } } kcmb_roleGrade.SelectedIndex = 0; kryptonPanel1.Focus(); } private void btnAdd_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtRoleCode.Text)) { KryptonMessageBox.Show(this.T("请输入角色编码!", "EnterRoleCodeInfo")); return; } if (string.IsNullOrEmpty(txtRoleName.Text)) { KryptonMessageBox.Show(this.T("请输入角色名称!", "EnterRoleNameInfo")); return; } int roleGrade = 0; if (kcmb_roleGrade.SelectedIndex == 0) { KryptonMessageBox.Show(this.T("请选择角色级别!", "SelectRoleGradeInfo")); return; } else if (kcmb_roleGrade.SelectedIndex == 1) { string sqlIsExistAdmin = $@"SELECT 1 FROM SYS_ROLE WHERE ROLE_GRADE = '100'"; DataTable dtIsExistAdmin = LeadDbHelperSQLite.Query(sqlIsExistAdmin).Tables[0]; if (dtIsExistAdmin != null && dtIsExistAdmin.Rows.Count > 0) { KryptonMessageBox.Show(this.T("管理员角色只能存在一个,请重新选择!", "AdminOnlyInfo")); return; } roleGrade = 100; } else { roleGrade = 1; } string sqlIsExistCode = $@"SELECT 1 FROM SYS_ROLE WHERE ROLE_CODE = '{txtRoleCode.Text}'"; DataTable dtIsExistCode = LeadDbHelperSQLite.Query(sqlIsExistCode).Tables[0]; if (dtIsExistCode != null && dtIsExistCode.Rows.Count > 0) { //KryptonMessageBox.Show($"角色名:【{txtRoleCode.Text}】已经存在,请重新输入!"); KryptonMessageBox.Show($"Role name 【{txtRoleCode.Text}】already exist, please re-enter!"); return; } string sql = $@" INSERT INTO main.SYS_ROLE ( ROLE_CODE, ROLE_NAME, ROLE_GRADE, USED_FLAG, DEL_FLAG, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, DATA_VERSION, REMARKS1, REMARKS2, REMARKS3, REMARKS4, REMARKS5 ) VALUES ( '{txtRoleCode.Text}', '{txtRoleName.Text}', '{roleGrade}', 1, 0, '{Global.UserInfo.UserId}', datetime('now', 'localtime'), '{Global.UserInfo.UserId}', datetime('now', 'localtime'), 0, NULL, NULL, NULL, NULL, NULL ); "; int row = LeadDbHelperSQLite.ExecuteSql(sql); if (row > 0) { KryptonMessageBox.Show(this.T("新增角色数据成功!", "AddSuccessInfo")); frmRole.RefreshFrmHost(); this.Close(); } else { KryptonMessageBox.Show(this.T("新增角色数据失败!", "AddFailInfo")); } } catch (Exception ex) { KryptonMessageBox.Show(this.T("新增角色数据发生异常", "AddRoleDataExp") + $":【{ex.Message}】!"); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } }