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

📄 dlgpassword.cpp

📁 VC实现基于串口通讯的食堂饭卡系统,需要和相应的硬件结合实现.废话不多说了,大家下载吧,呵呵,给点评价哦!
💻 CPP
字号:
// DlgPassword.cpp : implementation file
//

#include "stdafx.h"
#include "ShoolCard.h"
#include "DlgPassword.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "Employee.h"

//全局变量
extern CString gAccount;
/////////////////////////////////////////////////////////////////////////////
// CDlgPassword dialog


CDlgPassword::CDlgPassword(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgPassword::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgPassword)
	m_NewPassword1 = _T("");
	m_NewPassword2 = _T("");
	m_Password = _T("");
	//}}AFX_DATA_INIT
}


void CDlgPassword::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgPassword)
	DDX_Text(pDX, IDC_EDIT_NEW_PASSWORD1, m_NewPassword1);
	DDX_Text(pDX, IDC_EDIT_NEW_PASSWORD2, m_NewPassword2);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_Password);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgPassword, CDialog)
	//{{AFX_MSG_MAP(CDlgPassword)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgPassword message handlers

short int CDlgPassword::ChanagePassword(CString account, CString password, CString new_pwd)
{
    CEmployee employee;
	employee.m_strFilter = "account = '" + account + "'"
	    + " and " + "password = '" + password + "'";
	try
	{
		//===============验证旧密码是否正确====================
        if(!employee.Open()) return -1;
		//查找不到任何记录
	    if(employee.GetRecordCount() != 1) return -2;
		//================更该密码=========
	    employee.Edit();
	    employee.m_password = new_pwd;
	    employee.Update();
		return 1;
	}
	catch(CException ee)
	{
		//数据库错误
	    return -1;
	}

}

void CDlgPassword::ClearEdit()
{
    m_Password = "";
	m_NewPassword1 = "";
	m_NewPassword2 = "";
	UpdateData(VAR2CON);
}

void CDlgPassword::OnOK() 
{
	// TODO: Add extra validation here
	CWnd *pWnd = CheckInput();
	if(pWnd) 
	{
		MessageBox("输入错误,请重新输入!");
		pWnd->SetWindowText("");
		pWnd->SetFocus();
		return;
	}
	pWnd = CheckValid();
	if(pWnd)
	{
		MessageBox("两次输入的口令不一致,请重新输入!");
		pWnd->SetWindowText("");
		pWnd->SetFocus();
		return;
	}
	int nRet = this->ChanagePassword(gAccount,m_Password,m_NewPassword1);
	if(nRet == -2)
	{
	    MessageBox("你输入的旧密码错误!");
		return;
	}
	else if(nRet < 0)
	{
	    MessageBox("密码修改成功!");
		return;
	}
	MessageBox("密码修改成功!");
	CDialog::OnOK();
}

CWnd * CDlgPassword::CheckInput()
{
    UpdateData(CON2VAR);
	if(m_Password == "")
		return GetDlgItem(IDC_EDIT_PASSWORD);
    if(m_NewPassword1 == "")
		return GetDlgItem(IDC_EDIT_NEW_PASSWORD1);
	if(m_NewPassword2 == "")
		return GetDlgItem(IDC_EDIT_NEW_PASSWORD2);
    return NULL;
}

CWnd* CDlgPassword::CheckValid()
{
     UpdateData(CON2VAR);
	 if(m_NewPassword1 != m_NewPassword2)
		 return GetDlgItem(IDC_EDIT_NEW_PASSWORD1);
	 return NULL;
}

⌨️ 快捷键说明

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