Files
CleanMachine/CleanMachineHMI/frmChild/frmAddUser.cs

209 lines
8.1 KiB
C#
Raw Normal View History

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 frmAddUser : KryptonForm
{
public frmAddUser()
{
InitializeComponent();
}
2022-03-18 21:25:34 +08:00
2021-06-05 14:17:30 +08:00
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();
2022-03-18 19:06:26 +08:00
this.SetFormControlText();
2022-03-18 21:25:34 +08:00
2021-06-05 14:17:30 +08:00
{
cmbGender.Items.Clear();
2022-03-19 16:14:32 +08:00
foreach (string item in this.GetComBoboxItemArr(cmbGender.Name))
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 sql = $"SELECT ROLE_ID,ROLE_CODE,ROLE_NAME FROM SYS_ROLE ";
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
2021-12-31 19:53:53 +08:00
kcmb_Role.DisplayMember = "Text";
kcmb_Role.DisplayMember = "Text";
2021-06-05 14:17:30 +08:00
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))
{
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 (kcmb_Role.SelectedIndex == 0)
{
//KryptonMessageBox.Show("请选择所属角色!");
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("请选择所属角色!", "SelectUserRoleInfo"));
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;
}
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,
2022-05-06 12:28:16 +08:00
'{Global.UserInfo.UserId}',
2021-06-05 14:17:30 +08:00
datetime('now', 'localtime'),
2022-05-06 12:28:16 +08:00
'{Global.UserInfo.UserId}',
2021-06-05 14:17:30 +08:00
datetime('now', 'localtime'),
0,
NULL,
NULL,
NULL,
NULL,
NULL
);
";
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("新增用户数据成功!", "AddSuccessInfo"));
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("新增用户数据失败!", "AddFailInfo"));
2021-06-05 14:17:30 +08:00
}
}
catch (Exception ex)
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox.Show(this.T("新增用户数据发生异常", "AddUserDataExp") + $":【{ex.Message}】!");
2021-06-05 14:17:30 +08:00
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}