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

📄 updatedlg.cpp

📁 vc编写的简单的学生成绩管理系统
💻 CPP
字号:
////////////////////////////////////
// the UpdateDlg.cpp

#include "UpdateDlg.h"
#include "MenuID.h"
#include "StuFrame.h"
#include "hStudent.h"

////////////////////////////////////
// CUpdateDlg::CUpdateDLg
// constructor
CUpdateDlg::CUpdateDlg(CWnd* parentWnd) : CInputDlg(parentWnd)
{
	m_parentWnd = parentWnd;
    SetWindowText(_T("信息修改"));

	int iIndex = ((CStuFrame*)m_parentWnd)->GetListSelID();
	CStudent* pStu = ((CStuFrame*)m_parentWnd)->GetStudbObj()->FindRecord(iIndex);
	m_szName   = pStu->GetStudentName();
	m_szSex    = pStu->GetStudentSex();
	m_szPhone  = pStu->GetStudentPhone();
	m_szAddress= pStu->GetStudentAddress();
	m_iID      = pStu->GetStudentID();
	m_fChinese = pStu->GetStudentGradeChinese();
	m_fEnglish = pStu->GetStudentGradeEnglish();
	m_fMath    = pStu->GetStudentGradeMath();

	UpdateData(FALSE);
}

/////////////////////////////////////
// CUpdateDlg::~CUpdateDlg
// destructor
CUpdateDlg::~CUpdateDlg()
{

}

/////////////////////////////////////
//message map and member functions
BEGIN_MESSAGE_MAP(CUpdateDlg,CInputDlg)
    ON_BN_CLICKED(ID_INPUT_OK,OnInput)
	ON_BN_CLICKED(ID_INPUT_CANCEL,OnCancel)
END_MESSAGE_MAP()

//////////////////////////////////////
//CUpdateDlg::OnInput
void CUpdateDlg::OnInput()
{
	UpdateData(TRUE);

	if (m_szName == "")
	{
		AfxMessageBox("请输入姓名");
		return;
	}
	if (m_szSex == "")
	{
		AfxMessageBox("请输入性别!");
		return;
	}
	if (m_szPhone == "")
	{
		AfxMessageBox("请输入电话号码!");
		return;
	}
	if (m_szAddress == "")
	{
		AfxMessageBox("请输入您的地址!");
		return;
	}
    
	//
	// 主窗体指针
	//
	CStuFrame* pMainWnd = (CStuFrame*)m_parentWnd;
	//
	// 主窗体的LISTBOX控件当前选中的项对应的学生ID
	//
    int iIndex = pMainWnd->GetListSelID();
    
	//
	// 开始更新记录
	//
	CStudent stu;
	stu.AddStudentName( (LPTSTR)(LPCTSTR)m_szName );
	stu.AddStudentAddress( (LPTSTR)(LPCTSTR)m_szAddress );
	stu.AddStudentSex( (LPTSTR)(LPCTSTR)m_szSex );
	stu.AddStudentPhone( (LPTSTR)(LPCTSTR)m_szPhone );
	stu.AddStudentID(m_iID);
	stu.AddStudentGrade(m_fChinese,m_fEnglish,m_fMath);

	if (pMainWnd->GetStudbObj()->UpdateRecord(&stu,iIndex))
	{
		pMainWnd->LoadFile();        // 从数据文件中重新截入数据
		AfxMessageBox("修改成功!");
	}
	else
		AfxMessageBox("修改失败!");

}

///////////////////////////////////////
//CUpdateDlg::OnCancel
void CUpdateDlg::OnCancel()
{
    DestroyWindow();
}

⌨️ 快捷键说明

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