-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstuui.cpp
More file actions
152 lines (122 loc) · 4.49 KB
/
Copy pathstuui.cpp
File metadata and controls
152 lines (122 loc) · 4.49 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
#include "stuui.h"
#include "Computer.h"
#include "stulog.h"
#include "ui_stuui.h"
#include "QMessageBox"
#include "QDebug"
stuui::stuui(ComputerClassroom* m_classroom,QWidget *parent)
: QWidget(parent)
, ui(new Ui::stuui)
,m_classroom(m_classroom)
{
ui->setupUi(this);
}
stuui::~stuui()
{
delete ui;
}
bool stuui::studentLogin(const std::string& name, const std::string& id,int classroom, int hor, int ver, const std::string& loginTime){
Computer& computer = m_classroom[classroom-1].getcomputers(ver,hor);
qDebug()<<computer.getPcid();
qDebug()<<computer.getLocation().get_hor()<<" "<<computer.getLocation().get_ver();
qDebug()<<computer.getComputerType();
if (computer.getComputerType()!= IDLE) {
qDebug()<<"计算机不是空闲状态,不能上机";
return false;
}
UsageRecord record(name, id, loginTime, "");
std::list<UsageRecord> &usageRecords = computer.getUsagerecords();
usageRecords.push_back(record);
computer.settype(IN_USE);
m_classroom[classroom-1].setcomputer(computer,ver,hor);
return true;
}
// 学生离开登记
bool stuui::studentLogout(const std::string& name, const std::string& id,int classroom, int hor, int ver,const std::string &logintime, const std::string& logoutTime){
Computer& computer = m_classroom[classroom-1].getcomputers(ver,hor);
std::list<UsageRecord> &usageRecords = computer.getUsagerecords();
auto it=usageRecords.begin();
for(;it!=usageRecords.end();it++){
qDebug()<<it->getStudentId();
if((it->getStudentId()==id)&&(it->getLoginTimeString()==logintime)){
break;
}
}
if (it == usageRecords.end()) {
qDebug()<<"未找到该学生的上机记录";
return false; // 未找到该学生的上机记录
}
it->setLogoutTimeString(logoutTime);
computer.settype(IDLE);
m_classroom[classroom-1].setcomputer(computer,ver,hor);
return true;
}
void stuui::on_loginpushButton_clicked()
{
// 获取界面上的学生信息
std::string name = ui->name->text().toStdString();
std::string id = ui->stuid->text().toStdString();
// 获取选择的计算机位置
int hang = ui->hang->text().toInt();
int lie = ui->lie->text().toInt();
int classroom=ui->classroom->text().toInt();
QString intime=ui->inyear->text()+"/"+ui->inmouth->text()+"/"+ui->inday->text()+" "+ui->intime->text();
std::string intimes=intime.toStdString();
if(classroom<1||classroom>6){
QMessageBox::warning(this, "警告", "选择的机房无效");
return;
}
// 检查计算机位置是否有效
if (hang < 1 || hang >10 || lie< 1 || lie > 5) {
QMessageBox::warning(this, "警告", "选择的计算机位置无效");
return;
}
if(studentLogin(name,id,classroom,hang,lie,intimes)){
QMessageBox::information(this,"提醒","上机成功");
}
else{
QMessageBox::warning(this,"警告", "上机失败");
}
}
void stuui::on_lgoutpushButton_clicked()
{
// 获取界面上的学生信息
std::string name = ui->name->text().toStdString();
std::string id = ui->stuid->text().toStdString();
// 获取选择的计算机位置
int hang = ui->hang->text().toInt();
int lie = ui->lie->text().toInt();
int classroom=ui->classroom->text().toInt();
QString outtime=ui->outyear->text()+"/"+ui->outmouth->text()+"/"+ui->outday->text()+" "+ui->outtime->text();
QString intime=ui->inyear->text()+"/"+ui->inmouth->text()+"/"+ui->inday->text()+" "+ui->intime->text();
std::string outtimes=outtime.toStdString();
std::string intimes=intime.toStdString();
if(classroom<1||classroom>6){
QMessageBox::warning(this,"警告", "选择的计算机位置无效");
return;
}
// 检查计算机位置是否有效
if (hang < 1 || hang >10 || lie< 1 || lie > 5) {
QMessageBox::warning(this, "警告", "选择的计算机位置无效");
return;
}
if(studentLogout(name,id,classroom,hang,lie,intimes,outtimes)){
QMessageBox::information(this,"提醒","下机成功");
return;
}
else{
QMessageBox::warning(this,"警告", "下机失败");
}
}
void stuui::on_pushButton_clicked()
{
stulog *a=new stulog(m_classroom);
for (int i = 0; i < 6; ++i) {
QString filePath = QString("classroom%1.csv").arg(i + 1);
//qDebug()<<"b";
file.exportDataToCSV((m_classroom[i]), filePath);
//qDebug()<<"chengg";
}
this->close();
a->show();
}