From a8f69e824b94851c51e8b719079d1d38019618fc Mon Sep 17 00:00:00 2001 From: zyx <1029606625@qq.com> Date: Sun, 3 Jul 2022 18:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Course.cpp | 32 ++++++++++ CourseDAO.h | 16 +++++ CourseDAOImpl.cpp | 45 +++++++++++++ DBCUtils.cpp | 73 ++++++++++++++++++++++ DBCUtils.h | 15 +++++ Grade.cpp | 38 +++++++++++ GradeDAO.h | 19 ++++++ GradeDAOImpl.cpp | 76 ++++++++++++++++++++++ SAS.sln | 31 +++++++++ SAS.vcxproj | 149 ++++++++++++++++++++++++++++++++++++++++++++ SAS.vcxproj.filters | 60 ++++++++++++++++++ Student.cpp | 46 ++++++++++++++ StudentDAO.h | 17 +++++ StudentDAOImpl.cpp | 60 ++++++++++++++++++ Test.cpp | 100 +++++++++++++++++++++++++++++ main.cpp | 34 ++++++++++ 16 files changed, 811 insertions(+) create mode 100644 Course.cpp create mode 100644 CourseDAO.h create mode 100644 CourseDAOImpl.cpp create mode 100644 DBCUtils.cpp create mode 100644 DBCUtils.h create mode 100644 Grade.cpp create mode 100644 GradeDAO.h create mode 100644 GradeDAOImpl.cpp create mode 100644 SAS.sln create mode 100644 SAS.vcxproj create mode 100644 SAS.vcxproj.filters create mode 100644 Student.cpp create mode 100644 StudentDAO.h create mode 100644 StudentDAOImpl.cpp create mode 100644 Test.cpp create mode 100644 main.cpp diff --git a/Course.cpp b/Course.cpp new file mode 100644 index 0000000..0555f2e --- /dev/null +++ b/Course.cpp @@ -0,0 +1,32 @@ +#ifndef COURSE_CPP +#define COURSE_CPP + +#include +using std::string; +class Course +{ +public: + Course() { ; } + Course(string id, string name) { + this->id = id; + this->name = name; + } + + string getId() { return id; } + void setId(string id) { this->id = id; } + string getName() { return name; } + void setName(string name) { this->name = name; } + + string toString() { + string toStr = "Course{"; + toStr += "id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + return toStr; + } +private: + string id;//课程号 + string name;//课程名 +}; + +#endif // !COURSE_CPP \ No newline at end of file diff --git a/CourseDAO.h b/CourseDAO.h new file mode 100644 index 0000000..0a6e955 --- /dev/null +++ b/CourseDAO.h @@ -0,0 +1,16 @@ +#ifndef COURSE_DAO_H +#define COURSE_DAO_H + +#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile") + +#include +#include +#include"Course.cpp" + +void addCourse(_ConnectionPtr connection, Course course); +void deleteCourse(_ConnectionPtr connection, string id); +void updateCourseName(_ConnectionPtr connection, string id, string name); +Course& getCourseById(_ConnectionPtr connection, string id); +std::vector& getCourseByName(_ConnectionPtr connection, string name); + +#endif // !COURSE_DAO_H \ No newline at end of file diff --git a/CourseDAOImpl.cpp b/CourseDAOImpl.cpp new file mode 100644 index 0000000..2b71c95 --- /dev/null +++ b/CourseDAOImpl.cpp @@ -0,0 +1,45 @@ +#include"CourseDAO.h" + +void addCourse(_ConnectionPtr connection, Course course) { + string sql = "insert into course values('" + course.getId() + "'," + + "'" + course.getName() + "')"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void deleteCourse(_ConnectionPtr connection, string id) { + string sql = "delete from course where id = '" + id + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void updateCourseName(_ConnectionPtr connection, string id, string name) { + string sql = "update course set name = '" + name + "\' where id = \'" + id + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +Course& getCourseById(_ConnectionPtr connection, string id) { + string sql = "select * from course where id = '" + id + "'"; + _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); + + Course* course = new Course(); + course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); + course->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value); + return *course; +} + +std::vector& getCourseByName(_ConnectionPtr connection, string name) { + string sql = "select * from course where name = '" + name + "'"; + _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); + + std::vector* v = new std::vector(); + Course* course; + for (; !record->EndOfFile; record->MoveNext()) { + course = new Course(); + course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); + course->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value); + v->push_back(*course); + } + return *v; +} \ No newline at end of file diff --git a/DBCUtils.cpp b/DBCUtils.cpp new file mode 100644 index 0000000..a088ae5 --- /dev/null +++ b/DBCUtils.cpp @@ -0,0 +1,73 @@ +#include"DBCUtils.h" + +bool getConnection(std::string& pwd, _ConnectionPtr& connection) { + bool isPwdTrue = false; + _bstr_t strConnect; + if (!pwd.empty()) { + 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"); + 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) { + wprintf(L"密码错误!"); + return false; + } + } + else { + 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"); + 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) { + wprintf(L"验证失败!"); + return false; + } + } +} + +void getSqlType(std::string& sql, std::string& comType) { + int len = sql.length(); + for (int i = 0; i < len; i++) {//判断sql语句类型 + if (sql[i] != ' ') + comType += isupper(sql[i]) ? (sql[i] - 32) : sql[i]; + else return; + } +} + +void showRecordInfo(_RecordsetPtr& recordSet) { + COORD pos = { 0,0 }; + for (long i = 0; i < recordSet->Fields->Count; i++) { + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); + wprintf(L"%s", (wchar_t*)recordSet->Fields->GetItem(i)->Name); + pos.X += (short)recordSet->Fields->GetItem(i)->DefinedSize % 16 + 4; + } + for (; !recordSet->EndOfFile; recordSet->MoveNext()) { + pos.X = 0; + pos.Y++; + for (long i = 0; i < recordSet->Fields->Count; i++) { + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); + if (recordSet->Fields->GetItem(i)->Value.vt == VT_NULL) { + wprintf(L"Null"); + } + else { + wprintf(L"%s", (wchar_t*)(_bstr_t)recordSet->Fields->GetItem(i)->Value); + } + pos.X += (short)recordSet->Fields->GetItem(i)->DefinedSize % 16 + 4; + } + } +} \ No newline at end of file diff --git a/DBCUtils.h b/DBCUtils.h new file mode 100644 index 0000000..3adaffa --- /dev/null +++ b/DBCUtils.h @@ -0,0 +1,15 @@ +#ifndef DBCUTILS_H +#define DBCUTILS_H + +#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile") + +#include // wprintf +#include +#include // setlocale +#include + +bool getConnection(std::string& pwd, _ConnectionPtr& connection); +void getSqlType(std::string& sql, std::string& comType); +void showRecordInfo(_RecordsetPtr& recordSet); + +#endif // !DBCUTILS_H \ No newline at end of file diff --git a/Grade.cpp b/Grade.cpp new file mode 100644 index 0000000..f614302 --- /dev/null +++ b/Grade.cpp @@ -0,0 +1,38 @@ +#ifndef GRADE_CPP +#define GRADE_CPP + +#include +using std::string; + +class Grade { +public: + Grade() { ; } + Grade(string stuId, string courseId, string grade) { + this->stuId = stuId; + this->courseId = courseId; + this->grade = grade; + } + + string getStuId() { return stuId; } + void setStuId(string stuId) { this->stuId = stuId; } + string getCourseId() { return courseId; } + void setCourseId(string courseId) { this->courseId = courseId; } + double getGrade() { return atof(grade.c_str()); } + string getGradeStr() { return grade; } + void setGrade(string grade) { this->grade = grade; } + + string toString() { + string toStr = "Grade{"; + toStr += "stuId='" + stuId + '\'' + + ", courseId='" + courseId + '\'' + + ", grade='" + grade + '\'' + + '}'; + return toStr; + } +private: + string stuId; + string courseId; + string grade; +}; + +#endif // !GRADE_CPP \ No newline at end of file diff --git a/GradeDAO.h b/GradeDAO.h new file mode 100644 index 0000000..0a83362 --- /dev/null +++ b/GradeDAO.h @@ -0,0 +1,19 @@ +#ifndef GRADE_DAO_H +#define GRADE_DAO_H + +#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile") + +#include +#include +#include"Grade.cpp" + +void addGrade(_ConnectionPtr connection, Grade grade); +void deleteOnesGrade(_ConnectionPtr connection, string stuId,string courseId); +void deleteGradeByStuId(_ConnectionPtr connection, string stuId); +void deleteGradeByCourseId(_ConnectionPtr connection, string courseId); +void updateOnesGrade(_ConnectionPtr connection, string stuId, string courseId, string grade); +Grade& getOnesGrade(_ConnectionPtr connection, string stuId, string courseId); +std::vector& getGradeByStuId(_ConnectionPtr connection, string stuId); +std::vector& getGradeByCourseId(_ConnectionPtr connection, string courseId); + +#endif // !GRADE_DAO_H diff --git a/GradeDAOImpl.cpp b/GradeDAOImpl.cpp new file mode 100644 index 0000000..716dc25 --- /dev/null +++ b/GradeDAOImpl.cpp @@ -0,0 +1,76 @@ +#include"GradeDAO.h" + +void addGrade(_ConnectionPtr connection, Grade grade) { + string sql = "insert into grade values('" + grade.getStuId() + "'," + + "'" + grade.getCourseId() + "'," + + "'" + grade.getGradeStr() + "')"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void deleteOnesGrade(_ConnectionPtr connection, string stuId, string courseId) { + string sql = "delete from grade where stuId = '" + stuId + "\' and courseId = \'" + courseId + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void deleteGradeByStuId(_ConnectionPtr connection, string stuId) { + string sql = "delete from grade where stuId = '" + stuId + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void deleteGradeByCourseId(_ConnectionPtr connection, string courseId) { + string sql = "delete from grade where courseId = '" + courseId + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void updateOnesGrade(_ConnectionPtr connection, string stuId, string courseId, string grade) { + string sql = "update grade set grade = " + grade + " where stuId = '" + stuId + "\' and courseId = \'" + courseId + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +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); + + Grade* grade = new Grade(); + grade->setStuId((char*)(_bstr_t)record->Fields->GetItem("stuId")->Value); + grade->setCourseId((char*)(_bstr_t)record->Fields->GetItem("courseId")->Value); + grade->setGrade((char*)(_bstr_t)record->Fields->GetItem("grade")->Value); + return *grade; +} + +std::vector& getGradeByStuId(_ConnectionPtr connection, string stuId) { + string sql = "select * from grade where stuId = '" + stuId + "'"; + _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); + + std::vector* v = new std::vector(); + Grade* grade; + for (; !record->EndOfFile; record->MoveNext()) { + grade = new Grade(); + grade->setStuId((char*)(_bstr_t)record->Fields->GetItem("stuId")->Value); + grade->setCourseId((char*)(_bstr_t)record->Fields->GetItem("courseId")->Value); + grade->setGrade((char*)(_bstr_t)record->Fields->GetItem("grade")->Value); + v->push_back(*grade); + } + return *v; +} + +std::vector& getGradeByCourseId(_ConnectionPtr connection, string courseId) { + string sql = "select * from grade where courseId = '" + courseId + "'"; + _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); + + std::vector* v = new std::vector(); + Grade* grade; + for (; !record->EndOfFile; record->MoveNext()) { + grade = new Grade(); + grade->setStuId((char*)(_bstr_t)record->Fields->GetItem("stuId")->Value); + grade->setCourseId((char*)(_bstr_t)record->Fields->GetItem("courseId")->Value); + grade->setGrade((char*)(_bstr_t)record->Fields->GetItem("grade")->Value); + v->push_back(*grade); + } + return *v; +} \ No newline at end of file diff --git a/SAS.sln b/SAS.sln new file mode 100644 index 0000000..20f366d --- /dev/null +++ b/SAS.sln @@ -0,0 +1,31 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32616.157 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SAS", "SAS.vcxproj", "{D458779C-7429-43D9-9228-69B41BBC903B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D458779C-7429-43D9-9228-69B41BBC903B}.Debug|x64.ActiveCfg = Debug|x64 + {D458779C-7429-43D9-9228-69B41BBC903B}.Debug|x64.Build.0 = Debug|x64 + {D458779C-7429-43D9-9228-69B41BBC903B}.Debug|x86.ActiveCfg = Debug|Win32 + {D458779C-7429-43D9-9228-69B41BBC903B}.Debug|x86.Build.0 = Debug|Win32 + {D458779C-7429-43D9-9228-69B41BBC903B}.Release|x64.ActiveCfg = Release|x64 + {D458779C-7429-43D9-9228-69B41BBC903B}.Release|x64.Build.0 = Release|x64 + {D458779C-7429-43D9-9228-69B41BBC903B}.Release|x86.ActiveCfg = Release|Win32 + {D458779C-7429-43D9-9228-69B41BBC903B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D725A19-22A9-456E-B8B9-C6AB04B4FED1} + EndGlobalSection +EndGlobal diff --git a/SAS.vcxproj b/SAS.vcxproj new file mode 100644 index 0000000..e80c9f9 --- /dev/null +++ b/SAS.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {d458779c-7429-43d9-9228-69b41bbc903b} + SAS + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SAS.vcxproj.filters b/SAS.vcxproj.filters new file mode 100644 index 0000000..e4cc194 --- /dev/null +++ b/SAS.vcxproj.filters @@ -0,0 +1,60 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + \ No newline at end of file diff --git a/Student.cpp b/Student.cpp new file mode 100644 index 0000000..651f358 --- /dev/null +++ b/Student.cpp @@ -0,0 +1,46 @@ +#ifndef STUDENT_CPP +#define STUDENT_CPP + +#include +using std::string; + +class Student { +public: + Student() { ; } + Student(string id, string name, string sex, string stuClass, string status) { + this->id = id; + this->name = name; + this->sex = sex; + this->stuClass = stuClass; + this->status = status; + } + string getId() { return id; } + void setId(string id) { this->id = id; } + string getName() { return name; } + void setName(string name) { this->name = name; } + string getSex() { return sex; } + void setSex(string sex) { this->sex = sex; } + string getStuClass() { return stuClass; } + void setStuClass(string stuClass) { this->stuClass = stuClass; } + string getStatus() { return status; } + void setStatus(string status) { this->status = status; } + + string toString() { + string toStr = "Student{"; + toStr += "id='" + id + '\'' + + ", name='" + name + '\'' + + ", sex='" + sex + '\'' + + ", stuClass='" + stuClass + '\'' + + ", status='" + status + '\'' + + '}'; + return toStr; + } +private: + string id;//学号 + string name;//姓名 + string sex;//性别 + string stuClass;//班级 + string status;//状态(在读、休学、退学) +}; + +#endif // !STUDENT_CPP \ No newline at end of file diff --git a/StudentDAO.h b/StudentDAO.h new file mode 100644 index 0000000..3a08fa8 --- /dev/null +++ b/StudentDAO.h @@ -0,0 +1,17 @@ +#ifndef STUDENT_DAO_H +#define STUDENT_DAO_H + +#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile") + +#include +#include +#include"Student.cpp" + +void addStudent(_ConnectionPtr connection, Student student); +void deleteStudent(_ConnectionPtr connection, string id); +void updateStudentClass(_ConnectionPtr connection, string id, string stuClass); +void updateStudentStatus(_ConnectionPtr connection, string id, string status); +Student& getStudentById(_ConnectionPtr connection, string id); +std::vector& getStudentByName(_ConnectionPtr connection, string name); + +#endif // !STUDENT_DAO_H \ No newline at end of file diff --git a/StudentDAOImpl.cpp b/StudentDAOImpl.cpp new file mode 100644 index 0000000..6b9d986 --- /dev/null +++ b/StudentDAOImpl.cpp @@ -0,0 +1,60 @@ +#include"StudentDAO.h" + +void addStudent(_ConnectionPtr connection, Student student) { + string sql = "insert into student values('" + student.getId() + "'," + + "'" + student.getName() + "'," + + "'" + student.getSex() + "'," + + "'" + student.getStuClass() + "'," + + "'" + student.getStatus() + "')"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void deleteStudent(_ConnectionPtr connection, string id) { + string sql = "delete from student where id = '" + id + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void updateStudentClass(_ConnectionPtr connection, string id, string stuClass) { + string sql = "update student set stuClass = '" + stuClass + "\' where id = \'" + id + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +void updateStudentStatus(_ConnectionPtr connection, string id, string status) { + string sql = "update student set status = '" + status + "\' where id = \'" + id + "'"; + + connection->Execute(sql.c_str(), NULL, (long)0); +} + +Student& getStudentById(_ConnectionPtr connection, string id) { + string sql = "select * from student where id = '" + id + "'"; + _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); + + Student *student = new Student(); + student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); + student->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value); + student->setSex((char*)(_bstr_t)record->Fields->GetItem("sex")->Value); + student->setStuClass((char*)(_bstr_t)record->Fields->GetItem("stuClass")->Value); + student->setStatus((char*)(_bstr_t)record->Fields->GetItem("status")->Value); + return *student; +} + +std::vector& getStudentByName(_ConnectionPtr connection, string name) { + string sql = "select * from student where name = '" + name + "'"; + _RecordsetPtr record = connection->Execute(sql.c_str(), NULL, (long)0); + + std::vector *v = new std::vector(); + Student* student; + for (; !record->EndOfFile; record->MoveNext()) { + student = new Student(); + student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value); + student->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value); + student->setSex((char*)(_bstr_t)record->Fields->GetItem("sex")->Value); + student->setStuClass((char*)(_bstr_t)record->Fields->GetItem("stuClass")->Value); + student->setStatus((char*)(_bstr_t)record->Fields->GetItem("status")->Value); + v->push_back(*student); + } + return *v; +} \ No newline at end of file diff --git a/Test.cpp b/Test.cpp new file mode 100644 index 0000000..755a36b --- /dev/null +++ b/Test.cpp @@ -0,0 +1,100 @@ +/* +用于测试DAO功能是否能正常运行 +*/ +#if 0 +#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile") + +#include // wprintf +#include +#include // setlocale +#include +#include +#include "DBCUtils.h" +#include "StudentDAO.h" +#include "CourseDAO.h" +#include "GradeDAO.h" +using namespace std; + +int main() { + setlocale(LC_ALL, "chs"); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + + _ConnectionPtr pconnect(_uuidof(Connection)); + string strConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=stuAdminSystem;Data Source=LAPTOP-4DMOD6O5"; + pconnect->Open(strConnect.c_str(), "", "", NULL); + + //student + /* + Student* stu = new Student("2", "李四", "女", "计科00000", "休学"); + addStudent(pconnect, *stu); + deleteStudent(pconnect, "4"); + updateStudentClass(pconnect, "3", "软件12004"); + updateStudentStatus(pconnect, "3", "休学"); + + Student student = getStudentById(pconnect, "1"); + cout << student.toString() << "\n"; + + vector v = getStudentByName(pconnect, "张三"); + for (int i = 0; i < v.size(); i++) + cout << v[i].toString() << "\n"; + */ + + //course + /* + Course* course1 = new Course("A001","高数"); + Course* course2 = new Course("A002","C语言"); + Course* course3 = new Course("A003","体育"); + addCourse(pconnect, *course1); + addCourse(pconnect, *course2); + addCourse(pconnect, *course3); + + deleteCourse(pconnect, "A002"); + updateCourseName(pconnect, "A003", "物理"); + + Course cou = getCourseById(pconnect, "A001"); + cout << cou.toString() << "\n"; + + vector v = getCourseByName(pconnect, "高数"); + for (int i = 0; i < v.size(); i++) + cout << v[i].toString() << "\n"; + */ + + //grade + /* + Grade* course1 = new Grade("1","A001","95"); + Grade* course2 = new Grade("1","A001-1", "95"); + Grade* course3 = new Grade("1","A003", "95"); + Grade* course4 = new Grade("2","A001", "95"); + Grade* course5 = new Grade("2","A003", "95"); + addGrade(pconnect, *course1); + addGrade(pconnect, *course2); + addGrade(pconnect, *course3); + addGrade(pconnect, *course4); + addGrade(pconnect, *course5); + + deleteOnesGrade(pconnect, "1","A001-1"); + deleteGradeByStuId(pconnect, "1"); + deleteGradeByCourseId(pconnect, "A001"); + + + updateOnesGrade(pconnect,"1","A001-1","98.4"); + + Grade gra = getOnesGrade(pconnect, "1","A001"); + cout << gra.toString() << "\n"; + + cout << "\n"; + + vector v = getGradeByStuId(pconnect, "1"); + for (int i = 0; i < v.size(); i++) + cout << v[i].toString() << "\n"; + + cout << "\n"; + + vector v1 = getGradeByCourseId(pconnect, "A001"); + for (int i = 0; i < v1.size(); i++) + cout << v1[i].toString() << "\n"; + */ + CoUninitialize(); + return 0; +} +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b01f75a --- /dev/null +++ b/main.cpp @@ -0,0 +1,34 @@ +#import "c:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "EndOfFile") + +#include // wprintf +#include +#include // setlocale +#include +#include +#include "DBCUtils.h" +#include "StudentDAO.h" +using namespace std; + +//高级功能 直接输入sql语句 +int main() { + setlocale(LC_ALL, "chs"); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + + string pwd; + + wprintf(L"Enter password:"); + getline(cin, pwd); + + _ConnectionPtr pconnect(_uuidof(Connection)); + + if (getConnection(pwd, pconnect)) { + try { + + }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()); + } + } + CoUninitialize(); + return 0; +} \ No newline at end of file