-
Notifications
You must be signed in to change notification settings - Fork 1
/
sign_in.cpp
87 lines (70 loc) · 2.09 KB
/
sign_in.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
#include "sign_in.h"
#include "ui_sign_in.h"
sign_In::sign_In(QWidget *parent) :
QDialog(parent),
ui(new Ui::sign_In)
{
ui->setupUi(this);
readCard=ReadCard::getReadCard();
connect(readCard,SIGNAL(readSuccess(QString,QString)),this,SLOT(readCardSucc(QString,QString)));
}
sign_In::~sign_In()
{
delete ui;
}
ReadCard *sign_In::getReadCard()
{
return this->readCard;
}
void sign_In::setReadCard(ReadCard *reader)
{
this->readCard=reader;
}
void sign_In::on_pushButton_clicked()
{
this->hide();
this->ui->textBrowser->setText("");
this->ui->label_2->setText("请刷卡......");
parentWidget()->show();
readCard->stop();
}
void sign_In::readCardSucc(QString uid, QString resType)
{
if(resType!=QString(SIGN_IN)) return;
StudentDAO stuDao;
stu=stuDao.findByUId(Util::toStdString(uid));
QString now=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
string startTime=Util::toStdString(now);
#ifdef DEBUG
qDebug()<<Util::toQString(startTime);
#endif
Record record=Record();
record.setStartTime(startTime);
record.setEndTime(startTime);
record.setCount(0);
record.setStuId(stu.getId());
RecordDao rcdDao;
Record last=rcdDao.findLastByStuId(stu.getId());
if(last.getStartTime().empty()){
ui->textBrowser->setText("数据库访问异常......");
return;
}
//已存在签到记录
if(last.getStartTime()==last.getEndTime()){
ui->textBrowser->setText("请勿重复签到......");
return;
}
bool flag=rcdDao.insert(record);
if(flag){
ui->label_2->setText("签到成功......");
list<Record> records=rcdDao.queryByStuIdDesc(stu.getId());
string strRecord="*签到记录*";
strRecord.append(stu.getName());
strRecord.append("*\r\n");
Util::setRecords(ui->textBrowser,records,strRecord);
}else{ui->label_2->setText("签到失败......");}
}
void sign_In::closeEvent(QCloseEvent *event)
{
getReadCard()->stop();
}