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

📄 sreportdlg.cpp

📁 如果在您的软件中需要输出报表
💻 CPP
字号:
// sreportDlg.cpp : implementation file
//

#include "stdafx.h"
#include "sreport.h"
#include "sreportDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CSreportDlg dialog

CSreportDlg::CSreportDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSreportDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSreportDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_pHtmlDoc2=NULL;
}

void CSreportDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSreportDlg)
	DDX_Control(pDX, IDC_SREPORT, m_sReport);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSreportDlg, CDialog)
	//{{AFX_MSG_MAP(CSreportDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_LOADTEMP, OnLoadtemp)
	ON_BN_CLICKED(IDC_INSERTROW, OnInsertrow)
	ON_BN_CLICKED(IDC_SETCELLTEXT, OnSetcelltext)
	ON_BN_CLICKED(IDC_DELROW, OnDelrow)
	ON_BN_CLICKED(IDC_MERGEROW, OnMergerow)
	ON_BN_CLICKED(IDC_MERGECOL, OnMergecol)
	ON_BN_CLICKED(IDC_VIEWCODE, OnViewcode)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSreportDlg message handlers
CString ResourceToURL(LPCTSTR lpszURL)
{
	// This functions shows how to convert an URL to point
	// within the application
	// I only use it once to get the startup page

	CString m_strURL;
	HINSTANCE hInstance = AfxGetResourceHandle();
	ASSERT(hInstance != NULL);
	
	LPTSTR lpszModule = new TCHAR[_MAX_PATH];
	
	if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
	{
		m_strURL.Format(_T("res://%s/%s"), lpszModule, lpszURL);
	}
	
	delete []lpszModule;

	return m_strURL;
}

BOOL CSreportDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	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
	OnLoadtemp();
	// TODO: Add extra initialization here
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSreportDlg::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 CSreportDlg::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 CSreportDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CSreportDlg::OnLoadtemp() 
{
	m_sReport.Navigate(ResourceToURL("template.htm"),NULL,NULL,NULL,NULL);
	LPDISPATCH lpDispatch;
	lpDispatch=m_sReport.GetDocument();
	ASSERT(lpDispatch);
	//get html document from IDispatch
	HRESULT hr=lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&m_pHtmlDoc2);
	if(hr!=S_OK) MessageBox("error");
	m_shtmlReport.SetHtmlDocPtr(m_pHtmlDoc2);
	m_shtmlReport.SetTableName("test");
	m_shtmlReport.SetIndexFormat("line %d");
}

void CSreportDlg::GetText(CString& cs,IHTMLElement *pElement)
{
	cs.Empty();
	CString str= "";
	BSTR bsStr = str.AllocSysString();
	pElement->get_outerHTML(&bsStr);
	_bstr_t bstStr;
	bstStr = bsStr;
	str.Format("%s",(LPCTSTR)bstStr);
	SysFreeString(bsStr);
	cs = str;
}


void CSreportDlg::OnViewcode() 
{
	IHTMLElement *body;
	m_pHtmlDoc2->get_body(&body);
	CString op;
	GetText(op,body);
	SetDlgItemText(IDC_EDIT1,op);
}

#include "setcellinputdlg.h"
void CSreportDlg::OnSetcelltext() 
{
	// TODO: Add your control notification handler code here
	ASSERT(m_pHtmlDoc2);
	CSetCellInputDlg inputdlg;
	if(inputdlg.DoModal()!=IDOK) return;
	m_shtmlReport.SetItemHTML(inputdlg.m_row,inputdlg.m_col,inputdlg.m_strValue);

}

#include "RowColInputDlg.h"

void CSreportDlg::OnDelrow() 
{
	ASSERT(m_pHtmlDoc2);
	CRowColInputDlg inputdlg;
	if(inputdlg.DoModal()==IDOK)
		m_shtmlReport.DeleteRow(inputdlg.m_index);
}

void CSreportDlg::OnMergerow() 
{
	// TODO: Add your control notification handler code here
	ASSERT(m_pHtmlDoc2);
	CRowColInputDlg inputdlg;
	if(inputdlg.DoModal()==IDOK)
		m_shtmlReport.MergeRow(inputdlg.m_index);
}

void CSreportDlg::OnMergecol() 
{
	// TODO: Add your control notification handler code here
	ASSERT(m_pHtmlDoc2);
	CRowColInputDlg inputdlg;
	if(inputdlg.DoModal()==IDOK)
		m_shtmlReport.MergeCol(inputdlg.m_index);
}

void CSreportDlg::OnInsertrow() 
{
	// TODO: Add your control notification handler code here
	ASSERT(m_pHtmlDoc2);
	CRowColInputDlg inputdlg;
	if(inputdlg.DoModal()==IDOK)
		m_shtmlReport.InsertRow(inputdlg.m_index);
}

⌨️ 快捷键说明

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