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

📄 goodsdlg.cpp

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

#include "stdafx.h"
#include "MoneyAnyWhere.h"
#include "GoodsDlg.h"
#include "GoodsAddDlg.h"
#include "GoodsDetailDlg.h"
#include "CashDlg.h"
#include "GoodsModifyDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGoodsDlg dialog


CGoodsDlg::CGoodsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGoodsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGoodsDlg)
	// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_strGoodsAccountName = L"物品帐户";
	m_strMoneyType=L"人民币";  //默认是RMB
	m_strBeginDate=L"2004-02-01";  //默认是2005-01-01
	m_strLastDate=L"2005-03-17";  //默认是2005-01-01
	
	m_iBeginSum=0; //开户金额
	m_iSumOut=0;
	m_iSumIn=0;
	m_iLeft=0;
}


void CGoodsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGoodsDlg)
	// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Control(pDX, IDC_LIST_GOODSALL, m_ctrAllGoodsList);
	DDX_Control(pDX, IDC_BTN_GOODSOPERATEMENU, m_btnGoodsOperateMenu);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGoodsDlg, CDialog)
//{{AFX_MSG_MAP(CGoodsDlg)
ON_WM_PAINT()
ON_COMMAND(ID_MENUITEM_GOODSADD, OnMenuitemGoodsadd)
ON_COMMAND(ID_MENUITEM_GOODSDEL, OnMenuitemGoodsdel)
ON_COMMAND(ID_MENUITEM_GOODSMODIFY, OnMenuitemGoodsmodify)
ON_BN_CLICKED(IDC_BTN_GOODSDETAIL, OnBtnGoodsdetail)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGoodsDlg message handlers

BOOL CGoodsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_btnGoodsOperateMenu.SetMenu(IDR_MENUBAR_GOODSOPER, m_hWnd);
	m_btnGoodsOperateMenu.SetFlat(FALSE);
	
	//改变列表的背景色
	m_ctrAllGoodsList.SetBkColor(COLORREF(RGB(251,251,249)));
	m_ctrAllGoodsList.SetExtendedStyle(LVS_EX_FULLROWSELECT);//|LVS_EX_GRIDLINES);
	//设置表头格式为Account/Name/Date
	m_ctrAllGoodsList.SetHeadings(_T("日期,48;物品,48;数量,48;价格,48;金额,48"));
	//宽度设置
	m_ctrAllGoodsList.SetColumnWidth(0,60);
	m_ctrAllGoodsList.SetColumnWidth(1,40);
	m_ctrAllGoodsList.SetColumnWidth(2,50);
	m_ctrAllGoodsList.SetColumnWidth(3,60);
	m_ctrAllGoodsList.SetColumnWidth(4,30);
	
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CGoodsDlg::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_strGoodsAccountName,CRect(0,0,100,20),NULL);
	CString	str;
	str.Format(L"帐户类型:(%s)物品",m_strMoneyType);
	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);
	
	// TODO: Add your message handler code here
	
	// Do not call CDialog::OnPaint() for painting messages
}

