📄 queryteachdlg.cpp
字号:
// QueryTeachDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Scoremanager.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)
//}}AFX_DATA_INIT
}
void CQueryTeachDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CQueryTeachDlg)
DDX_Control(pDX, IDCANCEL3, m_can1);
DDX_Control(pDX, IDCANCEL, m_can);
DDX_Control(pDX, IDC_COMBO_BY, m_combox);
DDX_Control(pDX, IDC_LIST, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CQueryTeachDlg, CDialog)
//{{AFX_MSG_MAP(CQueryTeachDlg)
ON_CBN_SELCHANGE(IDC_COMBO_BY, OnSelchangeComboBy)
ON_BN_CLICKED(IDCANCEL3, OnQUERY)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQueryTeachDlg message handlers
BOOL CQueryTeachDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(!m_database.IsOpen())
{
m_database.Open(_T("Scoremanager"));
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;
}
void CQueryTeachDlg::OnSelchangeComboBy()
{
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="teacher";
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_value->AddString(temp);
m_recordSet.MoveNext();
}
m_recordSet.Close();
}
void CQueryTeachDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CQueryTeachDlg::OnQUERY()
{
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();
if(i!=-1)
{
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(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 teacher,teach 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::forwardOnly,strSQL);
for(int k=m_list.GetCount();k>=0;k--)
m_list.DeleteString(k);
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_list.AddString(temp);
m_recordSet.MoveNext();
}
m_recordSet.Close();
}
//CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -