Files
CleanMachine/CleanMachineHMI/frmLogin.cs

138 lines
5.6 KiB
C#
Raw Normal View History

2021-06-05 14:17:30 +08:00
using CleanMachineHMI.Domain.Enums;
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 NX_LogUtility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CleanMachineHMI
{
[FormType(EnumFormType.Login)]
public partial class frmLogin : KryptonForm
{
public frmLogin()
{
InitializeComponent();
2022-03-18 19:06:26 +08:00
this.SetFormControlText();
2021-06-05 14:17:30 +08:00
}
private void Init()
{
//txtAccount.Text = "";
txtPs.Text = "";
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtAccount.Text))
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("请输入登陆账号!", "PleaseInputAccount"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
2021-06-05 14:17:30 +08:00
return;
}
if (string.IsNullOrWhiteSpace(txtPs.Text))
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("请输入登陆密码!", "PleaseInputPassword"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
2021-06-05 14:17:30 +08:00
return;
}
var sql = $@"SELECT A.USER_ID,A.USER_CODE,A.USER_NAME,A.SCHEDULE_CODE,A.USED_FLAG,A.DEL_FLAG,A.PASSWORD,B.ROLE_ID,B.ROLE_GRADE FROM SYS_USER A LEFT JOIN SYS_ROLE B ON A.ROLE_ID = B.ROLE_ID WHERE A.USER_CODE= '{txtAccount.Text}'";
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
if (dt.Rows.Count > 0)
{
var data = dt.Rows[0];
if (data["USED_FLAG"].ToString() == "0")
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("用户已被停用!", "UserStop"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
2021-06-05 14:17:30 +08:00
return;
}
if (data["DEL_FLAG"].ToString() == "1")
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("用户已被删除!", "UserDeleted"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
2021-06-05 14:17:30 +08:00
return;
}
if (data["PASSWORD"].ToString().ToLower() != txtPs.Text.ToLower())
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("输入密码错误!", "PasswordFail"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
2021-06-05 14:17:30 +08:00
return;
}
AppConfigHelper.Update("LastTimeUserCode",txtAccount.Text.Trim());
//登陆成功
Init();
//获取基础配置
sql = "select * from SYS_PARAMETER where used_flag=1 and del_flag=0";
DataTable dtTemp = LeadDbHelperSQLite.Query(sql).Tables[0];
GlobalHelper.ParameterList = dtTemp;
GlobalHelper.UserInfo = new Domain.Models.ViewModels.UserInfo
{
2021-12-31 16:27:14 +08:00
Gender = Convert.ToInt32(data["USED_FLAG"].ToString()),
ScheduleCode = data["SCHEDULE_CODE"] == null ? "" : data["SCHEDULE_CODE"].ToString(),
UserCode = data["USER_CODE"].ToString(),
UserId = Convert.ToInt32(data["USER_ID"].ToString()),
UserName = data["USER_NAME"].ToString(),
RoleId = Convert.ToInt32(data["ROLE_ID"].ToString()),
RoleGrade = Convert.ToInt32(data["ROLE_GRADE"].ToString()),
2021-06-05 14:17:30 +08:00
};
this.Hide();
2021-12-31 16:27:14 +08:00
LogHelper.WriteLog($"用户:【{GlobalHelper.UserInfo.UserName}】登录系统成功!",LogTypeEum.Run);
sql = $@"SELECT A.ROLE_ID,A.ROLE_CODE,A.ROLE_NAME,B.MENU_ID,C.MENU_CODE,C.MENU_NAME,C.MENU_URL,C.MENU_PID FROM SYS_ROLE A LEFT JOIN SYS_ROLE_MENU_PERMISSION B on A.ROLE_ID = B.ROLE_ID LEFT JOIN SYS_MENU C on B.MENU_ID = C.MENU_ID WHERE A.ROLE_ID = '{GlobalHelper.UserInfo.RoleId}'";
2021-06-05 14:17:30 +08:00
GlobalHelper.RoleMenuPermission = LeadDbHelperSQLite.Query(sql).Tables[0];
GlobalHelper.MainFormNew = new frmMainNew();
GlobalHelper.MainFormNew.Show();
}
else
{
2022-03-18 19:06:26 +08:00
KryptonMessageBox.Show(this.GetInfoText("请输入正确的登陆账号!", "PleaseCorrectAccount"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
2021-06-05 14:17:30 +08:00
return;
}
}
private void frmLogin_Load(object sender, EventArgs e)
{
try
{
txtAccount.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
txtAccount.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
txtPs.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
txtPs.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
txtAccount.Text = AppConfigHelper.Get("LastTimeUserCode");
}
catch (Exception ex)
{
KryptonMessageBox.Show(ex.Message);
}
}
private void txt_GotFocus(object sender, EventArgs e)
{
KeyboardAutoPopUp.ShowInputPanel();
}
private void txt_LostFocus(object sender, EventArgs e)
{
KeyboardAutoPopUp.HideInputPanel();
}
}
}