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

📄 dlglogin.cpp

📁 这是一个管理信息系统
💻 CPP
字号:
// DlgLogin.cpp : implementation file
//

#include "stdafx.h"
#include "a1.h"
#include "DlgLogin.h"
#include "Crypt.h"
#include "myfunction.h"

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


/////////////////////////////////////////////////////////////////////////////
// CDlgLogin dialog


CDlgLogin::CDlgLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgLogin::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgLogin)
	m_sUserName = _T("");
	m_sPassWord = _T("");
	//}}AFX_DATA_INIT
	m_iLogOnCount=0;
}


void CDlgLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgLogin)
	DDX_Control(pDX, IDC_STATIC_PICTURE, m_picture);
	DDX_Control(pDX, IDOK, m_ok);
	DDX_Control(pDX, IDC_EDIT_NAME, m_editUserName);
	DDX_Control(pDX, IDC_EDIT_PASSWORD, m_editPassWord);
	DDX_Text(pDX, IDC_EDIT_NAME, m_sUserName);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_sPassWord);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CDlgLogin message handlers

void CDlgLogin::OnOK() 
{
	BOOL bLogOn=FALSE;
	CString sUserPassWord, sPurview,sUserName,sInputPassWord;

	LRunSql m_runsql;
	CString sql;
	_variant_t value;

	CString sError;

	// 更新数据变量
	this->m_editPassWord.GetWindowText(sInputPassWord);
	this->m_editUserName.GetWindowText(sUserName);

	CA1App* App=(CA1App*)AfxGetApp();

	sql.Format("select admi_password,admi_purview from tabpurview where admi_name='%s'",
		sUserName);
	if(m_runsql.CheckSQLResult(sql))
	{

		value=m_runsql.m_recordset->GetCollect("admi_password");
		if(value.vt!=VT_NULL)
			sUserPassWord=(char*)(_bstr_t)value;
  		value=m_runsql.m_recordset->GetCollect("admi_purview");
		if(value.vt!=VT_NULL)
			sPurview=(char*)(_bstr_t)value;
		if(sUserPassWord==CCrypt::Encrypt(sInputPassWord))
		{
			App->m_sUserName=sUserName;
			App->m_sPurview=sPurview;
			bLogOn=TRUE;
		}
		else
		{
			sError="请重新输入密码。\n注意大小写!","密码错误";
			this->m_editPassWord.SetFocus();
		}
	}
	else
	{
		sError="请确认用户名大小写是否正确!","无此用户";
		this->m_editUserName.SetFocus();
	}

	if(bLogOn) EndDialog(IDOK);
	else 
	{	
			m_iLogOnCount++;
			if(m_iLogOnCount>=3)
				this->EndDialog(0);
			else
				MessageBox(sError);
	}
}

void CDlgLogin::OnCancel() 
{
	CDialog::OnCancel();
}

BOOL CDlgLogin::PreTranslateMessage(MSG* pMsg) 
{
	if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==13)
	{
		if(this->SetTheFocus())
			return true;
	}
	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CDlgLogin::OnInitDialog() 
{
	CDialog::OnInitDialog();

	::PostMessage(m_editUserName.GetSafeHwnd(),WM_ACTIVATE ,WA_CLICKACTIVE,0);

	
//	ShowWindow(SW_MAXIMIZE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

bool CDlgLogin::SetTheFocus()
{
	HWND hwnd=::GetFocus();
	UINT id=::GetDlgCtrlID(hwnd);
	switch(id)
	{
	case IDC_EDIT_NAME:
		this->m_editPassWord.SetFocus();
		::PostMessage(m_editPassWord.GetSafeHwnd(),WM_KEYDOWN,VK_END,0);
		return true;
	case IDC_EDIT_PASSWORD:
		this->GetDlgItem(IDOK)->SetFocus();
		return true;
	case IDOK:
		this->OnOK();
		return true;
	case IDCANCEL:
		this->OnCancel();
		return true;
	}
	return false;
}

⌨️ 快捷键说明

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