📄 showresultview.cpp
字号:
// ShowResultView.cpp : implementation file
//
#include "stdafx.h"
#include "MySqlPlus.h"
#include "ShowResultView.h"
#include "common.h"
#include "mainfrm.h"
#include "seldatadlg.h"
#include "sqlinputview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShowResultView
extern CMySqlPlusApp theApp;
IMPLEMENT_DYNCREATE(CShowResultView, CScrollView)
CShowResultView::CShowResultView()
{
b_showMessage = true;
message = "connection already ok!!";
}
CShowResultView::~CShowResultView()
{
}
BEGIN_MESSAGE_MAP(CShowResultView, CView)
//{{AFX_MSG_MAP(CShowResultView)
ON_WM_HSCROLL()
ON_COMMAND(ID_CONNECT, OnConnect)
ON_WM_KEYUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowResultView drawing
void CShowResultView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
CClientDC dc(this);
RECT rect;
GetClientRect (&rect);
/* xsize = GetDeviceCaps(dc.m_hDC,LOGPIXELSX);
sizeTotal.cx = 152*5.1;
sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
*/
listTable.Create (WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,rect,this,100);
listTable.ShowWindow (SW_HIDE);
}
void CShowResultView::OnDraw(CDC* pDC)
{
//CDocument* pDoc = GetDocument();
RECT rect;
GetClientRect(&rect);
listTable.MoveWindow (&rect);
if(b_showMessage)
{
if(message!="") //show message informage
{
pDC->DrawText (message,&rect,DT_LEFT|DT_TOP);
}
}
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CShowResultView diagnostics
#ifdef _DEBUG
void CShowResultView::AssertValid() const
{
CView::AssertValid();
}
void CShowResultView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CShowResultView message handlers
/*
param : long recordCount used by 'update' or 'delete'
*/
void CShowResultView::ShowResult(long recordCount)
{
CMainFrame* MainFrame=(CMainFrame*)this->GetParent()->GetParent();
_RecordsetPtr Rsc = MainFrame->m_pUserSet;
if (!Rsc->State)
{
listTable.ShowWindow (SW_HIDE);
message.Format ("Command execute success!\r\n%d rows processed.",recordCount);
b_showMessage = true;
RECT rect;
GetClientRect(&rect);
this->InvalidateRect (&rect);
}
else
{
ShowResultSet(Rsc);
}
}
void CShowResultView::ShowError()
{
listTable.ShowWindow (SW_HIDE);
CCommon common;
message = common.DisplayAdoError(theApp.m_pConnection);
b_showMessage = true;
RECT rect;
GetClientRect(&rect);
this->InvalidateRect (&rect);
}
void CShowResultView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CView::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CShowResultView::ShowResultSet(_RecordsetPtr Rsc)
{
b_showMessage = false;
int i=0;
listTable.ShowWindow (SW_SHOW);
listTable.DeleteAllItems ();
int nColumnCount = listTable.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (i=0;i < nColumnCount;i++)
{
listTable.DeleteColumn (0);
}
int fieldCount=Rsc->Fields ->Count;
int fieldLength = 0;
FieldPtr m_fieldCtl;
for(i=0;i<fieldCount;i++)
{
m_fieldCtl = Rsc->Fields ->GetItem(long(i));
fieldLength = m_fieldCtl->DefinedSize*10;
if (fieldLength >500) //when field is very long then trim it
{
fieldLength = 500;
}
else if (fieldLength < 50)
{
fieldLength = 50;
}
if (fieldLength<m_fieldCtl->Name.length ()*12)
{
fieldLength = m_fieldCtl->Name.length ()*12;
}
listTable.InsertColumn(i,m_fieldCtl->Name,LVCFMT_LEFT,fieldLength);
}
int nItem = 0;
_variant_t varValue;
_bstr_t bstrValue;
while(!Rsc->adoEOF)
{
m_fieldCtl = Rsc->Fields ->GetItem(long(0));
varValue = m_fieldCtl->Value;
if (varValue.vt == VT_NULL)
{
bstrValue = "";
}
else
{
bstrValue=varValue;
}
nItem=listTable.InsertItem(0xffff,bstrValue); //fisrt value
for(i=1;i<fieldCount;i++) //next all value
{
m_fieldCtl = Rsc->Fields ->GetItem(long(i));
varValue = m_fieldCtl->Value;
if (varValue.vt == VT_NULL)
{
bstrValue = "";
}
else
{
bstrValue=varValue;
}
listTable.SetItem(nItem,i,1,bstrValue,NULL,0,0,0);
}
Rsc->MoveNext ();
}
}
void CShowResultView::OnConnect()
{
CSelDataDlg selectDlg;
if(selectDlg.DoModal ()==IDOK)
{
CMainFrame* MainFrame=(CMainFrame*)this->GetParent()->GetParent();
if (MainFrame->m_pUserSet->State)
{
MainFrame->m_pUserSet->Close ();
}
MainFrame->m_commandptr->ActiveConnection =theApp.m_pConnection;
message = "connection already ok!!";
listTable.ShowWindow (SW_HIDE);
b_showMessage = TRUE;
RECT rect;
GetClientRect(&rect);
this->InvalidateRect (&rect);
}
}
void CShowResultView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == VK_F5)
{
CMainFrame* MainFrame=(CMainFrame*)this->GetParent()->GetParent();
CSqlInputView* View=(CSqlInputView*)MainFrame->m_wndSplitter.GetPane(1,0);
View->PostMessage (WM_KEYUP,VK_F5);
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -