📄 add_user.cpp
字号:
// add_user.cpp : implementation file
//
#include "stdafx.h"
#include "salsary.h"
#include "add_user.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// add_user dialog
add_user::add_user(CWnd* pParent /*=NULL*/)
: CDialog(add_user::IDD, pParent)
{
//{{AFX_DATA_INIT(add_user)
m_user = _T("");
m_key = _T("");
m_name = _T("");
m_salary = _T("");
m_age = _T("");
//}}AFX_DATA_INIT
}
void add_user::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(add_user)
DDX_Text(pDX, IDC_user, m_user);
DDV_MaxChars(pDX, m_user, 10);
DDX_Text(pDX, IDC_key, m_key);
DDV_MaxChars(pDX, m_key, 10);
DDX_Text(pDX, IDC_name, m_name);
DDV_MaxChars(pDX, m_name, 10);
DDX_Text(pDX, IDC_salary, m_salary);
DDV_MaxChars(pDX, m_salary, 10);
DDX_Text(pDX, IDC_age, m_age);
DDV_MaxChars(pDX, m_age, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(add_user, CDialog)
//{{AFX_MSG_MAP(add_user)
ON_EN_CHANGE(IDC_user, OnChangeuser)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_EN_CHANGE(IDC_age, OnChangeage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// add_user message handlers
void add_user::OnChangeuser()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
#include"wh.h"
void add_user::OnButton1()
{int t=MessageBox("确认增加用户?","提示!",4+32);
if(t==6)
{UpdateData();
fstream iof("C:\\user.dat",ios::binary|ios::in|ios::out);
if(!iof)
{cerr<<"文件不能打开"<<endl;
return;
}
if (m_user.IsEmpty())
{MessageBox("用户名不得为空!");}
else
{iof.seekp(0,ios::end);
long posEnd=iof.tellp();
user_data Data;
CString user;
iof.seekp(0,ios::beg);
do{iof.read((char*)&Data,sizeof(user_data));
user=Data.user;
}while(user.Compare(m_user)&&iof.tellp()!=posEnd);
if(user.Compare(m_user))
{iof.seekp(0,ios::end);
strcpy((Data.user),(LPSTR)(LPCTSTR)(m_user));
strcpy((Data.key),(LPSTR)(LPCTSTR)(m_key));
strcpy((Data.name),(LPSTR)(LPCTSTR)(m_name));
(Data.age)=atoi(m_age);
(Data.salary)=atoi(m_salary);
iof.write((char*)&Data,sizeof(user_data));
iof.close();
MessageBox("添加用户成功!"); // TODO: Add your control notification handler code here
}
else MessageBox("该用户已存在!");
}}}
void add_user::OnButton2()
{
EndDialog(1); // TODO: Add your control notification handler code here
}
void add_user::OnChangeage()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -