-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadminwindow.cpp
More file actions
520 lines (481 loc) · 21.3 KB
/
adminwindow.cpp
File metadata and controls
520 lines (481 loc) · 21.3 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
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
#include "adminwindow.h"
#include "ui_adminwindow.h"
AdminWindow::AdminWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::AdminWindow)
{
ui->setupUi(this);
QApplication::setQuitOnLastWindowClosed(true);
// pd=new QProgressDialog("初始化...","取消",0,100,this);
// pd->setWindowModality(Qt::WindowModal);
// pd->setMinimumDuration(5);
// pd->setWindowTitle("请稍后");
// pd->setFixedWidth(300);
// pd->setValue(currentValue);
// pd->show();
// timer=new QTimer(this);
// connect(timer,SIGNAL(timeout()),this,SLOT(updateProgressDialog()));
// timer->start(100);
//Data* data=Data::getData();
//ui->MsgBoard->append(data->getCurrentTime()+"管理员登录成功");
//登陆后首先需要连接数据库
DataQuery *query=DataQuery::getDataQuery();
QString result=query->connectToDatabase("sa","9638527410.s");
if(result==""){
//QMessageBox::information(this,"连接到数据库","数据库连接成功!");
}else{
QMessageBox::warning(this,"连接到数据库",result);
}
// timer->stop();//停止定时器
// if(currentValue != 100)
// currentValue = 100;
// pd->setValue(currentValue);//进度达到最大值
// delete pd;//关闭进度对话框
}
void AdminWindow::updateProgressDialog(){
currentValue++;
if( currentValue == 100 )
currentValue = 0;
pd ->setValue(currentValue);
QCoreApplication::processEvents();//避免界面冻结
if(pd->wasCanceled())
pd->setHidden(true);//隐藏对话框
}
AdminWindow::~AdminWindow()
{
delete ui;
}
//导入课程触发函数
void AdminWindow::on_actionLoadClassFromWeb_triggered()
{
LoadClassFromWebWidget *loadWidget=new LoadClassFromWebWidget();
loadWidget->show();
Data *data=Data::getData();
if(!data->haveLoggedInSIMS){
WebLogWidget *webLogWidget=new WebLogWidget();
webLogWidget->show();
}
}
void AdminWindow::closeEvent(QCloseEvent *event){
qApp->quit();
event->accept();
}
void AdminWindow::on_actionInit_triggered()
{
DataQuery *query=DataQuery::getDataQuery();
if(!query->databaseOnline){
ConnectDabaseWidget *cdwidget=new ConnectDabaseWidget();
cdwidget->show();
}else{
QString result=query->init();
QMessageBox::information(this,"数据库初始化",result);
}
}
void AdminWindow::on_actionAbout_triggered()
{
AboutWidget *aboutwidget=new AboutWidget();
aboutwidget->show();
}
void AdminWindow::on_actionDeptManagement_triggered()
{
DeptWidget *deptwdiget=new DeptWidget();
deptwdiget->show();
}
void AdminWindow::on_actionDatabaseRenew_triggered()
{
QSqlQuery query,query1,query2,query3;
query1.exec("Select name From SysUsers");
if(query1.lastError().type()==QSqlError::NoError){
QStringList list;
while(query1.next()){
list<<query1.value(0).toString();
}
QSqlQuery q;
for(int i=0;i<list.size();i++){
if(list.at(i).size()>=2){
if(list.at(i).at(0)=='S'||list.at(i).at(0)=='T'){
if(list.at(i).at(1)>='0' && list.at(i).at(1)<='9'){
q.exec("EXEC sp_droplogin '"+list.at(i)+"'"+" EXEC sp_dropuser '"+list.at(i)+"'");
if(q.lastError().type()!=QSqlError::NoError) qDebug()<<q.lastError().text();
}
}
}
}
}
query.exec("drop table S2A;drop table T2A;drop table Systbl;drop table ScholarAppli;drop table ScholarLst;drop table ProjectAppli;drop table ProjectLst;drop table CTime;drop table Tcourse;drop table Teacher;drop table Stu_Cour;drop table CourseBasic;drop table Student;drop table Dept");
query2.exec("select identity(int,1,1) flag,[name] names into #tmp from sysobjects where crdate>'2020-12-18' declare @tb varchar(1000) ,@a int,@b int,@sql varchar(8000) select @a=min(flag),@b=max(flag) from #tmp while @a<=@b begin select @tb=names from #tmp where flag=@a set @sql='drop view '+@tb exec(@sql) set @a=@a+1 end DROP TABLE #tmp select * from sysobjects where crdate>'2020-12-18'");
query3.exec("select identity(int,1,1) flag,[name] names into #tmp from sysobjects where crdate>'2020-12-18' declare @tb varchar(1000) ,@a int,@b int,@sql varchar(8000) select @a=min(flag),@b=max(flag) from #tmp while @a<=@b begin select @tb=names from #tmp where flag=@a set @sql='drop user '+@tb exec(@sql) set @a=@a+1 end DROP TABLE #tmp select * from sysobjects where crdate>'2020-12-18'");
if(query.lastError().type()==QSqlError::NoError){
QMessageBox::information(this,"数据库重置","数据库重置成功!");
}else{
QMessageBox::warning(this,"错误",query.lastError().text());
}
}
void AdminWindow::on_FlushButton_clicked()
{
ui->LessonWidget->clearContents();
ui->LessonWidget->setRowCount(0);
QSqlQuery query;
query.exec("select * from CourseBasic");
if(query.lastError().type()==QSqlError::NoError){
while(query.next()){
// ui->DeptMsgWidget->setRowCount(ui->DeptMsgWidget->rowCount()+1);
// ui->DeptMsgWidget->setItem(ui->DeptMsgWidget->rowCount()-1,0,new QTableWidgetItem(query.value(0).toString()));
QString teacher1,teacher2;
Lesson_time lt1,lt2;
bool term1=false,term2=false;
// ui->LessonWidget->setRowCount(ui->LessonWidget->rowCount()+1);
// ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,0,new QTableWidgetItem(query.value(0).toString()));
// ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,1,new QTableWidgetItem(query.value(1).toString()));
QSqlQuery teacherQuery;
teacherQuery.exec("select Cterm,Tname from Tcourse,Teacher where Tcourse.Tno=Teacher.Tno and Cno='"+query.value(0).toString()+"'");
if(teacherQuery.lastError().type()==QSqlError::NoError){
while(teacherQuery.next()){
if(teacherQuery.value(0).toInt()==1){
term1=true;
teacher1+=teacherQuery.value(1).toString()+" ";
}else if(teacherQuery.value(0).toInt()==2){
term2=true;
teacher2+=teacherQuery.value(1).toString()+" ";
}
}
}else{
QMessageBox::warning(this,"错误",teacherQuery.lastError().text());
return;
}
QSqlQuery ltQuery;
ltQuery.exec("select * from CTime where Cno='"+query.value(0).toString()+"'");
if(ltQuery.lastError().type()==QSqlError::NoError){
while(ltQuery.next()){
if(ltQuery.value(1).toInt()==1){
term1=true;
lt1.weekDay.push_back(ltQuery.value(2).toInt());
lt1.begin.push_back(ltQuery.value(3).toInt());
lt1.end.push_back(ltQuery.value(4).toInt());
}else if(ltQuery.value(1).toInt()==2){
term2=true;
lt2.weekDay.push_back(ltQuery.value(2).toInt());
lt2.begin.push_back(ltQuery.value(3).toInt());
lt2.end.push_back(ltQuery.value(4).toInt());
}
}
}else{
QMessageBox::warning(this,"错误",ltQuery.lastError().text());
return;
}
//开始展示课程
QStringList timeThansfer;
timeThansfer<<"一"<<"二"<<"三"<<"四"<<"五"<<"六"<<"日";
//updateProgress();
if(term1){
//处理课程时间
QString time;
for(int i=0;i<lt1.weekDay.size();i++){
time+="周"+timeThansfer.at(lt1.weekDay.at(i)-1)+"第"+QString::number(lt1.begin.at(i))+"-"+QString::number(lt1.end.at(i))+"节 ";
}
//显示课程
ui->LessonWidget->setRowCount(ui->LessonWidget->rowCount()+1);
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,0,new QTableWidgetItem(query.value(0).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,1,new QTableWidgetItem(query.value(1).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,2,new QTableWidgetItem(query.value(4).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,3,new QTableWidgetItem(teacher1));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,4,new QTableWidgetItem(query.value(2).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,5,new QTableWidgetItem(query.value(3).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,6,new QTableWidgetItem(query.value(5).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,7,new QTableWidgetItem(query.value(6).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,8,new QTableWidgetItem(query.value(7).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,9,new QTableWidgetItem("第一学期"));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,10,new QTableWidgetItem(time));
}
if(term2){
//处理课程时间
QString time;
for(int i=0;i<lt2.weekDay.size();i++){
time+="周"+timeThansfer.at(lt2.weekDay.at(i)-1)+"第"+QString::number(lt2.begin.at(i))+"-"+QString::number(lt2.end.at(i))+"节 ";
}
//显示课程
ui->LessonWidget->setRowCount(ui->LessonWidget->rowCount()+1);
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,0,new QTableWidgetItem(query.value(0).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,1,new QTableWidgetItem(query.value(1).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,2,new QTableWidgetItem(query.value(4).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,3,new QTableWidgetItem(teacher2));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,4,new QTableWidgetItem(query.value(2).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,5,new QTableWidgetItem(query.value(3).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,6,new QTableWidgetItem(query.value(5).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,7,new QTableWidgetItem(query.value(6).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,8,new QTableWidgetItem(query.value(7).toString()));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,9,new QTableWidgetItem("第二学期"));
ui->LessonWidget->setItem(ui->LessonWidget->rowCount()-1,10,new QTableWidgetItem(time));
}
}
}else{
QMessageBox::warning(this,"查询全校课程错误",query.lastError().text());
}
}
void AdminWindow::on_FlushButton_2_clicked()
{
ui->TeacherWidget->clearContents();
ui->TeacherWidget->setRowCount(0);
QSqlQuery query;
query.exec("select * from Teacher");
if(query.lastError().type()==QSqlError::NoError){
while(query.next()){
//updateProgress();
ui->TeacherWidget->setRowCount(ui->TeacherWidget->rowCount()+1);
ui->TeacherWidget->setItem(ui->TeacherWidget->rowCount()-1,0,new QTableWidgetItem(query.value(0).toString()));
ui->TeacherWidget->setItem(ui->TeacherWidget->rowCount()-1,1,new QTableWidgetItem(query.value(1).toString()));
ui->TeacherWidget->setItem(ui->TeacherWidget->rowCount()-1,2,new QTableWidgetItem(query.value(2).toString()));
}
}else{
QMessageBox::warning(this,"查询教师信息错误",query.lastError().text());
}
}
void AdminWindow::on_AddStudentButton_clicked()
{
AddStuWidget* addstuwidget=new AddStuWidget();
addstuwidget->show();
}
void AdminWindow::on_FlushButton_3_clicked()
{
ui->StudentWidget->clearContents();
ui->StudentWidget->setRowCount(0);
QSqlQuery query;
query.exec("select * from Student");
if(query.lastError().type()==QSqlError::NoError){
while(query.next()){
//updateProgress();
ui->StudentWidget->setRowCount(ui->StudentWidget->rowCount()+1);
ui->StudentWidget->setItem(ui->StudentWidget->rowCount()-1,0,new QTableWidgetItem(query.value(0).toString()));
ui->StudentWidget->setItem(ui->StudentWidget->rowCount()-1,1,new QTableWidgetItem(query.value(1).toString()));
ui->StudentWidget->setItem(ui->StudentWidget->rowCount()-1,2,new QTableWidgetItem(query.value(2).toString()));
ui->StudentWidget->setItem(ui->StudentWidget->rowCount()-1,3,new QTableWidgetItem(query.value(3).toString()));
ui->StudentWidget->setItem(ui->StudentWidget->rowCount()-1,4,new QTableWidgetItem(query.value(4).toString()));
}
}else{
QMessageBox::warning(this,"查询学生信息错误",query.lastError().text());
}
}
void AdminWindow::on_AddLessonButton_2_clicked()
{
AddTeacherWidget* widget=new AddTeacherWidget();
widget->show();
}
void AdminWindow::on_FlushButton_4_clicked()
{
ui->ScholarshipWidget->clear();
QSqlQuery query;
query.exec("select * from ScholarLst");
if(query.lastError().type()==QSqlError::NoError){
while(query.next()){
QSqlQuery examQuery;
examQuery.exec("select * from ScholarAppli where Scholarship='"+query.value(0).toString()+"' and Response='3'");
if(examQuery.lastError().type()==QSqlError::NoError){
if(examQuery.next()){
ui->ScholarshipWidget->addItem("* "+query.value(0).toString()+" 金额:"+query.value(2).toString()+"元"+" 介绍:"+query.value(1).toString());
}else{
ui->ScholarshipWidget->addItem(query.value(0).toString()+" 金额:"+query.value(2).toString()+"元"+" 介绍:"+query.value(1).toString());
}
}else{
QMessageBox::warning(this,"查询奖学金申请信息错误",examQuery.lastError().text());
}
}
}else{
QMessageBox::warning(this,"查询奖学金错误",query.lastError().text());
}
}
void AdminWindow::setProgressDialog(QProgressDialog * pd_){
this->pd=pd_;
}
void AdminWindow::updateProgress(){
if(pd){
if(pd->value()==pd->maximum()){
pd->setValue(0);
}else{
pd->setValue(pd->value()+1);
}
}
}
void AdminWindow::on_toolButton_26_clicked()
{
AddScholarWidget *widget=new AddScholarWidget();
widget->show();
}
void AdminWindow::on_ScholarshipWidget_itemDoubleClicked(QListWidgetItem *item)
{
QString content=item->text();
QString name;
for(int i=0;i<content.size();i++){
if(content.at(i)==' '){
break;
}else if(content.at(i)=='*'){
i++;
}
else{
name+=content.at(i);
}
}
ScholarMsgWidget *widget=new ScholarMsgWidget();
widget->setName(name);
widget->flush();
widget->show();
}
void AdminWindow::on_ModifyTeacherButton_clicked()
{
QList<QTableWidgetItem*> items = ui->TeacherWidget->selectedItems();
if(items.size()<=0){
QMessageBox::warning(this,"错误","您没有选中任何教师!");
}else{
int rowIndex=ui->TeacherWidget->row(items.at(0));
QString tno=ui->TeacherWidget->item(rowIndex,0)->text();
QString tname=ui->TeacherWidget->item(rowIndex,1)->text();
QString dept=ui->TeacherWidget->item(rowIndex,2)->text();
ModifyTeacherWidget *widget=new ModifyTeacherWidget();
widget->setTno(tno,tname,dept);
widget->flush();
widget->show();
}
}
void AdminWindow::on_FlushButton_5_clicked()
{
ui->MsgWidget->clear();
QSqlQuery query;
query.exec("select Sname,Rcontent,Response from S2A,Student where S2A.Sno=Student.Sno");
if(query.lastError().type()==QSqlError::NoError){
while(query.next()){
ui->MsgWidget->addItem("学生:"+query.value(0).toString()+" 内容:"+query.value(1).toString()+" 回复:"+query.value(2).toString());
}
}else{
QMessageBox::warning(this,"查询待处理信息错误",query.lastError().text());
}
query.exec("select Tname,Rcontent,Response from T2A,Teacher where T2A.Tno=Teacher.Tno");
if(query.lastError().type()==QSqlError::NoError){
while(query.next()){
ui->MsgWidget->addItem("教师:"+query.value(0).toString()+" 内容:"+query.value(1).toString()+" 回复:"+query.value(2).toString());
}
}else{
QMessageBox::warning(this,"查询待处理信息错误",query.lastError().text());
}
}
void AdminWindow::on_MsgWidget_itemDoubleClicked(QListWidgetItem *item)
{
ModifyApplyWidget* widget=new ModifyApplyWidget();
QString content="";
int i=0;
for(;i<item->text().size();i++){
if(item->text().at(i)==':'){
i++;
break;
}
}
for(;i<item->text().size();i++){
if(item->text().at(i)==' ') break;
else{
content+=item->text().at(i);
}
}
qDebug()<<content;
widget->setContent(content);
widget->show();
}
void AdminWindow::on_toolButton_27_clicked()
{
QList<QListWidgetItem*> items=ui->ScholarshipWidget->selectedItems();
if(items.size()<=0){
QMessageBox::warning(this,"错误","您没有选中任何奖学金!");
}else{
QSqlQuery query;
for(int i=0;i<items.size();i++){
QString name;
QString con=items.at(i)->text();
for(int j=0;j<con.size();j++){
if(con.at(j)=='*') j++;
else if(con.at(j)==' ') break;
else name+=con.at(j);
}
query.exec("delete from ScholarLst where Scholarship='"+name+"' delete from ScholarAppli where Scholarship='"+name+"'");
if(query.lastError().type()==QSqlError::NoError){
QMessageBox::information(this,"删除奖学金","删除奖学金成功!");
}else{
QMessageBox::warning(this,"错误",query.lastError().text());
}
}
}
}
void AdminWindow::on_ModifyStudentButton_clicked()
{
ModifyStuWidget *widget=new ModifyStuWidget();
QList<QTableWidgetItem*> items=ui->StudentWidget->selectedItems();
if(items.size()<=0){
QMessageBox::warning(this,"错误","您没有选中任何学生!");
}else{
int index=ui->StudentWidget->row(items.at(0));
widget->setMsg(ui->StudentWidget->item(index,0)->text(),ui->StudentWidget->item(index,1)->text(),ui->StudentWidget->item(index,2)->text(),ui->StudentWidget->item(index,3)->text(),ui->StudentWidget->item(index,4)->text());
widget->show();
}
}
void AdminWindow::on_FindLessonButton_clicked()
{
QList<QTableWidgetItem*> items=ui->LessonWidget->selectedItems();
if(items.size()<=0){
QMessageBox::warning(this,"错误","您没有选中任何课程!");
}else{
QString res;
QSqlQuery query;
for(int i=0;i<items.size();i++){
int index=ui->LessonWidget->row(items.at(i));
query.exec("delete from CourseBasic where Cno='"+ui->LessonWidget->item(index,0)->text()+"'");
if(query.lastError().text()!=QSqlError::NoError){
res+=query.lastError().text();
}
}
if(res==""){
QMessageBox::warning(this,"删除课程","删除课程成功!");
}else{
QMessageBox::information(this,"删除课程",res);
}
}
}
void AdminWindow::on_DeleteTeacherButton_clicked()
{
QList<QTableWidgetItem*> items=ui->TeacherWidget->selectedItems();
if(items.size()<=0){
QMessageBox::warning(this,"错误","您没有选中任何学生!");
}else{
QString res;
QSqlQuery query;
for(int i=0;i<items.size();i++){
int index=ui->TeacherWidget->row(items.at(i));
query.exec("delete from Teacher where Tno='"+ui->TeacherWidget->item(index,0)->text()+"'");
if(query.lastError().type()!=QSqlError::NoError){
res+=query.lastError().text();
}
}
if(res==""){
QMessageBox::information(this,"删除教师","删除教师成功!");
}else{
QMessageBox::warning(this,"删除教师",query.lastError().text());
}
}
}
void AdminWindow::on_DeleteStudentButton_clicked()
{
QList<QTableWidgetItem*> items=ui->StudentWidget->selectedItems();
if(items.size()<=0){
QMessageBox::warning(this,"错误","您没有选中任何学生!");
}else{
QString res;
QSqlQuery query;
for(int i=0;i<items.size();i++){
int index=ui->StudentWidget->row(items.at(i));
query.exec("delete from Student where Sno='"+ui->StudentWidget->item(index,0)->text()+"'");
if(query.lastError().type()!=QSqlError::NoError){
res+=query.lastError().text();
}
}
if(res==""){
QMessageBox::information(this,"删除学生","删除学生成功!");
}else{
QMessageBox::warning(this,"删除学生",query.lastError().text());
}
}
}