using DataEntity.Share; using DataRWDAL; using System; using System.ComponentModel; using System.Security.Cryptography; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using XHandler.Class; using XImagingXhandler.XDAL; namespace XHandler.View.Login { /// /// BacteriaLogin.xaml 的交互逻辑 /// public partial class BacteriaLogin : UserControl { public event EventHandler closeEvent; public MainWindow mainWindow; public static readonly RoutedEvent okRoutedEvent = EventManager.RegisterRoutedEvent("okEvent", RoutingStrategy.Bubble, typeof(CustomEvent.CustomRoutedEventHandler), typeof(BacteriaLogin)); [Description("okEvent")] public event CustomEvent.CustomRoutedEventHandler okEvent { add { this.AddHandler(okRoutedEvent, value); } remove { this.RemoveHandler(okRoutedEvent, value); } } private void RaiseOKEvent(string data) { CustomRoutedEventArgs arg = new CustomRoutedEventArgs(okRoutedEvent, data); this.RaiseEvent(arg); } public BacteriaLogin() { InitializeComponent(); } private void btnClose_Click(object sender, RoutedEventArgs e) { if (EventResponseController.Instance.CanExecute() == false) return; closeEvent?.Invoke(this, EventArgs.Empty); } private void LoginUser_TextChanged(object sender, TextChangedEventArgs e) { if (!string.IsNullOrEmpty(LoginUser.Text.Trim())) { LoginUser.BorderThickness = new Thickness(0, 0, 0, 0); LoginUserTips.Visibility = Visibility.Collapsed; } LoginErrorTips.Visibility = Visibility.Collapsed; } private void LoginPassword_PasswordChanged(object sender, RoutedEventArgs e) { if (LoginPassword.Password.Length <= 0) { pawdHintText.Text = Properties.Resources.strPassword; //okBtn.IsEnabled = false; } else { pawdHintText.Text = ""; LoginPassword.BorderThickness = new Thickness(0, 0, 0, 0); LoginPasswordTips.Visibility = Visibility.Collapsed; } LoginErrorTips.Visibility = Visibility.Collapsed; } private void btnLogin_Click(object sender, RoutedEventArgs e) { if (EventResponseController.Instance.CanExecute() == false) return; if (string.IsNullOrEmpty(LoginUser.Text.Trim())) { LoginUser.BorderThickness = new Thickness(1, 1, 1, 1); LoginUserTips.Content = Properties.Resources.strPlsInputUsername; LoginUserTips.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(LoginPassword.Password)) { LoginPassword.BorderThickness = new Thickness(1, 1, 1, 1); LoginPasswordTips.Content = Properties.Resources.strPlsInputPassword; LoginPasswordTips.Visibility = Visibility.Visible; return; } string user = LoginUser.Text; string pswd = LoginPassword.Password; string md5pswd = GetMD5(pswd); bool isAuthor = true;// IsAuthority.IsAuthorityDog(); if (isAuthor) { bool ok = UserDB.isExistUserByUserInfo(user, md5pswd); if (ok) { Shared.User = UserDB.GetUserInfByUserName(user); RaiseOKEvent(user); LoginPassword.Password = ""; OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.operateAuditLogBll.GenerateOperateAuditLog("登录", "用户:" + Shared.User.username + "登录系统", Shared.User.username, "登录模块", "", "", "用户[id:" + Shared.User.username + "]", "成功")); } else { LoginErrorTips.Content = Properties.Resources.strUserOrPswdError; LoginErrorTips.Visibility = Visibility.Visible; OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.operateAuditLogBll.GenerateOperateAuditLog("登录", "用户:" + user + "登录系统", user, "登录模块", "", "", "用户[id:" + user + "]", "输入错误失败")); } } else { MessageBoxResult messageBoxResult = MessageBox.Show("请检查加密狗后再试!", "Error", MessageBoxButton.OK); OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.operateAuditLogBll.GenerateOperateAuditLog("登录", "用户:" + user + "登录系统", user, "登录模块", "", "", "用户[id:" + user + "]", "失败:未通过加密狗验证")); } } public static string GetMD5(string password) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytValue, bytHash; bytValue = System.Text.Encoding.UTF8.GetBytes(password); bytHash = md5.ComputeHash(bytValue); md5.Clear(); string sTemp = ""; for (int i = 0; i < bytHash.Length; i++) { sTemp += bytHash[i].ToString("X").PadLeft(2, '0'); } return sTemp.ToLower(); } private void LoginPassword_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { btnLogin_Click(this, null); } } private void UserControl_Loaded(object sender, RoutedEventArgs e) { // 软件系统名称 lblSysName.Content = Shared.SoftwareInformation.software_sys_name; LoginUser.Focus(); // wdy Test LoginUser.Text = "admin"; LoginPassword.Password = "123456"; } } }