BOOL CGoodsDlg::ReadIni(CString filename)
{
	m_iBeginSum = 0;
	m_iSumOut=0;
	m_iSumIn=0;
	m_iLeft=0;

	m_strGoodsName = filename ;
	m_ctrAllGoodsList.DeleteAllItems();
	filename +=".ini";

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

	pGoodsIni = new CIniReader(filename);
	pGoodsInfo = new CIniReader(filename);
	//装载和解析INI文件
	if(! pGoodsInfo->Load())
	{
		::AfxMessageBox(L"Can not load ini");
		delete pGoodsInfo;
		pGoodsInfo = NULL;
		return FALSE;
	}
	
	if(! pGoodsInfo->Parse())
	{
		::AfxMessageBox(L"Invalid format  ");
		delete pGoodsInfo;
		pGoodsInfo = NULL;
		return FALSE;
	}
	CSection	GoodsInfo= (*pGoodsInfo)[L"Info"];

	POSITION _pos = GoodsInfo.m_item.GetStartPosition();

	while( _pos != NULL)
	{
		String _key;
		String _value;

		GoodsInfo.m_item.GetNextAssoc(_pos, _key, _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(! pGoodsIni->Load())
	{
		::AfxMessageBox(L"Can not load ini");
		delete pGoodsIni;
		pGoodsIni = NULL;
		return FALSE;
	}
	
	if(! pGoodsIni->Parse())
	{
		::AfxMessageBox(L"Invalid format  ");
		delete pGoodsIni;
		pGoodsIni = NULL;
		return FALSE;
	}
	//AfxMessageBox(pAccountIni->GetFilePath());
	
	for(int i=0;i<m_iCount;i++)
	{
		CString	str;
		str.Format(L"%d",i);
		CSection	Info= (*pGoodsIni)[str];
		
		POSITION pos = Info.m_item.GetStartPosition();
		m_pGoods[i] = new CGoods();
		while( pos != NULL)
		{
			String key;
			String value;
			
			// Get key ( string ) and value ( string )
			Info.m_item.GetNextAssoc(pos, key, value);
			//AfxMessageBox((CString)key);
			SetGoods((CString)key,(CString)value,i);
			
		}
	
	//判断出入
	if((m_pGoods[i]->m_GoodsValue.GetAt(0))=='-')
		{
			m_iSumIn +=_wtoi(m_pGoods[i]->m_GoodsValue);
		}
	else
		m_iSumOut +=_wtoi(m_pGoods[i]->m_GoodsValue);
	}	

	for(i=0;i<m_iCount;i++)
	{
		m_ctrAllGoodsList.AddItem(m_pGoods[i]->m_GoodsDate,m_pGoods[i]->m_GoodsName,m_pGoods[i]->m_GoodsNum,m_pGoods[i]->m_GoodsPrice,m_pGoods[i]->m_GoodsValue);
	}
	
	m_iLeft = m_iBeginSum + m_iSumIn - m_iSumOut;
	return TRUE;
}

void CGoodsDlg::SetGoods(String key, CString value, int i)
{
	
	if(key=="GoodsDate")
		m_pGoods[i]->m_GoodsDate = value;
	else
		if(key=="GoodsName")
			m_pGoods[i]->m_GoodsName  = value;
		else
			if(key=="GoodsNum")
				m_pGoods[i]->m_GoodsNum = value;
			else
				if(key=="GoodsPrice")
					m_pGoods[i]->m_GoodsPrice  = value;
				else
					if(key == "GoodsValue")
						m_pGoods[i]->m_GoodsValue  = value;
}

void CGoodsDlg::OnMenuitemGoodsadd() 
{
	CString	str,str2;
	CString	tmpStr;
	CSection tmpSec,tmpSec2;
	CGoods	*pGoods = new CGoods();
	CGoodsAddDlg goodsAddDlg(this);

	//goodsAddDlg.m_strDealAccount = m_strAssetName;
	if(goodsAddDlg.DoModal() == IDOK)
	{
		
		pGoods->m_GoodsDate= goodsAddDlg.m_strGoodsAddDate;
		pGoods->m_GoodsName= goodsAddDlg.m_strGoodsAddName;
		pGoods->m_GoodsNum =goodsAddDlg.m_strGoodsAddNum;
		pGoods->m_GoodsPrice = goodsAddDlg.m_strGoodsAddPrice;
		pGoods->m_GoodsValue = goodsAddDlg.m_strGoodsAddValue;
		
		//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strAssetName+".ini";

		tmpStr =m_strGoodsAccountName+".ini";
		pGoodsIni = new CIniReader(tmpStr);
		
		if(! pGoodsIni->Load())
		{
			::AfxMessageBox(L"Can not load ini");
			delete pGoodsIni;
			pGoodsIni = NULL;
			return ;
		}
		
		if(! pGoodsIni->Parse())
		{
			::AfxMessageBox(L"Invalid format  ");
			delete pGoodsIni;
			pGoodsIni = NULL;
			return ;
		}
		//向文件中增加信息:
		tmpSec2.m_SectionName.Format(L"%d",m_iCount);
		m_iCount++;
		tmpStr.Format(L"%d",m_iCount);
		pGoodsIni->AddPair(L"deal_count",tmpStr,L"Info"); //将帐户数自增1
		pGoodsIni->AddPair(L"GoodsDate",pGoods->m_GoodsDate,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsName",pGoods->m_GoodsName,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsNum",pGoods->m_GoodsNum,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsPrice",pGoods->m_GoodsPrice,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsValue",pGoods->m_GoodsValue,tmpSec2.m_SectionName);
		pGoodsIni->Store();
		ReadIni(m_strGoodsAccountName);
	}
	if(pGoods)
		delete pGoods;

}

void CGoodsDlg::OnMenuitemGoodsdel() 
{
	CString tmpStr;	
	POSITION	pos;
	pos = m_ctrAllGoodsList.GetFirstSelectedItemPosition();
	
	int Select= m_ctrAllGoodsList.GetNextSelectedItem(pos);
	//如果双击空白处
	if(Select==-1)
		return;
	
	
	if(::MessageBox(NULL,L"确定删除?",L"警告!",MB_OKCANCEL) != IDOK )
		return ;

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

	tmpStr =m_strGoodsAccountName+".ini";
	pGoodsIni = new CIniReader(tmpStr);
	
	if(! pGoodsIni->Load())
	{
		::AfxMessageBox(L"Can not load ini");
		delete pGoodsIni;
		pGoodsIni = NULL;
		return ;
	}
	
	if(! pGoodsIni->Parse())
	{
		::AfxMessageBox(L"Invalid format ini");
		delete pGoodsIni;
		pGoodsIni = NULL;
		return ;
	}
	for(int i=1;i<pGoodsIni->m_Sections.GetSize();i++)
	{
		CString value;
		pGoodsIni->m_Sections[i].m_item.Lookup(L"GoodsDate",value);
		if(value==m_ctrAllGoodsList.GetItemText(Select,0))
		{
			pGoodsIni->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);
					pGoodsIni->m_Sections[j].m_SectionName = tmp;
				}
			}
			//else
			//	AfxMessageBox(L"删除最后一项");
			m_iCount--;
		}
		
	}

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

