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

📄 dlglogon.cpp

📁 一个简单的公司人员考勤系统的源代码,我已经编译运行过
💻 CPP
字号:
// dlgLogOn.cpp : implementation file
//

#include "stdafx.h"
#include "CheckIn.h"
#include "dlgLogOn.h"
#include "userrecordset.h"

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

/////////////////////////////////////////////////////////////////////////////
// CdlgLogOn dialog


CdlgLogOn::CdlgLogOn(CWnd* pParent /*=NULL*/)
	: CDialog(CdlgLogOn::IDD, pParent)
{
	//{{AFX_DATA_INIT(CdlgLogOn)
	m_strUserName = _T("");
	m_strPassword = _T("");
	//}}AFX_DATA_INIT

}


void CdlgLogOn::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CdlgLogOn)
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUserName);
	DDX_Text(pDX, IDC_EDIT_USERPASSWORD, m_strPassword);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CdlgLogOn, CDialog)
	//{{AFX_MSG_MAP(CdlgLogOn)
	ON_BN_CLICKED(IDC_OK, OnConfirm)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CdlgLogOn message handlers

void CdlgLogOn::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CdlgLogOn::OnConfirm() 
{
	// TODO: Add your control notification handler code here
	CEdit *pEditUser = (CEdit*)this->GetDlgItem(IDC_EDIT_USERNAME);
	CEdit *pEditPass = (CEdit*)this->GetDlgItem(IDC_EDIT_USERPASSWORD);
	CUserRecordset rsUser;
	this->UpdateData(true);
	try
	{
		if(!rsUser.IsOpen())				
			rsUser.Open(CRecordset::dynaset,_T("select * from tbUser where UserName ='"+m_strUserName+"'"));			
		if (rsUser.MyGetRecordCount() <= 0)
		{			
			::MessageBox(NULL,"没有此用户,请使用其它用户登录!","登录错误",MB_ICONINFORMATION);
			pEditUser->SetWindowText("");
			/*也可以使用DDX机制*/
			//this->m_strUserName = "";
			//this->UpdateData(false);
			pEditUser->SetFocus();	
			return;
		}
		else//输入的用户存在表中,那么检查密码是否正确
		{
			rsUser.Close();
			rsUser.Open(CRecordset::dynaset,_T("select * from tbUser where Password ='"+m_strPassword+"' and UserName ='"+m_strUserName+"'"));
			if (rsUser.MyGetRecordCount() <= 0)
			{			
				::MessageBox(NULL,"密码输入不正确,请重新登录!","登录错误",MB_ICONINFORMATION);				
				pEditPass->SetWindowText("");
				pEditPass->SetFocus();				
				return;
			}
			else
			{
				//表明用户和密码输入完全正确
				//这时利用EndDialog函数的参数来返回用户的权限
				if (rsUser.m_Authority == "超级用户")
				{					
					this->EndDialog(IDSUPER);
				}
				if (rsUser.m_Authority == "签到用户")
				{
					this->EndDialog(IDCHECK);
				}
			}
		}
	}
	catch(CDBException *e)
	{
		AfxMessageBox(e->m_strError);
		return;
	}	
}

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

	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 + -