-
Notifications
You must be signed in to change notification settings - Fork 1
/
window.cpp
582 lines (489 loc) · 17.3 KB
/
window.cpp
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
#include "window.h"
#define GOD 0
extern char Is_AYmark;
Window::Window(QWidget *parent): QWidget(parent)
{
RFIDReader = new Reader;
memset(RFIDReader->PileNumber, 0, 13);
QGridLayout *grid = new QGridLayout;
grid->addWidget((QWidget*)createInputPileGroup(), 0, 0);
grid->addWidget((QWidget*)createChargingModeGroup(), 0, 1);
grid->addWidget((QWidget*)createWriteButtonGroup(), 1, 0);
grid->addWidget((QWidget*)createReadButtonGroup(), 1, 1);
grid->addWidget((QWidget*)createsavetextGroup(), 2, 0,1,0);
grid->addWidget((QWidget*)createcleanButtonGroup(), 3, 0,Qt::AlignLeft);
grid->addWidget((QWidget*)createsavebutGroup(),3,1,Qt::AlignRight);
grid->addWidget((QWidget*)createhelpbutGroup(),3,0,1,0,Qt::AlignHCenter);
//http://bbs.csdn.net/topics/360067516
setLayout(grid);
QIcon tem(":/new/prefix/1");
setWindowIcon(tem);
setWindowTitle(tr("埃士读写卡助手 V5.0 "));
resize(700,500);
if (!RFIDReader->LoadDll())
{
QMessageBox msgBox;
msgBox.setText("库文件装载失败!");
msgBox.exec();
parent->close();
}
}
QGroupBox *Window::createInputPileGroup()
{
QGroupBox *groupBox = new QGroupBox(tr("桩号[13] 写卡模式选择"));
checkbox01 = new QRadioButton (tr("写卡后桩号自动+1 卡号不变"));
checkbox02 = new QRadioButton (tr("写卡后卡号自动+1 桩号不变"));
checkbox03 = new QRadioButton (tr("写卡后卡号不变 桩号不变"));
checkbox01->setChecked(true);
lineEdit5 = new QLineEdit();
lineEdit5->setMaxLength(13);
lineEdit5->setText("E0043B7071000");
connect(lineEdit5,SIGNAL(returnPressed()),this,SLOT(on_lineEdit_returnPressed()));
connect( checkbox02,SIGNAL(toggled(bool)),this,SLOT(on_checkbox_Pressed(bool) ));
// clicked(bool)不好 上面的好!
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(lineEdit5);
vbox->addWidget(checkbox01);
vbox->addWidget(checkbox02);
vbox->addWidget(checkbox03);
vbox->addStretch(1);
groupBox->setLayout(vbox);
return groupBox;
}
void Window::on_checkbox_Pressed(bool a)
{
if( a )
{
popupButton3->show();
lineEdit8->show();
}
else
{
popupButton3->hide();
lineEdit8->hide();
}
}
QGroupBox *Window::createChargingModeGroup()
{
QGroupBox *groupBox = new QGroupBox(tr("卡号[15] 对应桩号显示 "));
lb1 = new QLabel(QWidget::tr(" 对应桩号"));
lineEdit6 = new QLineEdit();
lineEdit6->setMaxLength(13);
lineEdit6->setText("");
lb2 = new QLabel(QWidget::tr(" 卡片卡号"));
lineEdit7 = new QLineEdit();
lineEdit7->setMaxLength(15);
lineEdit7->setText("");
popupButton3 = new QPushButton(tr("设置卡号起点"));
lineEdit8 = new QLineEdit();
lineEdit8->setMaxLength(2);
lineEdit8->setText("");
popupButton3->hide();
lineEdit8->hide();
connect(popupButton3, SIGNAL(clicked()),this, SLOT(isCheckedButton3()));
QGridLayout *grid = new QGridLayout;
grid->addWidget(lb1, 0, 0);
grid->addWidget(lineEdit6, 0, 1);
grid->addWidget(lb2, 1, 0);
grid->addWidget(lineEdit7, 1, 1);
grid->addWidget(popupButton3, 2, 0);
grid->addWidget(lineEdit8, 2, 1);
grid -> setColumnStretch(0, 1);
grid -> setColumnStretch(1, 3);
groupBox->setLayout(grid);
return groupBox;
}
QGroupBox *Window::createcleanButtonGroup()
{
QGroupBox *groupBox = new QGroupBox();
popupButton6= new QPushButton(tr("写管理员卡"));
QIcon tem(":/new/prefix/2");
popupButton6->setIcon(tem);
popupButton6->setIconSize(QSize(180,30));
connect(popupButton6, SIGNAL(clicked()),this, SLOT(isCheckedButton6()));
// popupButton6->setEnabled(false);// ->setCheckable(false);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(popupButton6);
vbox->addStretch(1);
groupBox->setLayout(vbox);
return groupBox;
}
QGroupBox *Window::createsavetextGroup()
{
QGroupBox *groupBox = new QGroupBox(tr(""));
textBrowser = new QTextBrowser;
textBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
textBrowser->setTextColor(Qt::blue);//Qt::lightGray
connect(textBrowser, SIGNAL(textChanged()),this, SLOT(on_textBrowser_textChanged()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(textBrowser);
vbox->addStretch(1);
groupBox->setLayout(vbox);
return groupBox;
}
QGroupBox *Window::createsavebutGroup()
{
QGroupBox *groupBox = new QGroupBox();
popupButton7 = new QPushButton(tr("保存写卡记录"));
QIcon tem(":/new/prefix/2");
popupButton7->setIcon(tem);
popupButton7->setIconSize(QSize(180,30));
connect(popupButton7, SIGNAL(clicked()),this, SLOT(isCheckedButton7()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(popupButton7);
vbox->addStretch(1);
groupBox->setLayout(vbox);
return groupBox;
}
QGroupBox *Window::createhelpbutGroup()
{
QGroupBox *groupBox = new QGroupBox();
popupButton7 = new QPushButton(tr("帮助"));
QIcon tem(":/new/prefix/2");
popupButton7->setIcon(tem);
popupButton7->setIconSize(QSize(30,30));
connect(popupButton7, SIGNAL(clicked()),this, SLOT(isCheckedButtonhelp()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(popupButton7);
vbox->addStretch(0);
groupBox->setLayout(vbox);
return groupBox;
}
void Window::on_lineEdit_returnPressed()
{
}
void Window:: isCheckedButtonhelp()
{
QMessageBox msgBox;
msgBox.setText(" 软件说明\n\n\
1电脑连接读卡器,左上角输入框键入桩号,点击写卡。\n\n\
2严格执行桩号13位,卡号15位的规则,故桩号苛求13位。\n\n\
3写卡后桩号+1卡号不变,例如本次键入桩号ASP2017110217,\n\点击写卡,写出卡号ASP201711021700。随后桩号自动变成ASP2017110218,\n\换一张卡再次点击写卡,写出卡号成ASP201711021800\n\n\
4写卡后卡号+1桩号不变,例如本次键入桩号ASP2017110217,\n\点击写卡,写出卡号ASP201711021700。随后桩号依旧保持ASP2017110217,\n\换一张卡再次点击写卡,写出卡号成ASP201711021801\n\n\
5写卡后卡号桩号都不变,例如本次键入桩号ASP2017110217,\n\点击写卡,写出卡号ASP201711021700。随后每次写卡都如初\n\n\
6写卡以后可以点击读卡,确认写卡如你所愿。\n\n\
7软件下方显示桩号和卡号的对应关系,保存按键,方便工作存档。\n\n\
8左下角添加管理员卡,与输入桩号无关,软件强行写入管理员卡号。\n\n\
9新增:写卡后卡号+1桩号不变模式时可以手动设置卡号起点。\n\n" );
msgBox.exec();
}
void Window::isCheckedButton3()
{
#if 0
if(memcmp("A1SM1P",lineEdit8->text().toLatin1(),6)==0||memcmp("a1sm1p",lineEdit8->text().toLatin1(),6)==0)
/*.toLatin1()一句话QStr转char**/
{
popupButton6->setEnabled(true);
QMessageBox::information(this, "提示消息", tr("授权成功"), QMessageBox::Ok);
}
else
{
popupButton6->setEnabled(false);
QMessageBox::information(this, "提示消息", tr("貌似没有输入正确的密码呀"), QMessageBox::Ok);
}
# endif
QString str=lineEdit8->text();/*拿到QSTR*/
bool ok;
int dec=str.toInt(&ok,10); //dec=255 ; ok=rue
if(ok)
{
if(dec<10&&dec>=0)
{
RFIDReader->ADDA=0;
RFIDReader->ADDB=dec-1;
}
else if(dec<153)//0x99
{
RFIDReader->ADDA=str.mid(0,1).toInt(&ok,10);
RFIDReader->ADDB=str.mid(1,1).toInt(&ok,10)-1;
}
QMessageBox::information(this, "提示消息", tr("卡号结尾已经设置好"), QMessageBox::Ok);
}
else
QMessageBox::information(this, "提示消息", tr("貌似并不是0-99的数据哦"), QMessageBox::Ok);
}
/*龚金华版本*/
bool flypage=false;
void Window::isCheckedButton6()
{
const unsigned char admin[16]={0x12,0x34,0x56,0x78,0xED,0xCB,0xFF,0x07,0x80,0x69,0x56,0x78,0x01,0xFE,0x01,0xFE};
#if GOD
if(1)
#else
if(flypage)
#endif
{
memcpy(RFIDReader->CardNumber, admin, 16);
if(RFIDReader->writeAllBlk())
QMessageBox::information(this, "提示消息", tr("写管理员成功"), QMessageBox::Ok);
else
QMessageBox::information(this, "提示消息", tr("写管理员失败!!"), QMessageBox::Ok);
memset(RFIDReader->CardNumber, 0, 16);
flypage=false;
}
else
{
Password = new password();
Password->resize(180,80);
Password->show();
}
}
void Window::isCheckedButton7()
{
if(textBrowser->toPlainText().isEmpty())
{
QMessageBox::information(this, "提示消息", tr("貌似还没有数据记录哦!"), QMessageBox::Ok);
return;
}
QString filename = QFileDialog::getSaveFileName(this, tr("另存为"), tr("未命名.txt"));
QFile file(filename);
//如果用户取消了保存则直接退出函数
if(file.fileName().isEmpty())
{
return;
}
//如果打开失败则给出提示并退出函数
if(!file.open(QFile::WriteOnly | QIODevice::Text))
{
QMessageBox::warning(this, tr("保存文件"), tr("打开文件 %1 失败, 无法保存\n%2").arg(filename).arg(file.errorString()), QMessageBox::Ok);
return;
}
//写数据到文件
QTextStream out(&file);
out<<textBrowser->toPlainText();
file.close();
//修改窗口标题为保存文件路径
setWindowTitle("saved: " + QFileInfo(filename).canonicalFilePath());
}
QGroupBox *Window::createWriteButtonGroup()
{
QGroupBox *groupBox = new QGroupBox();
QPushButton *pushButton = new QPushButton(tr("写卡"));
QIcon tem(":/new/prefix/2");
pushButton->setIcon(tem);
pushButton->setFont(QFont( "Times", 25, QFont::Bold ) );/*字体*/
pushButton->setIconSize(QSize(80,110));
pushButton->setFlat(false);
connect(pushButton, SIGNAL(clicked()),this, SLOT(writeButtonClicked()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(pushButton);
vbox->addStretch(1);
groupBox->setLayout(vbox);
return groupBox;
}
QGroupBox *Window::createReadButtonGroup()
{
QGroupBox *groupBox = new QGroupBox();
QPushButton *pushButton = new QPushButton(tr("读卡"));
QIcon tem(":/new/prefix/2");
pushButton->setIcon(tem);
pushButton->setIconSize(QSize(80,110));
pushButton->setFlat(false);
pushButton->setFont(QFont( "Times", 25, QFont::Bold ) );/*字体*/
connect(pushButton, SIGNAL(clicked()),this, SLOT(readButtonClicked()));
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(pushButton);
vbox->addStretch(1);
groupBox->setLayout(vbox);
return groupBox;
}
void Window::writeButtonClicked()
{
memset(RFIDReader->PileNumber, 0, 13);
#if GOD
if(!QString(lineEdit5->text()).isEmpty())
#else
if(QString(lineEdit5->text()).length()==13)//龚金华修改
#endif
{
QByteArray ByteArray = lineEdit5->text().toLatin1();
memcpy(RFIDReader->PileNumber, ByteArray.data(), lineEdit5->text().size());
}
else
{
QMessageBox msgBox;
msgBox.setText("桩号貌似并不是13位呀");
msgBox.exec();
}
/*处理桩号++*/
if(checkbox01->isChecked())
{
ForPlusPlusLog1();
QString str = lineEdit5->text();/*拿到QSTR*/
QString last3old = str.mid(10,3);/*拿到QSTR结尾3个*/
int last3plus = last3old.toInt()+1;/*转化QSTR结尾3个为int*/
if(last3plus<=999)
{
QString last3new=QString::number(last3plus, 10);/*int转QSTR*/
QString tem1="0",tem2="00";
if(last3new.length()==1)
{
tem2+=last3new;
str.replace(10,3,tem2);
}
else if(last3new.length()==2)
{
tem1+=last3new;
str.replace(10,3,tem1);
}
else
str.replace(10,3,last3new);
lineEdit5->setText( str );
}
else
{
QMessageBox msgBox;
msgBox.setText("桩号流水已经0--999不能再写了!");
msgBox.exec();
}
}
/*处理卡号++*/
if(checkbox02->isChecked())
{
QString str = lineEdit5->text();
lineEdit5->setText( str );
ForPlusPlusLog2();
}
/*不变*/
if(checkbox03->isChecked())
{
RFIDReader->ADDA=0;
RFIDReader->ADDB=0;
}
if(RFIDReader->writeAllBlk())
{
RFIDReader->PtoC_Conversion();
static QString filestr = 0;
filestr += "桩号";
filestr+=lineEdit5->displayText();
filestr+="------>卡号";
QString strtem = QString( (char*)RFIDReader->CardNumber );/*char*转QSTR*/
strtem=strtem.mid(0,15);/*遗留问题后面有乱码所以我就拿前面15个*/
filestr += strtem;
filestr += "\n";
textBrowser->setText(filestr);
}
else
{
if(Is_AYmark==0)
{
QMessageBox msgBox;
msgBox.setText("写卡失败");
msgBox.exec();
}
else
{
Is_AYmark=0;
QMessageBox msgBox;
msgBox.setText("该卡为安悦卡,请勿写卡");
msgBox.exec();
}
}
}
void Window::ForPlusPlusLog1(void)
{
RFIDReader->ADDA=0;
RFIDReader->ADDB=0;
}
void Window::ForPlusPlusLog3(void)
{
}
void Window::ForPlusPlusLog2(void)
{
if(RFIDReader->ADDA<=9)
{
if(RFIDReader->ADDB==9)
{
RFIDReader->ADDA+=1;
RFIDReader->ADDB = 0;
}
else
{
RFIDReader->ADDB++;
}
}
else
{
QMessageBox msgBox;
msgBox.setText("write over 100!");
msgBox.exec();
}
}
void Window::readButtonClicked()
{
QMessageBox msgBox;
if(!RFIDReader->readAllBlk())
{
msgBox.setText("读卡失败!");
msgBox.exec();
return;
}
else
{
if(RFIDReader->CardNumber[0]==0x12&&
RFIDReader->CardNumber[1]==0x34&&
RFIDReader->CardNumber[2]==0x56&&
RFIDReader->CardNumber[3]==0x78&&
RFIDReader->CardNumber[4]==0xED&&
RFIDReader->CardNumber[5]==0xCB&&
RFIDReader->CardNumber[12]==0x01)
{
lineEdit6->setText("管理员");
lineEdit7->setText("管理员");
msgBox.setText("管理员卡");
msgBox.exec();
memset(RFIDReader->CardNumber, 0, 15);
}
else
{
RFIDReader->CtoP_Conversion();
lineEdit6->setText(QString(((char *)RFIDReader->PileNumber)));
lineEdit7->setText(QString(QLatin1String((char *)RFIDReader->CardNumber)));
// msgBox.setText("读卡成功");
// msgBox.exec();
memset(RFIDReader->CardNumber, 0, 15);
}
}
}
//https://wenku.baidu.com/view/5d4c8b3a804d2b160b4ec0cc.html 移动
void Window::on_textBrowser_textChanged()
{
textBrowser->moveCursor(QTextCursor::End);
}
void Window::mouseDoubleClickEvent(QMouseEvent *event)
{
QMessageBox msgBox;
// 如果是鼠标左键按下
if(event->button() == Qt::LeftButton)
{
msgBox.setText(" 软件说明\n\n\
1电脑连接读卡器,左上角输入框键入桩号,点击写卡。\n\n\
2严格执行桩号13位,卡号15位的规则,故桩号苛求13位。\n\n\
3写卡后桩号+1卡号不变,例如本次键入桩号ASP2017110217,\n\点击写卡,写出卡号ASP201711021700。随后桩号自动变成ASP2017110218,\n\换一张卡再次点击写卡,写出卡号成ASP201711021800\n\n\
4写卡后卡号+1桩号不变,例如本次键入桩号ASP2017110217,\n\点击写卡,写出卡号ASP201711021700。随后桩号依旧保持ASP2017110217,\n\换一张卡再次点击写卡,写出卡号成ASP201711021801\n\n\
5写卡后卡号桩号都不变,例如本次键入桩号ASP2017110217,\n\点击写卡,写出卡号ASP201711021700。随后每次写卡都如初\n\n\
6写卡以后可以点击读卡,确认写卡如你所愿。\n\n\
7软件下方显示桩号和卡号的对应关系,保存按键,方便工作存档。\n\n\
8左下角添加管理员卡,与输入桩号无关,软件强行写入管理员卡号。\n\n\
9新增:写卡后卡号+1桩号不变模式时可以手动设置卡号起点。\n\n" );
msgBox.exec();
}
}
void Window::mousePressEvent(QMouseEvent *event)
{
#if 0
QMessageBox msgBox;
// 如果是鼠标左键按下
if(event->button() == Qt::LeftButton)
{
msgBox.setText("瞎点什么左键!");
msgBox.exec();
}
// 如果是鼠标右键按下
else if(event->button() == Qt::RightButton)
{
msgBox.setText("瞎点什么右键!");
msgBox.exec();
}
#endif
}