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

📄 hange.cpp

📁 数据结构大作业
💻 CPP
字号:
// hange.cpp : implementation file
//

#include "stdafx.h"
#include "salsary.h"
#include "hange.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Change dialog


Change::Change(CWnd* pParent /*=NULL*/)
: CDialog(Change::IDD, pParent)
{
	//{{AFX_DATA_INIT(Change)
	m_oldPassword = _T("");
	m_newPassword = _T("");
	m_NewTwice = _T("");
	//}}AFX_DATA_INIT
}


void Change::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Change)
	DDX_Text(pDX, IDC_oldPassword, m_oldPassword);
	DDV_MaxChars(pDX, m_oldPassword, 10);
	DDX_Text(pDX, IDC_newPassword, m_newPassword);
	DDV_MaxChars(pDX, m_newPassword, 10);
	DDX_Text(pDX, IDC_NewTwice, m_NewTwice);
	DDV_MaxChars(pDX, m_NewTwice, 10);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Change, CDialog)
//{{AFX_MSG_MAP(Change)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_ENTER, OnEnter)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Change message handlers

void Change::OnExit() 
{
	EndDialog(1);}	// TODO: Add your control notification handler code here


#include"salsaryDlg.h"
#include"wh.h"
void Change::OnEnter()//修改密码
{int t=MessageBox("确定修改密码?","提示!",4+32);
if (t==6)
{CSalsaryDlg*ptr=(CSalsaryDlg*)::AfxGetApp()->GetMainWnd();//获取其它类的数据
UpdateData();
if(!(ptr->m_password).Compare(m_oldPassword))
{if (!m_newPassword.Compare(m_NewTwice))
{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.key),(LPSTR)(LPCTSTR)(m_newPassword));
f.seekp(-long(sizeof(user_data)),ios::cur);//文件指针复位
f.write((char*)&data,sizeof(user_data));
MessageBox("修改密码成功");
f.close();
}//if第三层
else MessageBox("未找到记录!");
}//if第二层
else MessageBox("两次密码输入不符!");
}//if第一层
else MessageBox("旧密码输入错误!");

}}
	
// TODO: Add your control notification handler code here


⌨️ 快捷键说明

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