-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
179 lines (151 loc) · 6.38 KB
/
Copy pathmainwindow.cpp
File metadata and controls
179 lines (151 loc) · 6.38 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QRandomGenerator>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_ptrStuSql(nullptr)
{
ui->setupUi(this);
m_dlgLogin.show();
auto f = [&](){
this->show();
};
connect(&m_dlgLogin, &Page_login::sendLoginSuccess, this, f);
// 左侧 treeWidget 初始化
ui -> treeWidget -> clear();
ui -> treeWidget -> setColumnCount(1);
QTreeWidgetItem *fp = new QTreeWidgetItem(ui->treeWidget, QStringList("学生管理系统"));
ui -> treeWidget -> addTopLevelItem(fp);
ui -> treeWidget -> addTopLevelItem(new QTreeWidgetItem(fp, QStringList("学生管理")));
ui -> treeWidget -> addTopLevelItem(new QTreeWidgetItem(fp, QStringList("管理员管理")));
m_ptrStuSql = stuSql::getInstance();
m_lNames = {
"赵思远", "钱梦瑶", "孙宇航", "李子萱", "周俊杰", "吴紫妍", "郑泽洋", "王雨桐", "冯思琪", "陈浩宇",
"褚伟", "卫芳", "蒋强", "沈敏", "韩丽", "杨勇", "朱静", "秦磊", "尤娜", "何杰",
"吕思远", "施梦瑶", "张宇航", "孔子萱", "曹俊杰", "严紫妍", "华泽洋", "金雨桐", "魏思琪", "陶浩宇",
"姜伟", "赵芳", "钱强", "孙敏", "李丽", "周勇", "吴静", "郑磊", "王娜", "冯杰",
"陈思远", "褚梦瑶", "卫宇航", "蒋子萱", "沈俊杰", "韩紫妍", "杨泽洋", "朱雨桐", "秦思琪", "尤浩宇",
"何伟", "吕芳", "施强", "张敏", "孔丽", "曹勇", "严静", "华磊", "金娜", "魏杰",
"陶思远", "姜梦瑶", "赵宇航", "钱子萱", "孙俊杰", "卫紫妍", "李泽洋", "周雨桐", "冯思琪", "陈浩宇",
"褚伟", "卫芳", "蒋强", "沈敏", "韩丽", "杨勇", "朱静", "秦磊", "尤娜", "何杰",
"吕思远", "施梦瑶", "张宇航", "孔子萱", "曹俊杰", "严紫妍", "华泽洋", "金雨桐", "魏思琪", "陶浩宇",
"姜伟", "赵芳", "钱强", "孙敏", "李丽", "周勇", "吴静", "郑磊", "王娜", "冯杰",
"陈思远", "褚梦瑶", "卫宇航", "蒋子萱", "沈俊杰", "韩紫妍", "杨泽洋", "朱雨桐", "秦思琪", "尤浩宇",
"何伟", "吕芳", "施强", "张敏", "孔丽", "曹勇", "严静", "华磊", "金娜", "魏杰"
};
stuRefresh();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btn_exit_clicked()
{
exit(0);
}
void MainWindow::on_btn_simul_clicked()
{
StuInfo info;
QRandomGenerator g;
g.seed(0);
for(int i = 0; i < m_lNames.size(); i ++){
info.id = i+1;
info.name = m_lNames[i];
info.age = g.bounded(10, 18);
info.grade = g.bounded(7, 10);
info.uiclass = g.bounded(1, 10);
info.phone = g.bounded(1000000, 9999999);
info.wechat = "wechat";
m_ptrStuSql -> addStu(info);
}
stuRefresh();
}
void MainWindow::on_btn_refresh_clicked()
{
stuRefresh();
}
// 学生表格页面刷新
void MainWindow::stuRefresh()
{
auto cnt = m_ptrStuSql -> getStuCnt();
QList<StuInfo> lStudents = m_ptrStuSql -> getPageStu(0, cnt);
ui -> tableWidget -> clearContents();
ui -> tableWidget -> setRowCount(cnt);
for(int i = 0; i < lStudents.size(); i ++){
ui -> tableWidget -> setItem(i, 0, new QTableWidgetItem(QString::number(lStudents[i].id)));
ui -> tableWidget -> setItem(i, 1, new QTableWidgetItem(lStudents[i].name));
ui -> tableWidget -> setItem(i, 2, new QTableWidgetItem(QString::number(lStudents[i].age)));
ui -> tableWidget -> setItem(i, 3, new QTableWidgetItem(QString::number(lStudents[i].grade)));
ui -> tableWidget -> setItem(i, 4, new QTableWidgetItem(QString::number(lStudents[i].uiclass)));
ui -> tableWidget -> setItem(i, 5, new QTableWidgetItem(QString::number(lStudents[i].phone)));
ui -> tableWidget -> setItem(i, 6, new QTableWidgetItem(lStudents[i].wechat));
}
}
void MainWindow::userRefresh()
{
}
void MainWindow::on_btn_add_clicked()
{
StuInfo info;
info.id = -1;
info.name = NULL;
info.age = -1;
info.grade = -1;
info.uiclass = -1;
info.phone = -1;
info.wechat = NULL;
m_dlg_add_stu.setType(false, info);
m_dlg_add_stu.exec();
stuRefresh();
}
void MainWindow::on_btn_revise_clicked()
{
StuInfo info;
int i = ui->tableWidget->currentRow();
if(i >= 0){
info.id = ui -> tableWidget -> item(i, 0) -> text().toUInt();
info.name = ui -> tableWidget -> item(i, 1) -> text();
info.age = ui -> tableWidget -> item(i, 2) -> text().toUInt();
info.grade = ui -> tableWidget -> item(i, 3) -> text().toUInt();
info.uiclass = ui -> tableWidget -> item(i, 4) -> text().toUInt();
info.phone = ui -> tableWidget -> item(i, 5) -> text().toUInt();
info.wechat = ui -> tableWidget -> item(i, 6) -> text();
}
m_dlg_add_stu.setType(true, info);
m_dlg_add_stu.exec();
stuRefresh();
}
void MainWindow::on_btn_delete_clicked()
{
int i = ui -> tableWidget -> currentRow();
if(i >= 0){
int id = ui -> tableWidget -> item(i, 0) -> text().toUInt();
m_ptrStuSql -> delStu(id);
stuRefresh();
}
}
void MainWindow::on_btn_search_clicked()
{
auto ptr = stuSql::getInstance();
int id = ui -> search_id -> text().toUInt();
if(!ptr->isIdExist(id)){
QMessageBox::warning(this, "ID 不存在", "该 ID 不存在,请输入其他 ID。");
}else{
int i = ptr->searchId(id)+1;
StuInfo info;
if(i >= 0){
info.id = ui -> tableWidget -> item(i, 0) -> text().toUInt();
info.name = ui -> tableWidget -> item(i, 1) -> text();
info.age = ui -> tableWidget -> item(i, 2) -> text().toUInt();
info.grade = ui -> tableWidget -> item(i, 3) -> text().toUInt();
info.uiclass = ui -> tableWidget -> item(i, 4) -> text().toUInt();
info.phone = ui -> tableWidget -> item(i, 5) -> text().toUInt();
info.wechat = ui -> tableWidget -> item(i, 6) -> text();
}
m_dlg_add_stu.setType(true, info);
m_dlg_add_stu.exec();
}
stuRefresh();
}