?? whmgr.cpp
字號:
// WhMgr.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "WhMgr.h"
#include "WhMgrDlg.h"
#include "LoginDlg.h"
#include "UserInfoDataSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWhMgrApp
BEGIN_MESSAGE_MAP(CWhMgrApp, CWinApp)
//{{AFX_MSG_MAP(CWhMgrApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWhMgrApp construction
CWhMgrApp::CWhMgrApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CWhMgrApp object
CWhMgrApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CWhMgrApp initialization
BOOL CWhMgrApp::InitInstance()
{
//初始化Com
::CoInitialize(NULL);
//初始化數據庫連接
m_pConn = new CDBConnection;
//得到當前程序所在的文件夾
CString strCommandLine = ::GetCommandLine();
int i;
int nLen = strCommandLine.GetLength();
for(i = nLen - 1; i >= 0; i--)
{
CHAR a = strCommandLine.GetAt(i);
if(a == '\\')
{
break;
}
}
strCommandLine.ReleaseBuffer(i + 1);
strCommandLine.Delete(0, 1);
//打開數據庫連接,數據庫地址為:當前程序所在文件夾\WhMgrDB.mdb
if(!m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strCommandLine + "WhMgrDB.mdb;Persist Security Info=False"))
{
::AfxMessageBox("打開數據庫失敗!");
return FALSE;
}
//用戶登錄
BOOL bLogined;
CLoginDlg loginDlg;
CUserInfoDataSet dsUserInfo;
dsUserInfo.m_cnn = m_pConn;
bLogined = FALSE;
//給3次登錄機會
for(i = 0; i < 3; i++)
{
if(loginDlg.DoModal() == IDOK)
{
dsUserInfo.LoadData(loginDlg.m_strUserName);
if(!dsUserInfo.IsEOF())
{
if(dsUserInfo.GetPassword() == loginDlg.m_strPassword)
{
bLogined = TRUE;
break;
}
}
else
{
::AfxMessageBox("用戶名或者密碼不正確,請重試!");
}
dsUserInfo.Close();
}
else
{
break;
}
}
if(!bLogined)
{
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CWhMgrDlg dlg;
//給dlg的m_pConn成員變量賦值
dlg.m_pConn = m_pConn;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
int CWhMgrApp::ExitInstance()
{
m_pConn->Close();
delete m_pConn;
::CoUninitialize();
return CWinApp::ExitInstance();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -