alielie
2026-06-15 f08871fe7d148d667f2f11f80f64de71a0d9504c
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
using HMI.Core.Entity;
using HMI.Core.Util;
using HMI.UI.Util;
using Panuon.WPF.UI;
using System.ComponentModel;
 
namespace HMI.Base
{
    /// <summary>
    /// RequirePasswordWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RequirePasswordByUser : WindowX
    {
        public RequirePasswordByUser(string username)
        {
            this.Username = username;
            this.DataContext = this;
            InitializeComponent();
        }
 
        private string username;
        public string Username
        {
            get => username;
            set
            {
                Set(ref username, value);
            }
        }
 
        protected override void OnClosing(CancelEventArgs e)
        {
            //Press Continue Button
            if (DialogResult == true)
            {
                try
                {
                    using (var helper = new Sqlite3Helper(PathHelper.DatabasePath))
                    {
                        if (!helper.HasData($"SELECT 1 FROM user WHERE username = '{Username}' AND password = '{PwdPassword.Password}';"))
                        {
                            ToastHelper.Error(this, "密码错误");
                            e.Cancel = true;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    ToastHelper.Error(this, $"验证用户信息失败: {ex.Message}");
                    e.Cancel = true;
                }
            }
            base.OnClosing(e);
        }
 
        private void WindowX_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            Username = UserInfo.User.Username;
            PwdPassword.Password = string.Empty;
        }
    }
}