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

📄 seldialog.cpp

📁 随着计算机信息技术的飞速发展
💻 CPP
字号:
// SelDialog.cpp : implementation file
//

#include "stdafx.h"
#include "NewADO.h"
#include "NewADODoc.h"
#include "SelDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSelDialog dialog


CSelDialog::CSelDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CSelDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSelDialog)
	m_iSel = 0;
	//}}AFX_DATA_INIT
	m_sTablename= "";
}


void CSelDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSelDialog)
	DDX_Control(pDX, IDC_COMBO1, m_Combo);
	DDX_Control(pDX, IDC_LISTBOX, m_ListBox);
	DDX_CBIndex(pDX, IDC_COMBO1, m_iSel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSelDialog, CDialog)
	//{{AFX_MSG_MAP(CSelDialog)
	ON_LBN_DBLCLK(IDC_LISTBOX, OnDblclkListbox)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelDialog message handlers

BOOL CSelDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Combo.ResetContent();
	m_Combo.InsertString(-1,"基本表");
	m_Combo.InsertString(-1,"视图");
	UpdateData(FALSE);
	ShowTable();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSelDialog::OnOK() 
{
	// TODO: Add extra validation here
	int iIndex= m_ListBox.GetCurSel();
	if( iIndex != -1 ){
		//CString s
		m_ListBox.GetText(iIndex, m_sTablename.GetBuffer(m_ListBox.GetTextLen(iIndex)));
		m_sTablename.ReleaseBuffer(m_ListBox.GetTextLen(iIndex));
	}
	CDialog::OnOK();
}

void CSelDialog::OnDblclkListbox() 
{
	CSelDialog::OnOK();
}

void CSelDialog::OnSelchangeCombo1() 
{
	UpdateData();
	ShowTable();
}		

void CSelDialog::ShowTable()
{
	if(m_IsConnectionOpen){

		try
		{
			_RecordsetPtr pRstSchema;
			pRstSchema = m_pConnection->OpenSchema(adSchemaTables, vtMissing, vtMissing);//adSchemaPrimaryKeys
			//pRstSchema = m_pConnection->OpenSchema(adSchemaPrimaryKeys, , vtMissing);
			m_ListBox.ResetContent();
			while(!pRstSchema->adoEOF)
			{
				_bstr_t table_name = pRstSchema->Fields->GetItem("TABLE_NAME")->Value;
				_bstr_t table_type = pRstSchema->Fields->GetItem("TABLE_TYPE")->Value;
				if( ( !m_iSel&&0==strcmp((LPCTSTR)table_type, "TABLE") ) || ( m_iSel&&0==strcmp((LPCTSTR)table_type, "VIEW") ) )
					m_ListBox.InsertString(-1,(LPCSTR)table_name);
				//printf("Table Name: %s\n",(LPCSTR) table_name);
				
				pRstSchema->MoveNext();
				
			}
			pRstSchema->Close();
		}
		catch (_com_error &e)
		{
			// Notify the user of errors if any.
			// Pass a connection pointer accessed from the Connection.        
			
			ErrorPtr    pErr  = NULL;
			
			if( (m_pConnection->Errors->Count) > 0)
			{
				long nCount = m_pConnection->Errors->Count;
				// Collection ranges from 0 to nCount -1.
				for(long i = 0;i < nCount;i++)
				{
					pErr = m_pConnection->Errors->GetItem(i);
					TRACE("\t Error number: %x\t%s", pErr->Number,\
						pErr->Description);
				}
			}
			
			_bstr_t bstrSource(e.Source());
			_bstr_t bstrDescription(e.Description());
			
			// Print COM errors. 
			TRACE("Error\n");
			TRACE("\tCode = %08lx\n", e.Error());
			TRACE("\tCode meaning = %s\n", e.ErrorMessage());
			TRACE("\tSource = %s\n", (LPCSTR) bstrSource);
			TRACE("\tDescription = %s\n", (LPCSTR) bstrDescription);
		}
	}
}

⌨️ 快捷键说明

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