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

📄 logindlg.cpp

📁 厨房仓库管理系统
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Storage.h"
#include "LoginDlg.h"
#include "StorageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog


CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers

void CLoginDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString m_account,m_password;
	this->GetDlgItemText(IDC_EDIT1,m_account);
	this->GetDlgItemText(IDC_EDIT2,m_password);
	if(m_account == "")
	{
		AfxMessageBox("帐号不能为空!");
		return;
	}

	// 使用ADO创建数据库记录集
	_RecordsetPtr	m_pRecordset;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	
	CString strSQL;
	strSQL.Format("SELECT * FROM 用户 where 用户昵称='%s' and 用户密码='%s'",m_account,m_password);
	// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
	// 因为它有时会经常出现一些想不到的错误。
	try
	{
		m_pRecordset->Open(_variant_t(strSQL),              
							((CStorageApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);

	}
	catch(_com_error e)
	{
		AfxMessageBox("数据库连接有误,请检查网络是否中断或者服务器是否正常启动。");
		return;
	}
	
	if(m_pRecordset->BOF && m_pRecordset->adoEOF)
	{
		AfxMessageBox("帐号和密码不正确,请重新输入!");
		return;
	}
	
	((CStorageApp*)AfxGetApp())->USER_NAME = (LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("用户昵称"));
	((CStorageApp*)AfxGetApp())->USER_TYPE = (LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("用户类别"));
	((CStorageApp*)AfxGetApp())->USER_RIGHT = atoi((LPCTSTR)(_bstr_t)(m_pRecordset->GetCollect("用户权限")));
	m_pRecordset->Close();
	m_pRecordset = NULL;

	if(((CStorageApp*)AfxGetApp())->USER_RIGHT != 1000 && ((CStorageApp*)AfxGetApp())->USER_RIGHT != 6000)
	{
		AfxMessageBox("您没有进入点单管理的权限!");
		return;
	}

	CStorageDlg dlg;
	AfxGetApp()->m_pMainWnd = &dlg;
	this->SetDlgItemText(IDC_EDIT1,"");
	this->SetDlgItemText(IDC_EDIT2,"");
	this->ShowWindow(SW_HIDE);
	dlg.DoModal();

	CDialog::OnOK();
}

⌨️ 快捷键说明

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