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

📄 login.cpp

📁 一个很好的VC源代码
💻 CPP
字号:
// Login.cpp : implementation file
//

#include "stdafx.h"
#include "aoManage.h"
#include "Login.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLogin dialog


CLogin::CLogin(CWnd* pParent /*=NULL*/)
	: CParentDlg(CLogin::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLogin)
	m_strName = _T("");
	m_strPassword = _T("");
	//}}AFX_DATA_INIT
	m_pUser=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
	m_pLogin=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
	m_nLogCount=0;
}


void CLogin::DoDataExchange(CDataExchange* pDX)
{
	CParentDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLogin)
	DDX_Text(pDX, IDC_EDIT1, m_strName);
	DDV_MaxChars(pDX, m_strName, 20);
	DDX_Text(pDX, IDC_EDIT2, m_strPassword);
	DDV_MaxChars(pDX, m_strPassword, 6);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLogin, CParentDlg)
	//{{AFX_MSG_MAP(CLogin)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogin message handlers

BOOL CLogin::OnInitDialog() 
{
	CParentDlg::OnInitDialog();
	
	m_pUser->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from user");
	m_pLogin->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from login");
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLogin::OnButton1() 
{
	UpdateData(TRUE);
	/*if (strcmp(m_strName,"administrator"))
		if (!m_strName.GetLength()||!m_strPassword.GetLength())
		{
			MessageBox("用户名或密码不能为空");
			return;
		}*/
	if (!m_strName.GetLength())
	{
		MessageBox("用户名不能为空");
		return;
	}
	CString strFilter;
	if (m_strPassword.GetLength())
		strFilter="name='"+m_strName+"' and password ='"+m_strPassword+"'";
	else
		strFilter="name='"+m_strName+"' and password = NULL";
	//m_pUser->MoveFirst();
	if (m_pUser->FindFirst(strFilter))
	{
		COleDateTime dtCrnt=COleDateTime::GetCurrentTime();
		m_pLogin->MoveLast();
		m_pLogin->AddNew();
		m_pLogin->SetFieldValue("name",(LPCTSTR)m_strName);
		m_pLogin->SetFieldValue("ldate",dtCrnt);
		m_pLogin->SetFieldValue("btime",dtCrnt);
		m_pLogin->Update();
		COleVariant vVal;
		m_pUser->GetFieldValue("priority",vVal);
		((CMainFrame*)AfxGetMainWnd())->m_strOperator=m_strName;
		((CMainFrame*)AfxGetMainWnd())->m_strPriority=(LPCTSTR)vVal.bstrVal;
		OnOK();
	}
	else 
	{
		if (++m_nLogCount==3) 
		{
			MessageBox("未注册用户,请与系统管理员联系");
			OnCancel();
		}
		else
		{
			MessageBox("用户名或密码不正确,请重新输入");
			m_strName="";
			m_strPassword="";
			UpdateData(FALSE);
		}
	}
}

void CLogin::OnClose() 
{
	if (m_pUser->IsOpen())
		m_pUser->Close();	
	if (m_pLogin->IsOpen())
		m_pLogin->Close();
	CParentDlg::OnClose();
}

void CLogin::OnButton2() 
{
	OnCancel();	
}

⌨️ 快捷键说明

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