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

📄 cashdlg.cpp

📁 该项目是为PPC(PocketPc)使用者提供方便的理财事务.如,现金的借贷,债务处理,证券买卖,以及物品管 理等等。该项目的主要用户群是:PPC使用者.
💻 CPP
字号:
// CashDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MoneyAnyWhere.h"
#include "CashDlg.h"
#include "Cash.h"
#include "CashDetailDlg.h"
#include "SavingDetailDlg.h"
#include "NewCashDealDlg.h"
#include "DealModifyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////
// CCashDlg dialog


CCashDlg::CCashDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCashDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCashDlg)
	//}}AFX_DATA_INIT
	m_strCashName = L"现金与存款中心";
}


void CCashDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCashDlg)
	DDX_Control(pDX, IDC_BTNCASHOPERATEMENU, m_btnOper);
	DDX_Control(pDX, IDC_LIST_CASH, m_ctrCashList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCashDlg, CDialog)
//{{AFX_MSG_MAP(CCashDlg)
ON_WM_PAINT()
ON_COMMAND(ID_MENUBTN_MODIFYACCOUNT, OnModify)
ON_COMMAND(ID_MENUBTN_ADDCASH, OnAdd)
ON_COMMAND(ID_MENUBTN_DELACCOUNT, OnDelete)
ON_BN_CLICKED(IDC_BTNCASHDETAIL, OnBtncashdetail)

//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCashDlg message handlers

BOOL CCashDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_strMoneyType=L"人民币";  //默认是RMB
	m_strBeginDate=L"2004-01-01";  //默认是2005-01-01
	m_strLastDate=L"2005-02-23";  //默认是2005-01-01
	m_iBeginSum=0;
	m_iSumOut=0;
	m_iSumIn=0;
	m_iLeft=0;
	m_iCount = 0;
	m_btnOper.SetMenu(IDR_MENUBTN_CASH, m_hWnd);
	m_btnOper.SetFlat(FALSE);
	
	//改变列表的背景色
	m_ctrCashList.SetBkColor(COLORREF(RGB(251,251,249)));
	m_ctrCashList.SetExtendedStyle(LVS_EX_FULLROWSELECT);//|LVS_EX_GRIDLINES);
	//设置表头格式为Account/Name/Date
	m_ctrCashList.SetHeadings(_T("交易日期,60;收支类型,60;收入/支出,60;金额,60"));
	//宽度设置
	m_ctrCashList.SetColumnWidth(0,80);
	m_ctrCashList.SetColumnWidth(1,40);
	m_ctrCashList.SetColumnWidth(2,50);
	m_ctrCashList.SetColumnWidth(3,70);
	
	
	return TRUE;  
}

void CCashDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect	rect;
	this->GetClientRect(&rect);
	CBrush	*pBrush = new CBrush(COLORREF(RGB(227,234,206)));
	dc.FillRect(rect,pBrush);	
	dc.SetBkColor(COLORREF(RGB(227,234,206)));
	dc.DrawText(m_strCashName,CRect(0,0,100,20),NULL);
	CString	str;
	if(m_strType == "现金")
		SetDlgItemText(IDC_BTNCASHDETAIL,L"现金概况");
	else
		SetDlgItemText(IDC_BTNCASHDETAIL,L"存款概况");
	str.Format(L"帐户类型:(%s)%s",m_strMoneyType,m_strType);
	dc.DrawText(str,CRect(0,160,140,180),NULL);
	str.Format(L"合计收入:%d",m_iSumIn);
	dc.DrawText(str,CRect(0,180,140,200),NULL);
	str.Format(L"合计支出:%d",m_iSumOut);
	dc.DrawText(str,CRect(0,200,140,220),NULL);
	str.Format(L"帐户余额:%d",m_iLeft);
	dc.DrawText(str,CRect(140,200,240,220),NULL);
	
	
}

BOOL CCashDlg::ReadIni(CString file)
{
	m_iBeginSum = 0;
	m_iSumOut=0;
	m_iSumIn=0;
	m_iLeft=0;
	m_strCashName = file ;
	m_ctrCashList.DeleteAllItems();
	file +=".ini";

	//file = "\\Program Files\\理财能手\\Data\\"+file;

	pCashIni = new CIniReader(file);
	pCashInfo = new CIniReader(file);
	//装载和解析INI文件
	if(! pCashInfo->Load())
	{
		::AfxMessageBox(L"Can not load ini");
		delete pCashInfo;
		pCashInfo = NULL;
		return FALSE;
	}
	
	if(! pCashInfo->Parse())
	{
		::AfxMessageBox(L"Invalid format  ");
		delete pCashInfo;
		pCashInfo = NULL;
		return FALSE;
	}
	CSection	CashInfo= (*pCashInfo)[L"Info"];
	
	POSITION _pos = CashInfo.m_item.GetStartPosition();
	
	while( _pos != NULL)
	{
		String _key;
		String _value;
		
		CashInfo.m_item.GetNextAssoc(_pos, _key, _value);
		if((CString)_key==(CString)"type")//获得该帐户的类型
		{
			m_strType =(CString)(_value);
			
		}
		if((CString)_key==(CString)"deal_count") //获得该帐户一共有多少笔交易
		{
			m_iCount = _wtoi(_value);
		}	
		if((CString)_key==(CString)"money_type")//获得该帐户的币种
		{
			
			m_strMoneyType =(CString)(_value);
		}
		if((CString)_key==(CString)"amount")//获得该帐户的开户金额
		{
			m_iBeginSum =_wtoi(_value);
			
		}
		if((CString)_key==(CString)"date")//获得该帐户的开户日期
		{
			m_strBeginDate =(CString)(_value);
			
		}
	
	}
	
	////////////////////////////////////////////////////////////////////
	//装载和解析INI文件
	if(! pCashIni->Load())
	{
		::AfxMessageBox(L"Can not load ini");
		delete pCashIni;
		pCashIni = NULL;
		return FALSE;
	}
	
	if(! pCashIni->Parse())
	{
		::AfxMessageBox(L"Invalid format  ");
		delete pCashIni;
		pCashIni = NULL;
		return FALSE;
	}
	//AfxMessageBox(pAccountIni->GetFilePath());
	
	for(int i=0;i<m_iCount;i++)
	{
		CString	str;
		str.Format(L"%d",i);
		CSection	Info= (*pCashIni)[str];
		
		POSITION pos = Info.m_item.GetStartPosition();
		m_pCCash[i] = new CCash();
		while( pos != NULL)
		{
			String key;
			String value;
			
			// Get key ( string ) and value ( string )
			Info.m_item.GetNextAssoc(pos, key, value);
			//AfxMessageBox((CString)key);
			SetCash((CString)key,(CString)value,i);
			
		}
		if(m_pCCash[i]->deal_inout=="out")
		{
			
			
			m_iSumOut +=m_pCCash[i]->deal_money;
		}
		else
		{
			m_iSumIn  +=m_pCCash[i]->deal_money;
		}
		//m_ctrCashList.AddItem(pCash->deal_time,pCash->deal_type,pCash->deal_inout,pCash->deal_money);
	}
	for(i=0;i<m_iCount;i++)
	{
		CString	strInout,strTmp;
		if(m_pCCash[i]->deal_inout=="out")
		{
			strInout = "支出";
			
			m_pCCash[i]->deal_money =0 - m_pCCash[i]->deal_money;
		}
		else
		{
			strInout = "收入";
			
		}
		CString tmp;
		tmp.Format(L"%d",m_pCCash[i]->deal_money);
		m_ctrCashList.AddItem(m_pCCash[i]->deal_time,m_pCCash[i]->deal_type,strInout,tmp);
	}
	
	m_iLeft = m_iBeginSum + m_iSumIn - m_iSumOut;
	Invalidate();
	return true;
}


void CCashDlg::SetCash(CString key,CString value,int i)
{
	
	if(key=="deal_time")
		m_pCCash[i]->deal_time = value;
	else
		if(key=="deal_type")
			m_pCCash[i]->deal_type = value;
		else
			if(key=="deal_money")
				m_pCCash[i]->deal_money = _wtoi(value);
			else
				if(key=="deal_inout")
					m_pCCash[i]->deal_inout = value;
}

