Repository navigation
Expand file tree
/
Copy pathpersonmanagedialog.cpp
More file actions
203 lines (180 loc) · 6.12 KB
/
Copy pathpersonmanagedialog.cpp
File metadata and controls
203 lines (180 loc) · 6.12 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
#include "personmanagedialog.h"
#include "ui_personmanagedialog.h"
PersonManageDialog::PersonManageDialog(QWidget *parent) :
QWidget(parent),
ui(new Ui::PersonManageDialog)
{
ui->setupUi(this);
this->setWindowTitle("人员管理界面");
ui->changePersonButton->setVisible(false);
connect(ui->closeButton, &QPushButton::clicked, [=](){this->close();});
connect(ui->submitButton, &QPushButton::clicked, [=](){
submitStatePage();
});
getData();
// newSetTableWidgetValue();
initWidget();
refreshWidget();
selectFirstPerson(getDeptId(0));
database = new SqliteDatabase();
connect(ui->addPersonButton, &QPushButton::clicked, [=](){
addPersonButton();
});
connect(ui->deleteButton, &QPushButton::clicked, [=](){
deletePersonButton();
});
connect(ui->changePersonButton, &QPushButton::clicked, [=](){
changePersonButton();
});
connect(ui->searchPersonButton, &QPushButton::clicked, [=](){
searchPersonButton();
});
connect(ui->tabWidget, &QTabWidget::currentChanged, [=](int index){
selectFirstPerson(getDeptId(index));
});
}
PersonManageDialog::~PersonManageDialog()
{
delete ui;
}
void PersonManageDialog::newSetTableWidgetValue()
{
}
void PersonManageDialog::getData()
{
m_pers = database->getEveryPerData();
m_depts = database->getDeptData();
m_state = database->getState();
tabTitleVec.clear();
for(auto dept: m_depts){
tabTitleVec.push_back(dept.deptName);
}
}
void PersonManageDialog::addPersonButton()
{
// 待做:重名检测
int curDeptNumMinus = ui->tabWidget->currentIndex();
QString curDeptName = ui->tabWidget->tabBar()->tabText(curDeptNumMinus);
qDebug() << "curDeptName"<< curDeptName << "curDeptNumMinus" << curDeptNumMinus;
AddPersonDialog* addPerDlg = new AddPersonDialog(curDeptName, [=](){
getData();
refreshWidget();
});
}
void PersonManageDialog::deletePersonButton()
{
int curDeptNumMinus = ui->tabWidget->currentIndex();
int deptId = getDeptId(curDeptNumMinus);
auto table = personShowTable[deptId];
auto currentRow = table->currentRow();
qDebug() << currentRow;
if(currentRow != -1){
ConfirmSthDialog* confirmDeleteDialog = new ConfirmSthDialog([=](){
auto pers = m_pers[deptId];
// qDebug() << table->rowCount();
auto per = pers[currentRow];
// qDebug() << per.perName<<per.absent<<per.deptId<<per.id;
if(database->manageDeletePerson(per.id, deptId)){
getData();
refreshWidget();
}
});
confirmDeleteDialog->show();
confirmDeleteDialog->setWindowModality(Qt::ApplicationModal);
confirmDeleteDialog->setLabelText("删除后不可恢复,您确认删除?");
confirmDeleteDialog->setWindowTitle("提示弹窗");
}
}
void PersonManageDialog::changePersonButton()
{
int curDeptNum = ui->tabWidget->currentIndex() + 1;
}
void PersonManageDialog::searchPersonButton()
{
SearchPersonDialog* searchPerDlg = new SearchPersonDialog();
searchPerDlg->setWindowModality(Qt::ApplicationModal);
searchPerDlg->show();
}
void PersonManageDialog::submitStatePage()
{
int deptId = 1;
int stateType;
for(auto &table: personShowTable){ // 遍历每一个表格/一个处室一个表
for(int i = 0; i < table->rowCount(); i++){ // 遍历每一行的状态量/重写m_pers的absent值
auto combox = reinterpret_cast<QComboBox*>(table->cellWidget(i, 1));
int count = 0;
for(auto state: m_state){
count++;
if(state == combox->currentText()){
stateType = m_state.key(state);
break;
}
}
m_pers[deptId][i].absent = stateType;
}
deptId++;
}
database->writeSqlPerState(m_pers);
}
void PersonManageDialog::initWidget()
{
for(auto dept: m_depts){
QTableWidget* table = new QTableWidget(ui->tabWidget);
if(nullptr != table)
table->setRowCount(0);
table->insertColumn(2);
headList << "名字" << "状态";
table->setColumnCount(2);
table->setHorizontalHeaderLabels(headList);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
table->setFocus();
table->setCurrentCell(0, 0);
personShowTable[dept.id] = table; // 表格初始化
ui->tabWidget->addTab(table, tabTitleVec[dept.id-1]); // 处室初始化
}
ui->tabWidget->tabBar()->setStyle(new CustomTabStyle);
}
void PersonManageDialog::refreshWidget()
{
for(auto dept: m_depts){
auto table = personShowTable[dept.id];
table->clearContents();
table->setRowCount(0);
for (auto &per : m_pers[dept.id]) {
int col = 0;
int row = table->rowCount();
table->insertRow(row);
QTableWidgetItem *firstPerName=new QTableWidgetItem();//创建一个Item
firstPerName->setText(per.perName);//设置内容
table->setItem(row,col,firstPerName);//把这个Item加到第一行第二列中
table->item(row,col)->setTextAlignment(Qt::AlignCenter);
table->item(row,col++)->setFont(QFont("song", 16));
QComboBox *classBox = new QComboBox;
for(auto state: m_state){
classBox->addItem(state);
}
table->setCellWidget(row, col++, classBox);
QString currentState = m_state[per.absent];
classBox->setCurrentText(currentState);
}
}
}
int PersonManageDialog::getDeptId(int index)
{
int deptId = -1;
QString curDeptName = ui->tabWidget->tabBar()->tabText(index);
for(auto dept: m_depts){
if(dept.deptName == curDeptName){
deptId = dept.id;
break;
}
}
return deptId;
}
void PersonManageDialog::selectFirstPerson(int deptId)
{
auto table = personShowTable[deptId];
table->setFocus();
table->setCurrentCell(0, 0);
}