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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using HxModel;
using HxUserManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XHandler.Class;
using XHandler.Controls;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
namespace XHandler.View.User
{
    /// <summary>
    /// ResetPassword.xaml 的交互逻辑
    /// </summary>
    public partial class ResetPassword : UserControl
    {
        public event EventHandler closeEvent;
        public event EventHandler okEvent;
        private UserInfo userInfoModel = null;
        private string Id;
        public ResetPassword()
        {
            InitializeComponent();
        }
 
        public ResetPassword(string id)
        {
            InitializeComponent();
            Id = id;
            userInfoModel = UserDB.GetUserInfByUserId(id);//userInfoBLL.GetInfodById(id);
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Storyboard storyboard = new Storyboard();
 
            DoubleAnimation doubleAnimation = new DoubleAnimation(0, 500, new Duration(TimeSpan.FromSeconds(0.25)));
            Storyboard.SetTarget(doubleAnimation, border);//Target对象
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性
            storyboard.Children.Add(doubleAnimation);
 
            ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames();
            showAnimation.BeginTime = TimeSpan.FromSeconds(0);
            Storyboard.SetTarget(showAnimation, border);
            Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)"));
            DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromSeconds(0.01));
            showAnimation.KeyFrames.Add(closeKeyFrame);
            storyboard.Children.Add(showAnimation);
 
            storyboard.Begin();
 
        }
 
        private void root_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource is Grid)
            {
                Grid grid = e.OriginalSource as Grid;
                if (grid.Name == "root")
                    Button_Click(this, null);
            }
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (EventResponseController.Instance.CanExecute() == false)
                return;
 
            Storyboard storyboard = new Storyboard();
 
            DoubleAnimation doubleAnimation = new DoubleAnimation(500, 0, new Duration(TimeSpan.FromSeconds(0.25)));
            Storyboard.SetTarget(doubleAnimation, border);//Target对象
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性
            storyboard.Children.Add(doubleAnimation);
 
            ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames();
            showAnimation.BeginTime = TimeSpan.FromSeconds(0);
            Storyboard.SetTarget(showAnimation, border);
            Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)"));
            DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Collapsed, TimeSpan.FromSeconds(0.26));
            showAnimation.KeyFrames.Add(closeKeyFrame);
            storyboard.Children.Add(showAnimation);
            storyboard.Completed += delegate { closeEvent?.Invoke(this, EventArgs.Empty); };
            storyboard.Begin();
        }
 
        private void textboxNewPswd_PasswordChanged(object sender, EventArgs e)
        {
            textboxNewPswd.BorderBrush = Brushes.DarkGray;
            pswdTips.Visibility = Visibility.Collapsed;
        }
 
        private void textboxConfirmPswd_PasswordChanged(object sender, EventArgs e)
        {
            textboxConfirmPswd.BorderBrush = Brushes.DarkGray;
            pswdConfirmTips.Visibility = Visibility.Collapsed;
        }
 
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Button_Click(this, null);
        }
 
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textboxNewPswd.Password))
            {
                textboxNewPswd.BorderBrush = Brushes.Red;
                pswdTips.Text = Properties.UserResource.strPswdLenght;
                pswdTips.Visibility = Visibility.Visible;
                return;
            }
            if (textboxNewPswd.Password.Length < 6)
            {
                textboxNewPswd.BorderBrush = Brushes.Red;
                pswdTips.Text = Properties.UserResource.strPswdLenght;
                pswdTips.Visibility = Visibility.Visible;
                return;
            }
            textboxNewPswd.BorderBrush = Brushes.DarkGray;
            pswdTips.Visibility = Visibility.Collapsed;
            if (string.Compare(textboxNewPswd.Password, textboxConfirmPswd.Password) != 0)
            {
                textboxConfirmPswd.BorderBrush = Brushes.Red;
                pswdConfirmTips.Text = Properties.UserResource.strPswdNotSame;
                pswdConfirmTips.Visibility = Visibility.Visible;
                return;
            }
            userInfoModel.userpwd = Utilities.GetMD5(textboxConfirmPswd.Password);
            userInfoModel.modifyname = UserManagerment.currentUser.username;
            userInfoModel.modifytime = DateTime.Now;
            int user = UserDB.UpdateUserIntodb(userInfoModel);
            if (user != 0)
            {
                PlsToolTipWin plsToolTipWin = new PlsToolTipWin(Properties.UserResource.strResetPswdSuccess);
                plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                plsToolTipWin.Height = 450;
                plsToolTipWin.Width = 600;
                plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
                SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
                plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                plsToolTipWin.ShowDialog();
            }
            else
            {
                PlsToolTipWin plsToolTipWin = new PlsToolTipWin(Properties.UserResource.strResetPswdFailed);
                plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                plsToolTipWin.Height = 450;
                plsToolTipWin.Width = 600;
                plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
                SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
                plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush;
                plsToolTipWin.ShowDialog();
            }
        }
 
        private void EyeButton_Click(object sender, RoutedEventArgs e)
        {
            ToggleButton button = sender as ToggleButton;
            if (button != null)
            {
                button.IsChecked = !button.IsChecked;
            }
        }
 
        private void textboxNewPswd_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (sender is System.Windows.Controls.PasswordBox pb)
            {
                PasswordBoxAttached.SetPassword(pb, pb.Password);
                int strength = GetPasswordStrength(pb.Password);
                SetStrengthText(strength);
            }
        }
 
        private void textboxConfirmPswd_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (sender is System.Windows.Controls.PasswordBox pb)
            {
                PasswordBoxAttached.SetPassword(pb, pb.Password);
            }
        }
 
        private int GetPasswordStrength(string password)
        {
            int score = 0;
            if (password.Length > 8) score += 2;
            if (password.Any(char.IsDigit)) score += 3;
            if (password.Any(char.IsUpper)) score += 3;
            if (password.Any(char.IsLower)) score += 2;
            if (password.Any(c => !char.IsLetterOrDigit(c))) score += 2;
            return score;
        }
 
        private void SetStrengthText(int strength)
        {
            string strengthText = "";
            switch (strength)
            {
                case 0:
                case 1:
                    strengthText = "Weak";
                    lessPwd.Background = Brushes.Red;
                    break;
                case 2:
                case 3:
                    strengthText = "Moderate";
                    midPwd.Background = Brushes.Orange;
                    break;
                case 4:
                case 5:
                    strengthText = "Strong";
                    strongPwd.Background = Brushes.Green;
                    break;
            }
        }
    }
}