studlg.cpp

来自「计算机图形学电子教案 上传者来自 兰州交通大学」· C++ 代码 · 共 113 行

CPP
113 行
字号
// StuDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ex_ODBC.h"
#include "StuDlg.h"
#include "CodeSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStuDlg dialog


CStuDlg::CStuDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStuDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStuDlg)
	m_StuID = _T("");
	m_StuName = _T("");
	m_StuSex = _T("");
	m_ProfCode = _T("");
	m_Disp = _T("");
	//}}AFX_DATA_INIT
}


void CStuDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStuDlg)
	DDX_Control(pDX, IDC_LIST1, m_CodeList);
	DDX_Text(pDX, IDC_STU_ID, m_StuID);
	DDV_MaxChars(pDX, m_StuID, 6);
	DDX_Text(pDX, IDC_STU_NAME, m_StuName);
	DDV_MaxChars(pDX, m_StuName, 8);
	DDX_Text(pDX, IDC_STU_SEX, m_StuSex);
	DDV_MaxChars(pDX, m_StuSex, 2);
	DDX_Text(pDX, IDC_PROF_CODE, m_ProfCode);
	DDV_MaxChars(pDX, m_ProfCode, 6);
	DDX_Text(pDX, IDC_DISP, m_Disp);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStuDlg, CDialog)
	//{{AFX_MSG_MAP(CStuDlg)
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStuDlg message handlers

void CStuDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(true);	
	CDialog::OnOK();
}

void CStuDlg::OnSelchangeList1() 
{
	// TODO: Add your control notification handler code here
	int index= m_CodeList.GetCurSel();
	if(index!=LB_ERR)
	{    CString str;
	     m_CodeList.GetText(index,str);
		 //在记录集中查找profcode字段的值为str的记录
		 CCodeSet codeSet;
		 codeSet.m_strFilter.Format("profcode='%s'",str);
		 if(codeSet.Open())
		 {     m_Disp.Format("%s%d",codeSet.m_profname,codeSet.m_stuyears);
		       m_ProfCode=str;
			   UpdateData(FALSE);
		 }
		 codeSet.Close();

	}
	
}

BOOL CStuDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CCodeSet codeSet;
	codeSet.Open();
	while(!codeSet.IsEOF())
	{    m_CodeList.AddString(codeSet.m_profcode);
	     codeSet.MoveNext();
	}
	codeSet.Close();
	//在列表框中查找m_ProfCode指定的专业代码,若找到则设置当前列表项
	//并调用OnSelchangeList1函数
	if(!m_ProfCode.IsEmpty())
	{     int index=m_CodeList.FindString(-1,m_ProfCode);
	      if(index!=LB_ERR)
		  {    m_CodeList.SetCurSel(index);
		       OnSelchangeList1();
		  }
	}

	
	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 + =
减小字号Ctrl + -
显示快捷键?