添加项目文件。
This commit is contained in:
166
CleanMachineHMI/frmChild/frmAddRole.cs
Normal file
166
CleanMachineHMI/frmChild/frmAddRole.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using CleanMachineHMI.forms;
|
||||
using CleanMachineHMI.FrmUserControl;
|
||||
using CleanMachineHMI.Utils;
|
||||
using ComponentFactory.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();
|
||||
_ComboBoxLanguageTextList = this.GetInfoLanguageText(GlobalHelper.LanguageCode, "KryptonComboBox");
|
||||
_InfoLanguageTextList = this.GetInfoLanguageText(GlobalHelper.LanguageCode);
|
||||
}
|
||||
private DataTable _ComboBoxLanguageTextList;
|
||||
private DataTable _InfoLanguageTextList;
|
||||
|
||||
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(GlobalHelper.LanguageCode);
|
||||
if (GlobalHelper.LanguageCode == "English")
|
||||
{
|
||||
kcmb_roleGrade.Items.Clear();
|
||||
foreach (DataRow item in _ComboBoxLanguageTextList.GetComBoboxItemArr(kcmb_roleGrade.Name, "KryptonComboBox"))
|
||||
{
|
||||
kcmb_roleGrade.Items.Add(item["CONTROL_NAME"].ToString());
|
||||
}
|
||||
}
|
||||
kcmb_roleGrade.SelectedIndex = 0;
|
||||
kryptonPanel1.Focus();
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(txtRoleCode.Text))
|
||||
{
|
||||
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请输入角色编码!", "EnterRoleCodeInfo"));
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(txtRoleName.Text))
|
||||
{
|
||||
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请输入角色名称!", "EnterRoleNameInfo"));
|
||||
return;
|
||||
}
|
||||
int roleGrade = 0;
|
||||
if (kcmb_roleGrade.SelectedIndex == 0)
|
||||
{
|
||||
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请选择角色级别!", "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(_InfoLanguageTextList.GetInfoText("管理员角色只能存在一个,请重新选择!", "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,
|
||||
'{GlobalHelper.UserInfo.USER_ID}',
|
||||
datetime('now', 'localtime'),
|
||||
'{GlobalHelper.UserInfo.USER_ID}',
|
||||
datetime('now', 'localtime'),
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
";
|
||||
int row = LeadDbHelperSQLite.ExecuteSql(sql);
|
||||
if (row > 0)
|
||||
{
|
||||
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("新增角色数据成功!", "AddSuccessInfo"));
|
||||
frmRole.RefreshFrmHost();
|
||||
this.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("新增角色数据失败!", "AddFailInfo"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("新增角色数据发生异常", "AddRoleDataExp") + $":【{ex.Message}】!");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user