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
| #include "dormManager.h" #include "mysql.h" #include <sstream> #include <string.h> #include "student.h" #include "manager.h" #include <mysql.h> DormManager::DormManager() { this->m_Num = 0; this->m_Array = NULL; }
void DormManager::Show_Menu() { cout << "*******************************************************************" << endl; cout << "************************ 欢迎使用宿舍管理系统 ****************" << endl; cout << "**************************** 0.退出管理程序 *********************" << endl; cout << "**************************** 1.增加人员信息 *********************" << endl; cout << "**************************** 2.显示人员信息 *********************" << endl; cout << "**************************** 3.删除人员信息 *********************" << endl; cout << "**************************** 4.修改人员信息 *********************" << endl; cout << "**************************** 5.查找人员信息 *********************" << endl; cout << "**************************** 6.按照编号排序 *********************" << endl; cout << "**************************** 7.清空所有文档 *********************" << endl; cout << "*******************************************************************" << endl; cout << endl; }
void DormManager::exitSystem() { cout << "欢迎下次使用" << endl; system("pause"); exit(0); }
void DormManager::Add() { cout << "请输入添加职工数量:" << endl; int addNum = 0; cin >> addNum;
if (addNum > 0) { int newSize = this->m_Num + addNum;
Person** newSpace = new Person * [newSize];
if (this->m_Array != NULL) { for (int i = 0; i < this->m_Num; i++) { newSpace[i] = this->m_Array[i]; } }
for (int i = 0; i < addNum; i++) { int id; string name; string sex; int building; string dorm; string phone;
DataBase* d = new DataBase; d->Connect("localhost", "root", "13525681378.Ll", "dormitory_management_system", 3306); Person* person = NULL;
int choice; cout << "请输入该人员类别:" << endl; cout << "1、学生" << endl; cout << "2、管理人员" << endl; cin >> choice; if (choice == 1) { string status = "学生"; cout << "请输入第 " << i + 1 << "个新人员编号:" << endl; cin >> id; cout << "请输入第 " << i + 1 << "个新人员姓名:" << endl; cin >> name; cout << "请输入第 " << i + 1 << "个新人员性别:" << endl; cin >> sex; cout << "请输入第 " << i + 1 << "个新人员公寓:" << endl; cin >> building; cout << "请输入第 " << i + 1 << "个新人员宿舍:" << endl; cin >> dorm; cout << "请输入第 " << i + 1 << "个新职工电话:" << endl; cin >> phone;
person = new Student(id, name, sex, building, dorm, phone); string sql = "insert into student(id, name, sex, building, dorm, phone, status) values(" + to_string(id) + ",'" + name + "','" + sex + "'," + to_string(building) + ",'" + dorm + "','" + phone + "','" + status + "')"; char query[150]; strcpy_s(query, sql.c_str()); d->Implement(query); } else { string status = "管理人员"; cout << "请输入第 " << i + 1 << "个新人员编号:" << endl; cin >> id; cout << "请输入第 " << i + 1 << "个新人员姓名:" << endl; cin >> name; cout << "请输入第 " << i + 1 << "个新人员性别:" << endl; cin >> sex; cout << "请输入第 " << i + 1 << "个新人员公寓:" << endl; cin >> building; cout << "请输入第 " << i + 1 << "个新人员宿舍:" << endl; cin >> dorm; cout << "请输入第 " << i + 1 << "个新职工电话:" << endl; cin >> phone;
person = new Manager(id, name, sex, building, dorm, phone); string sql = "insert into manager(id, name, sex, building, dorm, phone, status) values(" + to_string(id) + ",'" + name + "','" + sex + "'," + to_string(building) + ",'" + dorm + "','" + phone + "','" + status + "')"; char query[150]; strcpy_s(query, sql.c_str()); d->Implement(query);
string sql2 = "insert into normal(Mid, Mbuilding) values(" + to_string(id) + "," + to_string(building) + ")"; char query2[150]; strcpy_s(query2, sql2.c_str()); d->Implement(query2); }
newSpace[this->m_Num + i] = person; } delete[] this->m_Array;
this->m_Array = newSpace;
this->m_Num = newSize;
cout << "成功添加" << addNum << "名新人员" << endl; } else { cout << "输入数据有误" << endl; }
system("pause"); system("cls"); }
void DormManager::Show() { DataBase* d = new DataBase; d->Connect("localhost", "root", "13525681378.Ll", "dormitory_management_system", 3306); if (d->Query("student")) { cout << "学生信息显示成功" << endl; } else { cout << "学生信息显示失败" << endl; } if (d->Query("manager")) { cout << "管理人员信息显示成功" << endl; } else { cout << "管理人员信息显示失败" << endl; }
system("pause"); system("cls"); }
int DormManager::Exist(int id, string status) { int index = -1;
for (int i = 0; i < this->m_Num; i++) { if (this->m_Array[i]->id = id && this->m_Array[i]->status == status) { index = i; break; } } return index;
}
void DormManager::Delete() { cout << "删除的人员是:" << endl; cout << "1、学生" << endl; cout << "2、宿舍管理人员" << endl; int choice; cin >> choice;
DataBase* d = new DataBase; d->Connect("localhost", "root", "13525681378.Ll", "dormitory_management_system", 3306); if (choice == 1) { cout << "请输入删除人员的id号:" << endl; int id = 0; cin >> id; int index = this->Exist(id, "学生"); if (index != -1) { for (int i = index; i < this->m_Num - 1; i++) { this->m_Array[i] = this->m_Array[i + 1]; } this->m_Num--; string sql = "delete from student where id = '" + to_string(id) + "'"; char del[150]; strcpy_s(del, sql.c_str()); d->Implement(del); cout << "学生删除成功" << endl; } else { cout << "学生删除失败" << endl; }
} else { cout << "请输入删除人员的id号:" << endl; int id = 0; cin >> id; int index = this->Exist(id, "管理人员"); if (index != -1) { for (int i = index; i < this->m_Num - 1; i++) { this->m_Array[i] = this->m_Array[i + 1]; } this->m_Num--; string sql = "delete from manager where id = '" + to_string(id) + "'"; char del[150]; strcpy_s(del, sql.c_str()); d->Implement(del); string sql2 = "delete from normal where Mid = '" + to_string(id) + "'"; char del2[150]; strcpy_s(del2, sql.c_str()); d->Implement(del2); cout << "学生删除成功" << endl; } else { cout << "学生删除失败" << endl; } } }
void DormManager::Find() { cout << "请输入查找人员的编号" << endl; int newId; cin >> newId;
DataBase* d = new DataBase; d->Connect("localhost", "root", "13525681378.Ll", "dormitory_management_system", 3306);
string sql = "select * from student where id =" + to_string(newId); string sql2 = "select * from manager where id =" + to_string(newId); char find[150]; char find2[150]; strcpy_s(find, sql.c_str()); strcpy_s(find2, sql2.c_str()); d->Implement(find); d->Implement(find2);
}
void DormManager::Mod() { DataBase* d = new DataBase; d->Connect("localhost", "root", "13525681378.Ll", "dormitory_management_system", 3306);
cout << "请输入修改人员的身份" << endl; cout << "1、学生" << endl; cout << "2、管理人员" << endl; int choice; cin >> choice;
if (choice == 1) { cout << "请输入修改学生的编号:" << endl; int id; cin >> id;
int ret = this->Exist(id, "学生"); if (ret != -1) { delete this->m_Array[ret];
int newId = 0; string newName = ""; string newSex = ""; int newBuilding = 0; string newDorm = ""; string newPhone = ""; cout << "查到:" << id << "号学生,请输入新学生号:"; cin >> newId; cout << "请输入新的姓名:"; cin >> newName; cout << "请输入新的性别:"; cin >> newSex; cout << "请输入新的公寓:"; cin >> newBuilding; cout << "请输入新的宿舍:"; cin >> newDorm; cout << "请输入新的电话:"; cin >> newPhone;
Person* person = NULL; person = new Student(newId, newName, newSex, newBuilding, newDorm, newPhone);
this->m_Array[ret] = person;
string sql = "update student set id = " + to_string(newId) + ",name = '"+ newName + "', sex = '"+ newSex + "', building = "+to_string(newBuilding)+", dorm = '"+newDorm + "', phone = '"+newPhone +"' where id = " +to_string(id)+""; char update[150]; strcpy_s(update, sql.c_str()); d->Implement(update);
cout << "修改成功" << endl;
} else { cout << "找不到对应的数据,修改失败" << endl; } } else if (choice == 2) { cout << "请输入修改管理人员的编号:" << endl; int id; cin >> id;
int ret = this->Exist(id, "管理人员"); if (ret != -1) { delete this->m_Array[ret];
int newId = 0; string newName = ""; string newSex = ""; int newBuilding = 0; string newDorm = ""; string newPhone = ""; cout << "查到:" << id << "号管理人员,请输入新id号:"; cin >> newId; cout << "请输入新的姓名:"; cin >> newName; cout << "请输入新的性别:"; cin >> newSex; cout << "请输入新的公寓:"; cin >> newBuilding; cout << "请输入新的宿舍:"; cin >> newDorm; cout << "请输入新的电话:"; cin >> newPhone;
Person* person = NULL; person = new Manager(newId, newName, newSex, newBuilding, newDorm, newPhone);
this->m_Array[ret] = person;
string sql = "update manager set id = " + to_string(newId) + ",name = '" + newName + "', sex = '" + newSex + "', building = " + to_string(newBuilding) + ", dorm = '" + newDorm + "', phone = '" + newPhone + "' where id = " + to_string(id) + ";"; char update[150]; strcpy_s(update, sql.c_str()); d->Implement(update);
string sql2 = "update normal set Mid = " + to_string(newId) + "', building = " + to_string(newBuilding) + "' where Mid = " + to_string(id) + ";"; char update2[150]; strcpy_s(update2, sql.c_str()); d->Implement(update2);
cout << "修改成功" << endl;
} else { cout << "找不到对应的数据,修改失败" << endl; } } }
void DormManager::Clean() { cout << "确定清空?" << endl; cout << "1、确定" << endl; cout << "2、返回" << endl;
int select = 0; cin >> select;
if (select == 1) { DataBase* d = new DataBase; d->Connect("localhost", "root", "13525681378.Ll", "dormitory_management_system", 3306);
string sql = "delete from student"; string sql2 = "delete from manager"; string sql3 = "delete from normal"; char empty[150]; char empty2[150]; char empty3[150]; strcpy_s(empty, sql.c_str()); strcpy_s(empty2, sql2.c_str()); strcpy_s(empty3, sql3.c_str()); if (d->Implement(empty) && d->Implement(empty2) && d->Implement(empty3)) { cout << "数据库清空成功" << endl; }
if (this->m_Array != NULL) { for (int i = 0; i < m_Num; i++) { delete this->m_Array[i]; this->m_Array[i] = NULL; }
delete[] this->m_Array; this->m_Array = NULL; this->m_Num = 0; }
} system("pause"); system("cls"); }
void DormManager::Build() { cout << "请输入想要查询的公寓楼号:" << endl; int select = 0; cin >> select; int index = -1;
cout << select << "公寓的所有人员如下:" << endl; for (int i = 0; i < this->m_Num; i++) { if (this->m_Array[i]->building == select && this->m_Array [i]->status == "学生") { this->m_Array[i]->showInfo(); } } for (int i = 0; i < this->m_Num; i++) { if (this->m_Array[i]->building == select && this->m_Array[i]->status == "管理人员") { this->m_Array[i]->showInfo(); } } }
DormManager::~DormManager() { if (this->m_Array != NULL) { for (int i = 0; i < this->m_Num; i++) { if (this->m_Array[i] != NULL) { delete this->m_Array[i]; } } delete[] this->m_Array; this->m_Array = NULL; } }
|