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
232
233
234
using HxModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using XHandler.Class;
using HxUserManagement.Classes;
using HxUserManagement.HxBLL;
 
namespace HxUserManagement.Views
{
    /// <summary>
    /// UserCenter.xaml 的交互逻辑
    /// </summary>
    public partial class UserCenter : UserControl
    {
        #region CustomEvent
        public static readonly RoutedEvent editRoutedEvent =
           EventManager.RegisterRoutedEvent("editEvent", RoutingStrategy.Bubble, typeof(CustomEvent.CustomRoutedEventHandler<string>), typeof(UserCenter));
 
        [Description("editEvent")]
        public event CustomEvent.CustomRoutedEventHandler<string> editEvent
        {
            add
            {
                this.AddHandler(editRoutedEvent, value);
            }
            remove
            {
                this.RemoveHandler(editRoutedEvent, value);
            }
        }
 
        private void RaiseEditEvent(string l)
        {
            CustomRoutedEventArgs<string> arg = new CustomRoutedEventArgs<string>(editRoutedEvent, l);
            this.RaiseEvent(arg);
        }
 
        public static readonly RoutedEvent resetPswdRoutedEvent =
           EventManager.RegisterRoutedEvent("resetPswdEvent", RoutingStrategy.Bubble, typeof(CustomEvent.CustomRoutedEventHandler<string>), typeof(UserCenter));
 
        [Description("resetPswdEvent")]
        public event CustomEvent.CustomRoutedEventHandler<string> resetPswdEvent
        {
            add
            {
                this.AddHandler(resetPswdRoutedEvent, value);
            }
            remove
            {
                this.RemoveHandler(resetPswdRoutedEvent, value);
            }
        }
 
        private void RaiseResetPswdEvent(string l)
        {
            CustomRoutedEventArgs<string> arg = new CustomRoutedEventArgs<string>(resetPswdRoutedEvent, l);
            this.RaiseEvent(arg);
        }
        #endregion
 
        public List<UserInfoModel> userInfoList;
        public UserInfoBLL userInfoBLL = new UserInfoBLL();
        public List<RolesModel> roleList;
        public List<string> statusList;
        public UserCenter()
        {
            InitializeComponent();
 
            Debug.WriteLine("1   "+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
 
            Task.Factory.StartNew(() => {
                userInfoList = userInfoBLL.GetAllUserInfo();
                OnFinished();
            });
 
            //userInfoList = userInfoBLL.GetAllUserInfo();
            //datagrid.ItemsSource = userInfoList;
            Debug.WriteLine("2   " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
 
            roleList = DataModel.GetRoles();
            RolesModel role = new RolesModel();
            role.Name = Properties.Resources.strPleaseSelect;
            roleList.Insert(0, role);
            comboxRole.ItemsSource = roleList;
            comboxRole.SelectedIndex = 0;
 
            statusList = DataModel.GetStatusList();
            statusList.Insert(0, Properties.Resources.strPleaseSelect);
            comboxAccountStatus.ItemsSource = statusList;
            comboxAccountStatus.SelectedIndex = 0;
            Debug.WriteLine("3   " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
        }
 
        private void OnFinished()
        {
            Dispatcher.BeginInvoke(new Action(() => {
                Debug.WriteLine("4   " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                datagrid.ItemsSource = userInfoList;
                Debug.WriteLine("5   " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
            }));
            
        }
 
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (EventResponseController.Instance.CanExecute() == false)
                return;
            Button btn = (Button)sender;
            if (btn != null)
            {
                string id = (string)btn.Tag;
                RaiseEditEvent(id);
            }
        }
 
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (EventResponseController.Instance.CanExecute() == false)
                return;
            Button btn = (Button)sender;
            if (btn != null)
            {
                string id = (string)btn.Tag;
                UserInfoModel user = datagrid.SelectedItem as UserInfoModel;
 
                string msg = string.Format(Properties.Resources.strDeleteUserConfirm, user.UserName);
                MessageBoxResult ret = MessageBox.Show(msg, "Tips", MessageBoxButton.YesNo);
                if(ret == MessageBoxResult.Yes)
                {
                    bool result = userInfoBLL.DelById(id);
                    if (result)
                        MessageBox.Show(Properties.Resources.strDeleteSuccess, "Tips");
                    else
                        MessageBox.Show(Properties.Resources.strDeleteFailed, "Tips");
 
                    Refresh();
                }
            }
        }
 
        private void btnPswdReset_Click(object sender, RoutedEventArgs e)
        {
            if (EventResponseController.Instance.CanExecute() == false)
                return;
            Button btn = (Button)sender;
            if (btn != null)
            {
                string id = (string)btn.Tag;
                RaiseResetPswdEvent(id);
            }
        }
 
        private void ResetPassword_closeEvent(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
 
        private void datagrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = e.Row.GetIndex() + 1;
        }
 
        public void RefreshUserList()
        {
            userInfoList = userInfoBLL.GetAllUserInfo();
            datagrid.ItemsSource = userInfoList;
        }
 
        private void textboxUserName_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Refresh();
            }
        }
 
        private void textboxPhone_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Refresh();
            }
        }
 
       
        private void comboxRole_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Refresh();
        }
 
        private void comboxAccountStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Refresh();
        }
 
        public void Refresh()
        {
            string name = textboxUserName.Text;
            string phone = textboxPhone.Text;
            string state = "";
            if (comboxAccountStatus.SelectedIndex > 0)
                state = comboxAccountStatus.SelectedIndex == 1 ? "0" : "1";
            string authority = "";
            if (comboxRole.SelectedIndex > 0)
            {
                RolesModel role = comboxRole.SelectedItem as RolesModel;
                authority = role.Id;
            }
 
            userInfoList = Search(name, phone, state, authority);
            datagrid.ItemsSource = userInfoList;
        }
 
        private List<UserInfoModel> Search(string name, string phone, string state, string authority)
        {
            return userInfoBLL.Search(name, phone, state, authority);
        }
    }
 
}