schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
{
    /// <summary>
    /// BacteriaLogin.xaml 的交互逻辑
    /// </summary>
    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<string>), typeof(BacteriaLogin));
 
        [Description("okEvent")]
        public event CustomEvent.CustomRoutedEventHandler<string> okEvent
        {
            add
            {
                this.AddHandler(okRoutedEvent, value);
            }
            remove
            {
                this.RemoveHandler(okRoutedEvent, value);
            }
        }
 
        private void RaiseOKEvent(string data)
        {
            CustomRoutedEventArgs<string> arg = new CustomRoutedEventArgs<string>(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";
        }
    }
}