ex101View.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:7k
源码类别:
书籍源码
开发平台:
Visual C++
- // ex101View.cpp : implementation of the CEx101View class
- //
- #include "stdafx.h"
- #include "ex101.h"
- #include "ex101Doc.h"
- #include "ex101View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEx101View
- IMPLEMENT_DYNCREATE(CEx101View, CFormView)
- BEGIN_MESSAGE_MAP(CEx101View, CFormView)
- //{{AFX_MSG_MAP(CEx101View)
- ON_EN_CHANGE(IDC_MON_MEM, OnChangeMonMem)
- ON_EN_CHANGE(IDC_MON_PRO, OnChangeMonPro)
- 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()
- /////////////////////////////////////////////////////////////////////////////
- // CEx101View construction/destruction
- CEx101View::CEx101View()
- : CFormView(CEx101View::IDD)
- {
- //{{AFX_DATA_INIT(CEx101View)
- m_nYear = 0;
- m_nMonPro = 0;
- m_strMonMem = _T("");
- m_strRiseRate = _T("");
- m_nCurrentMonth=0; //0代表1月
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- }
- CEx101View::~CEx101View()
- {
- }
- void CEx101View::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEx101View)
- DDX_Control(pDX, IDC_MONTH, m_ctrlMonthList);
- DDX_Text(pDX, IDC_YEAR, m_nYear);
- DDV_MinMaxInt(pDX, m_nYear, 2005, 2008);
- DDX_Text(pDX, IDC_MON_PRO, m_nMonPro);
- DDX_Text(pDX, IDC_MON_MEM, m_strMonMem);
- DDX_Text(pDX, IDC_RISERATE, m_strRiseRate);
- DDX_Control(pDX, IDC_YEAE_PRO, m_YearPro);
- //}}AFX_DATA_MAP
- }
- BOOL CEx101View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CFormView::PreCreateWindow(cs);
- }
- void CEx101View::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- ResizeParentToFit();
- CEx101Doc *pDoc=GetDocument();
- m_nYear=pDoc->m_nYear; //获取文档中的年份
- m_ctrlMonthList.SetCurSel(0);//选择一月
- m_nCurrentMonth=0; //当前月是一月
- m_nMonPro=pDoc->m_Month[0].nProduct;//一月产值
- m_strMonMem=pDoc->m_Month[0].sNote;//一月备注
- m_strRiseRate="第一月无此值";
- CString str;
- str.Format("%d",pDoc->m_nTotalProduct);
- m_YearPro.SetCaption(str);
- //调用CLableControl设置标题函数显示年总产值
- UpdateData(false);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx101View printing
- BOOL CEx101View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CEx101View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CEx101View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- void CEx101View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
- {
- // TODO: add customized printing code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx101View diagnostics
- #ifdef _DEBUG
- void CEx101View::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CEx101View::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- CEx101Doc* CEx101View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx101Doc)));
- return (CEx101Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CEx101View message handlers
- void CEx101View::OnChangeMonMem()
- {
- // 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.
- CEx101Doc* pDoc=GetDocument();
- UpdateData(); //获取最新输入数据
- //和文档中的数据比较,看是否有变化
- if(strcmp(pDoc->m_Month[m_nCurrentMonth].sNote,m_strMonMem))
- {
- //记录新数据
- strcpy(pDoc->m_Month[m_nCurrentMonth].sNote,m_strMonMem);
- pDoc->SetModifiedFlag(); //设置文档改变标志
- }
- }
- void CEx101View::OnChangeMonPro()
- {
- // 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.
- CEx101Doc* pDoc=GetDocument();
- UpdateData(); //获取输入的月份值
- if(pDoc->m_Month[m_nCurrentMonth].nProduct!=m_nMonPro)
- {//比较判断数据是否改变,并改变总产值
- pDoc->m_nTotalProduct+=m_nMonPro-pDoc->m_Month[m_nCurrentMonth].nProduct;
- CString str;
- str.Format("%d",pDoc->m_nTotalProduct);
- m_YearPro.SetCaption(str);//显示总产值
- pDoc->m_Month[m_nCurrentMonth].nProduct=m_nMonPro;
- //记录当月产值,并计算增长率
- if(m_nCurrentMonth==0)
- m_strRiseRate="第一月无此值";
- else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)
- m_strRiseRate="上月无产值";
- else
- m_strRiseRate.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 CEx101View::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.
- CEx101Doc* pDoc=GetDocument();
- UpdateData();//获取最新输入
- if(pDoc->m_nYear!=m_nYear)
- {//判断数据变化
- pDoc->m_nYear=m_nYear;//记录到Doc中
- pDoc->SetModifiedFlag();//设置修改标志
- }
- }
- void CEx101View::OnDeltaposSpinYear(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- UpdateData();//获取最新输入
- if((pNMUpDown->iDelta>0)&&(m_nYear>0))
- m_nYear--;//减小年份并且不能小于0
- else if(pNMUpDown->iDelta<0)
- m_nYear++;//增加年份
- else //非法输入
- {
- AfxMessageBox("年份必须是非负数!");
- *pResult=0;
- return;
- }
- GetDocument()->m_nYear=m_nYear;//文档记录年份
- GetDocument()->SetModifiedFlag();
- UpdateData(FALSE);
- *pResult = 0;
- }
- void CEx101View::OnSelchangeMonth()
- {
- CEx101Doc* pDoc=GetDocument();
- //获得当前选择月份并设置正确显示
- m_nCurrentMonth=m_ctrlMonthList.GetCurSel();
- //计算这个月增长率
- if(m_nCurrentMonth==0) //是一月?
- m_strRiseRate="第一月无此值!";
- else if(pDoc->m_Month[m_nCurrentMonth-1].nProduct==0)
- m_strRiseRate="上月无产值";
- else //计算增长率
- m_strRiseRate.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_nMonPro=pDoc->m_Month[m_nCurrentMonth].nProduct;
- m_strMonMem=pDoc->m_Month[m_nCurrentMonth].sNote;
- UpdateData(FALSE);
- }