-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.cpp
230 lines (197 loc) · 4.6 KB
/
manager.cpp
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
#include"manager.h"
#include<string>
#include"globalFile.h"
#include<fstream>
#include<algorithm>
Manager::Manager()
{
}
Manager::Manager(string name, string pwd)
{
this->m_Name = name;
this->m_Pwd=pwd;
this->initVector();
ifstream ifs;
ComputerRoom computer;
ifs.open(COMPUTER_FILE, ios::in);
while (ifs >> computer.m_RoomNum && ifs >> computer.m_ComputerNum)
{
Com.push_back(computer);
}
cout << "当前机房数量为" << Com.size() << endl;
ifs.close();
}
void Manager::OpenMenu()
{
cout << "欢迎管理员" <<this->m_Name<<"登录!"<< endl;
cout << "\t\t --------------------------\n" << endl;
cout << "\t\t| |\n" << endl;
cout << "\t\t| 1.添加账号 |\n" << endl;
cout << "\t\t| |\n" << endl;
cout << "\t\t| 2.查看账号 |\n" << endl;
cout << "\t\t| |\n" << endl;
cout << "\t\t| 3.查看机房 |\n" << endl;
cout << "\t\t| |\n" << endl;
cout << "\t\t| 4.清空预约 |\n" << endl;
cout << "\t\t| |\n" << endl;
cout << "\t\t| 0.注销登录 |\n" << endl;
cout << "\t\t| |\n" << endl;
cout << "\t\t -------------------------- \n" << endl;
cout << endl << " 请选择您的操作:" << endl;
}
void Manager::initVector()
{
ifstream ifs;
ifs.open(STUDENT_FILE, ios::in);
if (!ifs.is_open())
{
cout << "文件打开失败" << endl;
return;
}
Stu.clear();
Tea.clear();
Com.clear();
Student s;
while (ifs >> s.m_Id && ifs >> s.m_Name && ifs >> s.m_Pwd)
{
Stu.push_back(s);
}
cout << "当前学生数量为" << Stu.size() << endl;
ifs.close();
Teacher t;
ifs.open(TEACHER_FILE, ios::in);
while (ifs >> t.m_empId && ifs >> t.m_Name && ifs >> t.m_Pwd)
{
Tea.push_back(t);
}
cout << "当前老师数量为" << Tea.size() << endl;
ifs.close();
}
bool Manager::checkRepeat(int id, int type)
{
if (type == 1)
{
for (vector<Student>::iterator it = Stu.begin(); it != Stu.end(); it++)
{
if (id ==it->m_Id)
{
return true;
}
}
}
else
{
for (vector<Teacher>::iterator it = Tea.begin(); it != Tea.end(); it++)
{
if (id == it->m_empId)
{
return true;
}
}
}
return false;
}
void Manager::addPerson()
{
cout << "请选择添加的账户:" << endl;
cout << "1.学生:" << endl;
cout << "2.老师:" << endl;
string tip;
string FileName;
string errorTip;
ofstream ofs;
int select = 0;
cin >> select;
if (select == 1)
{
tip = "请输入添加学生学号:";
FileName = STUDENT_FILE;
errorTip = "学号重复,请重新输入";
}
else if (select == 2)
{
tip = "请输入添加老师职工号:";
FileName = TEACHER_FILE;
errorTip = "职工号重复,请重新输入";
}
else
{
cout << "输入有误,请重新输入" << endl;
return;
}
int id;
string name;
string pwd;
ofs.open(FileName, ios::out | ios::app);
cout << tip << endl;
while (true)
{
cin >> id;
bool ref =this->checkRepeat(id, select);
if (ref)
{
cout << errorTip << endl;
}
else
{
break;
}
}
cout << "请输入姓名:" << endl;
cin >> name;
cout << "请输入密码:" << endl;
cin >> pwd;
ofs << id << " " << name << " " << pwd<<" " << endl;
cout << "添加成功!" << endl;
system("pause");
system("cls");
ofs.close();
this->initVector();
}
void printStudent(Student &s)
{
cout << "学号:" << s.m_Id << " " << "姓名:" << s.m_Name << " " << "密码:" << s.m_Pwd << endl;
}
void printTeacher(Teacher &t)
{
cout << "职工号:" << t.m_empId << " " << "姓名:" << t.m_Name << " " << "密码:" << t.m_Pwd << endl;
}
void Manager::showPerson()
{
cout << "请输入您想要查看内容:" << endl;
cout << "1.所有学生" << endl;
cout << "2.所有老师" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
cout << "所有学生的信息如下:" << endl;
for_each(Stu.begin(), Stu.end(), printStudent);
}
else
{
cout << "所有老师的信息如下:" << endl;
for_each(Tea.begin(), Tea.end(), printTeacher);
}
system("pause");
system("cls");
}
void Manager::showCompuer()
{
cout << "所有机房的信息如下:" << endl;
for (vector<ComputerRoom>::iterator it = Com.begin(); it != Com.end(); it++)
{
cout << "机房号:" << it->m_RoomNum << " 电脑数:" << it->m_ComputerNum << endl;
}
system("pause");
system("cls");
}
void Manager::cleanYu()
{
ofstream ofs;
ofs.open(YU_FILE, ios::trunc);
ofs.close();
cout << "清空成功" << endl;
system("pause");
system("cls");
}