2022-07-06 14:06:57 +08:00
|
|
|
|
/*
|
|
|
|
|
* 菜单接口实现
|
|
|
|
|
*/
|
2022-07-04 00:31:52 +08:00
|
|
|
|
#include"Menu.h"
|
|
|
|
|
|
|
|
|
|
void mainMenu(_ConnectionPtr connection) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
|
|
|
|
system("cls");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("1.显示所有学生\n");
|
|
|
|
|
printf("2.增加学生\n");
|
|
|
|
|
printf("3.删除学生\n");
|
|
|
|
|
printf("4.修改学生\n");
|
|
|
|
|
printf("5.从文件导入学生信息\n");
|
|
|
|
|
printf("6.导出学生信息到文件\n");
|
|
|
|
|
printf("7.学生成绩管理\n");
|
|
|
|
|
printf("8.课程管理\n");
|
|
|
|
|
printf("9.高级功能\n");
|
|
|
|
|
printf("0.退出\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 9);
|
2022-07-04 00:31:52 +08:00
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 1://显示所有学生
|
2022-07-04 15:59:30 +08:00
|
|
|
|
showAllStudent(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 2://增加学生
|
2022-07-04 15:59:30 +08:00
|
|
|
|
insertStudent(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 3://删除学生
|
2022-07-04 15:59:30 +08:00
|
|
|
|
deleteStudent(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 4://修改学生
|
2022-07-04 15:59:30 +08:00
|
|
|
|
changeStudent(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 5://从文件导入学生信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
importData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 6://导出学生信息到文件
|
2022-07-04 15:59:30 +08:00
|
|
|
|
exportData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 7://学生成绩管理
|
2022-07-04 15:59:30 +08:00
|
|
|
|
studentGradeMenu(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 8://课程管理
|
2022-07-04 15:59:30 +08:00
|
|
|
|
courseMenu(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 9://高级功能
|
2022-07-04 15:59:30 +08:00
|
|
|
|
advancedFunction(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://退出程序
|
2022-07-04 15:59:30 +08:00
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
wprintf(L"操作失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void studentGradeMenu(_ConnectionPtr connection) {
|
|
|
|
|
while (true) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
try {
|
|
|
|
|
system("cls");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("1.输入学生成绩\n");
|
|
|
|
|
printf("2.获取学生平均成绩\n");
|
|
|
|
|
printf("3.获取学生总成绩\n");
|
|
|
|
|
printf("4.获取班级平均分\n");
|
|
|
|
|
printf("5.获取班级最高分\n");
|
|
|
|
|
printf("6.获取班级最低分\n");
|
|
|
|
|
printf("7.获取班级成绩\n");
|
|
|
|
|
printf("8.二级拓展菜单\n");
|
|
|
|
|
printf("0.返回上一级\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
|
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 8);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
string stuId, courseId;
|
|
|
|
|
string stuClass, courseName;
|
|
|
|
|
double grade = -1;
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
Student* student;
|
|
|
|
|
Course* course;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
vector<Grade>* v;
|
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 1://输入学生成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
cin >> courseName;
|
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入分数(0-100):");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
while (!(cin >> grade) || (grade < 0) || (grade > 100)) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "输入错误!请重新输入:";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin.clear();
|
|
|
|
|
while (cin.get() != '\n');
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
|
|
|
|
addGrade(connection, *new Grade(stuId, course->getId(), doubleToString(grade)));
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("添加成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 2://获取学生平均成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("学生平均成绩为:%.2lf\n", getOnesAvgGrade(connection, stuId));
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 3://获取学生总成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("学生总成绩为:%.2lf\n", getOnesAllGrade(connection, stuId));
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 4://获取班级平均分
|
|
|
|
|
printf("请输入班级:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuClass;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
v = getGradeByStuClass(connection, stuClass);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该班级不存在或无成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << stuClass << " 班级 " << courseName << " 课程的平均分为:" << getClassAvgGrade(connection, stuClass, courseName) << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 5://获取班级最高分
|
|
|
|
|
printf("请输入班级:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuClass;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
v = getGradeByStuClass(connection, stuClass);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该班级不存在或无成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << stuClass << " 班级 " << courseName << " 课程的最高分为:" << getClassMaxGrade(connection, stuClass, courseName) << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 6://获取班级最低分
|
|
|
|
|
printf("请输入班级:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuClass;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
v = getGradeByStuClass(connection, stuClass);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该班级不存在或无成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << stuClass << " 班级 " << courseName << " 课程的最低分为:" << getClassMinGrade(connection, stuClass, courseName) << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 7://获取班级成绩
|
|
|
|
|
printf("请输入班级:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuClass;
|
|
|
|
|
v = getGradeByStuClass(connection, stuClass);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该班级不存在或无成绩记录!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
size = v->size();
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "学号\t" << "课程名\t" << "成绩\n";
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*v)[i].toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 8://二级拓展菜单
|
2022-07-04 00:31:52 +08:00
|
|
|
|
studentGradeExternMenu(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://返回上一级
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
wprintf(L"操作失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
|
|
|
|
|
system("pause");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void studentGradeExternMenu(_ConnectionPtr connection) {
|
|
|
|
|
while (true) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
try {
|
|
|
|
|
system("cls");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("1.删除某学生某科成绩\n");
|
|
|
|
|
printf("2.删除某学生成绩\n");
|
|
|
|
|
printf("3.删除某科成绩\n");
|
|
|
|
|
printf("4.更改某学生某科成绩\n");
|
|
|
|
|
printf("5.查询某学生某科成绩\n");
|
|
|
|
|
printf("6.查询某学生成绩\n");
|
|
|
|
|
printf("7.查询某科成绩\n");
|
|
|
|
|
printf("8.查询所有成绩\n");
|
|
|
|
|
printf("0.返回上一级\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
|
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 8);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
string stuId, courseId;
|
|
|
|
|
string stuClass, courseName;
|
|
|
|
|
double grade = -1;
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
vector<Grade>* v;
|
|
|
|
|
Grade* gra;
|
|
|
|
|
Course* course;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
Student* student;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 1://删除某学生某科成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
|
|
|
|
gra = getOnesGrade(connection, stuId, course->getId());
|
|
|
|
|
if (gra == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在该课程的成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
deleteOnesGrade(connection, stuId, course->getId());
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("删除成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 2://删除某学生成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v = getGradeByStuId(connection, stuId);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
deleteGradeByStuId(connection, stuId);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("删除成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 3://删除某科成绩
|
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
|
|
|
|
v = getGradeByCourseId(connection, course->getId());
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
deleteGradeByCourseId(connection, course->getId());
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("删除成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 4://更改某学生某科成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
|
|
|
|
gra = getOnesGrade(connection, stuId, course->getId());
|
|
|
|
|
if (gra == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在该课程的成绩记录!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入新分数(0-100):");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
while (!(cin >> grade) || (opt < 0) || (opt > 100)) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "输入错误!请重新输入:";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin.clear();
|
|
|
|
|
while (cin.get() != '\n');
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
updateOnesGrade(connection, stuId, course->getId(), doubleToString(grade));
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("更改成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 5://查询某学生某科成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
gra = getOnesGrade(connection, stuId, course->getId());
|
|
|
|
|
if (gra == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在该课程的成绩记录!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "学号\t" << "课程名\t" << "成绩\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*gra).toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 6://查询某学生成绩
|
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> stuId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
student = getStudentById(connection, stuId);
|
|
|
|
|
if (student == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
v = getGradeByStuId(connection, stuId);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在成绩记录!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
size = v->size();
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "学号\t" << "课程名\t" << "成绩\n";
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*v)[i].toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 7://查询某科成绩
|
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
|
|
|
|
course = getCourseByName(connection, courseName);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
v = getGradeByCourseId(connection, course->getId());
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在对应成绩!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
size = v->size();
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "学号\t" << "课程名\t" << "成绩\n";
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*v)[i].toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 8://查询所有成绩
|
2022-07-04 00:31:52 +08:00
|
|
|
|
v = getAllGrade(connection);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("无成绩记录!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
size = v->size();
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "学号\t" << "课程名\t" << "成绩\n";
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*v)[i].toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://返回上一级
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
wprintf(L"操作失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
|
|
|
|
|
system("pause");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void courseMenu(_ConnectionPtr connection) {
|
|
|
|
|
while (true) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
try {
|
|
|
|
|
system("cls");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("1.添加课程\n");
|
|
|
|
|
printf("2.删除课程\n");
|
|
|
|
|
printf("3.更改课程\n");
|
|
|
|
|
printf("4.查询所有课程\n");
|
|
|
|
|
printf("0.返回上一级\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 4);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
string courseId, courseName;
|
|
|
|
|
vector<Course>* v;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
Course* course;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 1://添加课程
|
|
|
|
|
printf("请输入课程号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
course = getCourseById(connection,courseId);
|
|
|
|
|
if (course != NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程已存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
addCourse(connection, *new Course(courseId, courseName));
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("添加成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 2://删除课程
|
|
|
|
|
printf("请输入课程号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
course = getCourseById(connection, courseId);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
deleteCourse(connection, courseId);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("删除成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 3://更改课程
|
|
|
|
|
printf("请输入课程号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseId;
|
2022-07-04 23:39:46 +08:00
|
|
|
|
course = getCourseById(connection, courseId);
|
|
|
|
|
if (course == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该课程不存在!\n");
|
2022-07-04 23:39:46 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入课程名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> courseName;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
updateCourseName(connection, courseId, courseName);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("更新成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 4://查询所有课程
|
2022-07-04 00:31:52 +08:00
|
|
|
|
v = getAllCourse(connection);
|
|
|
|
|
if (v == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("不存在课程记录!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
size = v->size();
|
2022-07-06 14:06:57 +08:00
|
|
|
|
cout << "课程号\t" << "课程名\n";
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*v)[i].toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://返回上一级
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
wprintf(L"操作失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void advancedFunction(_ConnectionPtr connection) {
|
|
|
|
|
system("cls");
|
|
|
|
|
_RecordsetPtr record(_uuidof(Recordset));
|
|
|
|
|
string sql;
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
//重置cin并清空缓冲区
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cin.clear();
|
|
|
|
|
while (cin.get() != '\n');
|
2022-07-04 22:17:38 +08:00
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
//输出提示符
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"sql>");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
//获取SQL命令
|
2022-07-04 15:59:30 +08:00
|
|
|
|
getline(cin, sql);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
while (sql == "" || trim(sql)[trim(sql).size() - 1] != ';') {//获取多行的SQL语句
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L" >");
|
|
|
|
|
string tmp;
|
|
|
|
|
getline(cin, tmp);
|
|
|
|
|
sql += " " + tmp;
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
//去除首尾空格及中间多余空格
|
2022-07-04 22:17:38 +08:00
|
|
|
|
sql = reduce(sql);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
//获取SQL语句类别
|
2022-07-04 15:59:30 +08:00
|
|
|
|
string comType = "";
|
|
|
|
|
getSqlType(sql, comType);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
//执行SQL命令
|
|
|
|
|
if (comType == "select") {//查询
|
2022-07-04 15:59:30 +08:00
|
|
|
|
record = connection->Execute(sql.c_str(), NULL, (long)0);
|
|
|
|
|
for (long i = 0; i < record->Fields->Count; i++)
|
|
|
|
|
wprintf(L"%s\t", (wchar_t*)record->Fields->GetItem(i)->Name);
|
|
|
|
|
printf("\n");
|
|
|
|
|
wprintf(L"%s", (wchar_t*)record->GetString(adClipString, long(-1), "\t", "\n", "Null"));
|
2022-07-06 14:06:57 +08:00
|
|
|
|
}else if (comType == "exit" || comType == "exit;") {//退出
|
2022-07-04 15:59:30 +08:00
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
}else {//其他类型
|
2022-07-04 15:59:30 +08:00
|
|
|
|
connection->Execute(sql.c_str(), NULL, (long)0);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
|
|
|
|
wprintf(L"\nThe application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n\n", (wchar_t*)err.Description());
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
void showAllStudent(_ConnectionPtr connection) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
vector<Student>* vs = getAllStudent(connection);
|
|
|
|
|
if (vs == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("学生信息为空!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size = vs->size();
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("学号\t姓名\t性别\t班级\t状态\n");
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
cout << (*vs)[i].toString() << "\n";
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insertStudent(_ConnectionPtr connection) {
|
|
|
|
|
Student *stu = new Student();
|
|
|
|
|
|
|
|
|
|
string str;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> str;
|
2022-07-04 22:17:38 +08:00
|
|
|
|
Student* checkExist = getStudentById(connection, str);
|
|
|
|
|
if (checkExist != NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生已存在!\n");
|
2022-07-04 22:17:38 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
stu->setId(str);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入姓名:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> str;
|
|
|
|
|
stu->setName(str);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入性别:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> str;
|
|
|
|
|
stu->setSex(str);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入班级:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> str;
|
|
|
|
|
stu->setStuClass(str);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入学生状态(在读、休学、退学):");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> str;
|
|
|
|
|
stu->setStatus(str);
|
|
|
|
|
|
|
|
|
|
addStudent(connection, *stu);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("添加成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteStudent(_ConnectionPtr connection) {
|
|
|
|
|
string id;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入待删除学生的学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> id;
|
|
|
|
|
Student *stu = getStudentById(connection,id);
|
|
|
|
|
if (stu == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-04 23:39:46 +08:00
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
deleteStudent(connection, id);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("删除成功!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changeStudent(_ConnectionPtr connection) {
|
|
|
|
|
string id;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请输入待修改学生的学号:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> id;
|
|
|
|
|
Student* stu = getStudentById(connection, id);
|
|
|
|
|
if (stu == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("该学生不存在!\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("请选择修改 班级(0) / 学生状态(1):\n");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 1);
|
|
|
|
|
|
|
|
|
|
string input;
|
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 0://修改班级
|
|
|
|
|
printf("\n请输入新班级:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> input;
|
|
|
|
|
updateStudentClass(connection,id,input);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://修改状态
|
|
|
|
|
printf("\n请输入新状态:");
|
2022-07-04 00:31:52 +08:00
|
|
|
|
cin >> input;
|
|
|
|
|
updateStudentStatus(connection,id, input);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void exportData(_ConnectionPtr connection) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
// 文件夹不存在则创建文件夹
|
2022-07-04 22:17:38 +08:00
|
|
|
|
if (_access("./data", 0) == -1) {
|
|
|
|
|
_mkdir("./data");
|
|
|
|
|
}
|
2022-07-04 15:59:30 +08:00
|
|
|
|
system("cls");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("1.导出学生信息\n");
|
|
|
|
|
printf("2.导出课程信息\n");
|
|
|
|
|
printf("3.导出成绩信息\n");
|
|
|
|
|
printf("4.导出所有信息\n");
|
|
|
|
|
printf("0.返回上一级\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 4);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 1://导出学生信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
exportStudentData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 2://导出课程信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
exportCourseData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 3://导出成绩信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
exportGradeData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 4://导出所有信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
exportAllData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://返回上一级
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
wprintf(L"操作失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void exportStudentData(_ConnectionPtr connection) {
|
2022-07-04 22:17:38 +08:00
|
|
|
|
ofstream outFile("./data/student.txt", ios::out);
|
2022-07-04 15:59:30 +08:00
|
|
|
|
if (!outFile.is_open()) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("导出student.txt文件失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
vector<Student>* vs;
|
|
|
|
|
vs = getAllStudent(connection);
|
|
|
|
|
if (vs == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("学生信息为空!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
outFile.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
outFile << "学号\t姓名\t性别\t班级\t状态\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
size = vs->size();
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
|
outFile << (*vs)[i].toString();
|
|
|
|
|
if (i != (size - 1)) outFile << "\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成功导出student.txt文件!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
outFile.close();
|
|
|
|
|
}
|
2022-07-04 00:31:52 +08:00
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
void exportCourseData(_ConnectionPtr connection) {
|
2022-07-04 22:17:38 +08:00
|
|
|
|
ofstream outFile("./data/course.txt", ios::out);
|
2022-07-04 15:59:30 +08:00
|
|
|
|
if (!outFile.is_open()) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("导出course.txt文件失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
vector<Course>* vc;
|
|
|
|
|
vc = getAllCourse(connection);
|
|
|
|
|
if (vc == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("课程信息为空!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
outFile.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
outFile << "课程号\t课程名\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
size = vc->size();
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
|
outFile << (*vc)[i].toString();
|
|
|
|
|
if (i != (size - 1)) outFile << "\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成功导出course.txt文件!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
outFile.close();
|
2022-07-04 00:31:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
void exportGradeData(_ConnectionPtr connection) {
|
2022-07-04 22:17:38 +08:00
|
|
|
|
ofstream outFile("./data/grade.txt", ios::out);
|
2022-07-04 15:59:30 +08:00
|
|
|
|
if (!outFile.is_open()) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("导出grade.txt文件失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 22:17:38 +08:00
|
|
|
|
size_t size;
|
2022-07-04 15:59:30 +08:00
|
|
|
|
vector<Grade>* vg;
|
|
|
|
|
vg = getAllGrade(connection);
|
|
|
|
|
if (vg == NULL) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成绩信息为空!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
outFile.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
outFile << "学号\t课程号\t成绩\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
size = vg->size();
|
2022-07-04 22:17:38 +08:00
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
|
outFile << (*vg)[i].toString();
|
|
|
|
|
if (i != (size - 1)) outFile << "\n";
|
2022-07-04 15:59:30 +08:00
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成功导出grade.txt文件!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
outFile.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void exportAllData(_ConnectionPtr connection) {
|
|
|
|
|
exportStudentData(connection);
|
|
|
|
|
exportCourseData(connection);
|
|
|
|
|
exportGradeData(connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
void importData(_ConnectionPtr connection) {
|
2022-07-04 15:59:30 +08:00
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
// 文件夹不存在则创建文件夹
|
2022-07-04 22:17:38 +08:00
|
|
|
|
if (_access("./data", 0) == -1) {
|
|
|
|
|
_mkdir("./data");
|
|
|
|
|
}
|
2022-07-04 15:59:30 +08:00
|
|
|
|
system("cls");
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("1.导入学生信息\n");
|
|
|
|
|
printf("2.导入课程信息\n");
|
|
|
|
|
printf("3.导入成绩信息\n");
|
|
|
|
|
printf("4.导入所有信息\n");
|
|
|
|
|
printf("0.返回上一级\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
int opt = -1;
|
|
|
|
|
checkOptInput(opt, 0, 4);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
switch (opt) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 1://导入学生信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
importStudentData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 2://导入课程信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
importCourseData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 3://导入成绩信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
importGradeData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
case 4://导入所有信息
|
2022-07-04 15:59:30 +08:00
|
|
|
|
importAllData(connection);
|
|
|
|
|
break;
|
2022-07-06 14:06:57 +08:00
|
|
|
|
default://返回上一级
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
catch (_com_error& err) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
wprintf(L"操作失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
|
|
|
|
|
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
|
|
|
|
|
system("pause");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void importStudentData(_ConnectionPtr connection) {
|
2022-07-04 22:17:38 +08:00
|
|
|
|
ifstream inFile("./data/student.txt", ios::in);
|
2022-07-04 15:59:30 +08:00
|
|
|
|
if (!inFile.is_open()) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("读取student.txt文件失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
string title[5];//用于存储表头及每行的数据
|
2022-07-04 15:59:30 +08:00
|
|
|
|
inFile >> title[0] >> title[1] >> title[2] >> title[3] >> title[4];
|
2022-07-06 14:06:57 +08:00
|
|
|
|
if (!(title[0] == "学号" && title[1] == "姓名" && title[2] == "性别" && title[3] == "班级" && title[4] == "状态")) {
|
|
|
|
|
printf("文件格式异常,读取失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Student* student = new Student();
|
|
|
|
|
while (!inFile.eof()) {
|
|
|
|
|
inFile >> title[0] >> title[1] >> title[2] >> title[3] >> title[4];
|
|
|
|
|
student->setId(title[0]);
|
|
|
|
|
student->setName(title[1]);
|
|
|
|
|
student->setSex(title[2]);
|
|
|
|
|
student->setStuClass(title[3]);
|
|
|
|
|
student->setStatus(title[4]);
|
|
|
|
|
addStudent(connection, *student);
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成功导入student.txt文件!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
inFile.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void importCourseData(_ConnectionPtr connection) {
|
2022-07-04 22:17:38 +08:00
|
|
|
|
ifstream inFile("./data/course.txt", ios::in);
|
2022-07-04 15:59:30 +08:00
|
|
|
|
if (!inFile.is_open()) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("读取course.txt文件失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
string title[2];//用于存储表头及每行的数据
|
2022-07-04 15:59:30 +08:00
|
|
|
|
inFile >> title[0] >> title[1];
|
2022-07-06 14:06:57 +08:00
|
|
|
|
if (!(title[0] == "课程号" && title[1] == "课程名")) {
|
|
|
|
|
printf("文件格式异常,读取失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Course* course = new Course();
|
|
|
|
|
while (!inFile.eof()) {
|
|
|
|
|
inFile >> title[0] >> title[1];
|
|
|
|
|
course->setId(title[0]);
|
|
|
|
|
course->setName(title[1]);
|
|
|
|
|
addCourse(connection, *course);
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成功导入course.txt文件!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
inFile.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void importGradeData(_ConnectionPtr connection) {
|
2022-07-04 22:17:38 +08:00
|
|
|
|
ifstream inFile("./data/grade.txt", ios::in);
|
2022-07-04 15:59:30 +08:00
|
|
|
|
if (!inFile.is_open()) {
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("读取grade.txt文件失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 14:06:57 +08:00
|
|
|
|
string title[3];//用于存储表头及每行的数据
|
2022-07-04 15:59:30 +08:00
|
|
|
|
inFile >> title[0] >> title[1] >> title[2];
|
2022-07-06 14:06:57 +08:00
|
|
|
|
if (!(title[0] == "学号" && title[1] == "课程号" && title[2] == "成绩")) {
|
|
|
|
|
printf("文件格式异常,读取失败!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Grade* grade = new Grade();
|
|
|
|
|
while (!inFile.eof()) {
|
|
|
|
|
inFile >> title[0] >> title[1] >> title[2];
|
|
|
|
|
grade->setStuId(title[0]);
|
|
|
|
|
grade->setCourseId(title[1]);
|
|
|
|
|
grade->setGrade(title[2]);
|
|
|
|
|
addGrade(connection, *grade);
|
|
|
|
|
}
|
2022-07-06 14:06:57 +08:00
|
|
|
|
printf("成功导入grade.txt文件!\n");
|
2022-07-04 15:59:30 +08:00
|
|
|
|
inFile.close();
|
|
|
|
|
}
|
2022-07-04 00:31:52 +08:00
|
|
|
|
|
2022-07-04 15:59:30 +08:00
|
|
|
|
void importAllData(_ConnectionPtr connection) {
|
|
|
|
|
importStudentData(connection);
|
|
|
|
|
importCourseData(connection);
|
|
|
|
|
importGradeData(connection);
|
2022-07-06 14:06:57 +08:00
|
|
|
|
}
|