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

📄 pubreportdlg.cpp

📁 Visual C++实践与提高--数据库开发与工程应用篇 随书代码 希望对用ADO开发的人会有所帮助 这是第8、9章的
💻 CPP
字号:
// PubReportDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PubReport.h"
#include "PubReportDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPubReportDlg dialog

CPubReportDlg::CPubReportDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPubReportDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPubReportDlg)
	m_bAuthor = FALSE;
	m_bTitle = FALSE;
	m_strState = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
}

void CPubReportDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPubReportDlg)
	DDX_Control(pDX, IDC_BUTTON_TYPE, m_btnType);
	DDX_Control(pDX, IDC_BUTTON_STATE, m_btnState);
	DDX_Control(pDX, IDC_CHECK_TITLE, m_CheckTitle);
	DDX_Control(pDX, IDC_CHECK_AUTHOR, m_CheckAuthor);
	DDX_Control(pDX, IDC_COMBO_TYPE, m_ComboType);
	DDX_Control(pDX, IDC_COMBO_STATE, m_ComboState);
	DDX_Check(pDX, IDC_CHECK_AUTHOR, m_bAuthor);
	DDX_Check(pDX, IDC_CHECK_TITLE, m_bTitle);
	DDX_CBString(pDX, IDC_COMBO_STATE, m_strState);
	DDX_Control(pDX, IDC_ACTIVEXREPORTVIEWER1, m_Viewer);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPubReportDlg, CDialog)
	//{{AFX_MSG_MAP(CPubReportDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CHECK_AUTHOR, OnCheckAuthor)
	ON_BN_CLICKED(IDC_CHECK_TITLE, OnCheckTitle)
	ON_BN_CLICKED(IDC_BUTTON_STATE, OnButtonState)
	ON_BN_CLICKED(IDC_BUTTON_TYPE, OnButtonType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPubReportDlg message handlers

BOOL CPubReportDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon	
	// TODO: Add extra initialization here
	//初始化设置控件的状态
	m_CheckAuthor.SetCheck(1);
	m_CheckTitle.SetCheck(0);
	m_ComboState.EnableWindow(TRUE);
	m_btnState.EnableWindow(TRUE);
	m_ComboType.EnableWindow(FALSE);
	m_btnType.EnableWindow(FALSE);
	//实例化应用程序智能指针
	m_pApp.CreateInstance("CrystalDesignRuntime.Application");
	InitReport();
	InitCombo();
	//调整对话框和Report Viewer控件的位置和大小
	MoveWindow(0,0,600,400,TRUE);
	m_Viewer.MoveWindow(10,100,580,250,TRUE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPubReportDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CPubReportDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPubReportDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPubReportDlg::InitReport()
{
	_bstr_t filename;
	if(m_bTitle)
	{
		filename="titleList.rpt";
	}
	else 
	{
		filename="authorList.rpt";
	}
	//打开报表
	m_pReport=m_pApp->OpenReport(filename);
	//设置报表显示器控件的数据源为上面打开的报表
	m_Viewer.SetReportSource(m_pReport);
	//不显示“组树”
	m_Viewer.SetDisplayGroupTree (FALSE);
	//不显示控件边框
	m_Viewer.SetDisplayBorder (FALSE);
	//不显示控件工具栏
	m_Viewer.SetDisplayToolbar (FALSE);
	//显示选项卡的标题
	m_Viewer.SetDisplayTabs(TRUE);
	//更新报表显示器控件
	m_Viewer.Refresh();
	//显示报表
	m_Viewer.ViewReport();	
}

void CPubReportDlg::OnCheckAuthor() 
{
	// TODO: Add your control notification handler code here
	m_CheckAuthor.SetCheck(1);
	m_CheckTitle.SetCheck(0);
	UpdateData(TRUE);
	m_ComboState.EnableWindow(TRUE);
	m_btnState.EnableWindow(TRUE);
	m_ComboType.EnableWindow(FALSE);
	m_btnType.EnableWindow(FALSE);
	InitReport();
}

void CPubReportDlg::OnCheckTitle() 
{
	// TODO: Add your control notification handler code here
	m_CheckAuthor.SetCheck(0);
	m_CheckTitle.SetCheck(1);
	UpdateData(TRUE);
	m_ComboState.EnableWindow(FALSE);
	m_btnState.EnableWindow(FALSE);
	m_ComboType.EnableWindow(TRUE);
	m_btnType.EnableWindow(TRUE);
	InitReport();
}

void CPubReportDlg::InitCombo()
{	//初始化两个ComboBox控件
	m_ComboState.AddString("CA");
	m_ComboState.AddString("IN");
	m_ComboState.AddString("MD");
	m_ComboState.AddString("MI");
	m_ComboState.AddString("OR");
	m_ComboState.AddString("TN");
	m_ComboState.AddString("UT");

	m_ComboType.AddString("business");
	m_ComboType.AddString("mod_cook");
	m_ComboType.AddString("popular_comp");
	m_ComboType.AddString("psychology");
	m_ComboType.AddString("trad_cook");
	m_ComboType.AddString("UNDECIDED");
}

void CPubReportDlg::OnButtonState() 
{
	// TODO: Add your control notification handler code here
	CString strState;
	m_ComboState.GetWindowText(strState);
	CString strRecordformula;
	strRecordformula.Format("{authors.state}='%s'",strState);
	m_pReport->PutRecordSelectionFormula(_bstr_t(strRecordformula));
	m_Viewer.Refresh();	
}

void CPubReportDlg::OnButtonType() 
{
	// TODO: Add your control notification handler code here
	CString strType;
	m_ComboType.GetWindowText(strType);
	CString strGroupformula;
	strGroupformula.Format("{titles.type}='%s'",strType);
	m_pReport->put_GroupSelectionFormula(_bstr_t(strGroupformula));
	m_Viewer.Refresh();

}

⌨️ 快捷键说明

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