SampleReportDoc.cpp
上传用户:jimmy1212
上传日期:2020-11-02
资源大小:40k
文件大小:4k
- // 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[] = {
- {"DeptartmentnName", 32, CEasyReport::CColInfo::eLeft},
- {"EmployeenName", 25, CEasyReport::CColInfo::eLeft },
- {"nSalary", 15, CEasyReport::CColInfo::eRight}
- };
- static CEasyReport::CColInfo s_SummaryCols[] = {
- {"Nonof 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