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

📄 docteview.cpp

📁 VC++是实现文件操作,可以生成报表用记事本打开,适合初学者学习
💻 CPP
字号:
// docTeView.cpp : implementation of the CDocTeView class
//

#include "stdafx.h"
#include "docTe.h"

#include "docTeDoc.h"
#include "docTeView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDocTeView

IMPLEMENT_DYNCREATE(CDocTeView, CFormView)

BEGIN_MESSAGE_MAP(CDocTeView, CFormView)
	//{{AFX_MSG_MAP(CDocTeView)
	ON_EN_CHANGE(IDC_MONTH_NOTE, OnChangeMonthNote)
	ON_EN_CHANGE(IDC_MONTH_PRODUCT, OnChangeMonthProduct)
	ON_EN_CHANGE(IDC_YEAR, OnChangeYear)
	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()

/////////////////////////////////////////////////////////////////////////////
// CDocTeView construction/destruction

CDocTeView::CDocTeView()
	: CFormView(CDocTeView::IDD)
{
	//{{AFX_DATA_INIT(CDocTeView)
	m_sNote = _T("");
	m_nMonthProduct = 0;
	m_nRiseRate = _T("");
	m_nYear = 0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CDocTeView::~CDocTeView()
{
}

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

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

	return CFormView::PreCreateWindow(cs);
}

void CDocTeView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	ResizeParentToFit();
	CDocTeDoc* pDoc=GetDocument();
    m_nYear=pDoc->m_nYear;
	m_nCurrentMonth=0;
	m_nMonthProduct=pDoc->m_Month[0].nProduct;
	m_sNote=pDoc->m_Month[0].sNote;
	m_nRiseRate="第一月无此值";
	CString str;
	str.Format("%d",pDoc->m_nTotalProduct);
	m_YearProduct.SetCaption(str);
	UpdateData(FALSE);


}

/////////////////////////////////////////////////////////////////////////////
// CDocTeView printing

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

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDocTeView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDocTeView message handlers

void CDocTeView::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
    CDocTeDoc* 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 CDocTeView::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
	CDocTeDoc* 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);
		//调用CLableControl设置标题函数显示年产总值
		m_YearProduct.SetCaption(str);
		//记录当月产值
		pDoc->m_Month[m_nCurrentMonth].nProduct=m_nMonthProduct;
		//计算增长率
		if(m_nCurrentMonth==0)     //是第一月
			m_nRiseRate="第一月无此值";
		else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)
			m_nRiseRate="上月无产值";
		else
			m_nRiseRate.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 CDocTeView::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
    CDocTeDoc* pDoc=GetDocument();
	UpdateData();
	if(pDoc->m_nYear!=m_nYear)  //判断数据是否变化
	{
		pDoc->m_nYear=m_nYear;   
		pDoc->SetModifiedFlag();   //设置文档更改标志
	}

	
}

void CDocTeView::OnDeltaposSpinYear(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
    //用spin控件更改年份
	UpdateData();  //调用它使m_nYear中是最新值
	if((pNMUpDown->iDelta>0)&&(m_nYear>0))    //减小年份,并且不能小于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 CDocTeView::OnSelchangeMonth() 
{
     CDocTeDoc* pDoc=GetDocument();
	 //因为每个数据改动,自己都响应了变动消息,所以不用做数据保存的工作
     //获得当前选择的月份并设置正确的显示
	 m_nCurrentMonth=m_MonthList.GetCurSel();
	 //计算这个月的增长率
	 if(m_nCurrentMonth==0)
		 m_nRiseRate="第一月无此值";
     else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)  //前一个月产值0
	     m_nRiseRate="上月无产值";
	 else
		 m_nRiseRate.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 + -