-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmUserOutLine.cs
408 lines (351 loc) · 19.3 KB
/
frmUserOutLine.cs
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
403
404
405
406
407
408
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinAtt
{
public partial class frmUserOutLine : Form
{
public frmUserOutLine()
{
InitializeComponent();
userdata = new DataTable();
userdata.Columns.Add(new DataColumn("EnrollNumber", typeof(string)));
userdata.Columns.Add(new DataColumn("UserName", typeof(string)));
userdata.Columns.Add(new DataColumn("Privilege", typeof(int)));
userdata.Columns.Add(new DataColumn("MPassword", typeof(string)));
userdata.Columns.Add(new DataColumn("IsEnabled", typeof(int)));
DataGridViewTextBoxColumn t1 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn t2 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn t3 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn t4 = new DataGridViewTextBoxColumn();
//DataGridViewTextBoxColumn t5 = new DataGridViewTextBoxColumn();
DataGridViewCheckBoxColumn t5 = new DataGridViewCheckBoxColumn();
t1.HeaderText = "用户";
t1.DataPropertyName = "UserName";
t1.Name = "userDataGridViewTextBoxColumn";
t2.HeaderText = "考勤号";
t2.DataPropertyName = "EnrollNumber";
t2.Name = "EnrollNumberDataGridViewTextBoxColumn";
t3.HeaderText = "编号";
t3.DataPropertyName = "Privilege";
t3.Name = "PrivilegeDataGridViewTextBoxColumn";
t4.HeaderText = "密码";
t4.DataPropertyName = "MPassword";
t4.Name = "MPasswordDataGridViewTextBoxColumn";
t5.HeaderText = "密码";
t5.DataPropertyName = "IsEnabled";
t5.Name = "IsEnabledDataGridViewTextBoxColumn";
this.dataGridView3.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
t1,t2,t3,t4,t5
});
}
private delegate void CmnLoadDataHandler(DataRow dr, out string b);
private delegate void CmnloadMdataHandler(DataRow dr, out DataTable dt, out string st);
private DataTable userdata, machinesdata;
private void frmUserOutLine_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“attDataSet.d_machines”中。您可以根据需要移动或删除它。
this.d_machinesTableAdapter.Fill(this.attDataSet.d_machines);
// TODO: 这行代码将数据加载到表“users.d_user”中。您可以根据需要移动或删除它。
this.d_userTableAdapter.Fill(this.users.d_user);
}
/// <summary>
/// 上传用户数据到机器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (dataGridView2.SelectedRows.Count > 0)
{
CmnLoadDataHandler handler = new CmnLoadDataHandler(this.CmnUpLoadData);
using (CmnLoadDataForm form = new CmnLoadDataForm())
for (int i = 0; i < dataGridView2.SelectedRows.Count; i++)
{
}
}
//for (int i = 0; i < LGridView.RowCount; i++)
//{
// if (LGridView.GetDataRow(i)["xuanding"].ToString() == "1")
// {
// this.gridView.CloseSaveEditor();
// CmnLoadDataHandler handler = new CmnLoadDataHandler(this.CmnUpLoadData);
// using (CmnLoadDataForm form = new CmnLoadDataForm())
// {
// string b = "";
// DataRow dr = LGridView.GetDataRow(i);
// IAsyncResult result = handler.BeginInvoke(dr, out b, null, null);
// form.AsyncResult = result;
// form.ShowDialog(this);
// handler.EndInvoke(out b, result);
// DXTravel.DXGUI.Util.MessageUtil.ShowInfo(b);
// RTable.GetMainTableByWhere(" AllowLogin=1");
// gridControl.DataSource = RTable;
// }
// }
//}
}
/// 上传用户数据到机器
private void CmnUpLoadData(DataRow dr, out string b)
{
b = "";
ZKAccess FG = new ZKAccess(ConvertUtil.GetDBInt(dr["SerialPort"]), ConvertUtil.GetDBInt(dr["Port"]), ConvertUtil.GetDBInt(dr["MachineNumber"]), ConvertUtil.GetDBInt(dr["Baudrate"]), dr["IP"].ToString());
if (FG.Connect_Net())
{
int idwErrorCode = 0;
string sdwEnrollNumber = "";
string sName = "";
int idwFingerIndex = 0;
string sTmpData = "";
///权限级别0:一般用户1:登记员2:管理员3:超级管理员
int iPrivilege = 0;
string sPassword = "";
string sEnabled = "";
bool bEnabled = true;
int iFlag = 1;
int iFaceLength = 128 * 1024;
int iFaceIndex = 50;
byte[] sFaceData = new byte[iFaceLength];
int iUpdateFlag = 1;
FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false);
// if (FG.m_CZKEMClass.BeginBatchUpdate(FG.COM_MACHINENUMBER, iUpdateFlag))//create memory space for batching data
// {
// string sLastEnrollNumber = "";//the former enrollnumber you have upload(define original value as 0)
// for (int i = 0; i < gridView.RowCount; i++)
// {
// DataRow newdr = gridView.GetDataRow(i);
// if (newdr["uploaded"].ToString() == "1")
// {
// sdwEnrollNumber = newdr["EnrollNumber"].ToString();
// sName = newdr["UserName"].ToString();
// idwFingerIndex = ConvertUtil.GetDBInt(newdr["FingerIndex"]);
// sTmpData = newdr["Finger"].ToString();
// iPrivilege = ConvertUtil.GetDBInt(newdr["Privilege"]);
// sPassword = newdr["MPassword"].ToString();
// sEnabled = newdr["IsEnabled"].ToString();
// iFlag = ConvertUtil.GetDBInt(newdr["Flag"]);
// iFaceLength = ConvertUtil.GetDBInt(newdr["FingerLength"]);
// sFaceData = (byte[])newdr["photo"];
// if (sEnabled == "true")
// {
// bEnabled = true;
// }
// else
// {
// bEnabled = false;
// }
// if (sdwEnrollNumber != sLastEnrollNumber)//identify whether the user information(except fingerprint templates) has been uploaded
// {
// if (FG.m_CZKEMClass.SSR_SetUserInfo(FG.COM_MACHINENUMBER, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled))//upload user information to the memory
// {
// FG.m_CZKEMClass.SetUserTmpExStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData);//upload templates information to the memory
// }
// else
// {
// FG.m_CZKEMClass.GetLastError(ref idwErrorCode);
// FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true);
// return;
// }
// }
// else//the current fingerprint and the former one belongs the same user,that is ,one user has more than one template
// {
// FG.m_CZKEMClass.SetUserTmpExStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, idwFingerIndex, iFlag, sTmpData);
// }
// //更新照片模版。先不要用,免得出错,丢失数据。试验能够成功再使用。
// //FG.m_CZKEMClass.SetUserFace(FG.COM_MACHINENUMBER, sdwEnrollNumber, 50,ref sFaceData[0], iFaceLength);
// sLastEnrollNumber = sdwEnrollNumber;//change the value of iLastEnrollNumber dynamicly
// }
// }
// }
// FG.m_CZKEMClass.BatchUpdate(FG.COM_MACHINENUMBER);//upload all the information in the memory
// FG.m_CZKEMClass.RefreshData(FG.COM_MACHINENUMBER);//the data in the device should be refreshed
// FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true);
// b = "上传完成";
}
else
{
listBox1.Items.Add(dr["MachineNumber"].ToString() + "指纹机无法连机");
}
}
/// <summary>
/// 下载用户数据到数据库
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
//if (userdata.Rows[i]["xuanding"].ToString() == "1")
//{
CmnLoadDataHandler handler = new CmnLoadDataHandler(this.CmnDownLoadData);
using (CmnLoadDataForm form = new CmnLoadDataForm())
{
string b = "";
DataRow dr = (dataGridView1.SelectedRows[i].DataBoundItem as DataRowView).Row;
listBox1.Items.Add("开始连接指纹机" + dr["MachineNumber"].ToString());
IAsyncResult result = handler.BeginInvoke(dr, out b, null, null);
form.AsyncResult = result;
form.ShowDialog(this);
handler.EndInvoke(out b, result);
listBox1.Items.Add(b);
//DXTravel.DXGUI.Util.MessageUtil.ShowInfo(b);
//RTable.GetMainTableByWhere(" AllowLogin=1");
//dataGridView3.DataSource = userdata;
}
}
}
}
/// <summary>
/// 下载更新数据库的用户数据
/// </summary>
/// <param name="dr"></param>
/// <param name="b"></param>
protected void CmnDownLoadData(DataRow dr, out string b)
{
int count = 0;
int sumcount = 0;
string rtstr = "";
b = "";
ZKAccess FG = new ZKAccess(ConvertUtil.GetDBInt(dr["SerialPort"]), ConvertUtil.GetDBInt(dr["Port"]), ConvertUtil.GetDBInt(dr["MachineNumber"]), ConvertUtil.GetDBInt(dr["Baudrate"]), dr["IP"].ToString());
if (FG.Connect_Net())
{
b = dr["MachineNumber"].ToString() + "指纹机连接成功";
string sdwEnrollNumber = "";
string sName = "";
string sPassword = "";
int iPrivilege = 0;
bool bEnabled = false;
int idwFingerIndex;
string sTmpData = "";
int iTmpLength = 0;
int iFlag = 0;
int iFaceLength = 128 * 1024;
int iFaceIndex = 50;
byte[] sFaceData = new byte[iFaceLength];
FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false);
//Cursor = Cursors.WaitCursor;
FG.m_CZKEMClass.ReadAllUserID(FG.COM_MACHINENUMBER);//read all the user information to the memory
FG.m_CZKEMClass.ReadAllTemplate(FG.COM_MACHINENUMBER);//read all the users' fingerprint templates to the memory
while (FG.m_CZKEMClass.SSR_GetAllUserInfo(FG.COM_MACHINENUMBER, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled))//get all the users' information from the memory
{
sumcount = sumcount + 1;
//if (FG.m_CZKEMClass.GetUserFaceStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, iFaceIndex, ref sFaceData, ref iFaceLength))//get the face templates from the memory
//{
//}
if (FG.m_CZKEMClass.GetUserFace(FG.COM_MACHINENUMBER, sdwEnrollNumber, iFaceIndex, ref sFaceData[0], ref iFaceLength))
{
}
for (idwFingerIndex = 0; idwFingerIndex < 10; idwFingerIndex++)
{
if (FG.m_CZKEMClass.GetUserTmpExStr(FG.COM_MACHINENUMBER, sdwEnrollNumber, idwFingerIndex, out iFlag, out sTmpData, out iTmpLength))//get the corresponding templates string and length from the memory
{
if (DBLinker.Linker.GetDataRow("select 1 from d_user where EnrollNumber='" + sdwEnrollNumber.ToString() + "'") == null)
{
string sql = "insert into [d_user] ([LoginName],[UserName],[UserPassword] ,[AllowLogin],[MachineNumber] ,[EnrollNumber] ,[FingerIndex] ,[FaceIndex],[Finger] ,[photo],[Flag] ,[MPassword] ,[Privilege] ,[IsEnabled],FingerLength,FaceLength) VALUES ('" + sdwEnrollNumber + "','" + sName + "','r3B6n6Eq5z8=' ,1," + FG.COM_MACHINENUMBER.ToString() + " ,'" + sdwEnrollNumber + "' ," + idwFingerIndex + " ," + iFaceIndex + ",'" + sTmpData + "','" + sFaceData + "'," + iFlag.ToString() + " ,'" + sPassword + "' ," + iPrivilege.ToString() + " ,'" + bEnabled + "'," + iTmpLength + "," + iFaceLength + ")";
if (DBLinker.Linker.ExecuteNonQuery(sql) != -1)
count = count + 1;
else
rtstr = rtstr + sql + "\r\n";
}
else
{
string sql = "UPDATE [d_user] SET [MachineNumber] =" + FG.COM_MACHINENUMBER.ToString() + ",[FingerIndex] = " + idwFingerIndex + ",[FaceIndex] = " + iFaceIndex + " ,[Finger] = '" + sTmpData + "',[photo] = '" + sFaceData + "' ,[Flag] = " + iFlag.ToString() + " ,[MPassword] ='" + sPassword + "' ,[Privilege] =" + iPrivilege.ToString() + " ,[IsEnabled] = '" + bEnabled + "',[FingerLength] = " + iTmpLength + " ,[FaceLength] = " + iFaceLength + " where [EnrollNumber]='" + sdwEnrollNumber + "'";
if (DBLinker.Linker.ExecuteNonQuery(sql) != -1)
count = count + 1;
else
rtstr = rtstr + sql + "\r\n";
}
}
}
}
FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true);
b = ("下载或更新用户信息" + count.ToString() + "条,合计" + sumcount.ToString() + "条,错误提示:\r\n " + rtstr);
}
else
{
b = dr["MachineNumber"].ToString() + "指纹机连接失败";
}
}
/// <summary>
/// 查看机器人员列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
CmnloadMdataHandler handler = new CmnloadMdataHandler(this.CmnLookData);
using (CmnLoadDataForm form = new CmnLoadDataForm())
{
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
DataRow dr = (dataGridView1.SelectedRows[i].DataBoundItem as DataRowView).Row;
listBox1.Items.Add("开始连接指纹机" + dr["MachineNumber"].ToString());
DataTable d = (DataTable)userdata.Clone();
string st;
IAsyncResult result = handler.BeginInvoke(dr, out d, out st, null, null);
form.AsyncResult = result;
form.ShowDialog(this);
handler.EndInvoke(out d, out st, result);
listBox1.Items.Add(st);
dataGridView3.DataSource = d;
}
}
}
}
private void button5_Click(object sender, EventArgs e)
{
}
private void CmnLookData(DataRow dr, out DataTable dt, out string st)
{
//dt = (DataTable)RTable.Clone();
dt = (DataTable)userdata.Clone();
ZKAccess FG = new ZKAccess(ConvertUtil.GetDBInt(dr["SerialPort"]), ConvertUtil.GetDBInt(dr["Port"]), ConvertUtil.GetDBInt(dr["MachineNumber"]), ConvertUtil.GetDBInt(dr["Baudrate"]), dr["IP"].ToString());
if (FG.Connect_Net())
{
st = "连接成功!";
string sdwEnrollNumber = "";
string sName = "";
string sPassword = "";
int iPrivilege = 0;
bool bEnabled = false;
//int idwFingerIndex;
//string sTmpData = "";
//int iTmpLength = 0;
//int iFlag = 0;
//string sFaceData = "";
//int iFaceLength = 0;
//int iFaceIndex = 50;
FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, false);
//Cursor = Cursors.WaitCursor;
FG.m_CZKEMClass.ReadAllUserID(FG.COM_MACHINENUMBER);//read all the user information to the memory
FG.m_CZKEMClass.ReadAllTemplate(FG.COM_MACHINENUMBER);//read all the users' fingerprint templates to the memory
while (FG.m_CZKEMClass.SSR_GetAllUserInfo(FG.COM_MACHINENUMBER, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled))//get all the users' information from the memory
{
DataRow newdr = dt.NewRow();
newdr["EnrollNumber"] = sdwEnrollNumber.ToString();
newdr["UserName"] = sName.ToString();
newdr["Privilege"] = iPrivilege;
newdr["MPassword"] = sPassword;
newdr["IsEnabled"] = bEnabled;
dt.Rows.Add(newdr);
}
FG.m_CZKEMClass.EnableDevice(FG.COM_MACHINENUMBER, true);
}
else
{
st = dr["MachineNumber"].ToString() + "指纹机连接失败";
}
}
}
}