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

📄 alterdlg.cpp

📁 MFC做的学生管理系统
💻 CPP
字号:
// AlterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MfcDesign.h"
#include "AlterDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAlterDlg dialog
 
CAlterDlg::CAlterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAlterDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAlterDlg)
	m_nValAge = 0;
	m_ValEomputer = 0;
	m_ValEnglish = 0;
	m_ValEthic = 0;
	//}}AFX_DATA_INIT
}


void CAlterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAlterDlg)
	DDX_Control(pDX, IDC_EditTel, m_nEditTel);
	DDX_Control(pDX, IDC_EditSex, m_nEditSex);
	DDX_Control(pDX, IDC_EditEthic, m_nEditEthic);
	DDX_Control(pDX, IDC_EditEnglish, m_nEditEnglish);
	DDX_Control(pDX, IDC_EditEducation, m_nEditEducation);
	DDX_Control(pDX, IDC_EditComputer, m_nEditComputer);
	DDX_Control(pDX, IDC_EditAge, m_nEditAge);
	DDX_Control(pDX, IDC_EditName, m_nEditName);
	DDX_Control(pDX, IDC_EditStuNum, m_nEditStuNum);
	DDX_Text(pDX, IDC_EditAge, m_nValAge);
	DDX_Text(pDX, IDC_EditComputer, m_ValEomputer);
	DDX_Text(pDX, IDC_EditEnglish, m_ValEnglish);
	DDX_Text(pDX, IDC_EditEthic, m_ValEthic);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAlterDlg, CDialog)
	//{{AFX_MSG_MAP(CAlterDlg)
	ON_BN_CLICKED(IDC_Find, OnFind)
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAlterDlg message handlers
void SetData(CAlterDlg* Dlg, CStudent* pCStudent)
{
	char Age_Buf[100] ;
	char Com_Buf[100] ;
    char Eng_Buf[100] ;
	char Ethic_buf[100] ;
	
 	sprintf(Age_Buf, "%d", pCStudent->m_nAge);
 
    sprintf(Com_Buf,"%d",pCStudent->m_csScore.m_nComputer);
 	sprintf(Eng_Buf ,"%d",pCStudent->m_csScore.m_nEnglish);
 	sprintf(Ethic_buf ,"%d",pCStudent->m_csScore.m_nEthic);

	Dlg->m_nEditName.SetWindowText(pCStudent->m_strName) ;
	Dlg->m_nEditSex.SetWindowText(pCStudent->m_strSex) ;
 	Dlg->m_nEditAge.SetWindowText(Age_Buf);
	Dlg->m_nEditTel.SetWindowText(pCStudent->m_strTel);
	Dlg->m_nEditEducation.SetWindowText(pCStudent->m_strEducation);
	Dlg->m_nEditComputer.SetWindowText(Com_Buf);
 	Dlg->m_nEditEnglish.SetWindowText(Eng_Buf);
	Dlg->m_nEditEthic.SetWindowText(Ethic_buf);
}

void CAlterDlg::OnFind() 
{
   //ClearListBox(&this->m_ResultList);

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

    this->m_nEditStuNum.GetWindowText(sz_StuNum);

    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)
		{
           this->m_Pos = pos;
		   SetData(this,pCStudent);
           
		   n_Status = 1;
		   break;
		}
		else
		{
	    	pDoc->m_StudentList.GetNext(pos);
		}
	}

	if(n_Status == 0)
	{
		MessageBox("没有此记录");
	}
}

void GetData(CAlterDlg* Dlg, CStudent* pCStudent)
{

    Dlg->m_nEditName.GetWindowText(pCStudent->m_strName);
    Dlg->m_nEditSex.GetWindowText(pCStudent->m_strSex );  
    Dlg->m_nEditTel.GetWindowText( pCStudent->m_strTel);
    Dlg->m_nEditStuNum.GetWindowText( pCStudent->m_strStuNum );
    Dlg->m_nEditEducation.GetWindowText( pCStudent->m_strEducation);

   // Dlg->m_nEditAge.GetWindowText(pCStudent->m_nAge);
   // Dlg->m_nEditComputer.GetWindowText(pCStudent->m_csScore.m_nComputer );
   // Dlg->m_nEditEnglish.GetWindowText(pCStudent->m_csScore.m_nEnglish );
   // Dlg->m_nEditEthic.GetWindowText(pCStudent->m_csScore.m_nEthic );

    pCStudent->m_nAge = Dlg->m_nValAge;
    pCStudent->m_csScore.m_nComputer = Dlg->m_ValEomputer;
    pCStudent->m_csScore.m_nEnglish = Dlg->m_ValEnglish;
    pCStudent->m_csScore.m_nEthic = Dlg->m_ValEthic;
}

void CAlterDlg::OnOK() 
{
	// TODO: Add extra validation here

    if(this->m_Pos == NULL)
	{
		AfxMessageBox("请先确定要修改的记录");
	}
	else
	{
      CMfcDesignDoc* pDoc = theApp.GetDocPointer();

	  CStudent* pCStudent = new CStudent;

      GetData(this, pCStudent);

      pDoc->m_StudentList.SetAt(this->m_Pos,pCStudent);
	}
 	CDialog::OnOK();
}

BOOL CAlterDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	this->m_Pos = NULL;
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAlterDlg::OnCancelMode() 
{
	CDialog::OnCancelMode();	
}

⌨️ 快捷键说明

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