?? logdlg.cpp
字號:
// LogDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Rent.h"
#include "LogDlg.h"
#include "connectionDB.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLogDlg dialog
CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLogDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLogDlg)
m_name = _T("");
m_psw = _T("");
//}}AFX_DATA_INIT
}
void CLogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLogDlg)
DDX_Control(pDX, IDC_EDIT_PSWORD, m_Editpsw);
DDX_Control(pDX, IDC_EDIT_NAME, m_Editname);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDX_Text(pDX, IDC_EDIT_PSWORD, m_psw);
//}}AFX_DATA_MAP
}
BOOL CLogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}
BEGIN_MESSAGE_MAP(CLogDlg, CDialog)
//{{AFX_MSG_MAP(CLogDlg)
ON_BN_CLICKED(IDC_VAIL, OnVail)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLogDlg message handlers
BOOL CLogDlg::ValidateUser()
{//登錄驗證
CConnectionDB *ConnectionPtr=new CConnectionDB();
m_pConnection=ConnectionPtr->GetConnectionPtr();
HRESULT hr;
_RecordsetPtr pAdminRecordset;
pAdminRecordset.CreateInstance(__uuidof(Recordset));
CString strSql;
_variant_t var;
CString strValue1,strValue2;
int flag=0;
strSql="select * from Admin";
try
{
hr=pAdminRecordset->Open(_variant_t(strSql),m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
if(SUCCEEDED(hr))
{
while(!pAdminRecordset->adoEOF)
{
var=pAdminRecordset->GetCollect((long)0);//取用戶名
if(var.vt!=VT_NULL)
strValue1=(LPCSTR)_bstr_t(var);
var=pAdminRecordset->GetCollect("password");
if(var.vt!=VT_NULL)
strValue2=(LPCSTR)_bstr_t(var);
if(m_name==strValue1&&m_psw==strValue2)
{
flag=1;
break;
}
pAdminRecordset->MoveNext();
}
}
else
{
AfxMessageBox("open recordset fail!");
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return FALSE;
}
pAdminRecordset->Close();
pAdminRecordset=NULL;
delete ConnectionPtr;
if(flag)
return TRUE;
else
return FALSE;
}
void CLogDlg::OnVail()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
BOOL vali;
vali=ValidateUser();
if(vali)//如果驗證成功,則發送OnOk消息關閉登錄對話框
CDialog::OnOK();
else
{
MessageBox("用戶名或密碼錯誤,請重新輸入!");
return;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -