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

📄 sqlcommandview.cpp

📁 Wince 中ADO3.0的使用方法
💻 CPP
字号:
// SQLCommandView.cpp : implementation of the CSQLCommandView class
//

#include "stdafx.h"
#include "SQLCommand.h"

#include "SQLCommandDoc.h"
#include "SQLCommandView.h"

#include "VORecordset.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSQLCommandView

IMPLEMENT_DYNCREATE(CSQLCommandView, CFormView)

BEGIN_MESSAGE_MAP(CSQLCommandView, CFormView)
	//{{AFX_MSG_MAP(CSQLCommandView)
	ON_COMMAND(ID_SQL_EXIT, OnSqlExit)
	ON_BN_CLICKED(IDC_GO_BUTTON, OnGoButton)
	ON_CBN_SELCHANGE(IDC_COMMAND, OnSelchangeCommand)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

extern CSQLCommandApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSQLCommandView construction/destruction

CSQLCommandView::CSQLCommandView()
	: CFormView(CSQLCommandView::IDD)
{
	//{{AFX_DATA_INIT(CSQLCommandView)
	m_strSQL = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CSQLCommandView::~CSQLCommandView()
{
}

void CSQLCommandView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSQLCommandView)
	DDX_Control(pDX, IDC_COMMAND, m_CommandCombo);
	DDX_Control(pDX, IDC_GO_BUTTON, m_GoButton);
	DDX_Control(pDX, IDC_RESULTS, m_Results);
	DDX_Text(pDX, IDC_SQL, m_strSQL);
	//}}AFX_DATA_MAP
}

BOOL CSQLCommandView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSQLCommandView diagnostics

#ifdef _DEBUG
void CSQLCommandView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSQLCommandView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CSQLCommandDoc* CSQLCommandView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSQLCommandDoc)));
	return (CSQLCommandDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSQLCommandView message handlers

void CSQLCommandView::OnSqlExit() 
{
	PostQuitMessage(0);	
}

void CSQLCommandView::OnGoButton() 
{
	UpdateData(TRUE);
	m_GoButton.EnableWindow(FALSE);
	
	CVORecordset rs(theApp.m_Conn);

	rs.Open(m_strSQL, adOpenForwardOnly, adLockReadOnly);
	m_Results.DeleteAllItems();
	while(m_Results.DeleteColumn(0));

	if(!rs.IsOpen() )
		AfxMessageBox(TEXT("Unable to execute command"));
	else
	{
		rs.MoveFirst();

		if(!rs.IsEOF() )	// If NOT at end of file
		{
			int		iNew;
			CString strFieldName;
			CString strFieldValue;

			for(int i = 0; i < rs.GetFieldCount(); i++)
			{
				strFieldName = rs.GetFieldName(i);

				m_Results.InsertColumn(-1, strFieldName);
			}

			while(!rs.IsEOF())
			{
				if(rs.GetFieldCount() < 1)
					break;

				for(int i = 0; i < rs.GetFieldCount(); i++)
				{
					strFieldValue = rs.GetFieldValueString(i);
					if(i == 0)
						iNew = m_Results.InsertItem(-1, strFieldValue);
					else
						m_Results.SetItemText(iNew, i, strFieldValue);
				}

				rs.MoveNext();
			}

			TRACE(TEXT("Field Count: %ld\n"), rs.GetFieldCount() );
		}
	}

	m_GoButton.EnableWindow(TRUE);
}

void CSQLCommandView::OnSelchangeCommand() 
{
	int iSel = m_CommandCombo.GetCurSel();
	
	if(iSel != -1)
	{
		m_CommandCombo.GetLBText(iSel, m_strSQL);
		UpdateData(FALSE);
	}
}

void CSQLCommandView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	m_CommandCombo.SetWindowText(TEXT("SQL Command"));
}

⌨️ 快捷键说明

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