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

View File

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

View File

@ -1,3 +1,6 @@
/*
*
*/
#include"CourseDAO.h"
void addCourse(_ConnectionPtr connection, Course course) {
@ -22,7 +25,7 @@ void updateCourseName(_ConnectionPtr connection, string id, string name) {
Course* getCourseById(_ConnectionPtr connection, string id) {
string sql = "select * from course where id = '" + id + "'";
_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->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) {
string sql = "select * from course where name = '" + name + "'";
_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->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) {
string sql = "select * from course";
_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>();
Course* course;

View File

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

View File

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

View File

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

View File

@ -1,3 +1,6 @@
/*
*
*/
#include"GradeDAO.h"
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) {
string sql = "select * from grade where stuId = '" + stuId + "\' and courseId = \'" + courseId + "'";
_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->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) {
string sql = "select * from grade where stuId = '" + stuId + "'";
_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>();
Grade* grade;
@ -64,7 +67,7 @@ std::vector<Grade>* getGradeByStuId(_ConnectionPtr connection, string stuId) {
std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseId) {
string sql = "select * from grade where courseId = '" + courseId + "'";
_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>();
Grade* grade;
@ -81,7 +84,7 @@ std::vector<Grade>* getGradeByCourseId(_ConnectionPtr connection, string courseI
std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string 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);
if (record->BOF == -1) return NULL;//记录集为空
if (record->BOF == -1) return NULL;//记录集为空
std::vector<Grade>* v = new std::vector<Grade>();
Grade* grade;
@ -98,7 +101,7 @@ std::vector<Grade>* getGradeByStuClass(_ConnectionPtr connection, string stuClas
std::vector<Grade>* getAllGrade(_ConnectionPtr connection) {
string sql = "select * from grade";
_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>();
Grade* grade;
@ -115,7 +118,7 @@ std::vector<Grade>* getAllGrade(_ConnectionPtr connection) {
double getOnesAvgGrade(_ConnectionPtr connection, string 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);
if (record->BOF == -1) return NULL;//记录集为空
if (record->BOF == -1) return NULL;//记录集为空
int cnt = atoi((char*)(_bstr_t)record->Fields->GetItem("cnt")->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) {
string sql = "select sum(grade) all_grade from grade where stuId = '" + stuId + "'";
_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);
}
@ -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 + "') ";
sql += "and courseId in (select id from course where name = '" + courseName + "')";
_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);
}
@ -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 + "') ";
sql += "and courseId in (select id from course where name = '" + courseName + "')";
_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);
}
@ -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 + "') ";
sql += "and courseId in (select id from course where name = '" + courseName + "')";
_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);
}

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

View File

@ -1,9 +1,12 @@
/*
*
*/
#include"MenuUtils.h"
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)) {
cout << "输入选项错误!请重新输入:";
cout << "输入选项错误!请重新输入:";
cin.clear();
while (cin.get() != '\n');
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,6 @@
/*
*
*/
#include"StudentDAO.h"
void addStudent(_ConnectionPtr connection, Student student) {
@ -31,7 +34,7 @@ void updateStudentStatus(_ConnectionPtr connection, string id, string status) {
Student* getStudentById(_ConnectionPtr connection, string id) {
string sql = "select * from student where id = '" + id + "'";
_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->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) {
string sql = "select * from student where name = '" + name + "'";
_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>();
Student* student;
@ -64,7 +67,7 @@ std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name) {
std::vector<Student>* getAllStudent(_ConnectionPtr connection) {
string sql = "select * from student";
_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>();
Student* student;