finddlg.cpp

来自「MFC做的学生管理系统」· C++ 代码 · 共 92 行

CPP
92
字号
// FindDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MfcDesign.h"
#include "FindDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void ShowRecord(char Buffer[200], CStudent* pCStudent);
/////////////////////////////////////////////////////////////////////////////
// CFindDlg dialog


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


void CFindDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFindDlg)
	DDX_Control(pDX, IDC_EditStuNum, m_strEditStuNum);
	DDX_Control(pDX, IDC_ListFind, m_ResultList);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CFindDlg message handlers
void ClearListBox(CListBox * List)//清空列表筐
{
	int num;
	num = List->GetCount();
	for(int i = 0; i < num; i++)
	{
		List->DeleteString(i);
	}
}

void CFindDlg::OnOK() 
{
    
	ClearListBox(&this->m_ResultList);

	int n_Status = 0;
    char sz_Buffer[200];
	CString sz_StuNum;

    this->m_strEditStuNum.GetWindowText(sz_StuNum);  //取出要删除记录的学号
    //MessageBox(sz_StuNum);
    CMfcDesignDoc* pDoc = theApp.GetDocPointer();

	POSITION pos =pDoc->m_StudentList.GetHeadPosition();
 
	while (pos != NULL)
	{	
		CStudent* pCStudent = pDoc->m_StudentList.GetAt(pos);
       // MessageBox(pCStudent->m_strStuNum);
       
		
		if(pCStudent->m_strStuNum == sz_StuNum)
		{
		   ShowRecord(sz_Buffer, pCStudent);
           this->m_ResultList.AddString(sz_Buffer);
		   n_Status = 1;
		   break;
		}
		else
		{
	    	pDoc->m_StudentList.GetNext(pos);
		}
	}

	if(n_Status == 0)
	{
		this->m_ResultList.AddString("没有此记录");
	}
}

⌨️ 快捷键说明

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