【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了DBaseQuery.cpp提供大家参考,希望对大家有所帮助!
// DBaseQuery.cpp : implementation file
//
#include "stdafx.h"
#include "qpglxt.h"
#include "DBaseQuery.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDBaseQuery dialog
extern CQpglxtApp theApp;
CDBaseQuery::CDBaseQuery(CString sCaption, CString sDateBaseName, CDialog *NextWnd,PrintStruct pr,CWnd* pParent /*=NULL*/)
: CDialog(CDBaseQuery::IDD, pParent)
{
//{{AFX_DATA_INIT(CDBaseQuery)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_Caption=sCaption;
m_DateBaseName=sDateBaseName;
m_pWnd=NextWnd;
m_ps =pr;
}
void CDBaseQuery::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDBaseQuery)
DDX_Control(pDX, IDC_BASEQUERY_EDTCONDITION, m_EdtCondition);
DDX_Control(pDX, IDC_BASEQUERY_COMEMBLEM, m_ComEmblem);
DDX_Control(pDX, IDC_BASEQUERY_COMFIELD, m_ComField);
DDX_Control(pDX, IDC_BASEQUERY_GRID, m_Grid);
DDX_Control(pDX, IDC_BUT_PRINT, m_ButPrint);
DDX_Control(pDX, IDC_BUT_QUERY, m_ButQuery);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDBaseQuery, CDialog)
//{{AFX_MSG_MAP(CDBaseQuery)
ON_BN_CLICKED(IDC_BUT_PRINT, OnButPrint)
ON_BN_CLICKED(IDC_BUT_QUERY, OnButQuery)
ON_NOTIFY(NM_DBLCLK, IDC_BASEQUERY_GRID, OnDblclkBasequeryGrid)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDBaseQuery message handlers
void CDBaseQuery::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDBaseQuery::OnButPrint()
{
CString sCount;
m_ps.MainCaptionFontSize=400;
m_ps.DeckCaptionFontSize=180;
sCount.Format("%d",rst.GetRecordCount());
m_ps.TotalNumber=1;
m_ps.Totals[0]="共计 "+sCount+" 条记录";
m_ps.Totals[1]="";
m_ps.Grid=&m_Grid;
theApp.Print();
}
BOOL CDBaseQuery::OnInitDialog()
{
CDialog::OnInitDialog();
this->SetWindowText(m_Caption);
rst.Open(m_DateBaseName);
this->m_ComField.SetFieldset(rst);
m_Grid.ReadOnly(true);
this->m_ComEmblem.SetCurSel(0);
this->m_ComField.SetCurSel(0);
m_Grid.SetDataBase(m_DateBaseName,adCmdTable);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
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 WHERE %s %s %s",this->m_DateBaseName,sField,sEmblem,sCondition);
if(m_ComField.m_CurrentFieldType=="字符型")
{
if(sEmblem!="LIKE")
sSQL.Format("SELECT * FROM %s WHERE %s %s '%s'",this->m_DateBaseName,sField,sEmblem,sCondition);
else
sSQL.Format("SELECT * FROM %s WHERE %s %s '%s%%'",this->m_DateBaseName,sField,sEmblem,sCondition);
}
if(m_ComField.m_CurrentFieldType=="日期型")
sSQL.Format("SELECT * FROM %s WHERE %s %s #%s#",this->m_DateBaseName,sField,sEmblem,sCondition);
rst.Open(sSQL,adCmdText);
m_Grid.AddCellValue(rst);
}
void CDBaseQuery::OnDblclkBasequeryGrid(NMHDR* pNMHDR, LRESULT* pResult)
{
if(rst.GetRecordCount()<1)
{
m_CurrentRow=0;
m_pWnd->DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButQuery();
}
if(m_Grid.GetHotItem()!=-1)
{
m_CurrentRow=m_Grid.GetHotItem();
m_pWnd->DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButQuery();
}
*pResult = 0;
}
上一篇:
FMIVTT.frm
下一篇:
学术论文摘要的定义及写作基本要求