deldlg.cpp

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

CPP
80
字号
// DelDlg.cpp : implementation file
//

#include "stdafx.h"


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

/////////////////////////////////////////////////////////////////////////////
// CDelDlg dialog


CDelDlg::CDelDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDelDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDelDlg)
	m_strEditStuNum = _T("");
	//}}AFX_DATA_INIT
}


void CDelDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDelDlg)
	DDX_Text(pDX, IDC_EditStuNum, m_strEditStuNum);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CDelDlg message handlers

void CDelDlg::OnOK() 
{
	// TODO: Add extra validation here	
	int n_Status = 0;
	CDialog::OnOK();
	CString sz_StuNum;
	sz_StuNum = this->m_strEditStuNum;  //取出要删除记录的学号

    CMfcDesignDoc* pDoc = theApp.GetDocPointer();

	POSITION pos =pDoc->m_StudentList.GetHeadPosition();
	while (pos != NULL)
	{	
		CStudent* pCStudent = pDoc->m_StudentList.GetAt(pos);
       
		if(pCStudent->m_strStuNum == sz_StuNum)
		{
           pDoc->m_StudentList.RemoveAt(pos); //删除记录
		   n_Status = 1;
		   break;
		}
		else
		{
	    	pDoc->m_StudentList.GetNext(pos);
		}
	}

	if(n_Status == 0)
	{
		MessageBox("删除失败!");
	}
	else
	{
		MessageBox("删除成功!");
	}

}

⌨️ 快捷键说明

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