?? logon.cpp
字號:
// Logon.cpp : implementation file
//
#include "stdafx.h"
#include "cc.h"
#include "Logon.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLogon dialog
extern CCcApp theApp;
CLogon::CLogon(CWnd* pParent /*=NULL*/)
: CDialog(CLogon::IDD, pParent)
{
//{{AFX_DATA_INIT(CLogon)
m_user = _T("");
m_pwd = _T("");
//}}AFX_DATA_INIT
}
void CLogon::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLogon)
DDX_Control(pDX, IDC_COMBO1, m_1);
DDX_CBString(pDX, IDC_COMBO1, m_user);
DDX_Text(pDX, IDC_EDIT1, m_pwd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLogon, CDialog)
//{{AFX_MSG_MAP(CLogon)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLogon message handlers
void CLogon::OnOK()
{
// TODO: Add extra validation here
UpdateData();
//如果用戶名和密碼不為空則執(zhí)行以下操作
if(!m_user.IsEmpty()&&!m_pwd.IsEmpty()||true)
{
//成生sql語句
m_pwd=theApp.addpwd(m_pwd,true);
CString sql="SELECT * FROM alluser where name='"+m_user+"' and pwd='"+m_pwd+"'";
try
{
//查詢數(shù)據(jù)庫,看是否有此用戶和密碼
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
//如果沒有此用戶和密碼,再查詢是否有此用戶
if(m_pRecordset->adoEOF)
{
m_pRecordset->Close();
sql="select name from alluser where name='"+m_user+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
//如果沒有此用戶,則提示叫用戶建立此用戶。
if(m_pRecordset->adoEOF)
{
if(AfxMessageBox("用戶名或密碼錯(cuò)誤!你想新建此用戶嗎?",MB_YESNO)==IDYES)
{
m_pRecordset->Close();
sql="insert into alluser (name,pwd) values('"+m_user+"','"+m_pwd+"')";
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
AfxMessageBox("新用戶成功建立!請記住:\n\n用戶名:"+m_user+"\n密 碼:"+theApp.addpwd(m_pwd,false));
theApp.name=m_user;
theApp.pwd=m_pwd;
CDialog::OnOK();
}
else
return;
}
//如果有,提示錯(cuò)誤信息。
else
{
AfxMessageBox("用戶名或密碼錯(cuò)誤!");
return;
}
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("連接數(shù)據(jù)庫錯(cuò)誤信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
//用戶名和密碼存在,登錄成功
else
{
theApp.name=m_user;
theApp.pwd=m_pwd;
CDialog::OnOK();
return;
}
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("連接數(shù)據(jù)庫錯(cuò)誤信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
//反之則
else
AfxMessageBox("請輸入用戶名和密碼!");
}
void CLogon::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CLogon::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//讀出數(shù)據(jù)庫中的用戶名,顯示在控件中。
int numline=0;
CString sql="select name from alluser order by name";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
;//AfxMessageBox("你的數(shù)據(jù)庫中還沒有出差記錄信息!");
}
else
{
while(!m_pRecordset->adoEOF)
{
m_1.InsertString(0,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name"));
sql=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");
m_pRecordset->MoveNext();
}
SetDlgItemText(IDC_COMBO1,sql);
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("連接數(shù)據(jù)庫錯(cuò)誤信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return false;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -