You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.8 KiB
C#

using MaterialTraceability.Business;
using MaterialTraceability.Entity.DAO;
using MaterialTraceability.Entity.UpLoad;
using MaterialTraceability.SqlSugar;
using MaterialTraceability.SqlSugar.ServiceImpl;
using MaterialTraceabilityUI.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace MaterialTraceabilityUI
{
/// <summary>
/// Login.xaml 的交互逻辑
/// </summary>
public partial class UserLogin : Window
{
//private IBaseServices<SysUserInfo> baseServices = new BaseServices<SysUserInfo>();
private UpLoadBusiness loadBusiness = UpLoadBusiness.Instance;
public UserLogin()
{
InitializeComponent();
// 定时器清空密码输入框,防止手写登录
var timer = new System.Timers.Timer(1500);
if (!timer.Enabled)
{
timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer1);
timer.AutoReset = true;
timer.Enabled = false;
timer.Start();
}
}
/// <summary>
/// 登录验证
/// </summary>
/// <param name="userName"></param>
/// <param name="userPwd"></param>
public void userLogin(string card)
{
// SysUser sysUser = loadBusiness.GetSysUserInfoByCard(card);
SysUser sysUser = loadBusiness.GetSysUserInfoByCard(card);
if (StringExtension.IsBlank(sysUser.userName))
{
MessageBox.Show(String.Format("登录失败,用户不存在"));
DialogResult = false;
}
else
{
ConfigHelper.UpdateAppConfig("userName", sysUser.userName);
ConfigHelper.UpdateAppConfig("roleId", sysUser.clientRole.ToString());
DialogResult = true;
}
}
private void password_KeyDown(object sender, KeyEventArgs e)
{
string str = this.password.Password.ToString();
if (str.Length == 10)
{
this.userLogin(str);
}
}
// 定时器一秒清空登录输入框,防止手动登录
private System.Timers.Timer timer = new System.Timers.Timer(1500);
private async void Timer1(object source, System.Timers.ElapsedEventArgs e)
{
if (timer.Enabled)
{
timer.Stop();
timer.Close();
timer.Dispose();
}
App.Current.Dispatcher.Invoke(() =>
{
try
{
this.password.Password = "";
}
catch (Exception ex)
{
LogHelperBusiness.LogError("定时清空密码异常", ex);
}
});
}
/// <summary>
/// 禁止粘贴
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.Handled = true;
}
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
}
//---------------------------------------------
//private void password_KeyDown(object sender, KeyEventArgs e)
//{
// string str = this.password.Password.ToString();
// if (str.Length == 10)
// {
// this.userLogin(str);
// }
//}
}
}