📄 modify.cpp
字号:
// modify.cpp : implementation file
//
#include "stdafx.h"
#include "salsary.h"
#include "modify.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// modify dialog
modify::modify(CWnd* pParent /*=NULL*/)
: CDialog(modify::IDD, pParent)
{
//{{AFX_DATA_INIT(modify)
m_name = _T("");
m_age = _T("");
//}}AFX_DATA_INIT
}
void modify::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(modify)
DDX_Text(pDX, IDC_name, m_name);
DDV_MaxChars(pDX, m_name, 10);
DDX_Text(pDX, IDC_age, m_age);
DDV_MaxChars(pDX, m_age, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(modify, CDialog)
//{{AFX_MSG_MAP(modify)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// modify message handlers
#include"wh.h"
#include"salsaryDlg.h"
BOOL modify::OnInitDialog()
{
CDialog::OnInitDialog();
CSalsaryDlg*ptr=(CSalsaryDlg*)::AfxGetApp()->GetMainWnd();
fstream f("C:\\user.dat",ios::binary|ios::in|ios::out);
if(!f)
{cerr<<"文件不能打开"<<endl;
return FALSE;
}
user_data data;
f.seekp(0,ios::end);
long posEnd=f.tellp();
f.seekp(0,ios::beg);
CString user;
do
{f.read((char*)&data,sizeof(user_data));
user=data.user;
}while((ptr->m_userID).Compare(user)&&f.tellp()!=posEnd);
if(!(ptr->m_userID).Compare(user))
{m_name=data.name;
m_age.Format("%d",(data.age));
UpdateData(FALSE);}
else MessageBox("程序出错!");
// 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 modify::OnButton1()
{ int t=MessageBox("确定要进行修改?","注意!",4+32+256);
if(t==6)
{CSalsaryDlg*ptr=(CSalsaryDlg*)::AfxGetApp()->GetMainWnd();
UpdateData();
fstream f("C:\\user.dat",ios::binary|ios::in|ios::out);
if(!f)
{cerr<<"文件不能打开"<<endl;
return ;
}
user_data data;
f.seekp(0,ios::end);
long posEnd=f.tellp();
f.seekp(0,ios::beg);
CString user;
do
{f.read((char*)&data,sizeof(user_data));
user=data.user;
}while((ptr->m_userID).Compare(user)&&f.tellp()!=posEnd);
if(!((ptr->m_userID).Compare(user)))
{strcpy((data.name),(LPSTR)(LPCTSTR)(m_name));
(data.age)=atoi(m_age);
f.seekp(-long(sizeof(user_data)),ios::cur);//文件指针复位
f.write((char*)&data,sizeof(user_data));
MessageBox("修改用户资料成功!");
f.close();
} // TODO: Add your control notification handler code here
}}
void modify::OnButton2()
{
EndDialog(1); // TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -