⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentcountagedlg.cpp

📁 教学管理系统
💻 CPP
字号:
// StudentCountAgeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "COdbc.h"
#include "StudentCountAgeDlg.h"
#include <afxdb.h>
#include "RecordStudents.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStudentCountAgeDlg dialog


CStudentCountAgeDlg::CStudentCountAgeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStudentCountAgeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStudentCountAgeDlg)
	m_countagefrom = _T("");
	m_result = _T("");
	m_check = FALSE;
	m_countageto = _T("");
	//}}AFX_DATA_INIT

}


void CStudentCountAgeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudentCountAgeDlg)
	DDX_Control(pDX, IDC_EDIT3, m_countagetoctr);
	DDX_Text(pDX, IDC_EDIT1, m_countagefrom);
	DDX_Text(pDX, IDC_EDIT2, m_result);
	DDX_Check(pDX, IDC_CHECK, m_check);
	DDX_Text(pDX, IDC_EDIT3, m_countageto);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStudentCountAgeDlg, CDialog)
	//{{AFX_MSG_MAP(CStudentCountAgeDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_CHECK, OnCheck)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudentCountAgeDlg message handlers

void CStudentCountAgeDlg::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 student where student_age='";
		sql +=m_countagefrom;
		sql +="'";
	}
	else
	{
		sql = "Select Count(*) from student where student_age>='";
		sql +=m_countagefrom;
		sql +="'";
		sql +=" and student_age<='";
		sql +=m_countageto;
		sql+="'";
	}

	CRecordStudents 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_student_id;
	UpdateData(false);
	rs.Close();
	db.Close();
}

void CStudentCountAgeDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}


void CStudentCountAgeDlg::OnCheck() 
{
	// TODO: Add your control notification handler code here
	m_check=!m_check;
	m_countagetoctr.EnableWindow(m_check);
}

BOOL CStudentCountAgeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
		m_countagetoctr.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 + -