-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
170 lines (145 loc) · 4.95 KB
/
mainwindow.cpp
File metadata and controls
170 lines (145 loc) · 4.95 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
database = new SqliteDatabase();
getData();
initGUI();
showDept();
showHisDialog();
PersonManagement();
AbsentManageButton();
DptManageButton();
showWorkPerNum();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::getData()
{
m_depts = database->getDeptData();
m_pers = database->getWorkPerData();
}
void MainWindow::initGUI()
{
for(int i = 0; i < m_depts.size(); i++) {
auto widget = new SingleRow(this->ui->widgetBig);
widget->move(10, i * 50);
// widget->setLabelVisible(true);
connect(widget->chooseButton(), &QPushButton::clicked, widget->lineEdit(), [=](){
QPair<int, QString> str = database->getRanPerString(widget->spinBoxNum(), i+1, m_pers);
m_readPersons[i] = str;
refreshSingleRow(i);
});
connect(widget->cancelButton(), &QPushButton::clicked, widget->lineEdit(), [=](){
m_readPersons[i] = {};
refreshSingleRow(i);
});
singleRows.append(widget);
}
connect(ui->checkButton, &QPushButton::clicked, [=](){
QVector<selectRecord> pickResultVec;
// current_date字符串结果为"2016.05.20 12:17:01.445 周五"
QDateTime current_date_time =QDateTime::currentDateTime();
QString current_date =current_date_time.toString("yyyy.MM.dd hh:mm:ss");
for(const auto& deptChoosenPersons: m_readPersons){
QString tempDept;
if(deptChoosenPersons.second.size()){
qDebug() << deptChoosenPersons.first << ": " << deptChoosenPersons.second;
database->writePickHis(current_date_time, deptChoosenPersons.first, deptChoosenPersons.second);
for(auto dept : m_depts){
if(dept.id == deptChoosenPersons.first){
tempDept = dept.deptName;
}
}
pickResultVec.push_back({tempDept, deptChoosenPersons.second});
}
}
// 清除
for(const auto& singleRow: singleRows){
auto index = singleRows.indexOf(singleRow);
singleRow->setLabelVisible(false);
m_readPersons[index] = {};
refreshSingleRow(index);
}
// 新加
auto pickResultDiagram = new PickResultDiagram();
pickResultDiagram->refresh(pickResultVec, current_date);
pickResultDiagram->setWindowModality(Qt::ApplicationModal);
pickResultDiagram->show();
});
for(const auto& singleRow: singleRows){
connect(singleRow->deptLabel(), &QPushButton::clicked, [=](){
for(const auto& singleRowTmp: singleRows){
auto index = singleRows.indexOf(singleRowTmp);
if(singleRow == singleRowTmp){
singleRowTmp->setLabelVisible(true);
} else {
singleRowTmp->setLabelVisible(false);
m_readPersons[index] = {};
refreshSingleRow(index);
}
}
});
}
}
void MainWindow::showDept()
{
for(int i = 0; i < m_depts.size(); i++) {
singleRows[i]->setDeptLabel(m_depts[i].deptName);
}
}
void MainWindow::refreshSingleRow(int line)
{
auto widget = singleRows[line];
widget->setLineEdit(m_readPersons[line].second);
}
void MainWindow::showWorkPerNum()
{
auto depts = database->getDeptData();
for(int i = 0; i < depts.size(); i++){
auto widget = singleRows[i];
widget->refresh(i + 1);
}
}
void MainWindow::showHisDialog()
{
connect(ui->hisShowButton, &QPushButton::clicked, [=](){
auto hisDiagram = new HistoryShow();
// 只显示一个窗体
hisDiagram->setWindowModality(Qt::ApplicationModal);
hisDiagram->setModal(true);
hisDiagram->setAttribute(Qt::WA_ShowModal, true);
m_his = database->getHisData();
hisDiagram->refresh(m_his, m_depts);
hisDiagram->show();
});
}
void MainWindow::PersonManagement()
{
connect(ui->personManageButton, &QPushButton::clicked, [=](){
PersonManageDialog* personManageDialog = new PersonManageDialog();
personManageDialog->setWindowModality(Qt::ApplicationModal);
personManageDialog->show();
});
}
void MainWindow::AbsentManageButton()
{
connect(ui->absentButton, &QPushButton::clicked, [=](){
AbsenceManageDialog* absenceManageDialog = new AbsenceManageDialog();
absenceManageDialog->setWindowModality(Qt::ApplicationModal);
absenceManageDialog->show();
});
}
void MainWindow::DptManageButton()
{
connect(ui->dptManageButton, &QPushButton::clicked, [=](){
DptManageDialog* dptManageDialog = new DptManageDialog();
dptManageDialog->setWindowModality(Qt::ApplicationModal);
dptManageDialog->show();
});
}