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

📄 queryteachdlg.cpp

📁 最后的成品vc考勤ACCSEE数据库做的 还有文档 希望大家多多指点jilinshidalvdi@163.com
💻 CPP
字号:
// QueryTeachDlg.cpp : implementation file
//

#include "stdafx.h"
#include "studentscore.h"
#include "QueryTeachDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CQueryTeachDlg dialog


CQueryTeachDlg::CQueryTeachDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CQueryTeachDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQueryTeachDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CQueryTeachDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQueryTeachDlg)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Control(pDX, IDC_COMBO_BY, m_combox);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CQueryTeachDlg, CDialog)
	//{{AFX_MSG_MAP(CQueryTeachDlg)
	ON_CBN_SELCHANGE(IDC_COMBO_BY, OnSelchangeComboBy)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQueryTeachDlg message handlers

BOOL CQueryTeachDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	if(!m_database.IsOpen())
	{
		m_database.Open(_T("studentscore"));
		m_recordSet.m_pDatabase=&m_database;

	}
    m_combox.AddString("课程名");

    m_combox.AddString("教师名");
    m_combox.SelectString(0,"课程名");
   
	CString strSQL;
	strSQL.Format("select * from course where active_status='Y'");


	m_recordSet.Open(CRecordset::forwardOnly,strSQL);
    CListBox* m_value=(CListBox*)this->GetDlgItem(IDC_LIST_VALUE);
	for(int j=0;j<m_recordSet.GetRecordCount();j++)
	
	{
		CString  temp;
		m_recordSet.GetFieldValue("course_name",temp);
		m_value->AddString(temp);
		m_recordSet.MoveNext();
	}
    m_recordSet.Close();
   return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CQueryTeachDlg::OnSelchangeComboBy() 
{
	// TODO: Add your control notification handler code here
	CListBox* m_value=(CListBox*)this->GetDlgItem(IDC_LIST_VALUE);
	for(int j=m_value->GetCount();j>=0;j--)
		m_value->DeleteString(j);
	CString type;
	m_combox.GetWindowText(type);
	if(type=="教师名")
		type="course";
	else 
		type="techer";
	CString strSQL;
	strSQL.Format("select * from %s where active_status='Y'",type);
	type=type+"_name";
m_recordSet.Open(CRecordset::forwardOnly,strSQL);

	for(int k=0;k<m_recordSet.GetRecordCount();k++)
	{
		CString temp;
		m_recordSet.GetFieldValue(type,temp);
		m_recordSet.MoveNext();
	}
	m_recordSet.Close();

}

void CQueryTeachDlg::OnOK() 
{
	// TODO: Add extra validation here
	CComboBox* m_type=(CComboBox*)this->GetDlgItem(IDC_COMBO_BY);
	CListBox* m_value=(CListBox*)this->GetDlgItem(IDC_LIST_VALUE);
	CString value,type;
	int i=m_value->GetCurSel();
	m_value->GetText(i,value);
	m_type->GetWindowText(type);
	if(type=="教师名")
		type="teacher";
	else 
		type="course";
	bool bSuccess=true;
	if(value=="")
	{
		MessageBox("请选择查询值");
        bSuccess=false;
	}

 if(!m_database.IsOpen())
			{
				if(m_database.Open(_T("studentscore")))
				{
					m_recordSet.m_pDatabase=&m_database;
                     if(bSuccess)
						{
							CString strSQL;
							if(type=="teacher")
								strSQL.Format("select * from teach,course where teacher_no in (select teacher_no from teacher where teacher_name='%s') and teach.active_status='Y' and teach.course_no=course.course_no",value);
							else
							strSQL.Format("select * from teach,teacher where course_no in (select course_no from course where course_name='%s') and teach.active_status='Y' and teach.teacher_no=teacher.teacher_no",value);
      						m_recordSet.Open(CRecordset::dynamic,strSQL);
							m_list.DeleteAllItems();
							  for(int j=0;j<m_recordSet.GetRecordCount();j++)
							  {
								  CString temp;
								  if(type=="teacher")
									  m_recordSet.GetFieldValue("course_name",temp);
								  else
								  m_recordSet.GetFieldValue("teacher_name",temp);
								  m_value->AddString(temp);
							  }
						m_recordSet.Close();
						m_database.Close();

				}
				else 
				{
					MessageBox("bu neng dakai");
				}
			}

//	CDialog::OnOK();
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -