www.gusucode.com > VC++操作SqlServer数据库的参考源程序源码程序 > VC++操作SqlServer数据库的参考源程序源码程序/code/IStudent.cpp
//Download by http://www.NewXing.com // Input.cpp : implementation file // #include "stdafx.h" #include "Student.h" #include "Istudent.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CStudentApp theApp; ///////////////////////////////////////////////////////////////////////////// // CInput dialog CInput::CInput(CWnd* pParent /*=NULL*/) : CDialog(CInput::IDD, pParent) { //{{AFX_DATA_INIT(CInput) m_sNumber = _T(""); m_sName = _T(""); m_sClassnum = _T(""); m_sSex = _T(""); m_dBrithday = COleDateTime::GetCurrentTime(); //}}AFX_DATA_INIT } void CInput::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CInput) DDX_Control(pDX, IDC_S_SEX, m_cboSex); DDX_Control(pDX, IDC_BTNSAVE, m_btnSave); DDX_Text(pDX, IDC_S_NUM, m_sNumber); DDX_Text(pDX, IDC_S_NAME, m_sName); DDX_Text(pDX, IDC_S_CLASSNUM, m_sClassnum); DDX_CBString(pDX, IDC_S_SEX, m_sSex); DDX_DateTimeCtrl(pDX, IDC_DTPBITTHDAY, m_dBrithday); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CInput, CDialog) //{{AFX_MSG_MAP(CInput) ON_BN_CLICKED(IDC_BTNSAVE, OnBtnsave) ON_EN_CHANGE(IDC_S_CLASSNUM, OnChangeSClassnum) ON_EN_CHANGE(IDC_S_NAME, OnChangeSName) ON_EN_CHANGE(IDC_S_NUM, OnChangeSNum) ON_CBN_SELENDOK(IDC_S_SEX, OnSelendokSSex) ON_BN_CLICKED(IDC_BTNEXIT, OnBtnexit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CInput message handlers void CInput::OnBtnsave() { UpdateData(TRUE); Save(theApp.m_opt.m_iOptStatus,theApp.m_opt.m_iTableFlag); } void CInput::Save(int m_iStatus, int sTFlag) { _RecordsetPtr Rsc; Rsc.CreateInstance("ADODB.Recordset"); char buf[100]; switch(sTFlag) { case 1://studnet table sprintf(buf,"select * from student where _id=%d",theApp.m_opt.m_iRecID); Rsc->Open(buf,theApp.m_pConnect.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText); if(m_iStatus==1)//addnew { Rsc->AddNew(); } Rsc->PutCollect("s_no",_variant_t(m_sNumber)); Rsc->PutCollect("s_name",_variant_t(m_sName)); Rsc->PutCollect("class_no",_variant_t(m_sClassnum)); Rsc->PutCollect("s_sex",_variant_t(m_sSex)); Rsc->PutCollect("s_birthday",_variant_t(m_dBrithday)); Rsc->Update(); Rsc->Close(); break; case 2://class Rsc->Open("select * from class",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText); break; case 3://course Rsc->Open("select * course",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText); break; case 4://choice Rsc->Open("select * from choice",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText); break; case 5://teach Rsc->Open("select * from teach",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText); break; case 6://teaching Rsc->Open("select * from teaching",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText); break; } AfxMessageBox("保存完毕!"); } void CInput::OnChangeSClassnum() { EnableSave(); } void CInput::OnChangeSName() { EnableSave(); } void CInput::OnChangeSNum() { EnableSave(); } void CInput::EnableSave() { UpdateData(); if((m_sName!="")&&(m_sNumber!="")&&(m_sClassnum!="")) m_btnSave.EnableWindow(TRUE); } BOOL CInput::OnInitDialog() { CDialog::OnInitDialog(); m_cboSex.AddString("男"); m_cboSex.AddString("女"); m_btnSave.EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CInput::OnSelendokSSex() { EnableSave(); } void CInput::OnBtnexit() { CInput::OnCancel(); }