📄 shouke.cpp
字号:
// shouke.cpp : implementation file
//
#include "stdafx.h"
#include "mark.h"
#include "shouke.h"
#include "MainFrm.h"
#include "adodc.h"
#include "_recordset.h"
#include "fields.h"
#include "field.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Cshouke
IMPLEMENT_DYNCREATE(Cshouke, CFormView)
Cshouke::Cshouke()
: CFormView(Cshouke::IDD)
{
//{{AFX_DATA_INIT(Cshouke)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
Cshouke::~Cshouke()
{
}
void Cshouke::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Cshouke)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Cshouke, CFormView)
//{{AFX_MSG_MAP(Cshouke)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Cshouke diagnostics
#ifdef _DEBUG
void Cshouke::AssertValid() const
{
CFormView::AssertValid();
}
void Cshouke::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Cshouke message handlers
void Cshouke::OnButton1()
{
CEdit *kech=(CEdit *)GetDlgItem(IDC_EDIT1);
CEdit *jiaosh=(CEdit *)GetDlgItem(IDC_EDIT2);
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
CString kch,jsh;
kech->GetWindowText(kch);
jiaosh->GetWindowText(jsh);
if(kch==""){
pframe->Agenttalk("课程号不能为空!");
return;
}
if(jsh==""){
pframe->Agenttalk("教师号不能为空!");
return;
}
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hello;Pwd=panpan;Initial Catalog=student;Data Source=localhost","hello","panpan",0);
// 使用ADO创建数据库记录集
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 授课",
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
m_pRecordset->MoveFirst();
bool isfound=false;
while(!m_pRecordset->GetadoEOF()){
if(m_pRecordset->GetCollect("课程号")==_variant_t(kch) && m_pRecordset->GetCollect("教师号")==_variant_t(jsh)){
isfound=true;
}
m_pRecordset->MoveNext();
}
if(isfound){
pframe->Agenttalk("记录已存在,不用添加!");
}else{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("课程号",_variant_t(kch));
m_pRecordset->PutCollect("教师号",_variant_t(jsh));
m_pRecordset->Update();
pframe->Agenttalk("添加成功!");
}
m_pRecordset->Close();
m_pRecordset=NULL;
m_pConnection->Close();
m_pConnection=NULL;
CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC1);
ado->Refresh();
}
void Cshouke::OnButton2()
{
CEdit *kech=(CEdit *)GetDlgItem(IDC_EDIT3);
CEdit *jiaosh=(CEdit *)GetDlgItem(IDC_EDIT4);
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
CString kch,jsh;
kech->GetWindowText(kch);
jiaosh->GetWindowText(jsh);
if(kch==""){
pframe->Agenttalk("课程号不能为空!");
return;
}
if(jsh==""){
pframe->Agenttalk("教师号不能为空!");
return;
}
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hello;Pwd=panpan;Initial Catalog=student;Data Source=localhost","hello","panpan",0);
// 使用ADO创建数据库记录集
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 授课",
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
m_pRecordset->MoveFirst();
bool isfound=false;
while(!m_pRecordset->GetadoEOF()){
if(m_pRecordset->GetCollect("课程号")==_variant_t(kch) && m_pRecordset->GetCollect("教师号")==_variant_t(jsh)){
isfound=true;
m_pRecordset->Delete(adAffectCurrent);
m_pRecordset->Update();
break;
}
m_pRecordset->MoveNext();
}
if(isfound){
pframe->Agenttalk("删除成功!");
}else{
pframe->Agenttalk("找不到符合条件的记录!");
}
m_pRecordset->Close();
m_pRecordset=NULL;
m_pConnection->Close();
m_pConnection=NULL;
CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC1);
ado->Refresh();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -