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

📄 studentsee.cpp

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

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


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

/////////////////////////////////////////////////////////////////////////////
// CStudentSee dialog


CStudentSee::CStudentSee(CWnd* pParent /*=NULL*/)
	: CDialog(CStudentSee::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStudentSee)
	//}}AFX_DATA_INIT
}


void CStudentSee::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudentSee)
	DDX_Control(pDX, IDC_LIST1, m_SeeList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStudentSee, CDialog)
	//{{AFX_MSG_MAP(CStudentSee)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudentSee message handlers

BOOL CStudentSee::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	LPTSTR lpszCols[]={"学员ID","姓名","年龄","性别","班级","系别",NULL}; // 列标题
	int nWidth[] = {65,90,60,75,60,60,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_SeeList.InsertColumn(i,&lvcol);
	}

	CDatabase db;
	BOOL bRtn;
	CString sql;
	UpdateData(true);
	sql = "Select * From student";


	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 true;
	}
	/* 4、逐条获取查询结果*/
	for(rs.MoveFirst();!rs.IsEOF();rs.MoveNext()) {
	// TODO: Add code here
	}
	/* 5、关闭记录集、数据库*/

		/* 清除列表中原有的项*/
	CString tmp;
	m_SeeList.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_student_id);
		item.cchTextMax = strlen(item.pszText);
		m_SeeList.InsertItem(&item); // 第一列应用InsertItem()

		item.iSubItem = iSubItem++;
		item.pszText = (char*)(LPCTSTR)(rs.m_student_name);
		item.cchTextMax = strlen(item.pszText);
		m_SeeList.SetItem(&item); // 其余列用SetItem()

		item.iSubItem = iSubItem++;
		item.pszText = (char*)(LPCTSTR)(rs.m_student_age);
		item.cchTextMax = strlen(item.pszText);
		m_SeeList.SetItem(&item);

		item.iSubItem = iSubItem++;
		item.pszText = (char*)(LPCTSTR)(rs.m_student_sex);
		item.cchTextMax = strlen(item.pszText);
		m_SeeList.SetItem(&item);

		item.iSubItem = iSubItem++;
		item.pszText = (char*)(LPCTSTR)(rs.m_class);
		item.cchTextMax = strlen(item.pszText);
		m_SeeList.SetItem(&item);

		item.iSubItem = iSubItem++;
		item.pszText = (char*)(LPCTSTR)(rs.m_department);
		item.cchTextMax = strlen(item.pszText);
		m_SeeList.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
}

⌨️ 快捷键说明

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