Update 11/06/2018

This commit is contained in:
2018-06-11 07:33:28 +07:00
parent 9ada3b29b4
commit 96bc3cf0e3
24 changed files with 1288 additions and 861 deletions
+224 -243
View File
@@ -1,20 +1,24 @@
#include "Process.h"
#include "process.h"
#include "Student.h"
#include "Teacher.h"
#include "DBHelper.h"
#include "Admin.h"
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
CourseList* ctemp = new CourseList();
CourseList* ttemp = new CourseList();
bool startProgram(User& random_user, UserList user_list) {
cout << "\t\t\t" << "+++++++++++++++++++++++++++++++++++++|\n\n";
cout << "\t\t\t" << "| Welcome to student manager site |\n\n";
cout << "\t\t\t" << "+++++++++++++++++++++++++++++++++++++|\n\n\n";
while (true) {
cout << "\t\t\t\t" << "|++++++++++++++++++++++++++++++++++++|\n\n";
cout << "\t\t\t\t" << "| Welcome to student manager site |\n\n";
cout << "\t\t\t\t" << "|++++++++++++++++++++++++++++++++++++|\n\n\n";
cout << "Username (Type q to exit): ";
cin >> random_user.username;
cout << "Password (Type q to exit): ";
@@ -48,12 +52,21 @@ bool startProgram(User& random_user, UserList user_list) {
}
}
}
bool studentMenu(Student& st, StudentCourseList db_st_course_list, CourseList db_course_list, UserList user_list) {
bool studentMenu(Student& st, StudentCourseList&db_st_course_list, CourseList&db_course_list, UserList&user_list) {
while (st.isLogin() == true) {
cout << "\t\t\t\t" << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout << "\t\t\t\t" << "|\t\tSTUDENT SITE\t\t | \n";
cout << "\t\t\t\t" << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n";
cout << setfill('-') << setw(50) << "-" << "Student: " << st.st_number << setw(50) << "-" << endl;
cout << setfill(' ') << setw(30) << left << "1. Change Password [cp]" << setw(30) << left << "2. View my courses [vc]" << setw(30) << left << "3. Search courses[sc]" << setw(30) << left << "4. Join course [jc]" << endl;
cout << setw(30) << left << "5. Cancel course [xc]" << setw(30) << left << "6. Log out [lo]" << setw(30) << left << "7. Help [h]" << endl;
cout << "Your command (press [e] to quit program): ";
cout << setw(40) << setfill(' ') << left << "1. Change password" << "[cp]" << endl;
cout << setw(40) << setfill(' ') << left << "2. View my courses" << "[vc]" << endl;
cout << setw(40) << setfill(' ') << left << "3. Search courses" << "[sc] [-n,-f]" << endl;
cout << setw(40) << setfill(' ') << left << "4. Join course" << "[jc]" << endl;
cout << setw(40) << setfill(' ') << left << "5. Cancel course" << "[xc]" << endl;
cout << setw(40) << setfill(' ') << left << "6. Log out" << "[lo]" << endl;
cout << setw(40) << setfill(' ') << left << "7. Help" << "[h]" << endl;
cout << "\nYour command (press [e] to quit program): ";
string command;
stringstream ss;
string agv;
@@ -63,13 +76,14 @@ bool studentMenu(Student& st, StudentCourseList db_st_course_list, CourseList db
do{
ss >> agv;
if (ss.fail() || agv == "") {
system("cls");
break;
}
else agvList.addToList(agv);
} while (true);
if (agvList.list[0] == "e" && agvList.size == 1) return false;
if (studentProcess(st, user_list, db_st_course_list, db_course_list, agvList) == true) {
system("cls");
}
else {
cout << "Error: command not found" << endl;
@@ -78,18 +92,19 @@ bool studentMenu(Student& st, StudentCourseList db_st_course_list, CourseList db
return true;
}
bool teacherMenu(Teacher& tc, StudentCourseList& db_st_course_list, CourseList& db_course_list, UserList user_list){
while (tc.isLogin() == true){
cout << setfill('-') << setw(30) << "-" << "Lecturer: " << tc.tc_name << setw(50) << "-" << endl;
cout << "1. Change Password [cp (new password) ]\n";
cout << "2. Open a course [oc]\n";
cout << "3. Grading student's course [gc]\n";
//cout << "4. Modify grade [mg]\n";
cout << "4. Log out [lo]\n";
cout << "5. Help [h]" << endl;
cout << "Your command (press [e] to quit program): ";
cout << "\t\t\t\t" << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout << "\t\t\t\t" << "|\t\tTEACHER SITE\t\t | \n";
cout << "\t\t\t\t" << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n";
cout << "Lecturer: " << tc.tc_name << "[" << tc.tc_identify << "]\n";
cout << setfill('=') << setw(100) << "=" << endl;
cout << setw(40) << setfill(' ') << left << "1. Change password" << "[cp (new password)]" << endl;
cout << setw(40) << setfill(' ') << left << "2. View my opened courses" << "[vc]" << endl;
cout << setw(40) << setfill(' ') << left << "3. Open a course" << "[oc]" << endl;
cout << setw(40) << setfill(' ') << left << "4. Grading student's course" << "[gc]" << endl;
cout << setw(40) << setfill(' ') << left << "5. Log out" << "[lo]" << endl;
cout << setw(40) << setfill(' ') << left << "6. Help" << "[h]" << endl;
cout << "\nYour command (press [e] to quit program): ";
string command;
stringstream ss;
string agv;
@@ -99,46 +114,32 @@ bool teacherMenu(Teacher& tc, StudentCourseList& db_st_course_list, CourseList&
do{
ss >> agv;
if (ss.fail() || agv == "") {
system("cls");
break;
}
else agvList.addToList(agv);
} while (true);
if (agvList.list[0] == "e" && agvList.size == 1) return false;
if (teacherProcess(tc, user_list, db_st_course_list, db_course_list, agvList) == true) {
system("cls");
}
else {
cout << "Error: command not found" << endl;
cout << "\nError: command not found\n" << endl;
}
}
//system("cls"); // xoa console menu sau moi lan xong 1 thao tac
return true;
}
bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_course_list, CourseList db_course_list, arrayList<string> agvList) {
bool studentProcess(Student&st, UserList& user_list, StudentCourseList& db_st_course_list, CourseList db_course_list, arrayList<string> agvList) {
if (agvList.list[0] == "cp") {
if (agvList.size == 2) {
string newPassword = agvList.list[1];
st.changePassword(newPassword);
user_list.updateList(st);
return true;
}
else if (agvList.size == 1){
string newPassword;
cout << "Your new password: ";
cin >> newPassword;
cin.ignore(INT_MAX, '\n');
st.changePassword(newPassword);
user_list.updateList(st);
cout << "CHANGE PASSWORD SUCCESSFULLY" << endl;
return true;
}
return cp(st, agvList, user_list);
}
else if (agvList.list[0] == "vc") {
system("cls");
studentCourse enrolledCourse;
st.getStudentCourse(db_st_course_list, enrolledCourse);
st.getStudentCourse(db_st_course_list, enrolledCourse, &db_course_list);
st.showStudentCourse(&db_course_list, enrolledCourse);
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
else if (agvList.list[0] == "sc") {
@@ -152,6 +153,7 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
}
else {
system("cls");
ctemp = cList;
cList->printCourse();
}
}
@@ -165,9 +167,12 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
}
else {
system("cls");
ctemp = cList;
cList->printCourse();
}
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
else if (agvList.list[1] == "-f") {
@@ -175,21 +180,30 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
agvList.removeFromList(0);
agvList.removeFromList(0);
CourseList* cList = db_course_list.findAllCourseByFalcuty(agvList);
ttemp = cList;
cList->printCourse();
}
else if (agvList.size == 2) {
cout << "Falcuty to search: ";
string fal_name;
getline(cin, fal_name);
CourseList* cList = db_course_list.findCourseByFacuty(fal_name);
ttemp = cList;
cList->printCourse();
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
}
else if (agvList.list[0] == "jc") {
studentCourse enrolledCourse;
st.getStudentCourse(db_st_course_list, enrolledCourse);
if (st.getStudentCourse(db_st_course_list, enrolledCourse, &db_course_list) == false) {
enrolledCourse.st_num = st.st_number;
}
if (agvList.size > 1) {
agvList.removeFromList(0);
if (st.joinCourse(enrolledCourse, agvList, db_st_course_list, db_course_list) == false) {
@@ -198,14 +212,34 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
for (size_t i = 0; i < agvList.size; i++) {
cout << "'" << agvList.list[i] << "'";
}
cout << ". You has already joined the course or it is not opened." << endl;
}
}
else {
cout << "Your have successfully joined the courses." << endl;
if (agvList.isEmpty() == true) {
cout << "Your have successfully joined the courses." << endl;
}
else {
cout << "Error: Failed to join in ";
for (size_t i = 0; i < agvList.size; i++) {
cout << "'" << agvList.list[i] << "'";
}
cout << endl;
}
}
}
else if (agvList.size == 1) {
if (ctemp->size!=0){
cout << "Search history: \n";
ctemp->printCourse();
}
else if (ttemp->size!=0){
cout << "Search history: \n";
ttemp->printCourse();
}
else{
db_course_list.printCourse();
}
string courseId;
arrayList<string> join_course;
cout << "Course to join: ";
@@ -215,28 +249,55 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
if (st.joinCourse(enrolledCourse, join_course, db_st_course_list, db_course_list) == false) {
cout << "Error: Failed to join in ";
for (size_t i = 0; i < join_course.size; i++) {
cout << join_course.list[i] << " | ";
cout << "'" << join_course.list[i] << "'";
}
cout << ". You has already joined the course or it is not opened." << endl;
cout << endl;
}
else {
cout << "Your have successfully joined the courses." << endl;
if (join_course.isEmpty() == true) {
cout << "Your have successfully joined the courses." << endl;
}
else {
cout << "Error: Failed to join in ";
for (size_t i = 0; i < join_course.size; i++) {
cout << "'" << join_course.list[i] << "'";
}
cout << endl;
}
}
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
else if (agvList.list[0] == "xc") {
studentCourse enrolledCourse;
st.getStudentCourse(db_st_course_list, enrolledCourse);
studentCourse tmp_enrolledCourse;
st.getStudentCourse(db_st_course_list, enrolledCourse, &db_course_list);
tmp_enrolledCourse = enrolledCourse;
st.showStudentCourse(&db_course_list, enrolledCourse);
cout << setfill('_') << setw(120) << "_" << endl;
cout << setfill(' ');//reset
if (agvList.size > 1) {
agvList.removeFromList(0);
for (size_t i = 0; i < agvList.size; i++) {
if (enrolledCourse.hasEnrolled(agvList.list[i]) == false) {
if (tmp_enrolledCourse.hasEnrolled(agvList.list[i]) == false) {
cout << "Error: You have not joined " << agvList.list[i] << endl;
cout << endl;
}
else {
cout << "You have canceled join " << agvList.list[i] << endl;
int index = 0;
tmp_enrolledCourse.st_course.isExist(agvList.list[i], index);
if (tmp_enrolledCourse.st_point.list[index] != -1) {
cout << "You are graded in \"" << agvList.list[i] << "\" so you can not cancel it." << endl;
}
else {
cout << "You have canceled join " << agvList.list[i] << endl;
tmp_enrolledCourse.st_course.removeFromList(index);
tmp_enrolledCourse.st_point.removeFromList(index);
}
}
}
st.cancelCourse(enrolledCourse, agvList, db_st_course_list, db_course_list);
@@ -248,17 +309,24 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
cin >> courseId;
cin.ignore(INT_MAX, '\n');
cancel_course.addToList(courseId);
for (size_t i = 0; i < agvList.size; i++) {
for (size_t i = 0; i < cancel_course.size; i++) {
if (enrolledCourse.hasEnrolled(cancel_course.list[i]) == false) {
cout << "Error: You have not joined " << agvList.list[i] << endl;
cout << "Error: You have not joined " << cancel_course.list[i] << endl;
cout << endl;
}
else {
cout << "You have canceled join " << agvList.list[i] << endl;
int index = 0;
enrolledCourse.st_course.isExist(cancel_course.list[i], index);
if (enrolledCourse.st_point.list[index] != -1) {
cout << "You are graded in \"" << cancel_course.list[i] << "\" so you can not cancel it." << endl;
}
else cout << "You have canceled join " << cancel_course.list[i] << endl;
}
}
st.cancelCourse(enrolledCourse, cancel_course, db_st_course_list, db_course_list);
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
else if (agvList.list[0] == "lo") {
@@ -278,9 +346,8 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
cout << setw(40) << left << "Cancel course" << setw(10) << left << "xc" << setw(10) << left << "<list of course id> (optional)" << endl;
cout << setw(40) << left << "Join course" << setw(10) << left << "jc" << setw(10) << left << "<list of course id> (optional)" << endl;
cout << setw(100) << setfill('=') << "=" << setfill(' ') << endl;
cout << "Press any key to exit." << endl;
getchar();
system("cls");
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
}
@@ -288,97 +355,20 @@ bool studentProcess(Student&st, UserList& user_list, StudentCourseList&db_st_cou
}
bool teacherProcess(Teacher& tc, UserList& user_list, StudentCourseList& db_st_course_list, CourseList& db_course_list, arrayList<string> agvList) {
#pragma region ChangePass
//Change Pass
if (agvList.list[0] == "cp"){
string newPassword;
if (agvList.size == 2){
newPassword = agvList.list[1];
}
else if (agvList.size == 1){
cout << "Input your new password: ";
cin >> newPassword;
cin.ignore(INT_MAX, '\n');
}
tc.changePassword(newPassword);
user_list.updateList(tc);
cout << "CHANGE PASSWORD SUCCESSFULLY\n";
return true;
return cp(tc, agvList, user_list);
}
#pragma endregion
#pragma region OpenCourse
// View course
else if (agvList.list[0] == "vc"){
return tc.viewCourse(tc, db_st_course_list, db_course_list);
}
//Open new course
else if (agvList.list[0] == "oc"){
CourseList* temp = new CourseList();
temp = db_course_list.findCourseByFacuty(tc.tc_name);
if (temp->size > 5){
cout << "You has open 5 courses for this term so you cannot open more course.\n";
return true;
}
else{
string newCourse_sub_id; //ms viet tat mon hoc
string newCourse_class_id; //nhom lop
string newCourse_id; //ms mon hoc
string newCourse_name; //ten mon hoc
int newCourse_max; //so luong sv toi da
int newCourse_ncredit; //tin chi
do{
cout << "Input new sub_course ID you want to open: ";
cin >> newCourse_sub_id;
cin.ignore(INT_MAX, '\n');
cout << "Input class group: ";
cin >> newCourse_class_id;
cin.ignore(INT_MAX, '\n');
//newCourse_sub_id=toUpperCase(newCourse_sub_id);
//newCourse_class_id = toUpperCase(newCourse_class_id);
newCourse_id = newCourse_sub_id + "_" + newCourse_class_id;
if (db_course_list.isCourseExist(newCourse_id)){
cout << "You can not open an existed course. Try again! \n";
}
} while (db_course_list.isCourseExist(newCourse_id));
cout << "Input new course details.\n";
cout << "Input course name: "; getline(cin, newCourse_name);
do{
cout << "Input student number limitation (at least 10) : "; cin >> newCourse_max;
cin.clear();
cin.ignore(INT_MAX, '\n');
if (newCourse_max < 10 || cin.bad() || newCourse_max != (int)newCourse_max){
cout << "Invalid input.Try again!\n";
}
} while (cin.bad() || newCourse_max < 10 || newCourse_max != (int)newCourse_max);
do{
cout << "Input course's credit number (1-6): "; cin >> newCourse_ncredit;
cin.clear();
cin.ignore(INT_MAX, '\n');
if (!cin.good() || newCourse_ncredit<1 || newCourse_ncredit>6 || newCourse_ncredit != (int)newCourse_ncredit){
cout << "Invalid input.Try again!\n";
}
} while (cin.bad() || newCourse_ncredit < 1 || newCourse_ncredit != (int)newCourse_ncredit);
Course newCourse(newCourse_sub_id, newCourse_name, tc.tc_name);
newCourse.course_id = newCourse_id;
newCourse.total_st = 0;
newCourse.max_st = newCourse_max;
newCourse.credit = newCourse_ncredit;
cout << "SUCESSFULLY OPEN A NEW COURSE : \n";
newCourse.printCourseInfo();
cout << "Date created: " << endl;
std::time_t t = std::time(0); // get time now
std::tm* now = std::localtime(&t);
std::cout << (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday << "\n";
cin.ignore(INT_MAX, '\n');
db_course_list.addToCourseList(newCourse);
return true;
}//else right
}//end br
#pragma endregion
return tc.openNewCourse(tc, db_st_course_list, db_course_list);
}
#pragma region Grading
@@ -386,58 +376,53 @@ bool teacherProcess(Teacher& tc, UserList& user_list, StudentCourseList& db_st_c
CourseList* tc_open_course = new CourseList();
tc_open_course = tc.teacherCourse(db_course_list); //lay danh sach nhung course ma teacher da mo
StudentCourseList* data = new StudentCourseList();
cout << "\nYour opened course: \n";
tc.showTeacherCouser(tc_open_course);
tc.showTeacherCouser(*tc_open_course,db_st_course_list);
if (tc_open_course->size == 0){
cout << "Try opening a course in main menu ! \n";
cout << "Try opening a course in main menu.\n";
cout << "PRESS ENTER TO GO BACK";
cin.get();
return true;
}
int option;
cout << "\n\nChose course to grade or press 0 to exit: ";
cin >> option;
cin.ignore(INT_MAX, '\n');
float option;
do{
cout << "\nChose course to grade or press 0 to exit: ";
cin >> option;
cin.clear();
cin.ignore(INT_MAX, '\n');
if (option<0 || option>tc_open_course->size || cin.bad() || option != (int)option){
cout << "Wrong input, try again!\n";
continue;
}
} while (option<0 || option>tc_open_course->size || cin.bad() || option != (int)option);
if (option == 0){
return true;
}
else if (option != 0){
int flag = 1;
for (size_t i = 0; i < tc_open_course->size; i++){
if (option == i + 1){
data = db_st_course_list.findStudentJoinCourse(tc_open_course->list[i].course_id); //lay danh sach sinh vien + diem ma sinh vien tham gia course;
cout << endl;
cout << setw(40) << right << "__Danh Sach Sinh Vien Da Dang Ky__\n" << endl;
cout << setw(5) << left << "STT";
cout << setw(30) << left << "MSSV";
cout << setw(20) << right << "Diem\n";
cout << setfill('-');
cout << setw(55) << "-" << endl;
cout << setfill(' ');
for (size_t j = 0; j < data->size; j++){
cout << setw(5) << left << j + 1;
cout << setw(30) << left << data->list[j].st_num;
cout << setw(20) << right << data->list[j].st_point.list[0] << endl;
if (data->size == 0){
cout << "There are no students applied to this course, try again later!\n";
flag = 0;
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
tc.gradingCourse(*data);
db_st_course_list.updatePoint(*data);
cout << "Successfully modify student's grade!\n";
cout << "Changes preview: \n";
//*data = db_st_course_list.findStudentJoinCourse(tc_open_course->list[i].course_id); //lay danh sach sinh vien + diem ma sinh vien tham gia course;
cout << endl;
//cout << setw(40) << right << "__Danh Sach Sinh Vien Da Dang Ky__\n" << endl;
cout << setw(5) << left << "STT";
cout << setw(30) << left << "MSSV";
cout << setw(20) << right << "Diem\n";
cout << setfill('-');
cout << setw(55) << "-" << endl;
cout << setfill(' ');
for (size_t j = 0; j < data->size; j++){
cout << setw(5) << left << j + 1;
cout << setw(30) << left << data->list[j].st_num;
cout << setw(20) << right << data->list[j].st_point.list[0] << endl;
if (flag == 1){
tc.gradingCourse(*data);
db_st_course_list.updatePoint(*data);
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
}
}
return true;
}
} //end else if
@@ -459,9 +444,9 @@ bool teacherProcess(Teacher& tc, UserList& user_list, StudentCourseList& db_st_c
cout << setw(40) << left << "Description " << setw(10) << left << "Command" << setw(10) << left << "Argument list" << endl;
cout << setw(100) << setfill('-') << "-" << setfill(' ') << endl;
cout << setw(40) << left << "Change password" << setw(10) << left << "cp" << setw(10) << left << "<new password> (optional)" << endl;
cout << setw(40) << left << "View your opened course" << setw(10) << left << "vc" << setw(10) << left << "none" << endl;
cout << setw(40) << left << "Opent a course" << setw(10) << left << "oc" << setw(10) << left << "none" << endl;
cout << setw(40) << left << "Grading a course" << setw(10) << left << "gc" << setw(10) << left << "<list of course's name> (optional)" << endl;
//cout << setw(40) << left << "Modify grade" << setw(10) << left << "mg" << setw(10) << left << "<list of course's name> (optional)" << endl;
cout << setw(40) << left << "Grading a course" << setw(10) << left << "gc" << setw(10) <<endl;
cout << setw(100) << setfill('=') << "=" << setfill(' ') << endl;
cout << "Press any key to exit." << endl;
getchar();
@@ -473,11 +458,12 @@ bool teacherProcess(Teacher& tc, UserList& user_list, StudentCourseList& db_st_c
}
#pragma region Tien
bool adminMenu(Admin& ad, StudentList& db_st_list, TeacherList& db_tc_list, UserList& user_list, CourseList &db_course_list, StudentCourseList &db_st_course_list)
{
#pragma region Admin(Tien)
bool adminMenu(Admin& ad, StudentList& db_st_list, TeacherList& db_tc_list, UserList& user_list, CourseList &db_course_list, StudentCourseList &db_st_course_list) {
while (ad.isLogin() == true) {
cout << "\t\t\t\t" << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout << "\t\t\t\t" << "|\t\tADMIN SITE\t\t | \n";
cout << "\t\t\t\t" << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n";
cout << setw(40) << setfill('-') << "-" << "ADMIN" << setw(40) << setfill('-') << "-" << endl;
cout << setw(40) << setfill(' ') << left << "Change password" << "[cp]" << endl;
cout << setw(40) << setfill(' ') << left << "Show teacher" << "[t]" << endl;
@@ -489,7 +475,7 @@ bool adminMenu(Admin& ad, StudentList& db_st_list, TeacherList& db_tc_list, User
cout << setw(40) << setfill(' ') << left << "Search Student by name" << "[ss]" << endl;
cout << setw(40) << setfill(' ') << left << "Log out" << "[lo]" << endl;
cout << setw(40) << setfill(' ') << left << "Help" << "[h]" << endl;
cout << "Your command (press [e] to quit program): ";
cout << "\nYour command (press [e] to quit program): ";
string command;
stringstream ss;
string agv;
@@ -499,13 +485,14 @@ bool adminMenu(Admin& ad, StudentList& db_st_list, TeacherList& db_tc_list, User
do {
ss >> agv;
if (ss.fail() || agv == "") {
system("cls");
break;
}
else agvList.addToList(agv);
} while (true);
if (agvList.list[0] == "e" && agvList.size == 1) return false;
if (adminProcess(ad, user_list, db_st_list, db_tc_list, db_course_list, db_st_course_list, agvList) == true) {
system("cls");
}
else {
cout << "Error: command not found" << endl;
@@ -515,44 +502,35 @@ bool adminMenu(Admin& ad, StudentList& db_st_list, TeacherList& db_tc_list, User
}
bool adminProcess(Admin& ad, UserList& user_list, StudentList& db_st_list, TeacherList& db_tc_list, CourseList &db_course_list, StudentCourseList &db_st_course_list, arrayList<string> agvList) {
//Doi mat khau
if (agvList.list[0] == "cp") {
if (agvList.size == 2) {
string newPassword = agvList.list[1];
ad.changePassword(newPassword);
user_list.updateList(ad);
return true;
}
else if (agvList.size == 1) {
string newPassword;
cout << "Your new password: ";
cin >> newPassword;
cin.ignore(INT_MAX, '\n');
ad.changePassword(newPassword);
user_list.updateList(ad);
cout << "CHANGE PASSWORD SUCCESSFULLY" << endl;
return true;
}
return cp(ad, agvList, user_list);
}
else if (agvList.list[0] == "as")
{
if (ad.addStudent(db_st_list, user_list)) {
cout << "Add Student successful!" << endl;
//Them student
else if (agvList.list[0] == "as") {
if (ad.addStudent(db_st_list, user_list) == 1) {
cout << "Add Student \"" << user_list.list[user_list.size - 1].username << "\" successful!" << endl;
}
else {
cout << "Add Student unsuccessful!\nMay be error in your input or the same username have exist." << endl;
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
else if (agvList.list[0] == "at")
{
if (ad.addTeacher(db_tc_list, user_list)) {
cout << "Add Teacher successful!" << endl;
//Them teacher
else if (agvList.list[0] == "at") {
if (ad.addTeacher(db_tc_list, user_list) == 1) {
cout << "Add Teacher \"" << user_list.list[user_list.size - 1].username << "\" successful!" << endl;
}
else {
cout << "Add Teacher unsuccessful! May be the same username have exist." << endl;
cout << "Add Teacher unsuccessful!\nMay be error in your input or the same username have exist." << endl;
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
//Tim kiem student
else if (agvList.list[0] == "ss") {
if (agvList.size > 1) {
agvList.removeFromList(0);
@@ -595,8 +573,11 @@ bool adminProcess(Admin& ad, UserList& user_list, StudentList& db_st_list, Teach
sList.print();
}
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
//Tim kiem teacher
else if (agvList.list[0] == "st") {
if (agvList.size > 1) {
agvList.removeFromList(0);
@@ -639,11 +620,14 @@ bool adminProcess(Admin& ad, UserList& user_list, StudentList& db_st_list, Teach
tList.print();
}
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
//Xoa user
else if (agvList.list[0] == "ru") {
if (agvList.size == 1) {
cout << "Input list of usernames to remove:" << endl;
cout << "Input list of usernames you want to remove (separate by space):" << endl;
string input;
stringstream ss;
string username;
@@ -667,41 +651,45 @@ bool adminProcess(Admin& ad, UserList& user_list, StudentList& db_st_list, Teach
}
}
if (remove_unsuccess.size == 0) {
cout << "Remove all user successful!" << endl;
cout << "Remove all user you in your list successful!" << endl;
}
else {
cout << "Some user remove unsuccessful! That is:" << endl;
cout << "Some user in your list remove unsuccessful! List:" << endl;
for (size_t j = 0; j < remove_unsuccess.size; j++) {
cout << j + 1 << ".\t" << remove_unsuccess.list[j] << endl;
}
cout << "Other user remove successful!" << endl;
cout << "Other user in your list remove successful!" << endl;
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
else
{
else {
arrayList<string> remove_unsuccess;
for (size_t i = 1; i < agvList.size; i++) {
if (ad.removeUser(agvList.list[i], user_list, db_st_list, db_tc_list, db_course_list, db_st_course_list) == 1) {
}
else {
remove_unsuccess.addToList(agvList.list[i]);
}
}
if (remove_unsuccess.size == 0) {
cout << "Remove all user successful!" << endl;
cout << "Remove all user in your list successful!" << endl;
}
else {
cout << "Some user remove unsuccessful! That is:" << endl;
cout << "Some user in your list remove unsuccessful! List:" << endl;
for (size_t j = 0; j < remove_unsuccess.size; j++) {
cout << j + 1 << ".\t" << remove_unsuccess.list[j] << endl;
}
cout << "Other user remove successful!" << endl;
cout << "Other user in your list remove successful!" << endl;
}
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
}
//In help
else if (agvList.list[0] == "h") {
if (agvList.size == 1) {
system("cls");
@@ -726,32 +714,26 @@ bool adminProcess(Admin& ad, UserList& user_list, StudentList& db_st_list, Teach
cout << "Input as this format <number, name, birthday, \"hometown\"> (separate by comma):" << endl << endl;
cout << setw(40) << setfill(' ') << left << "Log out" << "[lo]" << endl;
cout << "Input <lo> to log out. (Then you can log in as another user)." << endl << endl;
cout << "Input anything to return." << endl;
getchar();
cin.clear();
cin.ignore(INT_MAX, '\n');
system("cls");
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
}
//In danh sach teacher
else if (agvList.list[0] == "t") {
db_tc_list.print();
cout << "Input anything to return." << endl;
getchar();
system("cls");
cin.clear();
cin.ignore(INT_MAX, '\n');
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
//In danh sach student
else if (agvList.list[0] == "s") {
db_st_list.print();
cout << "Input anything to return." << endl;
getchar();
system("cls");
cin.clear();
cin.ignore(INT_MAX, '\n');
cout << "PRESS ENTER TO GO BACK\n";
cin.get();
return true;
}
//Dang xuat
else if (agvList.list[0] == "lo") {
ad.logout();
system("cls");
@@ -759,5 +741,4 @@ bool adminProcess(Admin& ad, UserList& user_list, StudentList& db_st_list, Teach
}
return false;
}
#pragma endregion