商店管理系统源代码(七)

本文介绍了一个用于显示报告信息的对话框类CDlgReport的设计与实现细节,包括类的构造、成员变量、数据交换及消息映射等功能,并演示了如何使用ADO连接数据库并填充列表控件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#if !defined(AFX_DLGREPORT_H__DD0CD5A3_4ED0_4056_8CF6_F394385DFEF1__INCLUDED_)
#define AFX_DLGREPORT_H__DD0CD5A3_4ED0_4056_8CF6_F394385DFEF1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgReport.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CDlgReport dialog

class CDlgReport : public CDialog
{
// Construction
public:
	CDlgReport(CWnd* pParent = NULL);   // standard constructor
	CString strSQL, strTitle;
	
// Dialog Data
	//{{AFX_DATA(CDlgReport)
	enum { IDD = IDD_REPORT };
	CListCtrl	m_ctrlListMain;
	//}}AFX_DATA


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

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CDlgReport)
	virtual BOOL OnInitDialog();
	afx_msg void OnExport();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLGREPORT_H__DD0CD5A3_4ED0_4056_8CF6_F394385DFEF1__INCLUDED_)






// DlgReport.cpp : implementation file
//

#include "stdafx.h"
#include "SalesManagementSystem.h"
#include "DlgReport.h"
#include "ADOConn.h"
#include "MyExcel.h"
#include "MyTime.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgReport dialog


CDlgReport::CDlgReport(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgReport::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgReport)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgReport::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgReport)
	DDX_Control(pDX, IDC_LISTMAIN, m_ctrlListMain);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgReport, CDialog)
	//{{AFX_MSG_MAP(CDlgReport)
	ON_BN_CLICKED(IDC_EXPORT, OnExport)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgReport message handlers

BOOL CDlgReport::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CADOConn adoReport;
	GetDlgItem(IDC_STATIC_THEME)->SetWindowText(strTitle);
	adoReport.Open(strSQL);
	adoReport.InitList(&m_ctrlListMain);
	adoReport.FillList(&m_ctrlListMain);
	adoReport.ExitConnect();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgReport::OnExport() 
{
	// TODO: Add your control notification handler code here
	CMyExcel myExcel;
	CMyTime myTime;
	CADOConn adoReport;
	int i, j, line;
	CString strFilePath;
	
	CFileDialog fileDialog(FALSE, "xls", "*.xls", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Excel file(*.xls)|*.xls||",NULL);
	if (fileDialog.DoModal() == IDOK)
	{
		myExcel.Open();
		myExcel.AddSheet(strTitle);
		myExcel.DeleteSheet123();
		adoReport.Open(strSQL);
		line = 1;

		for(i = 0; i < m_ctrlListMain.GetHeaderCtrl()->GetItemCount(); i++)
		{
			myExcel.SetItemText(line, i + 1, adoReport.GetFieldName(i));
		}
		adoReport.ExitConnect();

		for(j = 0; j < m_ctrlListMain.GetItemCount(); j++)
		{
			for(i = 0; i < m_ctrlListMain.GetHeaderCtrl()->GetItemCount(); i++)
			{
				myExcel.SetItemText(j + 2, i + 1, m_ctrlListMain.GetItemText(j, i));
			}
		}

		myExcel.SetItemText(j + 2, 1, myTime.GetAllString(TRUE));
		strFilePath = fileDialog.GetPathName();
		strFilePath.TrimRight();
		if (strFilePath.Right(3) != "xls" && strFilePath.Right(4) != "xlsx")
		{
			strFilePath += ".xls";
		}
		myExcel.SaveAs(strFilePath);
	}
	
	myExcel.Exit();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值