//显示现金概况
void CCashDlg::OnBtncashdetail() 
{
	CString strTmpAmout;
	strTmpAmout.Format(L"%d",m_iLeft);
	if(m_strType == "现金")
	{
		CCashDetailDlg dlg(this);
		dlg.m_strCashType = m_strMoneyType; 
		dlg.m_strCashLastDealDate = m_strLastDate;
		dlg.m_strCashName = m_strCashName;
		dlg.m_strLeftAmount = strTmpAmout;
		dlg.m_strCashDate = m_strBeginDate;
		dlg.DoModal();
	}
	else
	{
		CSavingDetailDlg dlg(this);
		dlg.m_strSavingType = m_strMoneyType; 
		dlg.m_strLastDate = m_strLastDate;
		dlg.m_strSavingName = m_strCashName;
		dlg.m_strLeftAmount = strTmpAmout;
		dlg.m_strSavingDate = m_strBeginDate;

		dlg.DoModal();
	}

}
void CCashDlg::OnAdd()
{
	
	CString	str,str2;
	CString	tmpStr;
	CSection tmpSec,tmpSec2;
	CCash	*pCash = new CCash();
	CNewCashDealDlg DealDlg(this) ;
	DealDlg.m_strDealAccount = m_strCashName;
	if( DealDlg.DoModal())
	{
		
		pCash->deal_money = DealDlg.m_iDealMoney;
		pCash->deal_inout = DealDlg.m_strInOrOut ;
		pCash->Account_Type = DealDlg.m_strCategory;
		pCash->deal_time = DealDlg.m_strDealTime ;
		
		//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strCashName+".ini";

		tmpStr =m_strCashName+".ini";
		pCashIni = new CIniReader(tmpStr);
		
		if(! pCashIni->Load())
		{
			::AfxMessageBox(L"Can not load ini");
			delete pCashIni;
			pCashIni = NULL;
			return ;
		}
		
		if(! pCashIni->Parse())
		{
			::AfxMessageBox(L"Invalid format  ");
			delete pCashIni;
			pCashIni = NULL;
			return ;
		}
		//向文件中增加信息:
		tmpSec2.m_SectionName.Format(L"%d",m_iCount);
		m_iCount++;
		tmpStr.Format(L"%d",m_iCount);
		pCashIni->AddPair(L"deal_count",tmpStr,L"Info"); //将帐户数自增1
		pCashIni->AddPair(L"deal_time",pCash->deal_time,tmpSec2.m_SectionName);
		pCashIni->AddPair(L"deal_type",pCash->Account_Type,tmpSec2.m_SectionName);
		tmpStr.Format(L"%d",pCash->deal_money);
		pCashIni->AddPair(L"deal_money",tmpStr,tmpSec2.m_SectionName);
		pCashIni->AddPair(L"deal_inout",pCash->deal_inout,tmpSec2.m_SectionName);
		pCashIni->Store();
		ReadIni(m_strCashName);
	}
	
	if(pCash)
		delete pCash;
}
//先从INI中找到所要修改的CSection,然后在这个CSection中AddPair,将自动覆盖原来的
void CCashDlg::OnModify()
{	
	CString	str,str2;
	int iPos = -1;
	CString	tmpStr;
	CSection tmpSec,tmpSec2;
	
	POSITION	pos;
	pos = m_ctrCashList.GetFirstSelectedItemPosition();
	
	int Select= m_ctrCashList.GetNextSelectedItem(pos);
	//如果双击空白处
	if(Select==-1)
		return;
	CDealModifyDlg DealModifyDlg(this) ;
	CCash	*pCash = new CCash();
	DealModifyDlg.m_strAccountName = m_strCashName ;
	DealModifyDlg.m_strDealTime = m_ctrCashList.GetItemText(Select,0);
	DealModifyDlg.m_strCategory = m_ctrCashList.GetItemText(Select,1);
	
	if( m_ctrCashList.GetItemText(Select,2) == "收入")
		DealModifyDlg.m_strInOrOut = "in";
	else
		DealModifyDlg.m_strInOrOut = "out";
	DealModifyDlg.m_iAmount = _wtoi(m_ctrCashList.GetItemText(Select,3));
	//显示修改对话框,并处理
	if( DealModifyDlg.DoModal() == IDOK )
	{
		pCash->deal_money = DealModifyDlg.m_iAmount;
		pCash->deal_inout = DealModifyDlg.m_strInOrOut ;
		pCash->deal_type = DealModifyDlg.m_strCategory;
		pCash->deal_time = DealModifyDlg.m_strDealTime ;
		//初始化INI

		//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strCashName+".ini";

		tmpStr =m_strCashName+".ini";
		pCashIni = new CIniReader(tmpStr);
		
		if(! pCashIni->Load())
		{
			::AfxMessageBox(L"Can not load ini");
			delete pCashIni;
			pCashIni = NULL;
			return ;
		}
		
		if(! pCashIni->Parse())
		{
			::AfxMessageBox(L"Invalid format ini");
			delete pCashIni;
			pCashIni = NULL;
			return ;
		}
		for(int i=0;i<m_iCount;i++)
		{
			
			CString	str;
			str.Format(L"%d",i);
			CSection	Info= (*pCashIni)[str];
			POSITION pos = Info.m_item.GetStartPosition();
			BOOL  btime ,bmoney,btype,binout;
			
			while( pos != NULL)
			{
				String key;
				String value;
				
				Info.m_item.GetNextAssoc(pos, key, value);
				if(key == "deal_time" && value == pCash->deal_time)
				   btime =  true;
				else if(key == "deal_type" && value == pCash->deal_type)
					btype = true;
				else if(key == "deal_money"&& value == pCash->deal_money)
					bmoney = true;
				else if(key == "deal_inout"&& value == pCash->deal_inout)
					binout = true;
		
			}
			if(btime&&bmoney&&btype&&binout)
				iPos = i;
		}
		if(iPos == -1)
		{
			AfxMessageBox(L"修改失败");
			return ;
		}
		//向文件中增加信息:
		
		tmpSec2.m_SectionName.Format(L"%d",iPos);
		pCashIni->AddPair(L"deal_time",pCash->deal_time,tmpSec2.m_SectionName);
		pCashIni->AddPair(L"deal_type",pCash->deal_type,tmpSec2.m_SectionName);
		tmpStr.Format(L"%d",pCash->deal_money);
		pCashIni->AddPair(L"deal_money",tmpStr,tmpSec2.m_SectionName);
		pCashIni->AddPair(L"deal_inout",pCash->deal_inout,tmpSec2.m_SectionName);
		pCashIni->Store();
		ReadIni(m_strCashName);
	
	
	}
	
	if(pCash)
		delete pCash;
	
}
void CCashDlg::OnDelete()
{
	CString tmpStr;
	POSITION	pos;
	pos = m_ctrCashList.GetFirstSelectedItemPosition();
	
	int Select= m_ctrCashList.GetNextSelectedItem(pos);
	//如果双击空白处
	if(Select==-1)
		return;
	
	
	if(::MessageBox(NULL,L"确定删除?",L"警告!",MB_OKCANCEL) != IDOK )
		return ;

	//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strCashName+".ini";

	tmpStr =m_strCashName+".ini";
	pCashIni = new CIniReader(tmpStr);
	
	if(! pCashIni->Load())
	{
		::AfxMessageBox(L"Can not load ini");
		delete pCashIni;
		pCashIni = NULL;
		return ;
	}
	
	if(! pCashIni->Parse())
	{
		::AfxMessageBox(L"Invalid format ini");
		delete pCashIni;
		pCashIni = NULL;
		return ;
	}
	for(int i=1;i<pCashIni->m_Sections.GetSize();i++)
	{
		CString value;
		pCashIni->m_Sections[i].m_item.Lookup(L"deal_time",value);
		if(value==m_ctrCashList.GetItemText(Select,0))
		{
			pCashIni->m_Sections.RemoveAt(i);
			if(i<m_iCount) //不是删除最后一项
			{
				CString tmp;
				//AfxMessageBox(L"不是删除最后一项");
				for(int j=i;j<m_iCount+1;j++)
				{
					tmp.Format(L"%d",j-1);
					pCashIni->m_Sections[j].m_SectionName = tmp;
				}
			}
			//else
			//	AfxMessageBox(L"删除最后一项");
			m_iCount--;
		}
		
	}

	tmpStr.Format(L"%d",m_iCount);
	pCashIni->AddPair(L"deal_count",tmpStr,L"Info"); //将帐户数自减1
	pCashIni->Store();
	
	ReadIni(m_strCashName);
	
	
}

BOOL CCashDlg::EqualSection(CSection *pSec, CCash *pCash)
{
	POSITION pos = pSec->m_item.GetStartPosition();
	CString  time ,money,type,inout;
	while( pos != NULL)
	{
		String key;
		String value;
		
		pSec->m_item.GetNextAssoc(pos, key, value);
		if(key == "deal_time")
			time = value;
		else if(key == "deal_type")
			type = value;
		else if(key == "deal_money")
			money = value;
		else if(key == "deal_inout")
			inout = value;
		
	}
	CString tmpStr;
	tmpStr.Format(L"%d",pCash->deal_money);
	if((time == pCash->deal_time)&&(type == pCash->deal_type))
		return true;
	else 
		return false;
}

⌨️ 快捷键说明

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