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

📄 s8_1view.cpp

📁 自己编写的一个年度产值报告
💻 CPP
字号:
// S8_1View.cpp : implementation of the CS8_1View class
//

#include "stdafx.h"
#include "S8_1.h"

#include "S8_1Doc.h"
#include "S8_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CS8_1View

IMPLEMENT_DYNCREATE(CS8_1View, CFormView)

BEGIN_MESSAGE_MAP(CS8_1View, CFormView)
	//{{AFX_MSG_MAP(CS8_1View)
	ON_EN_CHANGE(IDC_MONTH_NOTE_EDIT, OnChangeMonthNoteEdit)
	ON_EN_CHANGE(IDC_MONTH_PRODUCT_EDIT, OnChangeMonthProductEdit)
	ON_EN_CHANGE(IDC_YEAR_EDIT, OnChangeYearEdit)
	ON_NOTIFY(UDN_DELTAPOS, IDC_YEAR_SPIN, OnDeltaposYearSpin)
	ON_CBN_SELCHANGE(IDC_MONTH_COMBOX, OnSelchangeMonthCombox)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CS8_1View construction/destruction

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

}

CS8_1View::~CS8_1View()
{
}

void CS8_1View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CS8_1View)
	DDX_Control(pDX, IDC_MONTH_COMBOX, m_MonthList);
	DDX_Text(pDX, IDC_MONTH_NOTE_EDIT, m_sNote);
	DDX_Text(pDX, IDC_MONTH_PRODUCT_EDIT, m_nMonthProduct);
	DDX_Text(pDX, IDC_RISERATE, m_sRiseRate);
	DDX_Text(pDX, IDC_YEAR_EDIT, m_nYear);
	DDX_Control(pDX, IDC_YEAR_PRODUCT, m_YearProduct);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CS8_1View::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	ResizeParentToFit();
     //代码编写开始
    CS8_1Doc* pDoc=GetDocument();//获取CS9_1DOC文件
    m_nYear=pDoc->m_nYear;       //获取文档中的年份
    m_MonthList.SetCurSel(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);
	//调用CLableControl设置标题函数显示年总产值
	m_YearProduct.SetCaption(str);
	UpdateData(FALSE);
	//代码编写结束
}

/////////////////////////////////////////////////////////////////////////////
// CS8_1View printing

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

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CS8_1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CS8_1View message handlers

void CS8_1View::OnChangeMonthNoteEdit() 
{
	// 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
	//代码编写开始
    CS8_1Doc* pDoc=GetDocument();//获取CS9_1DOC文件
	UpdateData();
	//和文档中的数据比较是否有变化
	if(strcmp(pDoc->m_Month[m_nCurrentMonth].sNote,m_sNote))
	{//记录下新数据
		strcpy(pDoc->m_Month[m_nCurrentMonth].sNote,m_sNote);
		pDoc->SetModifiedFlag();//设置文档变化标志
	}
	//代码编写结束
}

void CS8_1View::OnChangeMonthProductEdit() 
{
	// 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
	//代码编写开始
	CS8_1Doc* pDoc=GetDocument();//获取CS9_1DOC文件
	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);
		//记录当月产值到CS9_1中
		pDoc->m_Month[m_nCurrentMonth].nProduct=m_nMonthProduct;
		//计算增长率
		if(m_nCurrentMonth==0)//第一月
			m_sRiseRate="第一月无此值";
		else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)//前一月产值0
            m_sRiseRate="上月无此值";
		else 
            m_sRiseRate.Format("%.2f%%",(pDoc->m_Month[m_nCurrentMonth].nProduct-
			pDoc->m_Month[m_nCurrentMonth-1].nProduct)/(double)(pDoc->m_Month[m_nCurrentMonth-1].nProduct)*100);
        
		pDoc->SetModifiedFlag();
		UpdateData(FALSE);
		//代码编写结束
	}
}

void CS8_1View::OnChangeYearEdit() 
{
	// 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
	//代码编写开始
    CS8_1Doc* pDoc=GetDocument();//获取CS9_1DOC文件
	UpdateData();
	if(pDoc->m_nYear!=m_nYear)//判断数据是否变化
	{
		pDoc->m_nYear=m_nYear;
		pDoc->SetModifiedFlag();
	}
    
	//代码编写结束
}

void CS8_1View::OnDeltaposYearSpin(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
		//代码编写开始

    //用spin控件更改年份
    	UpdateData();
	if((pNMUpDown->iDelta>0)&&(m_nYear>0))
		m_nYear--;
	else if(pNMUpDown->iDelta<0)
		m_nYear++;
	else
	{
		AfxMessageBox("年份必须是负整数!");
	}
    GetDocument()->m_nYear=m_nYear;
	GetDocument()->SetModifiedFlag();
	UpdateData(FALSE);
	//代码编写结束
	*pResult = 0;
}

void CS8_1View::OnSelchangeMonthCombox() 
{
	// TODO: Add your control notification handler code here
	//代码编写开始
    CS8_1Doc* pDoc=GetDocument();//获取CS9_1DOC文件
	//因为每个数据改动,自己都响应了变动的消息,所以不用做保存数据的工作

	//获得当前选择的月份并设置正确的显示
	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)/(double)(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 + -