📄 dlgreport.cpp
字号:
// DLgReport.cpp : implementation file
//
#include "stdafx.h"
#include "ncshop.h"
#include "DLgReport.h"
#include "ADOConn.h"
#include "MyExcel.h"
#include "MyTime.h"
#include "DlgPrint.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
intOpen=0;
strTitle="";
strSql="";
//}}AFX_DATA_INIT
}
void CDLgReport::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDLgReport)
DDX_Control(pDX, IDC_LIST1, m_listMain);
DDX_Control(pDX, IDC_BUTTON2, m_Btn2);
DDX_Control(pDX, IDC_BUTTON1, m_Btn1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDLgReport, CDialog)
//{{AFX_MSG_MAP(CDLgReport)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDLgReport message handlers
BOOL CDLgReport::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Btn1.SetXIcon(IDI_ICONBUTTON);
m_Btn2.SetXIcon(IDI_ICONBUTTON);
CADOConn adoMain;
GetDlgItem(IDC_STATIC1)->SetFont(&ftHeader);
GetDlgItem(IDC_STATIC1)->SetWindowText(strTitle);
adoMain.Open(strSql);
adoMain.InitList(&m_listMain,intOpen);
adoMain.FillList(&m_listMain,intOpen);
adoMain.ExitConnect();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDLgReport::OnButton1()
{
// TODO: Add your control notification handler code here
int i=0,j=0;
CMyExcel excel1;
CMyTime time1;
CFileDialog dlg(FALSE,"xls","C:\\*.xls",OFN_NOCHANGEDIR,"EXCEL文件|*.xls");
CADOConn adoMain;
time1.SetNow();
if(dlg.DoModal()==IDOK)
{
excel1.Open();
excel1.AddSheet("导出");
excel1.AutoRange();
excel1.SetItemText(1,1,strTitle);
adoMain.Open(strSql);
for(i=0;i<m_listMain.GetHeaderCtrl()->GetItemCount();i++)
{
excel1.SetItemText(2,i+1,adoMain.GetFieldsName(i));
}
adoMain.ExitConnect();
for(i=0;i<m_listMain.GetItemCount();i++)
{
for(j=0;j<m_listMain.GetHeaderCtrl()->GetItemCount();j++)
{
excel1.SetItemText(i+3,j+1,m_listMain.GetItemText(i,j));
}
}
excel1.SetItemText(i+3,1,time1.GetAllString(TRUE));
excel1.AutoColFit();
excel1.SaveAs(dlg.GetPathName());
}
excel1.Exit();
}
void CDLgReport::OnButton2()
{
// TODO: Add your control notification handler code here
CDlgPrint dlg;
dlg.strTitle=strTitle;
dlg.strSql=strSql;
dlg.m_ListMain=&m_listMain;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -