📄 coursequerytype.cpp
字号:
// CourseQueryType.cpp : implementation file
//
#include "stdafx.h"
#include "COdbc.h"
#include "CourseQueryType.h"
#include <afxdb.h>
#include "RecordCourse.h"
#include "CourseQueryTypeGet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCourseQueryType dialog
CCourseQueryType::CCourseQueryType(CWnd* pParent /*=NULL*/)
: CDialog(CCourseQueryType::IDD, pParent)
{
//{{AFX_DATA_INIT(CCourseQueryType)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CCourseQueryType::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCourseQueryType)
DDX_Control(pDX, IDC_COURSE_INFO, m_tList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCourseQueryType, CDialog)
//{{AFX_MSG_MAP(CCourseQueryType)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCourseQueryType message handlers
void CCourseQueryType::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CCourseQueryType::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
LPTSTR lpszCols[]={"课程号","课程名","课程类别",NULL}; // 列标题
int nWidth[] = {80,80,80,0}; // 列宽度
LV_COLUMN lvcol;
lvcol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvcol.fmt = LVCFMT_LEFT;
for(int i=0;lpszCols[i]!=NULL;i++)
{
lvcol.cx = nWidth[i];
lvcol.pszText = lpszCols[i];
m_tList.InsertColumn(i,&lvcol);
}
CCourseQueryTypeGet dlg(this);
if(dlg.DoModal()==IDCANCEL)
return false;
CDatabase db;
BOOL bRtn;
CString sql;
UpdateData(true);
sql = "Select * From lesson where lesson_type='";
sql +=m_type;
sql +="'";
CRecordCourse 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 true;
}
/* 4、逐条获取查询结果*/
for(rs.MoveFirst();!rs.IsEOF();rs.MoveNext()) {
// TODO: Add code here
}
/* 5、关闭记录集、数据库*/
/* 清除列表中原有的项*/
CString tmp;
m_tList.DeleteAllItems();
/* 在列表中显示纪录*/
LVITEM item;
int nRow=0;
item.mask = LVIF_TEXT;
item.state = LVIS_SELECTED;
item.stateMask = LVIS_SELECTED;
item.lParam = 1;
item.iIndent = 0;
for(rs.MoveFirst();!rs.IsEOF();rs.MoveNext(),nRow++)
{
item.iItem = nRow;
int iSubItem = 0;
item.iSubItem = iSubItem++;
item.pszText = (char*)(LPCTSTR)(rs.m_lesson_id);
item.cchTextMax = strlen(item.pszText);
m_tList.InsertItem(&item); // 第一列应用InsertItem()
item.iSubItem = iSubItem++;
item.pszText = (char*)(LPCTSTR)(rs.m_lesson_name);
item.cchTextMax = strlen(item.pszText);
m_tList.SetItem(&item); // 其余列用SetItem()
item.iSubItem = iSubItem++;
item.pszText = (char*)(LPCTSTR)(rs.m_lesson_type);
item.cchTextMax = strlen(item.pszText);
m_tList.SetItem(&item);
}
rs.Close();
db.Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCourseQueryType::GetName(CString str)
{
m_type=str;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -