MetroAccount.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dal;
using Comm;
namespace App
{
public partial class MetroAccount : FrmBase
{
Fuction fuction = new Fuction();
LoginManager _loginManger;
public MetroAccount(LoginManager loginManager)
{
InitializeComponent();
this.SetLanguage(this);
this._loginManger = loginManager;
init();
loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
loadAccount(this.cmbRePWDAccount, this.textBox1, this.textBox2);//刷新重置密码下拉框S
//showAdd();
}
/// <summary>
/// 初始化国际化
/// </summary>
private void init()
{
this.Text = getMsg("frmLoginManageckb_AMAccountManage3");
this.panelAddAccount.Text = getMsg("FrmMDIAuth_5020");
this.panelUpdateAccount.Text = getMsg("FrmMDIAuth_5030");
this.panelDeleteAccount.Text = getMsg("FrmMDIAuth_5040");
this.groupBox1.Text = getMsg("FrmMDIAuth_5010");
this.button1.Text = getMsg("back");
this.lblAddAccount.Text = getMsg("frmLoginManagelbl_Login")+" ";
this.lblAddCompany.Text = getMsg("frmLoginManagelbl_Company") + " ";
this.lblAddDepartment.Text = getMsg("frmLoginManagelbl_Department") + " ";
this.lblAddEnterPWD.Text = getMsg("frmLoginManagelbl_NewPSW") + " ";
this.lblAddReEnterPWD.Text = getMsg("frmLoginManagelbl_RePSW") + " ";
this.btnAddSave.Text = getMsg("FrmMDIbtn_Save");
this.lblUpdataAccount.Text = getMsg("frmLoginManagelbl_Login") + " ";
this.lblUpdataCompany.Text = getMsg("frmLoginManagelbl_Company") + " ";
this.lblUpdataDepartment.Text = getMsg("frmLoginManagelbl_Department") + " ";
this.lblUpdataNewPWD.Text = getMsg("frmLoginManagelbl_NewPSW") + " ";
this.lblUpdataReNewPWD.Text = getMsg("frmLoginManagelbl_RePSW") + " ";
this.btnUpdataSave.Text = getMsg("FrmMDIbtn_Save");
this.label1.Text = getMsg("frmLoginManagelbl_Login") + " ";
this.btnRePWDSave.Text = getMsg("FrmMDIbtn_Save");
this.lblDeleteAccounts.Text = getMsg("frmLoginManagelbl_Login") + " ";
this.lblDeleteCompany.Text = getMsg("frmLoginManagelbl_Company") + " ";
this.lblDeleteDepartment.Text = getMsg("frmLoginManagelbl_Department") + " ";
this.btnDeleteSave.Text = getMsg("frmProductbtn_Delete");
}
//创建和删除账户
private void addAndDeleteAccount(string operation, string login, string Parameter, string Value)
{
fuction.CreateParaConfig(operation ,login,Parameter,Value);
}
//点击添加账号
private void btnAdd_Click(object sender, EventArgs e)
{
showAdd();
}
private void showAdd()
{
this.panelAddAccount.Visible = true;
this.panelDeleteAccount.Visible = false;
this.panelUpdateAccount.Visible = false;
}
//点击删除账号
private void btnDelete_Click(object sender, EventArgs e)
{
this.panelAddAccount.Visible = false;
this.panelDeleteAccount.Visible = true;
this.panelUpdateAccount.Visible = false;
loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);
}
string[,] Accounts;
//加载账户
private void loadAccount(System.Windows.Forms.ComboBox cmb,System.Windows.Forms.TextBox companyName,System.Windows.Forms.TextBox department )
{
List<string[]> AllAccountsList = fuction.GetAllLoginName(Const.PARAMETERCONFIGNAME);
Accounts = new string[AllAccountsList.Count,3];
cmb.Items.Clear();
for (int i=0;i<AllAccountsList.Count;i++)
{
cmb.Items.Add(AllAccountsList[i][1]);//账户名称
Accounts[i,0] = AllAccountsList[i][1];
Accounts[i,1] = AllAccountsList[i][2];
Accounts[i,2] = AllAccountsList[i][3];
}
cmb.SelectedIndex = 0;
companyName.Text = Accounts[0,1];//公司
department.Text = Accounts[0,2];//部门
}
//点击修改账号
private void btnUpdate_Click(object sender, EventArgs e)
{
this.panelAddAccount.Visible = false;
this.panelDeleteAccount.Visible = false;
this.panelUpdateAccount.Visible = true;
loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);
}
//保存账户添加
private void btnSaveAdd_Click(object sender, EventArgs e)
{
//先判断内容是否不为空
if (!CheckNull(this.lblAddAccount.Text,this.txtAddCount)||
!CheckNull(this.lblAddCompany.Text, this.txtAddCompany)||
!CheckNull(this.lblAddDepartment.Text, this.lblAddDepartment)||
!CheckNull(this.lblAddEnterPWD.Text, this.txtAddEnterPWD)
)
{
}else
//判断再次密码输入是否一致
if (!(txtAddEnterPWD.Text.Trim().Equals(txtAddReEnterPWD.Text.Trim())))
{
//提示再次输入密码不一致
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
}
else
{
//判断用户名是否存在
if (fuction.CheckSameName("", Const.PARAMETERCONFIGNAME, this.txtAddCount.Text.Trim()))
{
//提示该用户名已存在
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_SAME);
}
else
{
//保存相关数据
if (fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_NAME, this.txtAddCount.Text.Trim()) &&
fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_LOGIN, this.txtAddCount.Text.Trim()) &&
fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_COMP, this.txtAddCompany.Text.Trim()) &&
fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_DEP, this.txtAddDepartment.Text.Trim()) &&
fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_PWD, Utility.SimpleEncode(this.txtAddEnterPWD.Text.Trim(), Utility.getExpandString(this.txtAddCount.Text.Trim(), 10))))
{
//提示保存成功
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
loadAccount(this.cmbRePWDAccount, this.textBox1,this.textBox2 );//刷新重置密码下拉框
}
else
{
//提示保存失败
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
}
}
}
}
//删除某个用户
private void btnSaveDelete_Click(object sender, EventArgs e)
{
if ("admin".Equals(this.cmbDeleteAccounts.Text))
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_WARNING_NOTE, "", Const.ERROR_CANT_DELETE);
}else
//提示确认要删除?
if (ShowMessageBox.ShowQuestionForDeleteProduce(Const.MESSAGEBOX_QUESTION_NOTE,cmbDeleteAccounts.Text.Trim()))
{
//确认删除后删除该用户
if (fuction.CreateParaConfig(Const.OPERATION_DELETE, this.cmbDeleteAccounts.Text.Trim(), Const.USER_PWD, this.txtAddEnterPWD.Text.Trim()))
{
//提示操作成功
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
loadAccount(this.cmbRePWDAccount, this.textBox1, this.textBox2);//刷新重置密码下拉框
}
else
{
//提示操作失败
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
}
}
}
//保存更新
private void button3_Click(object sender, EventArgs e)
{
//先判断内容是否不为空
if (!CheckNull(this.lblUpdataAccount.Text, this.cmbUpdataAccount) ||
!CheckNull(this.lblUpdataCompany.Text, this.txtUpdataCompanyName) ||
!CheckNull(this.lblUpdataDepartment.Text, this.lblUpdataDepartment)
)
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_WARNING_NOTE, "", Const.ERROR_NONE);
}
else
//确认再次输入的密码是否一致
if (!(txtAddEnterPWD.Text.Trim().Equals(txtAddReEnterPWD.Text.Trim())))
{
//提示再次输入密码不一致
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
}
else
{
//保存相关数据
if (fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_NAME, this.cmbUpdataAccount.Text.Trim()) &&
fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_LOGIN, this.cmbUpdataAccount.Text.Trim()) &&
fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_COMP, this.txtUpdataCompanyName.Text.Trim()) &&
fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_DEP, this.txtUpdataDepartment.Text.Trim()) &&
fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_PWD, this.txtUpdataNewPWD.Text.Trim()))
{
//提示操作成功
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
loadAccount(this.cmbRePWDAccount, this.textBox1, this.textBox2);//刷新重置密码下拉框
}
else
{
//提示操作失败
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
}
}
}
private void checkInputNull(List<Dictionary<string,System.Windows.Forms.Control>> InputInfo)
{
for (int i = 0; i < InputInfo.Count; i++)
{
Dictionary<string, System.Windows.Forms.Control> controlInfo = InputInfo[i];
}
}
#region 上一步,返回主菜单
private void btnUpdataCancel_Click(object sender, EventArgs e)
{
showMainMenu();
}
private void btnDeleteCance_Click(object sender, EventArgs e)
{
showMainMenu();
}
private void btnAddCancel_Click(object sender, EventArgs e)
{
showMainMenu();
}
private void showMainMenu()
{
this.Close();
MetroMDI mm = new MetroMDI(this._loginManger);
mm.ShowInTaskbar = true;
mm.Show();
mm.Activate();
}
#endregion
//保存密码重置
private void btnRePWDSave_Click(object sender, EventArgs e)
{
if (!CheckNull(this.lblUpdataNewPWD.Text, this.txtUpdataNewPWD)||
!CheckNull(this.lblUpdataReNewPWD.Text, this.txtUpdataReNewPWD))
{
}
else
//确认再次输入的密码是否一致
if (!(txtAddEnterPWD.Text.Trim().Equals(txtAddReEnterPWD.Text.Trim())))
{
//提示再次输入密码不一致
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
}
else
{
//保存相关数据
if (fuction.CreateParaConfig("", this.cmbRePWDAccount.Text, Const.USER_PWD, Utility.SimpleEncode(this.txtUpdataNewPWD.Text.Trim(), Utility.getExpandString(this.cmbRePWDAccount.Text.Trim(), 10))))
{
//提示操作成功
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
}
else
{
//提示操作失败
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
showMainMenu();
}
//切换下拉框
private void cmbUpdataAccount_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtUpdataCompanyName.Text = Accounts[cmbUpdataAccount.SelectedIndex,1];
this.txtUpdataDepartment.Text = Accounts[cmbUpdataAccount.SelectedIndex,2];
}
//切换下拉框
private void cmbDeleteAccounts_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtDeleteCompanyName.Text = Accounts[cmbDeleteAccounts.SelectedIndex,1];
this.txtDeleteDepartment.Text = Accounts[cmbDeleteAccounts.SelectedIndex,2];
}
private void MetroAccount_Load(object sender, EventArgs e)
{
this.panelAddAccount.Width = this.panel1.Width / 2 - 10;
this.panelDeleteAccount.Width = this.panel1.Width / 2 - 10;
this.panelUpdateAccount.Width = this.panel1.Width / 2 - 10;
this.groupBox1.Width = this.panel1.Width / 2 - 10;
this.panelUpdateAccount.Location = new Point(this.panelAddAccount.Location.X + this.panelAddAccount.Width+10, this.panelAddAccount.Location.Y);
this.groupBox1.Location = new Point(this.panelDeleteAccount.Location.X + this.panelDeleteAccount.Width+10, this.panelDeleteAccount.Location.Y);
}
}
}