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

📄 samplereportdoc.cpp

📁 这是一个不用任何控件的的纯VC报表源码。而且写得相当好!
💻 CPP
字号:
// SampleReportDoc.cpp : implementation of the CSampleReportDoc class
//

#include "stdafx.h"
#include "SampleReport.h"

#include "SampleReportDoc.h"
#include "EmpList.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSampleReportDoc

IMPLEMENT_DYNCREATE(CSampleReportDoc, CDocument)

BEGIN_MESSAGE_MAP(CSampleReportDoc, CDocument)
	//{{AFX_MSG_MAP(CSampleReportDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleReportDoc construction/destruction


// static data 
static CEasyReport::CColInfo			s_Cols[] = {
		{"Deptartment\nName",	32,		CEasyReport::CColInfo::eLeft},
		{"Employee\nName",		25,		CEasyReport::CColInfo::eLeft },
		{"\nSalary",			15,		CEasyReport::CColInfo::eRight}
	};

static CEasyReport::CColInfo			s_SummaryCols[] = {
		{"No\nof Emp.", 10,		CEasyReport::CColInfo::eRight},
		{"\nTot Sal.",	15,		CEasyReport::CColInfo::eRight },
		{"\nMax Sal.",	15,		CEasyReport::CColInfo::eRight}
	};


CSampleReportDoc::CSampleReportDoc()
{
	// TODO: add one-time construction code here
}


CSampleReportDoc::~CSampleReportDoc()
{
}

BOOL CSampleReportDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	long		aCurDept;
	int			aCount;
	double		aTotSalary, aMaxSalary;
	CEmpList	aList;
	CString		aTemp;
	
	try
	{
		aList.Open();
	}
	catch(CDaoException *ex)
	{
		AfxMessageBox(ex->m_pErrorInfo->m_strDescription);
		throw ex;
	}
	aList.MoveFirst();
	m_Report.SetReportTitle("Employees Salaries, by Department");
	m_Report.Start();
	// print a long paragraph
	m_Report.AtTab(0,
		"Hello World ! This is a simple long paragraph "
		"which needs to be Word-wrapped. Basically, if "
		"we set the data colums to 0, the report goes into "
		"a paragraph mode. In this mode, long paragraphs of "
		"text can be inserted and the text will be wrapped "
		"between the left and the right margins. You can insert "
		"a paragraph of text anywhere on the report. Comming soon "
		"bullet and numbered paragraph styles !");
	m_Report.NextRow();

	while(!aList.IsEOF())
	{
		// Initalize all totals etc at the start of a group
		aCurDept = aList.m_DeptID;
		aTotSalary = aMaxSalary = 0;
		aCount = 0;
		//m_Report.SetDataCols(NULL);
		//m_Report.AtTab(0,aTemp);
		
		// Set up a tabular section for the main section
		m_Report.SetDataCols(s_Cols,3);
		m_Report.AtTab(0,aList.m_DeptName);
		do
		{
			aTotSalary += aList.m_Salary;
			if( aList.m_Salary > aMaxSalary)
				aMaxSalary = aList.m_Salary;
			aTemp.Format("%s,%s",(LPCSTR)aList.m_LastName,(LPCSTR)aList.m_FirstName);
			m_Report.AtTab(1,aTemp);
			aTemp.Format("%5.2lf",aList.m_Salary);
			m_Report.AtTab(2,aTemp);
			m_Report.NextRow();
			aList.MoveNext();
			++aCount;
		}
		while( !aList.IsEOF() && aList.m_DeptID == aCurDept);

	// write a summary for this department
	m_Report.SetDataCols(s_SummaryCols,3);
	aTemp.Format("%3d",aCount);
	m_Report.AtTab(0,aTemp );
	aTemp.Format("%5.2lf",aTotSalary);
	m_Report.AtTab(1,aTemp);
	aTemp.Format("%5.2lf",aMaxSalary);
	m_Report.AtTab(2,aTemp);
	m_Report.SetDataCols(NULL);
	m_Report.NextRow();
	m_Report.NextRow();	// insert a blank row between two groups
	}

	m_Report.End();		// close report
	aList.Close();		// close database
	m_Report.GotoPage(0);

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CSampleReportDoc serialization

void CSampleReportDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CSampleReportDoc diagnostics

#ifdef _DEBUG
void CSampleReportDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CSampleReportDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSampleReportDoc commands

⌨️ 快捷键说明

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