2022-07-06 16:42:53 +08:00
/*
* <EFBFBD> ɼ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ݿ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӿ <EFBFBD> ʵ <EFBFBD> <EFBFBD>
*/
2022-07-03 18:22:02 +08:00
# include"GradeDAO.h"
void addGrade ( _ConnectionPtr connection , Grade grade ) {
2022-07-06 16:42:53 +08:00
string sql = " insert into grade values(?,?,?) " ;
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( grade . getStuId ( ) ) ;
v - > push_back ( grade . getCourseId ( ) ) ;
v - > push_back ( grade . getGradeStr ( ) ) ;
executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-03 18:22:02 +08:00
}
void deleteOnesGrade ( _ConnectionPtr connection , string stuId , string courseId ) {
2022-07-06 16:42:53 +08:00
string sql = " delete from grade where stuId = ? and courseId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuId ) ;
v - > push_back ( courseId ) ;
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-03 18:22:02 +08:00
}
void deleteGradeByStuId ( _ConnectionPtr connection , string stuId ) {
2022-07-06 16:42:53 +08:00
string sql = " delete from grade where stuId = ? " ;
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuId ) ;
executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-03 18:22:02 +08:00
}
void deleteGradeByCourseId ( _ConnectionPtr connection , string courseId ) {
2022-07-06 16:42:53 +08:00
string sql = " delete from grade where courseId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( courseId ) ;
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-03 18:22:02 +08:00
}
void updateOnesGrade ( _ConnectionPtr connection , string stuId , string courseId , string grade ) {
2022-07-06 16:42:53 +08:00
string sql = " update grade set grade = ? where stuId = ? and courseId = ? " ;
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( grade ) ;
v - > push_back ( stuId ) ;
v - > push_back ( courseId ) ;
executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-03 18:22:02 +08:00
}
2022-07-04 00:31:52 +08:00
Grade * getOnesGrade ( _ConnectionPtr connection , string stuId , string courseId ) {
2022-07-06 16:42:53 +08:00
string sql = " select * from grade where stuId = ? and courseId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuId ) ;
v - > push_back ( courseId ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-03 18:22:02 +08:00
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 ) ;
2022-07-04 00:31:52 +08:00
return grade ;
2022-07-03 18:22:02 +08:00
}
2022-07-04 00:31:52 +08:00
std : : vector < Grade > * getGradeByStuId ( _ConnectionPtr connection , string stuId ) {
2022-07-06 16:42:53 +08:00
string sql = " select * from grade where stuId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuId ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
std : : vector < Grade > * vg = new std : : vector < Grade > ( ) ;
2022-07-03 18:22:02 +08:00
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 ) ;
2022-07-06 16:42:53 +08:00
vg - > push_back ( * grade ) ;
2022-07-03 18:22:02 +08:00
}
2022-07-06 16:42:53 +08:00
return vg ;
2022-07-03 18:22:02 +08:00
}
2022-07-04 00:31:52 +08:00
std : : vector < Grade > * getGradeByCourseId ( _ConnectionPtr connection , string courseId ) {
2022-07-06 16:42:53 +08:00
string sql = " select * from grade where courseId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( courseId ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-03 18:22:02 +08:00
2022-07-06 16:42:53 +08:00
std : : vector < Grade > * vg = new std : : vector < Grade > ( ) ;
2022-07-03 18:22:02 +08:00
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 ) ;
2022-07-06 16:42:53 +08:00
vg - > push_back ( * grade ) ;
2022-07-03 18:22:02 +08:00
}
2022-07-06 16:42:53 +08:00
return vg ;
2022-07-04 00:31:52 +08:00
}
std : : vector < Grade > * getGradeByStuClass ( _ConnectionPtr connection , string stuClass ) {
2022-07-06 16:42:53 +08:00
string sql = " select * from grade where stuId in (select id from student where stuClass = ?) " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuClass ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
2022-07-06 16:42:53 +08:00
std : : vector < Grade > * vg = new std : : vector < Grade > ( ) ;
2022-07-04 00:31:52 +08:00
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 ) ;
2022-07-06 16:42:53 +08:00
vg - > push_back ( * grade ) ;
2022-07-04 00:31:52 +08:00
}
2022-07-06 16:42:53 +08:00
return vg ;
2022-07-04 00:31:52 +08:00
}
std : : vector < Grade > * getAllGrade ( _ConnectionPtr connection ) {
string sql = " select * from grade " ;
2022-07-06 16:42:53 +08:00
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , NULL ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
std : : vector < Grade > * v = new std : : vector < Grade > ( ) ;
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 ;
}
double getOnesAvgGrade ( _ConnectionPtr connection , string stuId ) {
2022-07-06 16:42:53 +08:00
string sql = " select count(*) cnt,sum(grade) all_grade from grade where stuId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuId ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
int cnt = atoi ( ( char * ) ( _bstr_t ) record - > Fields - > GetItem ( " cnt " ) - > Value ) ;
double all_grade = atof ( ( char * ) ( _bstr_t ) record - > Fields - > GetItem ( " all_grade " ) - > Value ) ;
return all_grade / cnt ;
}
double getOnesAllGrade ( _ConnectionPtr connection , string stuId ) {
2022-07-06 16:42:53 +08:00
string sql = " select sum(grade) all_grade from grade where stuId = ? " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuId ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
return atof ( ( char * ) ( _bstr_t ) record - > Fields - > GetItem ( " all_grade " ) - > Value ) ;
}
double getClassAvgGrade ( _ConnectionPtr connection , string stuClass , string courseName ) {
2022-07-06 16:42:53 +08:00
string sql = " select avg(grade) avg_grade from grade where stuId in (select id from student where stuClass = ?) and courseId in (select id from course where name = ?) " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuClass ) ;
v - > push_back ( courseName ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
return atof ( ( char * ) ( _bstr_t ) record - > Fields - > GetItem ( " avg_grade " ) - > Value ) ;
}
double getClassMaxGrade ( _ConnectionPtr connection , string stuClass , string courseName ) {
2022-07-06 16:42:53 +08:00
string sql = " select max(grade) max_grade from grade where stuId in (select id from student where stuClass = ?) and courseId in (select id from course where name = ?) " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuClass ) ;
v - > push_back ( courseName ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
return atof ( ( char * ) ( _bstr_t ) record - > Fields - > GetItem ( " max_grade " ) - > Value ) ;
}
double getClassMinGrade ( _ConnectionPtr connection , string stuClass , string courseName ) {
2022-07-06 16:42:53 +08:00
string sql = " select min(grade) min_grade from grade where stuId in (select id from student where stuClass = ?) and courseId in (select id from course where name = ?) " ;
vector < string > * v = new vector < string > ( ) ;
v - > push_back ( stuClass ) ;
v - > push_back ( courseName ) ;
_RecordsetPtr record = executeSql ( connection , sql . c_str ( ) , v ) ;
2022-07-04 22:17:38 +08:00
if ( record - > BOF = = - 1 ) return NULL ; //<2F> <> ¼<EFBFBD> <C2BC> Ϊ<EFBFBD> <CEAA>
2022-07-04 00:31:52 +08:00
return atof ( ( char * ) ( _bstr_t ) record - > Fields - > GetItem ( " min_grade " ) - > Value ) ;
2022-07-03 18:22:02 +08:00
}