/*void CGoodsDlg::OnMenuitemGoodslkfor() 
{
// TODO: Add your command handler code here

}*/

/**/

void CGoodsDlg::OnMenuitemGoodsmodify() 
{
	// TODO: Add your command handler code here
	CString	str,str2;
	int iPos = -1;
	CString	tmpStr;
	CSection tmpSec,tmpSec2;
	
	POSITION	pos;
	pos = m_ctrAllGoodsList.GetFirstSelectedItemPosition();
	
	int Select= m_ctrAllGoodsList.GetNextSelectedItem(pos);
	//如果双击空白处
	if(Select==-1)
		return;
	CGoodsModifyDlg goodsModifyDlg(this) ;
	CGoods	*pGoods = new CGoods();
	goodsModifyDlg.m_strGoodsMName = m_ctrAllGoodsList.GetItemText(Select,1);
	goodsModifyDlg.m_strGoodsMDate = m_ctrAllGoodsList.GetItemText(Select,0);
	
	if( goodsModifyDlg.DoModal() == IDOK )
	{
		pGoods->m_GoodsValue = goodsModifyDlg.m_strGoodsMValue;
		pGoods->m_GoodsNum = goodsModifyDlg.m_strGoodsMNum ;
		pGoods->m_GoodsPrice = goodsModifyDlg.m_strGoodsMPrice ;
		
		pGoodsIni = new CIniReader(m_strGoodsAccountName+".ini");
		
		if(! pGoodsIni->Load())
		{
			::AfxMessageBox(L"Can not load ini");
			delete pGoodsIni;
			pGoodsIni = NULL;
			return ;
		}
		
		if(! pGoodsIni->Parse())
		{
			::AfxMessageBox(L"Invalid format ini ");
			delete pGoodsIni;
			pGoodsIni = NULL;
			return ;
		}
		for(int i=0;i<m_iCount;i++)
		{
			CString	str;
			str.Format(L"%d",i);
			CSection	Info= (*pGoodsIni)[str];
			if(EqualSection(Info,pGoods))
			{
				iPos = i;
			}
		}
		if(iPos == -1)
		{
			AfxMessageBox(L"修改失败");
			return ;
		}
		//向文件中增加信息:
		
		tmpSec2.m_SectionName.Format(L"%d",iPos);
		
		pGoodsIni->AddPair(L"GoodsDate",pGoods->m_GoodsDate,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsName",pGoods->m_GoodsName,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsNum",pGoods->m_GoodsNum,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsPrice",pGoods->m_GoodsPrice,tmpSec2.m_SectionName);
		pGoodsIni->AddPair(L"GoodsValue",pGoods->m_GoodsValue,tmpSec2.m_SectionName);
		pGoodsIni->Store();
		ReadIni(m_strGoodsAccountName);		
	}
	
	if(pGoods)
		delete pGoods;
}

void CGoodsDlg::OnBtnGoodsdetail() 
{
	// TODO: Add your control notification handler code here
	CString strTmpAmout;
	strTmpAmout.Format(L"%d",m_iLeft);
	CGoodsDetailDlg goodsDetailDlg(this);
	goodsDetailDlg.m_strGoodsDetailType = m_strMoneyType; 
	goodsDetailDlg.m_strGoodsLastDate = m_strLastDate;
	goodsDetailDlg.m_strGoodsDetailName = m_strGoodsAccountName;
	goodsDetailDlg.m_strGoodsDetailLeft = strTmpAmout;
	goodsDetailDlg.m_strGoodsDetailDate = m_strBeginDate;
	goodsDetailDlg.DoModal();
	
}

BOOL CGoodsDlg::EqualSection(CSection sec, CGoods *pGoods)
{
	POSITION pos = sec.m_item.GetStartPosition();
	CString  date,name,number,price,amount;
	while( pos != NULL)
	{
		String key;
		String value;
		
		sec.m_item.GetNextAssoc(pos, key, value);
		if(key == "m_strGoodsDate")
			date = value;
		else if(key == "m_strGoodsName")
			name = value;
		else if(key == "m_strGoodsNum")
			number = value;
		else if(key == "m_strGoodsPrice")
			price = value;
		else if(key == "m_strGoodsValue")
			amount = value;
		
	}
	CString tmpStr;
	tmpStr.Format(L"%d",pGoods->m_GoodsValue);
	if((date == pGoods->m_GoodsDate)&&(name == pGoods->m_GoodsName)&&(amount == tmpStr))
		return true;
	else 
		return false;
}

⌨️ 快捷键说明

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