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

来源:互联网 发布:linux退出终端快捷键 编辑:程序博客网 时间:2024/04/30 19:24
#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 dialogclass CDlgReport : public CDialog{// Constructionpublic:CDlgReport(CWnd* pParent = NULL);   // standard constructorCString strSQL, strTitle;// Dialog Data//{{AFX_DATA(CDlgReport)enum { IDD = IDD_REPORT };CListCtrlm_ctrlListMain;//}}AFX_DATA// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CDlgReport)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected:// Generated message map functions//{{AFX_MSG(CDlgReport)virtual BOOL OnInitDialog();afx_msg void OnExport();//}}AFX_MSGDECLARE_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_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CDlgReport dialogCDlgReport::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_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CDlgReport message handlersBOOL CDlgReport::OnInitDialog() {CDialog::OnInitDialog();// TODO: Add extra initialization hereCADOConn 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 hereCMyExcel 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();}