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

📄 productreportview.cpp

📁 实现年度产值报表
💻 CPP
字号:
// ProductReportView.cpp : implementation of the CProductReportView class
//

#include "stdafx.h"
#include "ProductReport.h"

#include "ProductReportDoc.h"
#include "ProductReportView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CProductReportView

IMPLEMENT_DYNCREATE(CProductReportView, CFormView)

BEGIN_MESSAGE_MAP(CProductReportView, CFormView)
	//{{AFX_MSG_MAP(CProductReportView)
	ON_EN_CHANGE(IDC_MONTH_NOTE, OnChangeMonthNote)
	ON_EN_CHANGE(IDC_YEAR, OnChangeYear)
	ON_EN_CHANGE(IDC_MONTH_PRODUCT, OnChangeMonthProduct)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_YEAR, OnDeltaposSpinYear)
	ON_CBN_SELCHANGE(IDC_MONTH, OnSelchangeMonth)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProductReportView construction/destruction

CProductReportView::CProductReportView()
	: CFormView(CProductReportView::IDD)
{
	//{{AFX_DATA_INIT(CProductReportView)
	m_nYear = 0;
	m_nMonthProduct = 0;
	m_sNote = _T("");
	m_sRiseRate = _T("");
	m_nCurrentMonth=0;       //初始化当前月,0代表一月
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CProductReportView::~CProductReportView()
{
}

void CProductReportView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProductReportView)
	DDX_Control(pDX, IDC_MONTH, m_MonthList);
	DDX_Text(pDX, IDC_YEAR, m_nYear);
	DDX_Control(pDX, IDC_YEAR_PRODUCT, m_YearProduct);
	DDX_Text(pDX, IDC_MONTH_PRODUCT, m_nMonthProduct);
	DDX_Text(pDX, IDC_MONTH_NOTE, m_sNote);
	DDX_Text(pDX, IDC_RISERATE, m_sRiseRate);
	//}}AFX_DATA_MAP
}

BOOL CProductReportView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CProductReportView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	ResizeParentToFit();
	CProductReportDoc* pDoc=GetDocument();
	m_nYear=pDoc->m_nYear;
	m_MonthList.SetCurSel(0);
	m_nCurrentMonth=0;
	m_nMonthProduct=pDoc->m_Month[0].nProduct;
	m_sNote=pDoc->m_Month[0].sNote;
	m_sRiseRate="第一月无此值";
	CString str;
	str.Format("%d",pDoc->m_nTotalProduct);
	//调用CLabelControl设置标题函数显示年总产值
	m_YearProduct.SetCaption(str);
	UpdateData(FALSE);

}

/////////////////////////////////////////////////////////////////////////////
// CProductReportView printing

BOOL CProductReportView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CProductReportView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CProductReportView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CProductReportView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CProductReportView diagnostics

#ifdef _DEBUG
void CProductReportView::AssertValid() const
{
	CFormView::AssertValid();
}

void CProductReportView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CProductReportDoc* CProductReportView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CProductReportDoc)));
	return (CProductReportDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CProductReportView message handlers

void CProductReportView::OnChangeMonthNote() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CProductReportDoc* pDoc=GetDocument();
	UpdateData();
	//和文档中的数据比较是否有变化
	if(strcmp(pDoc->m_Month[m_nCurrentMonth].sNote,m_sNote))
	{
		strcpy(pDoc->m_Month[m_nCurrentMonth].sNote,m_sNote);
		pDoc->SetModifiedFlag();
	}
	
}

void CProductReportView::OnChangeYear() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CProductReportDoc* pDoc=GetDocument();
	UpdateData();
	if(pDoc->m_nYear!=m_nYear)
	{
		pDoc->m_nYear=m_nYear;
		pDoc->SetModifiedFlag();
	}
	
}

void CProductReportView::OnChangeMonthProduct() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CFormView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CProductReportDoc* pDoc=GetDocument();
	UpdateData();
	if(pDoc->m_Month[m_nCurrentMonth].nProduct!=m_nMonthProduct)
	{
		pDoc->m_nTotalProduct+=
			m_nMonthProduct-pDoc->m_Month[m_nCurrentMonth].nProduct;
		CString str;
		str.Format("%d",pDoc->m_nTotalProduct);
		m_YearProduct.SetCaption(str);
		pDoc->m_Month[m_nCurrentMonth].nProduct=m_nMonthProduct;
		if(m_nCurrentMonth==0)
			m_sRiseRate="第一月无产值";
		else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)
			m_sRiseRate="上月无产值";
			else
			m_sRiseRate.Format("%.2f%%",(pDoc->m_Month[m_nCurrentMonth].nProduct-pDoc->m_Month[m_nCurrentMonth-1].nProduct)/(float)(pDoc->m_Month[m_nCurrentMonth-1].nProduct)*100);
		pDoc->SetModifiedFlag();
		UpdateData(FALSE);
	}
	
}

void CProductReportView::OnDeltaposSpinYear(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	UpdateData();
	if((pNMUpDown->iDelta>0)&&(m_nYear>0))
		m_nYear--;
	else if(pNMUpDown->iDelta<0)
		m_nYear++;
	else
	{
		AfxMessageBox("年份必须是非负整数");
		*pResult=0;
		return;
	}
	GetDocument()->m_nYear=m_nYear;
	GetDocument()->SetModifiedFlag();
	UpdateData(FALSE);
	*pResult = 0;
}

void CProductReportView::OnSelchangeMonth() 
{
	// TODO: Add your control notification handler code here
	CProductReportDoc* pDoc=GetDocument();
	//获得当前选择的月份并设置正确的显示
	m_nCurrentMonth=m_MonthList.GetCurSel();
	if(m_nCurrentMonth==0)
		m_sRiseRate="第一月无实值";
	else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)
		m_sRiseRate="上月无产值";
	else
		m_sRiseRate.Format("%.2f%%",(pDoc->m_Month[m_nCurrentMonth].nProduct-pDoc->m_Month[m_nCurrentMonth-1].nProduct)/(float)(pDoc->m_Month[m_nCurrentMonth-1].nProduct)*100);
	m_nMonthProduct=pDoc->m_Month[m_nCurrentMonth].nProduct;
	m_sNote=pDoc->m_Month[m_nCurrentMonth].sNote;
	UpdateData(FALSE);
	
}

⌨️ 快捷键说明

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