2022-07-06 14:06 项目结构整理,bean对象转为h文件

This commit is contained in:
zyx 2022-07-06 14:06:57 +08:00
parent 6bfb44a15a
commit 95d278f325
17 changed files with 492 additions and 473 deletions

View File

@ -1,8 +1,8 @@
/* /*
* ¿Î³Ì±íDAO * DAO
*/ */
#ifndef COURSE_CPP #ifndef COURSE_H
#define COURSE_CPP #define COURSE_H
#include<string> #include<string>
using std::string; using std::string;
@ -24,8 +24,8 @@ public:
return id + "\t" + name; return id + "\t" + name;
} }
private: private:
string id;//¿Î³ÌºÅ string id;//课程号
string name;//¿Î³ÌÃû string name;//课程名
}; };
#endif // !COURSE_CPP #endif // !COURSE_H

View File

@ -1,5 +1,5 @@
/* /*
* *
*/ */
#ifndef COURSE_DAO_H #ifndef COURSE_DAO_H
#define COURSE_DAO_H #define COURSE_DAO_H
@ -8,50 +8,50 @@
#include<iostream> #include<iostream>
#include<vector> #include<vector>
#include"Course.cpp" #include"Course.h"
/* /*
* *
* @param connection * @param connection
* @param course * @param course
*/ */
void addCourse(_ConnectionPtr connection, Course course); void addCourse(_ConnectionPtr connection, Course course);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
*/ */
void deleteCourse(_ConnectionPtr connection, string id); void deleteCourse(_ConnectionPtr connection, string id);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
* @param name * @param name
*/ */
void updateCourseName(_ConnectionPtr connection, string id, string name); void updateCourseName(_ConnectionPtr connection, string id, string name);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
* @return Course* course对象指针 * @return Course* course对象指针
*/ */
Course* getCourseById(_ConnectionPtr connection, string id); Course* getCourseById(_ConnectionPtr connection, string id);
/* /*
* *
* @param connection * @param connection
* @param name * @param name
* @return Course* course对象指针 * @return Course* course对象指针
*/ */
Course* getCourseByName(_ConnectionPtr connection, string name); Course* getCourseByName(_ConnectionPtr connection, string name);
/* /*
* *
* @param connection * @param connection
* @return vector<Course>* Course对象为元素的vector数组指针 * @return vector<Course>* Course对象为元素的vector数组指针
*/ */
std::vector<Course>* getAllCourse(_ConnectionPtr connection); std::vector<Course>* getAllCourse(_ConnectionPtr connection);

View File

