📄 storage.cpp
字号:
// Storage.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Storage.h"
#include "StorageDlg.h"
#include "LoginDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStorageApp
BEGIN_MESSAGE_MAP(CStorageApp, CWinApp)
//{{AFX_MSG_MAP(CStorageApp)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CStorageApp construction
CStorageApp::CStorageApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CStorageApp object
CStorageApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CStorageApp initialization
BOOL CStorageApp::InitInstance()
{
m_hUnique = ::CreateMutex(NULL, FALSE, UNIQUE_ID);
if(m_hUnique != NULL)
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
AfxMessageBox("您已经打开了一个厨房管理程序!");
return FALSE;
}
}
else
{
AfxMessageBox("创建互斥对象失败!");
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.
if(!AfxOleInit())
{
AfxMessageBox("OLE初始化出错!");
return FALSE;
}
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。
try
{
CString server,db,userid,password;
// 打开
CString iniFile(GetAbsolutePath() + "server.ini");
GetPrivateProfileString("SQL Server","server","127.0.0.1",server.GetBuffer(MAX_PATH),MAX_PATH,iniFile);
GetPrivateProfileString("SQL Server","db","KGDB_A",db.GetBuffer(MAX_PATH),MAX_PATH,iniFile);
GetPrivateProfileString("SQL Server","userid","killgame",userid.GetBuffer(MAX_PATH),MAX_PATH,iniFile);
GetPrivateProfileString("SQL Server","password","killgame",password.GetBuffer(MAX_PATH),MAX_PATH,iniFile);
CString connStr;
//connStr.Format("Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s; Password=%s;",server,db,userid,password);
connStr.Format("Driver={SQL Server};Server=%s;Database=%s;Uid=%s;Pwd=%s;",server,db,userid,password);
m_pConnection->Open(_bstr_t(connStr),_bstr_t(userid),_bstr_t(password),adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库连接设置是否正确!");
return FALSE;
}
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CLoginDlg dlg;
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;
}
CString CStorageApp::GetAbsolutePath()
{
TCHAR exeFullPath[MAX_PATH];
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
CString strAbsolutePath(exeFullPath);
int pos = strAbsolutePath.ReverseFind('\\');
if(pos > 0)
strAbsolutePath = strAbsolutePath.Mid(0,pos + 1);
return strAbsolutePath;
}
int CStorageApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
CloseHandle(m_hUnique);
if(m_pConnection != NULL)
{
if(m_pConnection->State)
m_pConnection->Close();
m_pConnection= NULL;
}
CoUninitialize();
return CWinApp::ExitInstance();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -