?? updatedlg.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 + -