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

📄 userlogin.cpp

📁 一个简易的医药销售管理系统源码
💻 CPP
字号:
// UserLogin.cpp : 实现文件
//

#include "stdafx.h"
#include "MedicineSaleManages.h"
#include "UserLogin.h"
#include ".\userlogin.h"

UINT_PTR m_timerID;


// CUserLogin 对话框

IMPLEMENT_DYNAMIC(CUserLogin, CDialog)
CUserLogin::CUserLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CUserLogin::IDD, pParent)
	, lock(FALSE)
	, autologin(FALSE)
{
}

CUserLogin::~CUserLogin()
{
}

void CUserLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CUserLogin, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
	ON_EN_SETFOCUS(IDC_USERPASSWORD, OnEnSetfocusUserpassword)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CUserLogin 消息处理程序

void CUserLogin::OnBnClickedOk()
{
	CString user,password,UserName,UserPassword;
	UserName=user=password=UserPassword="";
	GetDlgItemText(IDC_USERNAME,UserName);
	GetDlgItemText(IDC_USERPASSWORD,UserPassword);
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		CString strSQL="SELECT * FROM USERS";
		m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
				((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
	try
	{
		_variant_t var;
		user=password=_T("");
		if(!m_pRecordset->BOF)
			m_pRecordset->MoveFirst();
		while(!m_pRecordset->adoEOF)
		{
			var = m_pRecordset->GetCollect("user");
			user = (LPCSTR)_bstr_t(var);
			var = m_pRecordset->GetCollect("password");
			password = (LPCSTR)_bstr_t(var);
			m_pRecordset->MoveNext();
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
	if(UserName==user && UserPassword==password)
	{
		theApp.userlogin=FALSE;
		theApp.userlock=FALSE;
		OnOK();
	}
	else
	{
		MessageBox("非法用户。","警告!!!",MB_OK|MB_ICONHAND);
		if(UserName!=user)
			GotoDlgCtrl(GetDlgItem(IDC_USERNAME));
		else
			GotoDlgCtrl(GetDlgItem(IDC_USERPASSWORD));
	}
}

void CUserLogin::OnBnClickedCancel()
{
	if(lock)
		AfxMessageBox("系统已经被锁定,不能退出!");
	else
		OnCancel();
}

BOOL CUserLogin::OnInitDialog()
{
	CDialog::OnInitDialog();
	if(lock)
		SetDlgItemText(IDCANCEL,_T("退    出"));
	m_tooltip.Create(this,TTS_ALWAYSTIP);
	m_tooltip.Activate(TRUE);
	m_tooltip.AddTool(GetDlgItem(IDC_USERNAME),IDS_USERNAME);
	m_tooltip.AddTool(GetDlgItem(IDC_USERPASSWORD),IDS_USERPASSWORD);
	m_tooltip.AddTool(GetDlgItem(IDCANCEL),IDS_USERCANCEL);
	m_tooltip.AddTool(GetDlgItem(IDOK),IDS_USEROK);
	if(autologin)
	{
		SetDlgItemText(IDC_USERNAME,theApp.ReadData("USERS","user"));
		SetDlgItemText(IDC_USERPASSWORD,theApp.ReadData("USERS","password"));
		m_timerID = this->SetTimer(1,200,NULL);
	}
	return TRUE;
}

void CUserLogin::OnEnSetfocusUserpassword()
{
	theApp.SetInputMethod(FALSE);
}

BOOL CUserLogin::PreTranslateMessage(MSG* pMsg)
{
	m_tooltip.RelayEvent(pMsg);
	return CDialog::PreTranslateMessage(pMsg);
}

void CUserLogin::WinHelp(DWORD dwData, UINT nCmd)
{
}

void CUserLogin::OnTimer(UINT nIDEvent)
{
	autologin=FALSE;
	KillTimer(m_timerID);
	OnBnClickedOk();
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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