?? groupreportview.cpp
字號:
// GroupReportView.cpp : implementation of the CGroupReportView class
//
#include "stdafx.h"
#include "GroupReport.h"
#include "GroupReportDoc.h"
#include "GroupReportView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGroupReportView
IMPLEMENT_DYNCREATE(CGroupReportView, CScrollView)
BEGIN_MESSAGE_MAP(CGroupReportView, CScrollView)
//{{AFX_MSG_MAP(CGroupReportView)
// 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
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGroupReportView construction/destruction
CGroupReportView::CGroupReportView()
{
// TODO: add construction code here
m_pSet=NULL;
classname="";
}
CGroupReportView::~CGroupReportView()
{
if(m_pSet)
delete m_pSet;
}
BOOL CGroupReportView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGroupReportView drawing
void CGroupReportView::OnDraw(CDC* pDC)
{
PrintReport(pDC);
}
void CGroupReportView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
m_pSet=new CStudentSet(NULL);
m_pSet->m_strSort = "classid";
m_pSet->Open();
CSize sizeTotal(29000,21000);
SetScrollSizes(MM_LOMETRIC,sizeTotal);//設(shè)置滾動屏幕大小
}
/////////////////////////////////////////////////////////////////////////////
// CGroupReportView printing
BOOL CGroupReportView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGroupReportView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGroupReportView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGroupReportView diagnostics
#ifdef _DEBUG
void CGroupReportView::AssertValid() const
CScrollView::AssertValid();
}
void CGroupReportView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CGroupReportDoc* CGroupReportView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGroupReportDoc)));
return (CGroupReportDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGroupReportView message handlers
void CGroupReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
PrintReport(pDC, pInfo);
}
void CGroupReportView::PrintReport(CDC* pDC, CPrintInfo* pInfo)
{
CString str;//用于將數(shù)值數(shù)據(jù)轉(zhuǎn)換為字符串,以便使用TextOut函數(shù)輸出
CTime time = CTime::GetCurrentTime();//在打印報表時用于在頁腳輸出日期
int nLineHeight=0;//用于計算每行數(shù)據(jù)占用高度
int y=0;//用于控制TextOut函數(shù)中輸出位置的y軸坐標(biāo)
CFont ftitle/*報表標(biāo)題字體*/,fdetail/*數(shù)據(jù)字體*/;
CFont fheader/*字段標(biāo)題字體*/,ffooter/*報表頁腳字體*/;
//創(chuàng)建報表各部分使用的字體
ftitle.CreateFont(100,0,0,0,FW_BOLD,0,0,0,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_ROMAN,"楷體_GB2312");
fheader.CreateFont(60,0,0,0,FW_SEMIBOLD,0,1,0,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_ROMAN,"楷體_GB2312");
fdetail.CreateFont(50,0,0,0,FW_NORMAL,0,0,0,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_ROMAN,"楷體_GB2312");
ffooter.CreateFont(40,0,0,0,FW_NORMAL,0,0,0,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_ROMAN,"楷體_GB2312");
if (m_pSet->IsBOF()){
return;//若記錄集沒有數(shù)據(jù),則直接返回
}
//如果是打印第一頁或在窗體顯示數(shù)據(jù),則刷新記錄集
//這樣可從第一條記錄開始輸出,否則繼續(xù)接著記錄集當(dāng)前記錄輸出
if (!pInfo || pInfo->m_nCurPage==1){
m_pSet->Requery();//刷新記錄集,第一條記錄自動成為當(dāng)前記錄輸出
}
pDC->SelectObject(&ftitle);//設(shè)置報表標(biāo)題字體
pDC->TextOut(250,0,"班級學(xué)生名單報表");//輸出報表標(biāo)題
/*
TEXTMETRIC tm;
//輸出數(shù)據(jù)庫表StudentInfo數(shù)據(jù)
while (!m_pSet->IsEOF())
{
if (pInfo && abs(y)>2700){
//如果是打印或打印預(yù)覽,不是在窗體中顯示數(shù)據(jù)
//則在一頁打滿時增加頁數(shù),跳出記錄集搜索循環(huán)
pInfo->SetMaxPage(pInfo->m_nCurPage + 1) ;
break;//記錄集搜索循環(huán),停止打印記錄數(shù)據(jù)
}
if(classname!=m_pSet->m_classname)
{//輸出新的班級名稱
pDC->GetTextMetrics(&tm);
nLineHeight=tm.tmHeight+tm.tmExternalLeading;//獲取行高
y = -nLineHeight-20;//計算下一行記錄輸出的y軸坐標(biāo)
pDC->SelectObject(&fheader);//設(shè)置字段標(biāo)題字體
pDC->TextOut(100,y,m_pSet->m_classname);//輸出班級名稱
classname=m_pSet->m_classname;
y-=nLineHeight;//計算下一行數(shù)據(jù)輸出的y軸坐標(biāo)
}
//pDC->GetTextMetrics(&tm);
//nLineHeight=tm.tmHeight+tm.tmExternalLeading;//獲取新字體下的行高
//y-=nLineHeight+20;//計算第一行記錄輸出的y軸坐標(biāo)
pDC->SelectObject(&fdetail);//設(shè)置記錄數(shù)據(jù)顯示字體
pDC->GetTextMetrics(&tm);
nLineHeight=tm.tmHeight+tm.tmExternalLeading;//獲取新字體下的行高
pDC->TextOut(300,y, m_pSet->m_stuid);//輸出學(xué)號
pDC->TextOut(450,y, m_pSet->m_stuname);//輸出姓名
y-=nLineHeight;//計算下一行數(shù)據(jù)輸出的y軸坐標(biāo)
m_pSet->MoveNext();//使下一條記錄成為當(dāng)前記錄
}
if(pInfo){
//打印報表頁腳
pDC->SelectObject(&ffooter);
str.Format("學(xué)生信息報表 第 %d 頁 %d年%d月%d日",
pInfo->m_nCurPage,
time.GetYear(),time.GetMonth(),time.GetDay());
pDC->TextOut(650,-2809,str);
} */
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -