cdbexptable.cpp

来自「本人买的<<VC++项目开发实例>>源代码配套光盘.」· C++ 代码 · 共 290 行

CPP
290
字号
// Copyright (C) 1991 - 1999 Rational Software Corporation

#include "stdafx.h"
#include "CDBExpTable.h"
#include "resource.h"
#include "DLLFuncs.h"
#include "CDBExpDatabase.h"
#include "..\DLLs\TableFunc\tableparamdef.h"

//##ModelId=3C5B9B9F0352
CDBExpTable::CDBExpTable(const CString &strName)
{
	m_strTableName = strName;
}

//##ModelId=3C5B9B9F033D
CDBExpTable::~CDBExpTable()
{
}
//##ModelId=3C5B9B9F0365
BOOL CDBExpTable::ExpandItem(HTREEITEM hItem, UINT state)
{
	return TRUE;
}
//##ModelId=3C5B9B9F0383
const char * CDBExpTable::GetTreeNodeCaption()
{
	return (const char *)m_strTableName;
}


//##ModelId=3C5CCCF3003F
BOOL CDBExpTable::OpenRelatedView(LPARAM lParam)
{
	// ToDo: Add your specialized code here
//	AfxMessageBox("Not");
	return static_cast<BOOL>(0);
}



//##ModelId=3C6287080335
void CDBExpTable::BuildTVITEM(HTREEITEM hParentItem)
{
	// ToDo: Add your specialized code here or after the call to base class
	
	CDBTreeNode::BuildTVITEM(hParentItem);
	this->m_tvInsertStruct.item.cChildren = 0;
	this->m_tvInsertStruct.item.iImage = 
		this->m_tvInsertStruct.item.iSelectedImage = 4;
}

//##ModelId=3C628775007F
BOOL CDBExpTable::PopupContextMenu(DBTREE_NODE_CONTEXT& context)
{
	// ToDo: Add your specialized code here or after the call to base class
	
	return CDBTreeNode::PopupContextMenu(context);
}

//##ModelId=3C62877301F9
void CDBExpTable::BuildContextMenu(DBTREE_NODE_CONTEXT& context)
{
	// ToDo: Add your specialized code here or after the call to base class
	
	m_pContextMenu->LoadMenu(IDR_MENU_TABLE);
	m_pContextMenu->DeleteMenu(ID_MENU_TABLE_STRUCT, MF_BYCOMMAND);
	m_pContextMenu->DeleteMenu(ID_MENU_EXP_DB_OBJECTS, MF_BYCOMMAND);
}

//##ModelId=3C62877402B1
void CDBExpTable::OnMenuItemClick(UINT nCmd)
{
	// ToDo: Add your specialized code here or after the call to base class
	PARAM_TABLE paramTable;
	memset(&paramTable, 0, sizeof(paramTable));

	strcpy(paramTable.szTableName, (const char *)this->GetTreeNodeCaption());
	strcpy(paramTable.szConnectionString, (const char *)this->GetDatabase()->m_strCnn);
	strcpy(paramTable.szDatabaseType, GetDatabaseType());

	LPARAM lParam = (LPARAM)&paramTable;
	HWND	hWnd =  AfxGetMainWnd()->m_hWnd;
	
	switch(nCmd)
	{
	case ID_MENU_NEW_INDEX:
		strcpy(paramTable.szCmd, "NewIndex");
		BCB_NewIndex(hWnd, lParam);
		break;
	case ID_MENU_NEW_TRIGGER:
		strcpy(paramTable.szCmd, "NewTrigger");
		this->BCB_NewTrigger(hWnd, lParam);
		break;
	case ID_MENU_EXP_TAB_RECCOUNT:
		//教训:,因为原来的paramTable.szCmd为char[11],所以造成字符串复制出界!!!
		//发生错误。
		strcpy(paramTable.szCmd, "RecordCount");

		this->BCB_GetRecordCount(hWnd, lParam);
		break;
	case ID_MENU_TABLE_OPEN:
		strcpy(paramTable.szCmd, "TableOpen");
		this->BCB_GetRecordSet(hWnd, lParam);
		break;
	case ID_MENU_TABLE_STRUCT:
		this->BCB_ModifyTableStructure(hWnd, lParam);
		break;
	case ID_MENU_EXP_DB_OBJECTS:
		this->BCB_ExportTable(hWnd, lParam);
		break;
	case ID_MENU_EXP_SCRIPT:
		this->BCB_GenerateScript(hWnd, lParam);
		break;
	case ID_MENU_PROP:
		strcpy(paramTable.szCmd, "Property");
		this->BCB_Property(hWnd, lParam);
		break;
	default:
		CDBTreeNode::OnMenuItemClick(nCmd);
		break;
	}
}



