#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();
}
商店管理系统源代码(七)
最新推荐文章于 2013-04-12 15:38:14 发布