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

📄 users.cpp

📁 自己弄得一个学生管理系统
💻 CPP
字号:
// Users.cpp : implementation file
//

#include "stdafx.h"
#include "StuChgManager.h"
#include "Users.h"

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

extern CStuChgManagerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CUsers dialog


CUsers::CUsers(CWnd* pParent /*=NULL*/)
	: CDialog(CUsers::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUsers)
	m_username = _T("");
	m_password = _T("");
	//}}AFX_DATA_INIT
}


void CUsers::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUsers)
	DDX_Control(pDX, IDC_USERpassword, m_ctrlpassword);
	DDX_Control(pDX, IDC_USERname, m_ctrlusername);
	DDX_Text(pDX, IDC_USERname, m_username);
	DDX_Text(pDX, IDC_USERpassword, m_password);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CUsers message handlers

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

	count = 0;  //初始登陆次数
	m_ctrlpassword.SetWindowText(""); //清空编辑框
	m_ctrlusername.SetWindowText("");

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
bool CUsers::notExist(CString str1,CString str2)
{
	CString sql; //查询记录
	sql.Format("select * from users where username = '%s' and userpassword = '%s'",str1,str2);
  
	theApp.record->raw_Close();   //关闭当前数据集they are the one
	theApp.record->CursorLocation = adUseClient; 
    
	try   //捕捉异常
	{
		theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
		
	}
	catch(_com_error & e)
	{
		AfxMessageBox(e.Description());
		return false;                          //捕捉到异常后就不在继续执行
	}

	if(theApp.record->RecordCount == 0)  //如果为空
		return true;
	return false;
}

void CUsers::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(true);

	if(m_username.GetLength() == 0)
	{
		MessageBox("用户名不能为空!");
		m_ctrlusername.SetFocus();
		return;
	}
	if(m_password.GetLength() == 0)
	{
		MessageBox("用户密码不能为空!");
		m_ctrlpassword.SetFocus();
		return;
	}
	if(notExist(m_username,m_password))
	{
		count ++;
		if(count < 3)
		{
			CString str;
			str.Format("用户信息错误,请仔细,您还有 %d次机会!",3-count);
			MessageBox(str);
			m_ctrlusername.SetWindowText("");
			m_ctrlpassword.SetWindowText("");
			m_ctrlusername.SetFocus();
			return;
		}
		else
		{
			MessageBox("登录次数超过3次,系统将关闭!");
			exit(0);
			return;
		}
	}

	CDialog::OnOK();
}

⌨️ 快捷键说明

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