@ -1,3 +1,6 @@
/*
*
*/
#include"CourseDAO.h" #include"CourseDAO.h"
void addCourse(_ConnectionPtr connection, Course course) { void addCourse(_ConnectionPtr connection, Course course) {
@ -22,7 +25,7 @@ void updateCourseName(_ConnectionPtr connection, string id, string name) {
Course* getCourseById(_ConnectionPtr connection, string id) { Course* getCourseById(_ConnectionPtr connection, string id) {
string sql = "select * from course where id = '" + id + "'"; string sql = "select * from course where id = '" + id + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
Course* course = new Course(); Course* course = new Course();
course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
@ -33,7 +36,7 @@ Course* getCourseById(_ConnectionPtr connection, string id) {
Course* getCourseByName(_ConnectionPtr connection, string name) { Course* getCourseByName(_ConnectionPtr connection, string name) {
string sql = "select * from course where name = '" + name + "'"; string sql = "select * from course where name = '" + name + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
Course* course = new Course(); Course* course = new Course();
course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
@ -44,7 +47,7 @@ Course* getCourseByName(_ConnectionPtr connection, string name) {
std::vector<Course>* getAllCourse(_ConnectionPtr connection) { std::vector<Course>* getAllCourse(_ConnectionPtr connection) {
string sql = "select * from course"; string sql = "select * from course";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Course>* v = new std::vector<Course>(); std::vector<Course>* v = new std::vector<Course>();
Course* course; Course* course;

View File

@ -1,40 +1,43 @@
/*
*
*/
#include"DBCUtils.h" #include"DBCUtils.h"
bool getConnection(std::string& pwd, _ConnectionPtr& connection) { bool getConnection(std::string& pwd, _ConnectionPtr& connection) {
bool isPwdTrue = false; bool isPwdTrue = false;
_bstr_t strConnect; _bstr_t strConnect;
if (!pwd.empty()) {//密码非空使用SQL Server身份验证 if (!pwd.empty()) {//密码非空使用SQL Server身份验证
try { try {
std::string con = "Provider=SQLOLEDB.1;Password=" + pwd + "; Persist Security Info = True; User ID = sa; Initial Catalog = stuAdminSystem; Data Source = LAPTOP-4DMOD6O5"; std::string con = "Provider=SQLOLEDB.1;Password=" + pwd + "; Persist Security Info = True; User ID = sa; Initial Catalog = stuAdminSystem; Data Source = LAPTOP-4DMOD6O5";
strConnect = con.c_str(); strConnect = con.c_str();
connection->Open(strConnect, "", "", NULL); connection->Open(strConnect, "", "", NULL);
isPwdTrue = true;//密码正确,连接成功 isPwdTrue = true;//密码正确,连接成功
wprintf(L"登录成功!\n"); wprintf(L"登录成功!\n");
return true; return true;
} }
catch (_com_error& err) { catch (_com_error& err) {
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage()); wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
wprintf(L"Description = %s\n", (wchar_t*)err.Description()); wprintf(L"Description = %s\n", (wchar_t*)err.Description());
} }
if (!isPwdTrue) {//密码错误连接失败打开连接失败跳出try块执行 if (!isPwdTrue) {//密码错误连接失败打开连接失败跳出try块执行
wprintf(L"密码错误!\n"); wprintf(L"密码错误!\n");
return false; return false;
} }
} }
else {//密码为空使用Windows 身份验证 else {//密码为空使用Windows 身份验证
try { try {
strConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=stuAdminSystem;Data Source=LAPTOP-4DMOD6O5"; strConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=stuAdminSystem;Data Source=LAPTOP-4DMOD6O5";
connection->Open(strConnect, "", "", NULL); connection->Open(strConnect, "", "", NULL);
isPwdTrue = true;//验证成功,连接成功 isPwdTrue = true;//验证成功,连接成功
wprintf(L"登录成功!\n"); wprintf(L"登录成功!\n");
return true; return true;
} }
catch (_com_error& err) { catch (_com_error& err) {
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage()); wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
wprintf(L"Description = %s\n", (wchar_t*)err.Description()); wprintf(L"Description = %s\n", (wchar_t*)err.Description());
} }
if (!isPwdTrue) {//验证失败连接失败打开连接失败跳出try块执行 if (!isPwdTrue) {//验证失败连接失败打开连接失败跳出try块执行
wprintf(L"验证失败!\n"); wprintf(L"验证失败!\n");
return false; return false;
} }
} }
@ -43,7 +46,7 @@ bool getConnection(std::string& pwd, _ConnectionPtr& connection) {
void getSqlType(std::string& sql, std::string& comType) { void getSqlType(std::string& sql, std::string& comType) {
size_t len = sql.length(); size_t len = sql.length();
for (size_t i = 0; i < len; i++) {//获取SQL语句的类别 for (size_t i = 0; i < len; i++) {//获取SQL语句的类别
if (sql[i] != ' ') if (sql[i] != ' ')
comType += isupper(sql[i]) ? (sql[i] - 32) : sql[i]; comType += isupper(sql[i]) ? (sql[i] - 32) : sql[i];
else return; else return;

View File

@ -1,8 +1,8 @@
/* /*
* DAO * DAO
*/ */
#ifndef GRADE_CPP #ifndef GRADE_H
#define GRADE_CPP #define GRADE_H
#include<string> #include<string>
using std::string; using std::string;
@ -28,9 +28,9 @@ public:
return stuId + "\t" + courseId + "\t" + grade; return stuId + "\t" + courseId + "\t" + grade;
} }
private: private:
string stuId;//学号 string stuId;//学号
string courseId;//课程号 string courseId;//课程号
string grade;//成绩 string grade;//成绩
}; };
#endif // !GRADE_CPP #endif // !GRADE_H

View File

@ -1,5 +1,5 @@
/* /*
* *
*/ */
#ifndef GRADE_DAO_H #ifndef GRADE_DAO_H
#define GRADE_DAO_H #define GRADE_DAO_H
@ -8,126 +8,126 @@
#include<iostream> #include<iostream>
#include<vector> #include<vector>
#include"Grade.cpp" #include"Grade.h"
/* /*
* *
* @param connection * @param connection
* @param grade * @param grade
*/ */
void addGrade(_ConnectionPtr connection, Grade grade); void addGrade(_ConnectionPtr connection, Grade grade);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
* @param courseId * @param courseId
*/ */
void deleteOnesGrade(_ConnectionPtr connection, string stuId,string courseId); void deleteOnesGrade(_ConnectionPtr connection, string stuId,string courseId);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
*/ */
void deleteGradeByStuId(_ConnectionPtr connection, string stuId); void deleteGradeByStuId(_ConnectionPtr connection, string stuId);
/* /*
* *
* @param connection * @param connection
* @param courseId * @param courseId
*/ */
void deleteGradeByCourseId(_ConnectionPtr connection, string courseId); void deleteGradeByCourseId(_ConnectionPtr connection, string courseId);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
* @param courseId * @param courseId
* @param grade * @param grade
*/ */
void updateOnesGrade(_ConnectionPtr connection, string stuId, string courseId, string grade); void updateOnesGrade(_ConnectionPtr connection, string stuId, string courseId, string grade);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
* @param courseId * @param courseId
* @return Grade* grade对象指针 * @return Grade* grade对象指针
*/ */
Grade* getOnesGrade(_ConnectionPtr connection, string stuId, string courseId); Grade* getOnesGrade(_ConnectionPtr connection, string stuId, string courseId);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
* @return vector<Grade>* Grade对象为元素的vector数组指针 * @return vector<Grade>* Grade对象为元素的vector数组指针
*/ */
std::vector<Grade>* getGradeByStuId(_ConnectionPtr connection, string stuId); std::vector<Grade>* getGradeByStuId(_ConnectionPtr connection, string stuId);
/* /*
* *
* @param connection * @param connection
* @param coursesId * @param coursesId
* @return vector<Grade>* Grade对象为元素的vector数组指针 * @return vector<Grade>* Grade对象为元素的vector数组指针
*/ */
std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseId); std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseId);
/* /*
* *
* @param connection * @param connection
* @param stuClass * @param stuClass
* @return vector<Grade>* Grade对象为元素的vector数组指针 * @return vector<Grade>* Grade对象为元素的vector数组指针
*/ */
std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string stuClass); std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string stuClass);
/* /*
* *
* @param connection * @param connection
* @return vector<Grade>* Grade对象为元素的vector数组指针 * @return vector<Grade>* Grade对象为元素的vector数组指针
*/ */
std::vector<Grade>* getAllGrade(_ConnectionPtr connection); std::vector<Grade>* getAllGrade(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
* @return double * @return double
*/ */
double getOnesAvgGrade(_ConnectionPtr connection, string stuId); double getOnesAvgGrade(_ConnectionPtr connection, string stuId);
/* /*
* *
* @param connection * @param connection
* @param stuId * @param stuId
* @return double * @return double
*/ */
double getOnesAllGrade(_ConnectionPtr connection, string stuId); double getOnesAllGrade(_ConnectionPtr connection, string stuId);
/* /*
* *
* @param connection * @param connection
* @param stuClass * @param stuClass
* @param courseName * @param courseName
* @return double * @return double
*/ */
double getClassAvgGrade(_ConnectionPtr connection, string stuClass, string courseName); double getClassAvgGrade(_ConnectionPtr connection, string stuClass, string courseName);
/* /*
* *
* @param connection * @param connection
* @param stuClass * @param stuClass
* @param courseName * @param courseName
* @return double * @return double
*/ */
double getClassMaxGrade(_ConnectionPtr connection, string stuClass, string courseName); double getClassMaxGrade(_ConnectionPtr connection, string stuClass, string courseName);
/* /*
* *
* @param connection * @param connection
* @param stuClass * @param stuClass
* @param courseName * @param courseName
* @return double * @return double
*/ */
double getClassMinGrade(_ConnectionPtr connection, string stuClass, string courseName); double getClassMinGrade(_ConnectionPtr connection, string stuClass, string courseName);

View File

@ -1,3 +1,6 @@
/*
*
*/
#include"GradeDAO.h" #include"GradeDAO.h"
void addGrade(_ConnectionPtr connection, Grade grade) { void addGrade(_ConnectionPtr connection, Grade grade) {
@ -35,7 +38,7 @@ void updateOnesGrade(_ConnectionPtr connection, string stuId, string courseId, s
Grade* getOnesGrade(_ConnectionPtr connection, string stuId,string courseId) { Grade* getOnesGrade(_ConnectionPtr connection, string stuId,string courseId) {
string sql = "select * from grade where stuId = '" + stuId + "\' and courseId = \'" + courseId + "'"; string sql = "select * from grade where stuId = '" + stuId + "\' and courseId = \'" + courseId + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
Grade* grade = new Grade(); Grade* grade = new Grade();
grade->setStuId((char*)(_bstr_t)record->Fields->GetItem("stuId")->Value); grade->setStuId((char*)(_bstr_t)record->Fields->GetItem("stuId")->Value);
@ -47,7 +50,7 @@ Grade* getOnesGrade(_ConnectionPtr connection, string stuId,string courseId) {
std::vector<Grade>* getGradeByStuId(_ConnectionPtr connection, string stuId) { std::vector<Grade>* getGradeByStuId(_ConnectionPtr connection, string stuId) {
string sql = "select * from grade where stuId = '" + stuId + "'"; string sql = "select * from grade where stuId = '" + stuId + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Grade>* v = new std::vector<Grade>(); std::vector<Grade>* v = new std::vector<Grade>();
Grade* grade; Grade* grade;
@ -64,7 +67,7 @@ std::vector<Grade>* getGradeByStuId(_ConnectionPtr connection, string stuId) {
std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseId) { std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseId) {
string sql = "select * from grade where courseId = '" + courseId + "'"; string sql = "select * from grade where courseId = '" + courseId + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Grade>* v = new std::vector<Grade>(); std::vector<Grade>* v = new std::vector<Grade>();
Grade* grade; Grade* grade;
@ -81,7 +84,7 @@ std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseI
std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string stuClass) { std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string stuClass) {
string sql = "select * from grade where stuId in(select id from student where stuClass = '" + stuClass + "')"; string sql = "select * from grade where stuId in(select id from student where stuClass = '" + stuClass + "')";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Grade>* v = new std::vector<Grade>(); std::vector<Grade>* v = new std::vector<Grade>();
Grade* grade; Grade* grade;
@ -98,7 +101,7 @@ std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string stuClas
std::vector<Grade>* getAllGrade(_ConnectionPtr connection) { std::vector<Grade>* getAllGrade(_ConnectionPtr connection) {
string sql = "select * from grade"; string sql = "select * from grade";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Grade>* v = new std::vector<Grade>(); std::vector<Grade>* v = new std::vector<Grade>();
Grade* grade; Grade* grade;
@ -115,7 +118,7 @@ std::vector<Grade>* getAllGrade(_ConnectionPtr connection) {
double getOnesAvgGrade(_ConnectionPtr connection, string stuId) { double getOnesAvgGrade(_ConnectionPtr connection, string stuId) {
string sql = "select count(*) cnt,sum(grade) all_grade from grade where stuId = '" + stuId + "'"; string sql = "select count(*) cnt,sum(grade) all_grade from grade where stuId = '" + stuId + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
int cnt = atoi((char*)(_bstr_t)record->Fields->GetItem("cnt")->Value); int cnt = atoi((char*)(_bstr_t)record->Fields->GetItem("cnt")->Value);
double all_grade = atof((char*)(_bstr_t)record->Fields->GetItem("all_grade")->Value); double all_grade = atof((char*)(_bstr_t)record->Fields->GetItem("all_grade")->Value);
@ -125,7 +128,7 @@ double getOnesAvgGrade(_ConnectionPtr connection, string stuId) {
double getOnesAllGrade(_ConnectionPtr connection, string stuId) { double getOnesAllGrade(_ConnectionPtr connection, string stuId) {
string sql = "select sum(grade) all_grade from grade where stuId = '" + stuId + "'"; string sql = "select sum(grade) all_grade from grade where stuId = '" + stuId + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
return atof((char*)(_bstr_t)record->Fields->GetItem("all_grade")->Value); return atof((char*)(_bstr_t)record->Fields->GetItem("all_grade")->Value);
} }
@ -134,7 +137,7 @@ double getClassAvgGrade(_ConnectionPtr connection, string stuClass, string cours
string sql = "select avg(grade) avg_grade from grade where stuId in (select id from student where stuClass = '" + stuClass + "') "; string sql = "select avg(grade) avg_grade from grade where stuId in (select id from student where stuClass = '" + stuClass + "') ";
sql += "and courseId in (select id from course where name = '" + courseName + "')"; sql += "and courseId in (select id from course where name = '" + courseName + "')";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
return atof((char*)(_bstr_t)record->Fields->GetItem("avg_grade")->Value); return atof((char*)(_bstr_t)record->Fields->GetItem("avg_grade")->Value);
} }
@ -143,7 +146,7 @@ double getClassMaxGrade(_ConnectionPtr connection, string stuClass, string cours
string sql = "select max(grade) max_grade from grade where stuId in (select id from student where stuClass = '" + stuClass + "') "; string sql = "select max(grade) max_grade from grade where stuId in (select id from student where stuClass = '" + stuClass + "') ";
sql += "and courseId in (select id from course where name = '" + courseName + "')"; sql += "and courseId in (select id from course where name = '" + courseName + "')";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
return atof((char*)(_bstr_t)record->Fields->GetItem("max_grade")->Value); return atof((char*)(_bstr_t)record->Fields->GetItem("max_grade")->Value);
} }
@ -152,7 +155,7 @@ double getClassMinGrade(_ConnectionPtr connection, string stuClass, string cours
string sql = "select min(grade) min_grade from grade where stuId in (select id from student where stuClass = '" + stuClass + "') "; string sql = "select min(grade) min_grade from grade where stuId in (select id from student where stuClass = '" + stuClass + "') ";
sql += "and courseId in (select id from course where name = '" + courseName + "')"; sql += "and courseId in (select id from course where name = '" + courseName + "')";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
return atof((char*)(_bstr_t)record->Fields->GetItem("min_grade")->Value); return atof((char*)(_bstr_t)record->Fields->GetItem("min_grade")->Value);
} }

467
Menu.cpp

File diff suppressed because it is too large Load Diff

83
Menu.h
View File

@ -1,20 +1,15 @@
/* /*
* *
*/ */
#ifndef MENU_H #ifndef MENU_H
#define MENU_H #define MENU_H
#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile")
#include<iostream> #include<iostream>
#include<fstream> #include<fstream>
#include<vector> #include<vector>
#include<direct.h> #include<direct.h>
#include<io.h> #include<io.h>
#include"Student.cpp"
#include"Course.cpp"
#include"Grade.cpp"
#include"DBCUtils.h" #include"DBCUtils.h"
#include"MenuUtils.h" #include"MenuUtils.h"
#include"StringUtils.h" #include"StringUtils.h"
@ -24,116 +19,116 @@
using namespace std; using namespace std;
/* /*
* *
* @param connection * @param connection
*/ */
void mainMenu(_ConnectionPtr connection); void mainMenu(_ConnectionPtr connection);
/* /*
* - * -
* @param connection * @param connection
*/ */
void studentGradeMenu(_ConnectionPtr connection); void studentGradeMenu(_ConnectionPtr connection);
/* /*
* -- * --
* @param connection * @param connection
*/ */
void studentGradeExternMenu(_ConnectionPtr connection); void studentGradeExternMenu(_ConnectionPtr connection);
/* /*
* - * -
* @param connection * @param connection
*/ */
void courseMenu(_ConnectionPtr connection); void courseMenu(_ConnectionPtr connection);
/* /*
* SQL语句 * SQL语句
* @param connection * @param connection
*/ */
void advancedFunction(_ConnectionPtr connection); void advancedFunction(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void showAllStudent(_ConnectionPtr connection); void showAllStudent(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void insertStudent(_ConnectionPtr connection); void insertStudent(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void deleteStudent(_ConnectionPtr connection); void deleteStudent(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void changeStudent(_ConnectionPtr connection); void changeStudent(_ConnectionPtr connection);
/* /*
* - * -
* @param connection * @param connection
*/ */
void exportData(_ConnectionPtr connection); void exportData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void exportStudentData(_ConnectionPtr connection); void exportStudentData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void exportCourseData(_ConnectionPtr connection); void exportCourseData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void exportGradeData(_ConnectionPtr connection); void exportGradeData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void exportAllData(_ConnectionPtr connection); void exportAllData(_ConnectionPtr connection);
/* /*
* - * -
* @param connection * @param connection
*/ */
void importData(_ConnectionPtr connection); void importData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void importStudentData(_ConnectionPtr connection); void importStudentData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void importCourseData(_ConnectionPtr connection); void importCourseData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void importGradeData(_ConnectionPtr connection); void importGradeData(_ConnectionPtr connection);
/* /*
* *
* @param connection * @param connection
*/ */
void importAllData(_ConnectionPtr connection); void importAllData(_ConnectionPtr connection);

View File

@ -1,9 +1,12 @@
/*
*
*/
#include"MenuUtils.h" #include"MenuUtils.h"
void checkOptInput(int& opt, int low, int high) { void checkOptInput(int& opt, int low, int high) {
printf(">>>请输入选项(%d-%d)", low, high); printf(">>>请输入选项(%d-%d)", low, high);
while (!(cin >> opt) || (opt < low) || (opt > high)) { while (!(cin >> opt) || (opt < low) || (opt > high)) {
cout << "输入选项错误!请重新输入:"; cout << "输入选项错误!请重新输入:";
cin.clear(); cin.clear();
while (cin.get() != '\n'); while (cin.get() != '\n');
} }

View File

@ -127,25 +127,25 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Course.cpp" />
<ClCompile Include="CourseDAOImpl.cpp" /> <ClCompile Include="CourseDAOImpl.cpp" />
<ClCompile Include="DBCUtils.cpp" /> <ClCompile Include="DBCUtils.cpp" />
<ClCompile Include="Grade.cpp" />
<ClCompile Include="GradeDAOImpl.cpp" /> <ClCompile Include="GradeDAOImpl.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="Menu.cpp" /> <ClCompile Include="Menu.cpp" />
<ClCompile Include="MenuUtils.cpp" /> <ClCompile Include="MenuUtils.cpp" />
<ClCompile Include="StringUtils.cpp" /> <ClCompile Include="StringUtils.cpp" />
<ClCompile Include="Student.cpp" />
<ClCompile Include="StudentDAOImpl.cpp" /> <ClCompile Include="StudentDAOImpl.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Course.h" />
<ClInclude Include="CourseDAO.h" /> <ClInclude Include="CourseDAO.h" />
<ClInclude Include="DBCUtils.h" /> <ClInclude Include="DBCUtils.h" />
<ClInclude Include="Grade.h" />
<ClInclude Include="GradeDAO.h" /> <ClInclude Include="GradeDAO.h" />
<ClInclude Include="Menu.h" /> <ClInclude Include="Menu.h" />
<ClInclude Include="MenuUtils.h" /> <ClInclude Include="MenuUtils.h" />
<ClInclude Include="StringUtils.h" /> <ClInclude Include="StringUtils.h" />
<ClInclude Include="Student.h" />
<ClInclude Include="StudentDAO.h" /> <ClInclude Include="StudentDAO.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -18,15 +18,6 @@
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Student.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Course.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Grade.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="DBCUtils.cpp"> <ClCompile Include="DBCUtils.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
@ -71,5 +62,14 @@
<ClInclude Include="StringUtils.h"> <ClInclude Include="StringUtils.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Course.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Student.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Grade.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,8 +1,11 @@
/*
*
*/
#include"StringUtils.h" #include"StringUtils.h"
string doubleToString(double num) { string doubleToString(double num) {
char* buf;//double数据转换为无符号整数字符串 如12.34 -> 1234 char* buf;//double数据转换为无符号整数字符串 如12.34 -> 1234
int dec, sign;//dec->小数点前有几位数字 sign->0为正数1为负数 int dec, sign;//dec->小数点前有几位数字 sign->0为正数1为负数
buf = _fcvt(num, 2, &dec, &sign); buf = _fcvt(num, 2, &dec, &sign);

View File

@ -1,3 +1,6 @@
/*
*
*/
#ifndef STRING_UTILS_H #ifndef STRING_UTILS_H
#define STRING_UTILS_H #define STRING_UTILS_H
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
@ -6,23 +9,23 @@
using std::string; using std::string;
/* /*
* double型数据转换为字符串并返回 * double型数据转换为字符串并返回
* @param num double型数据 * @param num double型数据
* @return string * @return string
*/ */
string doubleToString(double num); string doubleToString(double num);
/* /*
* *
* @param str * @param str
* @return string * @return string
*/ */
std::string trim(const std::string& str); std::string trim(const std::string& str);
/* /*
* *
* @param str * @param str
* @return string * @return string
*/ */
std::string reduce(const std::string& str); std::string reduce(const std::string& str);

View File

@ -1,8 +1,8 @@
/* /*
* DAO * DAO
*/ */
#ifndef STUDENT_CPP #ifndef STUDENT_H
#define STUDENT_CPP #define STUDENT_H
#include<string> #include<string>
using std::string; using std::string;
@ -32,11 +32,11 @@ public:
return id + "\t" + name + "\t" + sex + "\t" + stuClass + "\t" + status; return id + "\t" + name + "\t" + sex + "\t" + stuClass + "\t" + status;
} }
private: private:
string id;//学号 string id;//学号
string name;//姓名 string name;//姓名
string sex;//性别 string sex;//性别
string stuClass;//班级 string stuClass;//班级
string status;//状态(在读、休学、退学) string status;//状态(在读、休学、退学)
}; };
#endif // !STUDENT_CPP #endif // !STUDENT_H

View File

@ -1,5 +1,5 @@
/* /*
* *
*/ */
#ifndef STUDENT_DAO_H #ifndef STUDENT_DAO_H
#define STUDENT_DAO_H #define STUDENT_DAO_H
@ -8,58 +8,58 @@
#include<iostream> #include<iostream>
#include<vector> #include<vector>
#include"Student.cpp" #include"Student.h"
/* /*
* *
* @param connection * @param connection
* @param student * @param student
*/ */
void addStudent(_ConnectionPtr connection, Student student); void addStudent(_ConnectionPtr connection, Student student);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
*/ */
void deleteStudent(_ConnectionPtr connection, string id); void deleteStudent(_ConnectionPtr connection, string id);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
* @param stuClass * @param stuClass
*/ */
void updateStudentClass(_ConnectionPtr connection, string id, string stuClass); void updateStudentClass(_ConnectionPtr connection, string id, string stuClass);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
* @param status 退 * @param status 退
*/ */
void updateStudentStatus(_ConnectionPtr connection, string id, string status); void updateStudentStatus(_ConnectionPtr connection, string id, string status);
/* /*
* *
* @param connection * @param connection
* @param id * @param id
* @return Student* student对象指针 * @return Student* student对象指针
*/ */
Student* getStudentById(_ConnectionPtr connection, string id); Student* getStudentById(_ConnectionPtr connection, string id);
/* /*
* *
* @param connection * @param connection
* @param name * @param name
* @return vector<Student>* Student对象为元素的vector数组指针 * @return vector<Student>* Student对象为元素的vector数组指针
*/ */
std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name); std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name);
/* /*
* *
* @param connection * @param connection
* @return vector<Student>* Student对象为元素的vector数组指针 * @return vector<Student>* Student对象为元素的vector数组指针
*/ */
std::vector<Student>* getAllStudent(_ConnectionPtr connection); std::vector<Student>* getAllStudent(_ConnectionPtr connection);

View File

@ -1,3 +1,6 @@
/*
*
*/
#include"StudentDAO.h" #include"StudentDAO.h"
void addStudent(_ConnectionPtr connection, Student student) { void addStudent(_ConnectionPtr connection, Student student) {
@ -31,7 +34,7 @@ void updateStudentStatus(_ConnectionPtr connection, string id, string status) {
Student* getStudentById(_ConnectionPtr connection, string id) { Student* getStudentById(_ConnectionPtr connection, string id) {
string sql = "select * from student where id = '" + id + "'"; string sql = "select * from student where id = '" + id + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
Student *student = new Student(); Student *student = new Student();
student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
@ -45,7 +48,7 @@ Student* getStudentById(_ConnectionPtr connection, string id) {
std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name) { std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name) {
string sql = "select * from student where name = '" + name + "'"; string sql = "select * from student where name = '" + name + "'";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Student> *v = new std::vector<Student>(); std::vector<Student> *v = new std::vector<Student>();
Student* student; Student* student;
@ -64,7 +67,7 @@ std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name) {
std::vector<Student>* getAllStudent(_ConnectionPtr connection) { std::vector<Student>* getAllStudent(_ConnectionPtr connection) {
string sql = "select * from student"; string sql = "select * from student";
_RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0);
if (record->BOF == -1) return NULL;//记录集为空 if (record->BOF == -1) return NULL;//记录集为空
std::vector<Student>* v = new std::vector<Student>(); std::vector<Student>* v = new std::vector<Student>();
Student* student; Student* student;