📄 dbasequery.cpp
字号:
// DBaseQuery.cpp : implementation file
//
#include "stdafx.h"
#include "MyProject.h"
#include "DBaseQuery.h"
#include "RxRecordset.h"
#include "DBaseDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////#//////////////////////////////////////////////////////////////////////
// CDBaseQuery dialog
CDBaseQuery::CDBaseQuery(CString sCaption, CString sSQL,CString sIdentify, int nNumberStyle,CWnd* pParent /*=NULL*/)
: CDialog(CDBaseQuery::IDD, pParent)
{
m_DateBaseName=sSQL;
m_Caption=sCaption;
m_Identify=sIdentify;
m_NumberStyle=nNumberStyle;
//{{AFX_DATA_INIT(CDBaseQuery)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDBaseQuery::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDBaseQuery)
DDX_Control(pDX, IDC_STATIT, m_StaTit);
DDX_Control(pDX, IDC_GRID, m_Grid);
DDX_Control(pDX, IDC_EDTCONDITION, m_EdtCondition);
DDX_Control(pDX, IDC_COMFIELD, m_ComField);
DDX_Control(pDX, IDC_COMEMBLEM, m_ComEmblem);
DDX_Control(pDX, IDC_BUTQUERY, m_ButQuery);
DDX_Control(pDX, IDC_BUTPRINT, m_ButPrint);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDBaseQuery, CDialog)
//{{AFX_MSG_MAP(CDBaseQuery)
ON_BN_CLICKED(IDC_BUTQUERY, OnButquery)
ON_BN_CLICKED(IDC_BUTPRINT, OnButprint)
ON_NOTIFY(NM_DBLCLK, IDC_GRID, OnDblclkGrid)
ON_CBN_KILLFOCUS(IDC_COMFIELD, OnKillfocusComfield)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDBaseQuery message handlers
void CDBaseQuery::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDBaseQuery::OnButquery()
{
CString sSQL,sField,sEmblem,sCondition;
this->m_ComField.GetWindowText(sField);
this->m_ComEmblem.GetWindowText(sEmblem);
this->m_EdtCondition.GetWindowText(sCondition);
//判断查询字段的类型
if(m_ComField.m_CurrentFieldType=="数值型")
sSQL.Format("SELECT * FROM (%s) DERIVEDTBL WHERE %s %s %s",m_DateBaseName,sField,sEmblem,sCondition);
else
{
if(sEmblem!="LIKE")
sSQL.Format("SELECT * FROM (%s) DERIVEDTBL WHERE %s %s '%s'",m_DateBaseName,sField,sEmblem,sCondition);
else
sSQL.Format("SELECT * FROM (%s) DERIVEDTBL WHERE %s %s '%%%s%%'",m_DateBaseName,sField,sEmblem,sCondition);
}
rst.Open(sSQL,adCmdText);
m_Grid.AddCellValue(rst);
}
void CDBaseQuery::OnButprint()
{
CString sCount;
m_ps.MainCaptionFontSize=400;
m_ps.DeckCaptionFontSize=180;
CString sText;
this->GetWindowText(sText);
sText=sText.Left(sText.GetLength()-4);
sText=sText+"报表";
m_ps.MainCaption=sText;
sCount.Format("%d",rst.GetRecordCount());
m_ps.TotalNumber=1;
m_ps.Totals[0]="共计 "+sCount+" 条记录";
m_ps.Totals[1]="";
m_ps.Grid=&m_Grid;
CMyApp* theApp;
theApp=(CMyApp*)::AfxGetApp();
theApp->Print();
}
BOOL CDBaseQuery::OnInitDialog()
{
CDialog::OnInitDialog();
this->SetWindowText(m_Caption);
rst.Open(m_DateBaseName,adCmdText);
this->m_ComField.SetRecordset(rst);
m_Grid.ReadOnly(true);
this->m_ComEmblem.SetCurSel(0);
this->m_ComField.SetCurSel(0);
m_Grid.SetDataBase(m_DateBaseName,adCmdText);
if(m_Grid.GetCols()>12)
this->m_ButPrint.EnableWindow(false);
Init();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CDBaseQuery::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->hwnd==m_Grid.GetSafeHwnd() && pMsg->message==WM_LBUTTONDOWN)
{
pMsg->message=WM_RBUTTONDOWN;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CDBaseQuery::OnDblclkGrid(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if(m_Grid.GetSelectionMark()==-1 && m_Grid.GetRows()>0)
return;
CDBaseDlg dlg(&m_Grid,m_Identify,m_NumberStyle);
dlg.DoModal();
this->m_Grid.DeleteAllItems();
RxRecordset rst;
rst.Open(m_DateBaseName,adCmdText);
this->m_Grid.AddCellValue(rst);
*pResult = 0;
}
void CDBaseQuery::OnKillfocusComfield()
{
// TODO: Add your control notification handler code here
}
void CDBaseQuery::Init()
{
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -