2022-07-06 14:06 项目结构整理,bean对象转为h文件
This commit is contained in:
parent
6bfb44a15a
commit
95d278f325
@ -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
|
46
CourseDAO.h
46
CourseDAO.h
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
25
DBCUtils.cpp
25
DBCUtils.cpp
@ -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;
|
||||||
|
@ -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
|
126
GradeDAO.h
126
GradeDAO.h
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
83
Menu.h
83
Menu.h
@ -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);
|
||||||
|
|
||||||
|
@ -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');
|
||||||
}
|
}
|
||||||
|
@ -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" />
|
||||||
|
@ -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>
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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
|
54
StudentDAO.h
54
StudentDAO.h
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user