frmLoginManage.cs
15.2 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;
namespace App
{
public partial class frmLoginManage : FrmBase
{
private string m_operate;
private string m_login;
private string m_PWD;
private int nameIndex;
private bool m_HaveAuthSystem;//是否具有帐号管理的权限
Fuction fuction = new Fuction();
public frmLoginManage(string operate)
{
InitializeComponent();
m_HaveAuthSystem = fuction.HaveAuth(Const.AUTH_ACCOUNTMANAGER);
m_operate=operate;
BindDGLogin();
this.SetLanguage(this);
if (m_operate == Const.OPERATION_ADD)
{
SetBisicEmpty();
}
switch (m_operate)
{
case Const.OPERATION_ADD:
this.tabStrip1.SelectedTab = this.tabLogin;
this.tabSPlogin.Visible = true;
this.tabAuth.Visible = false;
this.tabPSW.Visible = false;
break;
case Const.OPERATION_MODIFY:
this.tabStrip1.SelectedTab = this.tabLogin;
this.tabSPlogin.Visible = true;
this.tabAuth.Visible = false;
this.tabPSW.Visible = false;
txt_Login.ReadOnly = true;
this.txt_Login.BackColor = Color.LightGray;
break;
case Const.OPERATION_DELETE:
this.tabStrip1.SelectedTab = this.tabLogin;
this.tabSPlogin.Visible = true;
this.tabAuth.Visible = false;
this.tabPSW.Visible = false;
txt_Login.ReadOnly = true;
txt_Name.ReadOnly = true;
txt_Company.ReadOnly = true;
txt_Department.ReadOnly = true;
this.txt_Login.BackColor = Color.LightGray;
this.txt_Name.BackColor = Color.LightGray;
this.txt_Company.BackColor = Color.LightGray;
this.txt_Department.BackColor = Color.LightGray;
break;
case Const.OPERATION_SETAUTH:
this.tabStrip1.SelectedTab = this.tabAuth;
this.tabStripPage1.Visible = true;
this.tabLogin.Visible = false;
this.tabPSW.Visible = false;
break;
case Const.OPERATION_SETPWD:
this.tabStrip1.SelectedTab = this.tabPSW;
this.tabStripPage2.Visible = true;
this.tabAuth.Visible = false;
this.tabLogin.Visible = false;
break;
default:
break;
}
}
private void SetBisicEmpty()
{
txt_Login.Text = String.Empty;
txt_Name.Text = String.Empty;
txt_Company.Text = String.Empty;
txt_Department.Text = String.Empty;
}
private void BindDGLogin()
{
DataTable table1;
if (m_HaveAuthSystem)
table1 = fuction.GetLoginInfoByLoginName("");
else
table1 = fuction.GetLoginInfoByLoginName(Fuction.m_UserLogin);
dg_Login.DataSource = table1;
DataGridViewCellStyle dataGridViewCellStyle0 = CreatDataGridViewCellStyle();
dg_Login.Columns[Const.USER_LOGIN].DefaultCellStyle = dataGridViewCellStyle0;
//dg_Login.Columns[Const.USER_LOGIN].FillWeight = 40F;
dg_Login.Columns[Const.USER_LOGIN].HeaderCell.Style.BackColor = Color.SkyBlue;
dg_Login.Columns[Const.USER_LOGIN].SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
dg_Login.Columns[Const.USER_LOGIN].Width = (dg_Login.Width - 20) / 2;
dg_Login.Columns[Const.USER_NAME].DefaultCellStyle = dataGridViewCellStyle0;
//dg_Login.Columns[Const.USER_NAME].FillWeight = 40F;
dg_Login.Columns[Const.USER_NAME].HeaderCell.Style.BackColor = Color.SkyBlue;
dg_Login.Columns[Const.USER_NAME].SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
dg_Login.Columns[Const.USER_NAME].Width = (dg_Login.Width - 20) / 2;
dg_Login.Columns[Const.USER_PWD].Visible = false;
dg_Login.Columns[Const.USER_COMP].Visible = false;
dg_Login.Columns[Const.USER_DEP].Visible = false;
dg_Login.Columns[Const.USER_AUTH].Visible = false;
if (table1.Rows.Count > 0)
{
nameIndex = 0;
dg_Login.Rows[nameIndex].Selected = true;
if (m_operate != Const.OPERATION_ADD)
{
ShowDetail(((DataTable)dg_Login.DataSource).Rows[nameIndex]);
}
}
}
private void dg_Login_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
dg_Login.Rows[e.RowIndex].Selected = true;
nameIndex = e.RowIndex;
if (m_operate != Const.OPERATION_ADD)
{
ShowDetail(((DataTable)dg_Login.DataSource).Rows[nameIndex]);
}
}
}
private void ShowDetail(DataRow drLogin)
{
txt_Login.Text = drLogin[Const.USER_LOGIN].ToString();
txt_Name.Text = drLogin[Const.USER_NAME].ToString();
m_PWD = drLogin[Const.USER_PWD].ToString();
txt_Company.Text = drLogin[Const.USER_COMP].ToString();
txt_Department.Text = drLogin[Const.USER_DEP].ToString();
string[] auth = drLogin[Const.USER_AUTH].ToString().Split(',');
if (auth[0] != "0")
this.ckb_AMTest1.Checked = true;
else
this.ckb_AMTest1.Checked = false;
if (auth[1] != "0")
this.ckb_AMAnalysis2.Checked = true;
else
this.ckb_AMAnalysis2.Checked = false;
if (auth[2] != "0")
this.ckb_AMAccountManage3.Checked = true;
else
this.ckb_AMAccountManage3.Checked = false;
if (auth[3] != "0")
this.ckb_AMMaintenance4.Checked = true;
else
this.ckb_AMMaintenance4.Checked = false;
m_login =
((DataTable)dg_Login.DataSource).Rows[nameIndex][Const.USER_LOGIN].ToString();
if (m_login == Const.LOGIN_ADMIN &&
m_operate == Const.OPERATION_DELETE)
{
//不能删除。修改权限
this.btn_OK1.Enabled = false;
}
else
{
this.btn_OK1.Enabled = true;
}
if (m_login == Const.LOGIN_ADMIN &&
m_operate == Const.OPERATION_SETAUTH)
{
this.btn_OK2.Enabled = false;
this.ckb_AMTest1.Enabled = false;
this.ckb_AMAnalysis2.Enabled = false;
this.ckb_AMAccountManage3.Enabled = false;
this.ckb_AMMaintenance4.Enabled = false;
}
else
{
this.btn_OK2.Enabled = true;
this.ckb_AMTest1.Enabled = true;
this.ckb_AMAnalysis2.Enabled = true;
this.ckb_AMAccountManage3.Enabled = true;
this.ckb_AMMaintenance4.Enabled = true;
}
if (m_HaveAuthSystem &&
(m_login != Fuction.m_UserLogin))//重置密码
{
this.txt_OldPSW.Text = m_PWD;
this.txt_OldPSW.ReadOnly = true;
this.txt_OldPSW.BackColor = Color.LightGray;
this.txt_NewPSW.Text = Const.PWD_INIT;
this.txt_RePSW.Text = Const.PWD_INIT;
}
else
{
this.txt_OldPSW.Text = String.Empty;
this.txt_OldPSW.ReadOnly = false;
this.txt_OldPSW.BackColor = Color.Azure;
this.txt_NewPSW.Text = String.Empty;
this.txt_RePSW.Text = String.Empty;
}
}
private void frmLoginManage_Shown(object sender, EventArgs e)
{
SetStyle("Azure");
//ResizeForm();
}
#region login
/// <summary>
///add ,modify delete login
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_OK1_Click(object sender, EventArgs e)
{
bool ifOpera;
//如果删除
if (m_operate == Const.OPERATION_DELETE)
{
if (ShowMessageBox.ShowWarning(Const.MESSAGEBOX_WARNING_NOTE, Const.IFCONFIRM_OPERATION))
ifOpera = fuction.CreateParaConfig(m_operate, m_login, "", "");
else
return;
}
else//add,modify
{
//判空
if (!CheckNull(this.lbl_Login.Text, txt_Login) ||
!CheckNull(this.lbl_Name.Text, txt_Name))
{
return;
}
//如果新增,
if (m_operate == Const.OPERATION_ADD)
{
//判第一个是否是数字
string tem = txt_Login.Text.Substring(0, 1);
try
{
Convert.ToInt32(tem);
ShowMessageBox.ShowError(
Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_NAME_FIRST_NUM);
this.txt_Login.Focus();
return;
}
catch(Exception ex)
{
LOGGER.Info(ex.StackTrace);
}
if (txt_Login.Text.Length<2)
{
ShowMessageBox.ShowError(
Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_NAME_LESSTWO);
this.txt_Login.Focus();
return;
}
//判登录名是否同名
if (!CheckSame(this.lbl_Login.Text, txt_Login, Const.PARAMETERCONFIGNAME))
{
return;
}
}
string m_Login = txt_Login.Text;
string m_Name = txt_Name.Text;
string m_Company = txt_Company.Text;
string m_Department = txt_Department.Text;
if (m_operate == Const.OPERATION_ADD)
{
ifOpera = (fuction.CreateParaConfig(m_operate, m_Login, Const.USER_NAME, m_Name) &&
fuction.CreateParaConfig(m_operate, m_Login, Const.USER_COMP, m_Company) &&
fuction.CreateParaConfig(m_operate, m_Login, Const.USER_DEP, m_Department) &&
fuction.CreateParaConfig(m_operate, m_Login, Const.USER_PWD, Utility.SimpleEncode(Const.PWD_INIT, Utility.getExpandString(m_Login, 10))) &&
fuction.CreateParaConfig(m_operate, m_Login, Const.USER_AUTH, Const.AUTH_INIT));
}
else
{
ifOpera = (fuction.CreateParaConfig(m_operate, m_Login, Const.USER_NAME, m_Name) &&
fuction.CreateParaConfig(m_operate, m_Login, Const.USER_COMP, m_Company) &&
fuction.CreateParaConfig(m_operate, m_Login, Const.USER_DEP, m_Department));
//if (ifOpera && m_Login == Fuction.m_UserLogin)
//{
// ((FrmMDI)this.ParentForm).GetRightInfo(Const.TREE_FACTORY, m_Company);
// ((FrmMDI)this.ParentForm).GetRightInfo(Const.TREE_DEP, m_Department);
// ((FrmMDI)this.ParentForm).GetRightInfo(Const.TREE_OPERATOR, m_Name);
//}
}
}
if (ifOpera)
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
SetBisicEmpty();
BindDGLogin();
}
else
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);
SetBisicEmpty();
BindDGLogin();
}
}
private void btn_Cancel1_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region auth
private void btn_OK2_Click(object sender, EventArgs e)
{
string auth;
if (this.ckb_AMTest1.Checked)
auth=Const.AUTH_TEST;
else
auth="0";
if (this.ckb_AMAnalysis2.Checked)
auth=auth+","+Const.AUTH_ANALYSIS;
else
auth=auth+","+"0";
if (this.ckb_AMAccountManage3.Checked)
auth=auth+","+Const.AUTH_ACCOUNTMANAGER;
else
auth=auth+","+"0";
if (this.ckb_AMMaintenance4.Checked)
auth=auth+","+Const.AUTH_MAINTENANCE;
else
auth=auth+","+"0";
if (fuction.CreateParaConfig(Const.OPERATION_SETAUTH, m_login, Const.USER_AUTH, auth))
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
BindDGLogin();
}
else
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);
BindDGLogin();
}
}
private void btn_Cancel2_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region PWD
private void btn_OK3_Click(object sender, EventArgs e)
{
string oldPWD = txt_OldPSW.Text;
string newPWD =txt_NewPSW.Text;
string rePWD = txt_RePSW.Text;
if ((!m_HaveAuthSystem ||
(m_login != Fuction.m_UserLogin) ) &&
oldPWD != m_PWD)
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OLDPWDWRONG);
return;
}
if (newPWD != rePWD)
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
return;
}
if(fuction.CreateParaConfig(Const.OPERATION_SETPWD, m_login, Const.USER_PWD,
Utility.SimpleEncode(newPWD, Utility.getExpandString(m_login, 10))))
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
BindDGLogin();
}
else
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);
BindDGLogin();
}
}
private void btn_Cancel3_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
}
}