📄 sqlcommandview.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
extern CSQLCommandApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSQLCommandView
IMPLEMENT_DYNCREATE(CSQLCommandView, CFormView)
BEGIN_MESSAGE_MAP(CSQLCommandView, CFormView)
//{{AFX_MSG_MAP(CSQLCommandView)
ON_BN_CLICKED(IDC_BTN_GO, OnBtnGo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSQLCommandView construction/destruction
CSQLCommandView::CSQLCommandView()
: CFormView(CSQLCommandView::IDD)
{
//{{AFX_DATA_INIT(CSQLCommandView)
m_szSQL = _T("SELECT * FROM EXAM");
//}}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_LIST, m_listCtrl);
DDX_Text(pDX, IDC_EDIT_SQL, m_szSQL);
//}}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::OnBtnGo()
{
UpdateData(TRUE);
GetDlgItem(IDC_BTN_GO)->EnableWindow(FALSE);
CVORecordset rs(theApp.m_Conn);
rs.Open(m_szSQL, adOpenForwardOnly, adLockReadOnly);
m_listCtrl.DeleteAllItems();
while(m_listCtrl.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_listCtrl.InsertColumn(i, strFieldName,LVCFMT_LEFT,60);
}
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_listCtrl.InsertItem(i, strFieldValue);
else
m_listCtrl.SetItemText(iNew, i, strFieldValue);
}
rs.MoveNext();
}
TRACE(TEXT("Field Count: %ld\n"), rs.GetFieldCount() );
}
}
GetDlgItem(IDC_BTN_GO)->EnableWindow(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -