?? 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 + -