//##ModelId=3CD0E14C0158
int CDBExpTable::BCB_NewIndex(HWND hParentWnd, LPARAM lParam)
{
	// TODO: Add your specialized code here.
	// NOTE: Requires a correct return value to compile.
	int ret = CDLLFuncs::Table_NewIndex(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;

	char *szSQL = ((PARAM_TABLE *)lParam)->szSQLString;
	ADODB::_ConnectionPtr ptrTempConn = 
			this->GetDatabase()->m_ptrConnection;


/*	try
    {
		_bstr_t bstrTemp = this->GetDatabase()->m_strCnn;
        ptrTempConn->Open(bstrTemp, L"", L"", NULL);
		ptrTempConn->Execute(szSQL, NULL, ADODB::adExecuteNoRecords);
		ptrTempConn->Close();
		AfxMessageBox("创建成功");
    }

    catch(_com_error &e)
    {
		CString strError = "创建失败,下面是错误的具体内容: ";
		strError += e.Description();
		AfxMessageBox((const char *)strError);    
		ptrTempConn->Close();
    }		*/
	return 1;
}

//##ModelId=3CD0E15A01A8
int CDBExpTable::BCB_NewTrigger(HWND hParentWnd, LPARAM lParam)
{
	// TODO: Add your specialized code here.
	int ret = CDLLFuncs::BCB_NewTrigger(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;

	char *szSQL = ((PARAM_TABLE *)lParam)->szSQLString;
	ADODB::_ConnectionPtr ptrTempConn = 
			this->GetDatabase()->m_ptrConnection;


/*	try
    {
		_bstr_t bstrTemp = this->GetDatabase()->m_strCnn;
        ptrTempConn->Open(bstrTemp, L"", L"", NULL);
		ptrTempConn->Execute(szSQL, NULL, ADODB::adExecuteNoRecords);
		ptrTempConn->Close();
		AfxMessageBox("创建成功");
    }

    catch(_com_error &e)
    {
		CString strError = "创建失败,下面是错误的具体内容: ";
		strError += e.Description();
		AfxMessageBox((const char *)strError);    
		ptrTempConn->Close();
    }		*/
	return 1;
}

//##ModelId=3CD0E16302CE
int CDBExpTable::BCB_GetRecordSet(HWND hParentWnd, LPARAM lParam)
{
	// TODO: Add your specialized code here.
	// NOTE: Requires a correct return value to compile.
	int ret = CDLLFuncs::Table_NewIndex(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;
	return 1;
}

//##ModelId=3CD0E32D0286
int CDBExpTable::BCB_GetRecordCount(HWND hParentWnd, LPARAM lParam)
{
	
	int ret = CDLLFuncs::BCB_GetRecordCount(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;

		CString strPrompt;
		strPrompt.Format("%s%d", "记录数是:", ret);
		AfxMessageBox(strPrompt);
	return TRUE;
}

//##ModelId=3CD0E3420010
int CDBExpTable::BCB_ModifyTableStructure(HWND hParentWnd, LPARAM lParam)
{
	int ret = CDLLFuncs::BCB_ModifyTableStructure(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;

	char *szSQL = ((PARAM_TABLE *)lParam)->szSQLString;
	ADODB::_ConnectionPtr ptrTempConn = 
			this->GetDatabase()->m_ptrConnection;


	try
    {
		_bstr_t bstrTemp = this->GetDatabase()->m_strCnn;
        ptrTempConn->Open(bstrTemp, L"", L"", NULL);
		ptrTempConn->Execute(szSQL, NULL, ADODB::adExecuteNoRecords);
		ptrTempConn->Close();
		AfxMessageBox("成功");
    }

    catch(_com_error &e)
    {
		CString strError = "失败,下面是错误的具体内容: ";
		strError += (const char *)e.Description();
		AfxMessageBox((const char *)strError);    
		ptrTempConn->Close();
    }		
	return 1;

}

//##ModelId=3CD0E3A703AE
int CDBExpTable::BCB_ExportTable(HWND hParentWnd, LPARAM lParam)
{
	int ret = CDLLFuncs::BCB_ExportTable(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;

	return 1;
}

//##ModelId=3CD0E3B803D1
int CDBExpTable::BCB_GenerateScript(HWND hParentWnd, LPARAM lParam)
{
	int ret = CDLLFuncs::BCB_GenerateScript(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;

	return 1;
}

//##ModelId=3CD0E3D503DC
int CDBExpTable::BCB_Property(HWND hParentWnd, LPARAM lParam)
{
	int ret = CDLLFuncs::Table_NewIndex(hParentWnd, lParam);
	if(FALSE == ret )
		return FALSE;
	return 1;
}



//##ModelId=3CD9574701F0
void CDBExpTable::BuildLVITEM(int& nIndex)
{
	// ToDo: Add your specialized code here or after the call to base class
	
	CDBTreeNode::BuildLVITEM(nIndex);
	m_lvInsertStruct.iImage	= 1;

}

⌨️ 快捷键说明

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