www.gusucode.com > 大学排课系统,VC++实现,能实现根据教师及课程资源自动排 > 大学排课系统,VC++实现,能实现根据教师及课程资源自动排课/ARRANGE/ModifyUserDlg.cpp

    // ModifyUserDlg.cpp : implementation file
//

#include "stdafx.h"
#include "arrange.h"
#include "ModifyUserDlg.h"
#include "LoginSet.h"
#include "WBButton.h"

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

/////////////////////////////////////////////////////////////////////////////
// CModifyUserDlg dialog


CModifyUserDlg::CModifyUserDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CModifyUserDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CModifyUserDlg)
	m_username = _T("");
	m_oldpassword = _T("");
	m_newpassword1 = _T("");
	m_newpassword2 = _T("");
	//}}AFX_DATA_INIT
}


void CModifyUserDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CModifyUserDlg)
	DDX_Text(pDX, IDC_EDIT1, m_username);
	DDX_Text(pDX, IDC_EDIT2, m_oldpassword);
	DDX_Text(pDX, IDC_EDIT3, m_newpassword1);
	DDX_Text(pDX, IDC_EDIT4, m_newpassword2);
	DDX_Control(pDX,IDOK,m_ok);
	DDX_Control(pDX,IDCANCEL,m_cancel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CModifyUserDlg, CDialog)
	//{{AFX_MSG_MAP(CModifyUserDlg)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModifyUserDlg message handlers

void CModifyUserDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	CLoginSet m_recordset(&m_database);
	CString strSQL;
	strSQL.Format("select * from UserInf where UserName='%s'",m_username);
	m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	int     iAuthority  = m_recordset.m_Authority; 
    CString oldpassword;
    oldpassword = m_recordset.m_PassWord;                   
	oldpassword.TrimRight(' ');                       //get the password string without the space followed      

	if(m_recordset.GetRecordCount()!=0)
	{
		if(m_oldpassword !=(LPCTSTR) oldpassword)          //check whether your password is correct 
		{
			MessageBox("你输入的原始密码不正确,请重新输入!");
			m_oldpassword.Empty();                         //delete every kind passwords inputed 
			m_newpassword1.Empty();
			m_newpassword2.Empty();
			UpdateData(FALSE);
		}
		else
		{
			if(m_newpassword1.Compare(m_newpassword2)!=0)     //confirm whether the two passords are the same 
			{
				MessageBox("两次输入的密码不一致,请重新输入!");
				m_oldpassword.Empty();
				m_newpassword1.Empty();
				m_newpassword2.Empty();
				UpdateData(FALSE);
			}
			else
			{
				strSQL.Format("delete from UserInf where UserName='%s'",m_username);
				m_database.ExecuteSQL(strSQL);
				strSQL.Format("insert into UserInf values(\'%s\',\'%s\',%d)",m_username,m_newpassword1,iAuthority);
				m_database.ExecuteSQL(strSQL);
				MessageBox("你已经成功修改你的密码!");
				CDialog::OnOK();
			}
		}		
	}
	else
		MessageBox("你输入的用户名并不存在,请重新输入!");
}


BOOL CModifyUserDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	 m_ok.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	 m_cancel.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CModifyUserDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
/*	CBitmap m_bitmap;
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	m_bitmap.LoadBitmap(IDB_BITMAP5);
	memDC.SelectObject(&m_bitmap);
	dc.BitBlt(0,0,600,800,&memDC,100,100,SRCCOPY);
*/	
	// Do not call CDialog::OnPaint() for painting messages
}