📄 results.cpp
字号:
// Results.cpp: implementation of the Results class.
//
//////////////////////////////////////////////////////////////////////
#include "adodc.h"
#include "datagrid.h"
#include "COMDEF.h"
#include "stdafx.h"
#include "SRMS.h"
#include "Results.h"
#include "ADOConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Results::Results()
{
Stu_id=0;
Stu_name="";
Sex="";
math=0;
chinese=0;
computer=0;
average=0;
}
Results::~Results()
{
}
void Results::sql_insert(){
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strId;
strId.Format("%d",Stu_id);
CString strmath;
strmath.Format("%f",math);
CString strchinese;
strchinese.Format("%f",chinese);
CString strcomputer;
strcomputer.Format("%f",computer);
CString straver;
straver.Format("%f",average);
_bstr_t vSQL;
vSQL = "INSERT INTO Results (Stu_id,Stu_name,Sex,math, chinese,computer,average) VALUES('"
+ strId + "','" + Stu_name + "','" + Sex + "','" + strmath + "','" + strchinese+ "','" + strcomputer+ "'," + straver + ")";
//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
//type=0按姓名查询
//type=1按学号查询
void Results::sql_search(int type,CAdodc *m_adodc,CDataGrid *m_datagrid){
_bstr_t vSQL;
if(type==0){
vSQL = "SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results WHERE Stu_name='" + Stu_name+"'";
}
else{
CString strId;
strId.Format("%d",Stu_id);
vSQL = "SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results WHERE Stu_id=" + strId;
}
m_adodc->SetRecordSource(vSQL);
m_adodc->Refresh();
_variant_t vIndex;
vIndex = long(0);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(60);
vIndex = long(1);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(70);
vIndex = long(2);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(30);
vIndex = long(3);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(4);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(5);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(6);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(58);
}
void Results::sql_delete(CString cStuId){
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM Results WHERE Stu_id=" + cStuId;
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
//type=0按数学
//type=1按语文
//type=2按计算机
//type=3按均分
void Results::sql_order(int type,CAdodc *m_adodc,CDataGrid *m_datagrid){
_bstr_t vSQL;
vSQL = "SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results ORDER BY ";
switch(type) {
case 0:
vSQL+="math DESC";
break;
case 1:
vSQL+="chinese DESC";
break;
case 2:
vSQL+="computer DESC";
break;
case 3:
vSQL+="average DESC";
break;
}
m_adodc->SetRecordSource(vSQL);
m_adodc->Refresh();
_variant_t vIndex;
vIndex = long(0);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(60);
vIndex = long(1);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(70);
vIndex = long(2);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(30);
vIndex = long(3);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(4);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(5);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(6);
m_datagrid->GetColumns().GetItem(vIndex).SetWidth(58);
}
void Results::SetId(int vStu_id)
{
Stu_id=vStu_id;
}
void Results::SetName(CString vStu_name)
{
Stu_name=vStu_name;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -