📄 productreportdoc.cpp
字号:
// ProductReportDoc.cpp : implementation of the CProductReportDoc class
//
#include "stdafx.h"
#include "ProductReport.h"
#include "ProductReportDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProductReportDoc
IMPLEMENT_DYNCREATE(CProductReportDoc, CDocument)
BEGIN_MESSAGE_MAP(CProductReportDoc, CDocument)
//{{AFX_MSG_MAP(CProductReportDoc)
ON_COMMAND(ID_CREATE_TEXT, OnCreateText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProductReportDoc construction/destruction
CProductReportDoc::CProductReportDoc()
{
// TODO: add one-time construction code here
m_nYear=1999;
m_nTotalProduct=0;
for(int i=0;i<12;i++)
{
m_Month[i].nProduct=0;
m_Month[i].sNote[0]=NULL;
}
}
CProductReportDoc::~CProductReportDoc()
{
}
BOOL CProductReportDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CProductReportDoc serialization
void CProductReportDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar<<m_nYear;
ar<<m_nTotalProduct;
for(int i=0;i<12;i++)
{
ar<<m_Month[i].nProduct;
ar.Write(m_Month[i].sNote,50);
}
}
else
{
// TODO: add loading code here
ar>>m_nYear;
ar>>m_nTotalProduct;
int nTemp=0;
for(int i=0;i<12;i++)
{
ar>>m_Month[i].nProduct;
if(m_Month[i].nProduct<0)
m_Month[i].nProduct=-m_Month[i].nProduct;
nTemp+=m_Month[i].nProduct;
ar.Read(m_Month[i].sNote,50);
m_Month[i].sNote[49]=NULL;
}
if(nTemp!=m_nTotalProduct)
{
AfxMessageBox("error");
m_nTotalProduct=nTemp;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CProductReportDoc diagnostics
#ifdef _DEBUG
void CProductReportDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CProductReportDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CProductReportDoc commands
void CProductReportDoc::OnCreateText()
{
// TODO: Add your command handler code here
CString str;
CString filename=GetPathName();
if(filename.IsEmpty())
filename=GetTitle()+".trp";
else
filename=filename.Left(filename.GetLength()-3)+"trp";
CStdioFile file;
if(file.Open(filename,CFile::modeCreate|CFile::modeWrite|CFile::typeText)==0)
{
str="创建文件"+filename+"失败";
AfxMessageBox(str);
return;
}
str.Format("%d年产值报表\n\n",m_nYear);
file.WriteString(str);
for(int i=0;i<12;i++)
{
str.Format("%4d%13d %s\n",i+1,m_Month[i].nProduct,m_Month[i].sNote);
file.WriteString(str);
}
file.SetLength(file.GetPosition());
file.Close();
str="notepad"+filename;
WinExec(str,SW_SHOW);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -