assetdlg.cpp
来自「该项目是为PPC(PocketPc)使用者提供方便的理财事务.如,现金的借贷,债」· C++ 代码 · 共 526 行
CPP
526 行
// AssetDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MoneyAnyWhere.h"
#include "AssetDlg.h"
#include "Asset.h"
#include "AssetDetailDlg.h"
#include "NewAssetDealDlg.h"
#include "AssetModifyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAssetDlg dialog
CAssetDlg::CAssetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAssetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAssetDlg)
//}}AFX_DATA_INIT
m_strAssetName = L"资产与债务中心";
g_strMoneyType=L"人民币"; //默认是RMB
g_strBeginDate=L"2004-01-01"; //默认是2005-01-01
g_strLastDate=L"2005-02-23"; //默认是2005-01-01
g_iBeginSum=0; //开户金额
g_iSumOut=0;
g_iSumIn=0;
g_iLeft=0;
}
void CAssetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAssetDlg)
DDX_Control(pDX, IDC_BTNASSETOPERATEMENU, m_btnAssetoper);
DDX_Control(pDX, IDC_LIST_ASSET, m_ctrAssetList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAssetDlg, CDialog)
//{{AFX_MSG_MAP(CAssetDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BTNASSETDETAIL, OnBtnassetdetail)
ON_COMMAND(ID_MENUBTN_ADDASSET, OnAdd)
ON_COMMAND(ID_MENUBTN_MODIFYASSET, OnModifyasset)
ON_COMMAND(ID_MENUBTN_DELASSET, OnDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAssetDlg message handlers
BOOL CAssetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
g_iBeginSum = 0;
g_iSumOut=0;
g_iSumIn=0;
g_iLeft=0;
m_btnAssetoper.SetMenu(IDR_MENUBTN_ASSET, m_hWnd);
m_btnAssetoper.SetFlat(FALSE);
//改变列表的背景色
m_ctrAssetList.SetBkColor(COLORREF(RGB(251,251,249)));
m_ctrAssetList.SetExtendedStyle(LVS_EX_FULLROWSELECT);//|LVS_EX_GRIDLINES);
//设置表头格式为Account/Name/Date
m_ctrAssetList.SetHeadings(_T("借款日期,48;对象,48;借入/借出,48;金额,48;还款日期,48"));
//宽度设置
m_ctrAssetList.SetColumnWidth(0,60);
m_ctrAssetList.SetColumnWidth(1,40);
m_ctrAssetList.SetColumnWidth(2,40);
m_ctrAssetList.SetColumnWidth(3,50);
m_ctrAssetList.SetColumnWidth(4,50);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAssetDlg::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_strAssetName,CRect(0,0,100,20),NULL);
CString str;
str.Format(L"帐户类型:(%s)债权债务",g_strMoneyType);
dc.DrawText(str,CRect(0,160,140,180),NULL);
str.Format(L"合计借入:%d",g_iSumIn);
dc.DrawText(str,CRect(0,180,140,200),NULL);
str.Format(L"合计借出:%d",g_iSumOut);
dc.DrawText(str,CRect(0,200,140,220),NULL);
str.Format(L"帐户余额:%d",g_iLeft);
dc.DrawText(str,CRect(140,200,240,220),NULL);
// Do not call CDialog::OnPaint() for painting messages
}
BOOL CAssetDlg::ReadIni(CString file)
{
g_iBeginSum = 0;
g_iSumOut=0;
g_iSumIn=0;
g_iLeft=0;
m_strAssetName = file ;
m_ctrAssetList.DeleteAllItems();
file +=".ini";
//file = "\\Program Files\\理财能手\\Data\\"+file;
pAssetIni = new CIniReader(file);
pAssetInfo = new CIniReader(file);
//装载和解析INI文件
if(! pAssetInfo->Load())
{
::AfxMessageBox(L"Can not load ini");
delete pAssetInfo;
pAssetInfo = NULL;
return FALSE;
}
if(! pAssetInfo->Parse())
{
::AfxMessageBox(L"Invalid format ");
delete pAssetInfo;
pAssetInfo = NULL;
return FALSE;
}
CSection AssetInfo= (*pAssetInfo)[L"Info"];
POSITION _pos = AssetInfo.m_item.GetStartPosition();
while( _pos != NULL)
{
String _key;
String _value;
AssetInfo.m_item.GetNextAssoc(_pos, _key, _value);
if((CString)_key==(CString)"deal_count") //获得该现金帐户一共有多少笔交易
{
m_iCount = _wtoi(_value);
}
if((CString)_key==(CString)"money_type")//获得该现金帐户的币种
{
g_strMoneyType =(CString)(_value);
}
if((CString)_key==(CString)"amount")//获得该现金帐户的开户金额
{
g_iBeginSum =_wtoi(_value);
}
if((CString)_key==(CString)"date")//获得该现金帐户的开户日期
{
g_strBeginDate =(CString)(_value);
}
}
////////////////////////////////////////////////////////////////////
//装载和解析INI文件
if(! pAssetIni->Load())
{
::AfxMessageBox(L"Can not load ini");
delete pAssetIni;
pAssetIni = NULL;
return FALSE;
}
if(! pAssetIni->Parse())
{
::AfxMessageBox(L"Invalid format ");
delete pAssetIni;
pAssetIni = NULL;
return FALSE;
}
//AfxMessageBox(pAccountIni->GetFilePath());
for(int i=0;i<m_iCount;i++)
{
CString str;
str.Format(L"%d",i);
CSection Info= (*pAssetIni)[str];
POSITION pos = Info.m_item.GetStartPosition();
m_pCAsset[i] = new CAsset();
while( pos != NULL)
{
String key;
String value;
// Get key ( string ) and value ( string )
Info.m_item.GetNextAssoc(pos, key, value);
//AfxMessageBox((CString)key);
SetAsset((CString)key,(CString)value,i);
}
if(m_pCAsset[i]->deal_inout=="out")
{
int amount=m_pCAsset[i]->deal_money;
g_iSumOut +=amount;
}
else
{
int amount=m_pCAsset[i]->deal_money;
g_iSumIn +=amount;
}
//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_pCAsset[i]->deal_inout=="out")
{
strInout = "借出";
int amount=m_pCAsset[i]->deal_money;
strTmp.Format(L"%d",amount);
m_pCAsset[i]->deal_money = 0 - m_pCAsset[i]->deal_money;
}
else
{
strInout = "借入";
int amount=m_pCAsset[i]->deal_money;
strTmp.Format(L"%d",amount);
//m_pCAsset[i]->deal_money = "+"+strTmp;
}
CString tmpStr;
tmpStr.Format(L"%d",m_pCAsset[i]->deal_money);
m_ctrAssetList.AddItem(m_pCAsset[i]->deal_time,m_pCAsset[i]->deal_withwho,strInout,tmpStr,m_pCAsset[i]->deal_backtime);
}
g_iLeft = g_iBeginSum + g_iSumIn - g_iSumOut;
return true;
}
void CAssetDlg::SetAsset(CString key,CString value,int i)
{
if(key=="deal_time")
m_pCAsset[i]->deal_time = value;
else
if(key=="deal_withwho")
m_pCAsset[i]->deal_withwho = value;
else
if(key=="deal_money")
m_pCAsset[i]->deal_money= _wtoi(value);
else
if(key=="deal_inout")
m_pCAsset[i]->deal_inout = value;
else
if(key == "deal_backtime")
m_pCAsset[i]->deal_backtime = value;
}
void CAssetDlg::OnBtnassetdetail()
{
// TODO: Add your control notification handler code here
CString strTmpAmout;
strTmpAmout.Format(L"%d",g_iLeft);
CAssetDetailDlg dlg(this);
dlg.m_strAssetType = g_strMoneyType;
dlg.m_strAssetLastDealDate = g_strLastDate;
dlg.m_strAssetName = m_strAssetName;
dlg.m_strLeftAmount = strTmpAmout;
dlg.m_strAssetDate = g_strBeginDate;
dlg.DoModal();
}
void CAssetDlg::OnAdd()
{
CString str,str2;
CString tmpStr;
CSection tmpSec,tmpSec2;
CAsset *pAsset = new CAsset();
CNewAssetDealDlg DealDlg(this) ;
DealDlg.m_strDealAccount = m_strAssetName;
if( DealDlg.DoModal() == IDOK )
{
pAsset->deal_money = DealDlg.m_iDealMoney;
pAsset->deal_inout = DealDlg.m_strInOrOut;
//pCash->Account_Type = DealDlg.m_strCategory;
pAsset->deal_time = DealDlg.m_strDealTime ;
pAsset->deal_withwho = DealDlg.m_strDealTarget;
pAsset->deal_backtime = DealDlg.m_strBackDealTime;
//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strAssetName+".ini";
tmpStr =m_strAssetName+".ini";
pAssetIni = new CIniReader(tmpStr);
if(! pAssetIni->Load())
{
::AfxMessageBox(L"Can not load ini");
delete pAssetIni;
pAssetIni = NULL;
return ;
}
if(! pAssetIni->Parse())
{
::AfxMessageBox(L"Invalid format ");
delete pAssetIni;
pAssetIni = NULL;
return ;
}
//向文件中增加信息:
tmpSec2.m_SectionName.Format(L"%d",m_iCount);
m_iCount++;
tmpStr.Format(L"%d",m_iCount);
pAssetIni->AddPair(L"deal_count",tmpStr,L"Info"); //将帐户数自增1
pAssetIni->AddPair(L"deal_time",pAsset->deal_time,tmpSec2.m_SectionName);
pAssetIni->AddPair(L"deal_withwho",pAsset->deal_withwho,tmpSec2.m_SectionName);
tmpStr.Format(L"%d",pAsset->deal_money);
pAssetIni->AddPair(L"deal_money",tmpStr,tmpSec2.m_SectionName);
pAssetIni->AddPair(L"deal_inout",pAsset->deal_inout,tmpSec2.m_SectionName);
pAssetIni->AddPair(L"deal_backtime",pAsset->deal_backtime,tmpSec2.m_SectionName);
pAssetIni->Store();
ReadIni(m_strAssetName);
}
if(pAsset)
delete pAsset;
}
void CAssetDlg::OnModifyasset()
{
CString str,str2;
int iPos = -1;
CString tmpStr;
CSection tmpSec,tmpSec2;
POSITION pos;
pos = m_ctrAssetList.GetFirstSelectedItemPosition();
int Select= m_ctrAssetList.GetNextSelectedItem(pos);
//如果双击空白处
if(Select==-1)
return;
CAssetModifyDlg DealModifyDlg(this) ;
CAsset *pAsset = new CAsset();
DealModifyDlg.m_strAccountName = m_strAssetName ;
DealModifyDlg.m_strTime = m_ctrAssetList.GetItemText(Select,0);
DealModifyDlg.m_strTarget = m_ctrAssetList.GetItemText(Select,1);
//DealModifyDlg.m_strCategory = m_ctrAssetList.GetItemText(Select,2);
DealModifyDlg.m_strBackTime = m_ctrAssetList.GetItemText(Select,4);
if( m_ctrAssetList.GetItemText(Select,2) == "借入")
DealModifyDlg.m_strInOrOut = "in";
else
DealModifyDlg.m_strInOrOut = "out";
DealModifyDlg.m_iAmount = _wtoi(m_ctrAssetList.GetItemText(Select,3));
//显示修改对话框,并处理
if( DealModifyDlg.DoModal() == IDOK )
{
pAsset->deal_money = DealModifyDlg.m_iAmount;
pAsset->deal_inout = DealModifyDlg.m_strInOrOut ;
pAsset->deal_withwho = DealModifyDlg.m_strTarget;
pAsset->deal_time = DealModifyDlg.m_strTime ;
pAsset->deal_backtime = DealModifyDlg.m_strBackTime;
//初始化INI,读!!
//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strAssetName+".ini";
tmpStr =m_strAssetName+".ini";
pAssetIni = new CIniReader(tmpStr);
if(! pAssetIni->Load())
{
::AfxMessageBox(L"Can not load ini");
delete pAssetIni;
pAssetIni = NULL;
return ;
}
if(! pAssetIni->Parse())
{
::AfxMessageBox(L"Invalid format ini");
delete pAssetIni;
pAssetIni = NULL;
return ;
}
for(int i=0;i<m_iCount;i++)
{
CString str;
str.Format(L"%d",i);
CSection Info= (*pAssetIni)[str];
POSITION pos = Info.m_item.GetStartPosition();
BOOL btime ,bmoney,btarget,binout,bbacktime;
while( pos != NULL)
{
String key;
String value;
Info.m_item.GetNextAssoc(pos, key, value);
if(key == "deal_time" && value == pAsset->deal_time)
btime = true;
else if(key == "deal_withwho" && value == pAsset->deal_withwho)
btarget = true;
else if(key == "deal_money" && value == pAsset->deal_money)
bmoney = true;
else if(key == "deal_inout" && value == pAsset->deal_inout)
binout = true;
else if(key == "deal_backtime" && value == pAsset->deal_backtime)
bbacktime = true;
}
if(btime&&bmoney&&btarget&&binout&&bbacktime)
iPos = i;
}
if(iPos == -1)
{
AfxMessageBox(L"修改失败");
return ;
}
//向文件中增加信息:
tmpSec2.m_SectionName.Format(L"%d",iPos);
pAssetIni->AddPair(L"deal_time",pAsset->deal_time,tmpSec2.m_SectionName);
pAssetIni->AddPair(L"deal_withwho",pAsset->deal_withwho,tmpSec2.m_SectionName);
tmpStr.Format(L"%d",pAsset->deal_money);
pAssetIni->AddPair(L"deal_money",tmpStr,tmpSec2.m_SectionName);
pAssetIni->AddPair(L"deal_inout",pAsset->deal_inout,tmpSec2.m_SectionName);
pAssetIni->AddPair(L"deal_backtime",pAsset->deal_backtime,tmpSec2.m_SectionName);
pAssetIni->Store();
ReadIni(m_strAssetName);
}
if(pAsset)
delete pAsset;
}
void CAssetDlg::OnDelete()
{
CString tmpStr;
POSITION pos;
pos = m_ctrAssetList.GetFirstSelectedItemPosition();
int Select= m_ctrAssetList.GetNextSelectedItem(pos);
//如果双击空白处
if(Select==-1)
return;
if(::MessageBox(NULL,L"确定删除?",L"警告!",MB_OKCANCEL) != IDOK )
return ;
//tmpStr ="\\Program Files\\理财能手\\Data\\"+m_strAssetName+".ini";
tmpStr =m_strAssetName+".ini";
pAssetIni = new CIniReader(tmpStr);
if(! pAssetIni->Load())
{
::AfxMessageBox(L"Can not load ini");
delete pAssetIni;
pAssetIni = NULL;
return ;
}
if(! pAssetIni->Parse())
{
::AfxMessageBox(L"Invalid format ini");
delete pAssetIni;
pAssetIni = NULL;
return ;
}
for(int i=1;i<pAssetIni->m_Sections.GetSize();i++)
{
CString value;
pAssetIni->m_Sections[i].m_item.Lookup(L"deal_time",value);
if(value==m_ctrAssetList.GetItemText(Select,0))
{
pAssetIni->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);
pAssetIni->m_Sections[j].m_SectionName = tmp;
}
}
//else
// AfxMessageBox(L"删除最后一项");
m_iCount--;
}
}
tmpStr.Format(L"%d",m_iCount);
pAssetIni->AddPair(L"deal_count",tmpStr,L"Info"); //将帐户数自减1
pAssetIni->Store();
ReadIni(m_strAssetName);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?