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

📄 modifypwddlg.cpp

📁 人事管理系统
💻 CPP
字号:
// ModifyPwdDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PersonelManage.h"
#include "ModifyPwdDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CModifyPwdDlg dialog


CModifyPwdDlg::CModifyPwdDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CModifyPwdDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CModifyPwdDlg)
	m_strNewPwd1 = _T("");
	m_strNewPwd2 = _T("");
	m_strOldPwd = _T("");
	//}}AFX_DATA_INIT
}


void CModifyPwdDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CModifyPwdDlg)
	DDX_Text(pDX, IDC_EDIT_NEWPWD1, m_strNewPwd1);
	DDV_MaxChars(pDX, m_strNewPwd1, 20);
	DDX_Text(pDX, IDC_EDIT_NEWPWD2, m_strNewPwd2);
	DDV_MaxChars(pDX, m_strNewPwd2, 20);
	DDX_Text(pDX, IDC_EDIT_OLDPWD, m_strOldPwd);
	DDV_MaxChars(pDX, m_strOldPwd, 20);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CModifyPwdDlg, CDialog)
	//{{AFX_MSG_MAP(CModifyPwdDlg)
	ON_EN_CHANGE(IDC_EDIT_NEWPWD1, OnChangeEditNewpwd1)
	ON_EN_CHANGE(IDC_EDIT_NEWPWD2, OnChangeEditNewpwd2)
	ON_EN_CHANGE(IDC_EDIT_OLDPWD, OnChangeEditOldpwd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModifyPwdDlg message handlers

void CModifyPwdDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	if(m_strOldPwd != m_strDBPwd)
	{
		AfxMessageBox("原始密码输入错误,请重新输入!");
		return;
	}
	if(m_strNewPwd1 != m_strNewPwd2)
	{
		AfxMessageBox("两次新密码输入不一致,请重新输入!");
		return;
	}

	long empID;
	BYTE password[20];
	memset(password, 0, 20);
	CADODatabase *pDb = new CADODatabase();
	try
	{
		if(pDb->Open())
		{
			CADORecordset *pRs = new CADORecordset(pDb);
			if(pRs->Open("tblEmployee", CADORecordset::openTable))
			{
				while(!pRs->IsEOF())
				{
					pRs->GetFieldValue("EmployeeID", empID);
					if(empID == m_nDBEmpID)
					{
						pRs->Edit();
						for(int i = 0, j = m_strNewPwd1.GetLength(); i < j; i++)
							password[i] = m_strNewPwd1[i];
						//修改密码
						_variant_t varBLOB;
						SAFEARRAY *psa;
						SAFEARRAYBOUND rgsabound[1];
						rgsabound[0].lLbound = 0;
						rgsabound[0].cElements = 20;
						psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
						BYTE *pByte;
						if(SafeArrayAccessData(psa, (void **)&pByte) == NOERROR)
							memcpy((LPVOID)pByte, (LPVOID)password, 20);
						SafeArrayUnaccessData(psa);

						varBLOB.vt = VT_ARRAY | VT_UI1;
						varBLOB.parray = psa;
						pRs->SetFieldValue("Password", varBLOB);
						//更新数据,勿忘记
						if(pRs->Update())
							AfxMessageBox("修改成功!");
					}
					pRs->MoveNext();
				}
				pRs->Close();
			}
			delete pRs;
			pDb->Close();
		}
		delete pDb;
	}
	catch(CADOException)
	{
	}
	
	CDialog::OnOK();
}

void CModifyPwdDlg::OnChangeEditNewpwd1() 
{
	// 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.
	UpdateData(TRUE);
	if(m_strOldPwd.GetLength() > 0 && m_strNewPwd1.GetLength() > 0 && m_strNewPwd2.GetLength() > 0)
		GetDlgItem(IDOK)->EnableWindow(TRUE);
	else
		GetDlgItem(IDOK)->EnableWindow(FALSE);
	
	// TODO: Add your control notification handler code here
	
}

void CModifyPwdDlg::OnChangeEditNewpwd2() 
{
	// 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
	UpdateData(TRUE);
	if(m_strOldPwd.GetLength() > 0 && m_strNewPwd1.GetLength() > 0 && m_strNewPwd2.GetLength() > 0)
		GetDlgItem(IDOK)->EnableWindow(TRUE);
	else
		GetDlgItem(IDOK)->EnableWindow(FALSE);
	
}

void CModifyPwdDlg::OnChangeEditOldpwd() 
{
	// 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
	UpdateData(TRUE);
	if(m_strOldPwd.GetLength() > 0 && m_strNewPwd1.GetLength() > 0 && m_strNewPwd2.GetLength() > 0)
		GetDlgItem(IDOK)->EnableWindow(TRUE);
	else
		GetDlgItem(IDOK)->EnableWindow(FALSE);
	
}

BOOL CModifyPwdDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	GetDlgItem(IDOK)->EnableWindow(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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