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
}
2022-05-06 10:36:42 +08:00
2021-06-05 14:17:30 +08:00
private void btnExit_Click ( object sender , EventArgs e )
{
2022-05-28 14:29:19 +08:00
2021-06-05 14:17:30 +08:00
Application . Exit ( ) ;
}
private void btnLogin_Click ( object sender , EventArgs e )
{
if ( string . IsNullOrWhiteSpace ( txtAccount . Text ) )
{
2022-05-06 10:36:42 +08:00
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请输入登陆账号!" , "PleaseInputAccount" ) , "Information" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2021-06-05 14:17:30 +08:00
return ;
}
if ( string . IsNullOrWhiteSpace ( txtPs . Text ) )
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请输入登陆密码!" , "PleaseInputPassword" ) , "Information" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2021-06-05 14:17:30 +08:00
return ;
}
2022-05-06 10:36:42 +08:00
//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];
var _user = new CleanMachine . BLL . SYS . UserBLL ( ) . GetModel ( txtAccount . Text ) ;
if ( _user ! = null )
2021-06-05 14:17:30 +08:00
{
2022-05-06 10:36:42 +08:00
if ( _user . UsedFlag = = 0 | | _user . DelFlag = = 1 )
2021-06-05 14:17:30 +08:00
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "用户已被停用!" , "UserStop" ) , "Information" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2021-06-05 14:17:30 +08:00
return ;
}
2022-05-28 14:29:19 +08:00
if ( _user . Password . ToLower ( ) ! = txtPs . Text . ToLower ( ) )
2021-06-05 14:17:30 +08:00
{
2022-05-06 10:36:42 +08:00
KryptonMessageBox . Show ( this . T ( "输入密码错误!" , "PasswordFail" ) ) ;
2021-06-05 14:17:30 +08:00
return ;
}
2022-05-06 10:36:42 +08:00
txtPs . Text = "" ;
2021-06-05 14:17:30 +08:00
2022-05-06 12:28:16 +08:00
Global . UserInfo = new Domain . Models . ViewModels . UserInfo
2021-06-05 14:17:30 +08:00
{
2022-05-06 10:36:42 +08:00
Gender = _user . Gender ,
ScheduleCode = _user . ScheduleCode ,
UserCode = _user . UserCode ,
UserId = _user . UserId ,
UserName = _user . UserName ,
RoleId = _user . RoleId ,
RoleGrade = _user . RoleGrade ,
2021-06-05 14:17:30 +08:00
} ;
2022-05-06 10:36:42 +08:00
//获取基础配置
//var sql = "select * from SYS_PARAMETER where used_flag=1 and del_flag=0";
//DataTable dtTemp = LeadDbHelperSQLite.Query(sql).Tables[0];
//GlobalHelper.ParameterList = dtTemp;
2022-05-06 12:28:16 +08:00
Global . ParameterList = new CleanMachine . BLL . SYS . ParameterBLL ( ) . GetList ( "" ) . ToList ( ) ;
2022-05-06 10:36:42 +08:00
//
2021-06-05 14:17:30 +08:00
this . Hide ( ) ;
2022-05-06 12:28:16 +08:00
LogHelper . WriteLog ( $"用户:【{Global.UserInfo.UserName}】登录系统成功!" , LogTypeEum . Run ) ;
2022-05-06 10:36:42 +08:00
// var 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
2022-05-06 10:36:42 +08:00
// GlobalHelper.RoleMenuPermission = LeadDbHelperSQLite.Query(sql).Tables[0];
2022-05-06 12:28:16 +08:00
Global . RoleMenuPermission = new CleanMachine . BLL . SYS . RoleMenuPermissionBLL ( ) . GetList ( _user . RoleId ) . ToList ( ) ;
2022-05-19 13:16:37 +08:00
if ( Global . MainFormNew = = null )
{
Global . MainFormNew = new frmMainNew ( ) ;
2022-05-28 14:29:19 +08:00
2022-05-19 13:16:37 +08:00
}
2022-05-06 12:28:16 +08:00
Global . MainFormNew . Show ( ) ;
2021-06-05 14:17:30 +08:00
}
else
{
2022-05-06 08:45:56 +08:00
KryptonMessageBox . Show ( this . T ( "请输入正确的登陆账号!" , "PleaseCorrectAccount" ) , "Information" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2021-06-05 14:17:30 +08:00
return ;
}
2022-05-06 10:36:42 +08:00
//if (dt.Rows.Count > 0)
//{
// var data = dt.Rows[0];
// if (data["USED_FLAG"].ToString() == "0")
// {
// KryptonMessageBox.Show(this.T("用户已被停用!", "UserStop"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
// }
// if (data["DEL_FLAG"].ToString() == "1")
// {
// KryptonMessageBox.Show(this.T("用户已被删除!", "UserDeleted"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
// }
// if (data["PASSWORD"].ToString().ToLower() != txtPs.Text.ToLower())
// {
// KryptonMessageBox.Show(this.T("输入密码错误!", "PasswordFail"));
// 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
// {
// 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()),
// };
// this.Hide();
// 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}'";
// GlobalHelper.RoleMenuPermission = LeadDbHelperSQLite.Query(sql).Tables[0];
// GlobalHelper.MainFormNew = new frmMainNew();
// GlobalHelper.MainFormNew.Show();
//}
//else
//{
// KryptonMessageBox.Show(this.T("请输入正确的登陆账号!", "PleaseCorrectAccount"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
2021-06-05 14:17:30 +08:00
}
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 ( ) ;
}
}
}