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

📄 lobtest.cpp

📁 这是书上的代码
💻 CPP
字号:
// LOBTest.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "LOBTest.h"
#include "LOBTestDlg.h"

//自己定义的头文件
#include "DBSelectDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLOBTestApp

BEGIN_MESSAGE_MAP(CLOBTestApp, CWinApp)
	//{{AFX_MSG_MAP(CLOBTestApp)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CLOBTestApp construction

CLOBTestApp::CLOBTestApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CLOBTestApp object

CLOBTestApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CLOBTestApp initialization

BOOL CLOBTestApp::InitInstance()
{
	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

	//先生成选择连接数据库类型的对话框 
	CDBSelectDlg selectDlg;

	if( selectDlg.DoModal() != IDOK)
	{
		return true;
	}

	//连接数据库
	if (DBConnect(selectDlg.m_strDBType) == false )
	{
		return true;
	}

	//调用主对话框
	CLOBTestDlg 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;
}

////////////////////////////////////////////////////////////////////////////////
//函数名				DBConnect
//函数输入参数			CString strDB	数据库名称
//函数返回值			BOOL			连接是否成功
//函数功能				添加按钮对应的消息函数
//函数开发人			林晨
//函数开发时间			2002年4月8日
//函数修改历史			...
//函数测试时间			2002年4月8日

BOOL CLOBTestApp::DBConnect(CString strDB)
{

	CString strConnect ;
	if ( strDB == "ACCESS 数据库")
	{
		strConnect = "ODBC;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=BLOBTest.mdb";
		m_nDBType = ACCESS_DATABASE;
	}
	else if ( strDB == "SQL SERVER 数据库")
	{
		strConnect = "ODBC;DRIVER={SQL Server};SERVER=WY;Database=pubs;UID=sa;PWD=sa";
		m_nDBType = SQL_SERVER_DATABASE;
	}
	else
	{
		AfxMessageBox("未指定数据库!");
		m_nDBType = NO_DATABASE;
		return false;
	}

	try
	{
		m_DB.Open(NULL, FALSE, FALSE, strConnect);
	}
    catch(CDBException* pE)
    {
        pE->ReportError();
        pE->Delete();
		AfxMessageBox("数据库连接失败");
        return false;
    }

	AfxMessageBox(strDB+" 连接成功");

	return true;
}
//	DBConnect
///////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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