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

📄 inputdialog.cpp

📁 一个简单的记账软件
💻 CPP
字号:
// InputDialog.cpp : implementation file
//

#include "stdafx.h"
#include "Tally.h"
#include "InputDialog.h"
#include "Item.h"
#include "TallyDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInputDialog dialog


CInputDialog::CInputDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CInputDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInputDialog)
	m_dCost = 0.0;
	m_Date = 0;
	m_sName = _T("");
	m_sRemark = _T("");
	isChange = FALSE;
	m_uiType = -1;
	//}}AFX_DATA_INIT
	
}


void CInputDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInputDialog)
	DDX_Text(pDX, IDC_COST, m_dCost);
	DDX_DateTimeCtrl(pDX, IDC_DATE, m_Date);
	DDX_Text(pDX, IDC_NAME, m_sName);
	DDX_Text(pDX, IDC_REMARK, m_sRemark);
	DDX_CBIndex(pDX, IDC_TYPE, m_uiType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInputDialog, CDialog)
	//{{AFX_MSG_MAP(CInputDialog)
	ON_BN_CLICKED(IDC_ADD_BOTTOM, OnAddItem)
	ON_EN_CHANGE(IDC_COST, OnChangeCost)
	ON_NOTIFY(DTN_DROPDOWN, IDC_DATE, OnDropdownDate)
	ON_EN_CHANGE(IDC_NAME, OnChangeName)
	ON_EN_CHANGE(IDC_REMARK, OnChangeRemark)
	ON_CBN_DROPDOWN(IDC_TYPE, OnDropdownType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInputDialog message handlers

void CInputDialog::OnAddItem() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData();
	if (m_sName.IsEmpty()){
		AfxMessageBox("名称不能为空!");
		return;
	}
	if (m_dCost == 0) {
		AfxMessageBox("金额不能为0");
		return;
	}
	if (m_uiType ==-1) {
		AfxMessageBox("请指定类型!");
		return;
	}
	CWnd * pMain = AfxGetApp( )->m_pMainWnd;
	CDocument * pActiveDoc = ((CMDIFrameWnd*)pMain)->MDIGetActive()->GetActiveDocument();
	CItem item(this->m_sName,this->m_Date.GetDay(),this->m_dCost, m_sRemark,this->m_uiType);
	((CTallyDoc*)pActiveDoc)->AddItem(this->m_Date.GetMonth(),item);
	((CTallyDoc*)pActiveDoc)->UpdateAllViews(NULL);
	AfxMessageBox("添加成功");
	isChange = FALSE;
}

void CInputDialog::OnOK() 
{
	// TODO: Add extra validation here
	int res;
	if (isChange){
		res = AfxMessageBox("当前数据尚未添加,是否添加?",MB_OKCANCEL);
		if (res == IDOK) {
			OnAddItem();
			CDialog::OnOK();
		}
		else {
			CDialog::OnCancel();
		}
		
	}
	else
		CDialog::OnOK();
}

void CInputDialog::OnChangeCost() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	isChange = TRUE;
	
}

void CInputDialog::OnDropdownDate(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	isChange = TRUE;
	
	*pResult = 0;
}

void CInputDialog::OnChangeName() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	isChange = TRUE;
	
}

void CInputDialog::OnChangeRemark() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	isChange = TRUE;
	
}

void CInputDialog::OnDropdownType() 
{
	// TODO: Add your control notification handler code here
	isChange = TRUE;
}

⌨️ 快捷键说明

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