📄 teachercountdepartdlg.cpp
字号:
// TeacherCountDepartDlg.cpp : implementation file
//
#include "stdafx.h"
#include "COdbc.h"
#include "TeacherCountDepartDlg.h"
#include "RecordTeacher.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTeacherCountDepartDlg dialog
CTeacherCountDepartDlg::CTeacherCountDepartDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTeacherCountDepartDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTeacherCountDepartDlg)
m_tcdfrom = _T("");
m_tcdto = _T("");
m_result = _T("");
m_check = FALSE;
//}}AFX_DATA_INIT
}
void CTeacherCountDepartDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTeacherCountDepartDlg)
DDX_Control(pDX, IDC_EDIT2, m_tcdtoctr);
DDX_Text(pDX, IDC_EDIT1, m_tcdfrom);
DDX_Text(pDX, IDC_EDIT2, m_tcdto);
DDX_Text(pDX, IDC_EDIT3, m_result);
DDX_Check(pDX, IDC_CHECK, m_check);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTeacherCountDepartDlg, CDialog)
//{{AFX_MSG_MAP(CTeacherCountDepartDlg)
ON_BN_CLICKED(IDC_CHECK, OnCheck)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTeacherCountDepartDlg message handlers
void CTeacherCountDepartDlg::OnCheck()
{
// TODO: Add your control notification handler code here
m_check=!m_check;
m_tcdtoctr.EnableWindow(m_check);
}
void CTeacherCountDepartDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CDatabase db;
BOOL bRtn;
CString sql,tmp;
try {
bRtn = db.OpenEx("DSN=教学管理系统;UID=sa", CDatabase::noOdbcDialog);
}catch (CDBException *pDBEx) {
pDBEx->ReportError();
}catch (CMemoryException *pMemEx) {
pMemEx->ReportError();
}
if (!bRtn)
printf("连接数据库失败!");
UpdateData(true);
if(m_check==false)
{
sql = "Select Count(*) From teacher where department ='";
sql +=m_tcdfrom;
sql +="'";
}
else
{
sql = "Select Count(*) From teacher where department >='";
sql +=m_tcdfrom;
sql +="' and department <='";
sql +=m_tcdto;
sql +="'";
}
CRecordTeacher rs(&db);
try {
bRtn = rs.Open(CRecordset::snapshot,sql);
} catch(CDBException *pDBEx) {
pDBEx->ReportError();
} catch(CMemoryException *pMemEx) {
pMemEx->ReportError();
}
if(!bRtn) {
AfxMessageBox("Query table failed!",MB_OK|MB_ICONERROR);
return ;
}
/* 4、逐条获取查询结果*/
for(rs.MoveFirst();!rs.IsEOF();rs.MoveNext()) {
// TODO: Add code here
}
/* 5、关闭记录集、数据库*/
m_result=rs.m_teacher_name;
UpdateData(false);
rs.Close();
db.Close();
}
void CTeacherCountDepartDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
BOOL CTeacherCountDepartDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_tcdtoctr.EnableWindow(m_check);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -