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

📄 moneybook.cpp

📁 理财小工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		AddMoneyRec(pdate, acount, memo, oldNode);	}#if 0	wxString temp(wxConvCurrent->cWX2WC(memo.mb_str()),wxConvUTF8);	xmlSetProp(oldNode->xmlNode, (const xmlChar*)"Acount", (const xmlChar*)wxString::Format("%.2f",acount).mb_str());	xmlSetProp(oldNode->xmlNode, (const xmlChar*)"Date", (const xmlChar*)pdate->FormatISODate().c_str());	xmlNodeSetContent(oldNode->xmlNode, (const xmlChar*)temp.mb_str());	savetofile();#endif	return TRUE;}xmlNodePtr MoneyBook::GetRecsFolder(xmlNodePtr parent){	xmlChar *xpath = GetNodeXPath(parent);	xmlChar nF[200]="//MoneyRecs";	xpath = xmlStrcat(xpath, nF);	xmlNodeSetPtr nodeset;	xmlXPathObjectPtr result;		result = getnodeset (doc, xpath);	if (result) {		nodeset = result->nodesetval;		return nodeset->nodeTab[0];		}	xmlXPathFreeObject (result);	xmlFree(xpath);		return NULL;}bool MoneyBook::GetHousePay(wxDouble *TotalCnt, wxDouble *MonthRate, long *terms, wxDateTime *startdate, long *PayMethod){	if (HouseFeeNode == NULL)	{		return FALSE;	}	xmlChar *TotalCntStr,*MonthRateStr,*termsStr,*startdateStr, *payMethodStr;	TotalCntStr = xmlGetProp(HouseFeeNode, (const xmlChar *)"TotalCnt");	MonthRateStr = xmlGetProp(HouseFeeNode, (const xmlChar *)"MonthRate");	termsStr = xmlGetProp(HouseFeeNode, (const xmlChar *)"Terms");	startdateStr = xmlGetProp(HouseFeeNode, (const xmlChar *)"StartDate");	payMethodStr = xmlGetProp(HouseFeeNode, (const xmlChar *)"PayMethod");	wxString temp((const char *)TotalCntStr);	temp.ToDouble(TotalCnt);	temp.assign((const char *)MonthRateStr);	temp.ToDouble(MonthRate);	temp.assign((const char *)termsStr);	temp.ToLong(terms,10);	temp.assign((const char *)payMethodStr);	temp.ToLong(PayMethod,10);	startdate->ParseDate((const char *)startdateStr);	xmlFree(TotalCntStr);	xmlFree(MonthRateStr);	xmlFree(termsStr);	xmlFree(startdateStr);	xmlFree(payMethodStr);		return TRUE;	}void MoneyBook::SetHousePay(wxDouble TotalCnt, wxDouble MonthRate, long terms, wxDateTime startdate, long PayMethod){	if (HouseFeeNode == NULL)	{		HouseFeeNode = xmlNewTextChild(ContentInfo, NULL, (const xmlChar *)"HouseFee", NULL);	}	xmlSetProp(HouseFeeNode, (const xmlChar *)"TotalCnt", (const xmlChar *)wxString::Format("%.2f",TotalCnt).mb_str());	xmlSetProp(HouseFeeNode, (const xmlChar *)"MonthRate", (const xmlChar *)wxString::Format("%f",MonthRate).mb_str());	xmlSetProp(HouseFeeNode, (const xmlChar *)"Terms", (const xmlChar *)wxString::Format("%d",terms).mb_str());	xmlSetProp(HouseFeeNode, (const xmlChar *)"PayMethod", (const xmlChar *)wxString::Format("%d",PayMethod).mb_str());	xmlSetProp(HouseFeeNode, (const xmlChar *)"StartDate", (const xmlChar *)startdate.FormatISODate().c_str());	savetofile();}int MoneyBook::GetMonthCntForPayHouse(wxDouble TotalCnt, wxDouble MonthRate, long terms, wxDateTime startdate, long PayMethod,	wxDouble BaseACount, wxDouble PerMonth, long MaxMonth){	MonthRate /= 100;	wxDouble needpay,hascash;	int passedmonth = wxDateTime::Today().GetYear()*12+wxDateTime::Today().GetMonth()					- startdate.GetYear() * 12 - startdate.GetMonth();	if (PayMethod == 0)	{		wxDouble BaseLose = 0;		wxDouble PerMonthPay = GetHouseFeeSameCountPlusTax(TotalCnt, MonthRate,terms);		for (int i=0; i<MaxMonth;i++)		{			needpay = (TotalCnt - BaseLose) * (MonthRate + 1);			hascash	= BaseACount + (i - passedmonth + 1)*PerMonth;			if (needpay<=hascash)			{				return i;			}			else			{				BaseLose += PerMonthPay - ((TotalCnt - BaseLose)*MonthRate);			}		}	}	else	{		for (int i=0; i<MaxMonth;i++)		{			needpay = (TotalCnt - (TotalCnt / terms) * i) * (MonthRate + 1);			hascash	= BaseACount + (i - passedmonth + 1)*PerMonth;			if (needpay<=hascash)			{				return i;			}		}	}	return -1;}xmlNodePtr MoneyBook::GetMonthFolder(xmlNodePtr parent, wxDateTime *pdate){	xmlChar *xpath = GetNodeXPath(parent);	xmlChar nF[200]="";	if (xmlStrcmp(parent->name, (const xmlChar*)"MoneyRecs")==0)	{		xmlStrPrintf(nF, 200, (const xmlChar*)"F%04d%02d",pdate->GetYear(),pdate->GetMonth()+1);	}	else	{		xmlStrPrintf(nF, 200, (const xmlChar*)"MoneyRecs//F%04d%02d",pdate->GetYear(),pdate->GetMonth()+1);	}	xpath = xmlStrcat(xpath, (const xmlChar*)"//");	xpath = xmlStrcat(xpath, nF);	xmlNodeSetPtr nodeset;	xmlXPathObjectPtr result;	result = getnodeset (doc, xpath);	if (result) {		nodeset = result->nodesetval;		//xpath may be included by finalxpath		xmlChar* finalXppath = GetNodeXPath(nodeset->nodeTab[0]);		if (xmlStrcmp(finalXppath,xpath)==0)		{			xmlFree(finalXppath);			return nodeset->nodeTab[0];		}				xmlFree(finalXppath);		return NULL;	}	xmlXPathFreeObject (result);	xmlFree(xpath);		return NULL;}bool MoneyBook::AddTestRec(int years, int permonth){	//TODO	return FALSE;}void MoneyBook::UpdateTotalCount(xmlNodePtr MonthPtr, wxDouble acount, bool Increase){	wxDouble curcount;	wxString totalCnt;	xmlNodePtr fathernode = MonthPtr->parent;	fathernode = MonthPtr->parent;	while ((fathernode!=NULL)&&			(fathernode!=ContentInfo))	{		xmlChar* curcountstr = xmlGetProp(fathernode,(const xmlChar*)"Total");		if (curcountstr == NULL)		{			xmlNewProp(fathernode, (const xmlChar*)"Total", (const xmlChar*)"0");		}		curcountstr = xmlGetProp(fathernode,(const xmlChar*)"Total");		if (curcountstr == NULL)		{			return;		}		totalCnt.assign(curcountstr);		totalCnt.ToDouble(&curcount);		if (Increase)			curcount+=acount;		else			curcount-=acount;		xmlSetProp(fathernode,(const xmlChar*)"Total", (const xmlChar*)wxString::Format("%.2f",curcount).mb_str());		xmlFree(curcountstr);				fathernode = fathernode->parent;	}	}	bool MoneyBook::AddMoneyRec(wxDateTime *pdate, wxDouble acount, wxString memo, xmlnodeGNode* item){	wxTreeItemId treeitem = uiTree->GetSelection();	if (!treeitem.IsOk()) 	{		return FALSE;	}	xmlnodeTreeItemData* itemdata = (xmlnodeTreeItemData*)uiTree->GetItemData(treeitem);	if (itemdata==NULL) 	{		return FALSE;	}	xmlChar *nodeprop = xmlGetProp(itemdata->xmlNode, (const xmlChar*)"Type");	if ((xmlStrcmp(nodeprop,(const xmlChar*)"Folder"))!=0)	{		xmlFree(nodeprop);		return FALSE;	}	xmlFree(nodeprop);	xmlNodePtr nodeitem = GetMonthFolder(itemdata->xmlNode,pdate);	xmlChar nF[200]="";	xmlStrPrintf(nF, 200, (const xmlChar*)"F%04d%02d",pdate->GetYear(),pdate->GetMonth()+1);	if (nodeitem ==NULL)	{		nodeitem = GetRecsFolder(itemdata->xmlNode);		if (nodeitem==NULL) return FALSE;				nodeitem = xmlNewTextChild(nodeitem, NULL,nF,NULL);		xmlNewProp(nodeitem, (const xmlChar*)"Type", (const xmlChar*)"MonthFolder");		xmlChar str[100];		xmlStrPrintf(str, 100, (const xmlChar*)_("%04d-%02d"),pdate->GetYear(),pdate->GetMonth()+1);		wxString temp(wxConvCurrent->cWX2WC((const char*)str),wxConvUTF8);		xmlNewProp(nodeitem, (const xmlChar*)"Desc", str);	}	wxString temp(wxConvCurrent->cWX2WC(memo.mb_str()),wxConvUTF8);	nodeitem = xmlNewTextChild (nodeitem, NULL, (const xmlChar*)_T("Money"), (const xmlChar*)temp.mb_str());	xmlSetProp(nodeitem, (const xmlChar*)"Date", (const xmlChar*)pdate->FormatISODate().c_str());	xmlSetProp(nodeitem, (const xmlChar*)"Acount", (const xmlChar*)wxString::Format("%.2f",acount).mb_str());	item->xmlNode = nodeitem;	UpdateTotalCount(nodeitem,acount);		savetofile();	return TRUE;	}bool MoneyBook::CanBeDelete(wxTreeItemId id){	if (!id.IsOk())	{		return FALSE;	}	xmlnodeTreeItemData* itemdata = (xmlnodeTreeItemData*)uiTree->GetItemData(id);	if (itemdata != NULL)	{		if ((itemdata->xmlNode == InComingNode)||(itemdata->xmlNode == OutGoingNode)) return FALSE;		xmlChar *nodeprop = xmlGetProp(itemdata->xmlNode, (const xmlChar*)"Type");		if ((xmlStrcmp(nodeprop,(const xmlChar*)"Folder"))==0)		{			xmlFree(nodeprop);			return TRUE;		}		xmlFree(nodeprop);	}	return FALSE;}bool MoneyBook::IsFolderNode(wxTreeItemId id){	if (id.IsOk())	{		xmlnodeTreeItemData *nodedata = (xmlnodeTreeItemData *)uiTree->GetItemData(id);		if (nodedata!=NULL)		{			return !(xmlStrcmp(xmlGetProp(nodedata->xmlNode, (const xmlChar*)"Type"),(const xmlChar*)"Folder"));		}	}	return FALSE;}void MoneyBook::uiExpendAll(wxTreeItemId Id){	wxTreeItemId item;	long cookie=0;	uiTree->Expand(Id);	xmlnodeTreeItemData* itemdata  = (xmlnodeTreeItemData *)uiTree->GetItemData(Id);	if (NULL != itemdata) 	{		xmlChar *defaultnodename = xmlGetProp(ContentInfo,(const xmlChar*)"Default");		if (xmlStrcmp(defaultnodename, itemdata->xmlNode->name)==0)		{			uiTree->SelectItem(Id);		}		xmlFree(defaultnodename);	}		item = uiTree->GetFirstChild(Id,cookie);	while (item.IsOk())	{		uiExpendAll(item);		item = uiTree->GetNextChild(Id,cookie);	}}void MoneyBook::RecursionInitUi(wxTreeItemId *pId){	xmlNodePtr cur;	if (!pId->IsOk()) return;	xmlnodeTreeItemData* itemdata  = (xmlnodeTreeItemData *)uiTree->GetItemData(*pId);	if (NULL == itemdata) return;		cur = itemdata->xmlNode->xmlChildrenNode;	while (cur != NULL)	{		xmlChar*nodeprop = xmlGetProp(cur, (const xmlChar*)"Type");				if (xmlStrcmp(nodeprop,(const xmlChar*)"Folder")==0)		{			xmlChar *desc = xmlGetProp(cur, (const xmlChar*)"Desc");			wxString temp(wxConvUTF8.cMB2WC((const char*)desc),*wxConvCurrent);			wxTreeItemId treeitem = uiTree->AppendItem(*pId,temp.mb_str(),2, 2,				new xmlnodeTreeItemData(cur));			xmlFree(desc);#ifdef APPEND_TEST_DATA			uiTree->SelectItem(treeitem);			for (int i=2004;i<2034; i++)			{				for (int j=0;j<11; j++)				{					wxDateTime tmpdate= wxDateTime::Today();					tmpdate.SetYear(i);					tmpdate.SetMonth(j);					xmlnodeGNode *item = new xmlnodeGNode(NULL);					AddMoneyRec(&tmpdate, 20, (const xmlChar*)"test", item);					delete(item);				}			}#endif			RecursionInitUi(&treeitem);		}		xmlFree(nodeprop);		cur = cur->next;	}}wxDouble MoneyBook::GetTotalInComing(void){	xmlChar *total = xmlGetProp(InComingNode,(const xmlChar*)"Total");	if (total!=NULL)	{		wxString tmp(total);		xmlFree(total);		wxDouble tmpdb;		tmp.ToDouble(&tmpdb);		return tmpdb;	}	return 0;}wxDouble MoneyBook::GetTotalOutGoing(void){	xmlChar *total = xmlGetProp(OutGoingNode,(const xmlChar*)"Total");	if (total!=NULL)	{		wxString tmp(total);		xmlFree(total);		wxDouble tmpdb;		tmp.ToDouble(&tmpdb);		return tmpdb;	}	return 0;	}wxDouble MoneyBook::GetBaseInComing(void){	xmlChar *total = xmlGetProp(InComingNode,(const xmlChar*)"Base");	if (total!=NULL)	{		wxString tmp(total);		xmlFree(total);		wxDouble tmpdb;		tmp.ToDouble(&tmpdb);		return tmpdb;	}	return 0;}wxDouble MoneyBook::GetBaseOutGoing(void){	xmlChar *total = xmlGetProp(OutGoingNode,(const xmlChar*)"Base");	if (total!=NULL)	{		wxString tmp(total);		xmlFree(total);		wxDouble tmpdb;		tmp.ToDouble(&tmpdb);		return tmpdb;	}	return 0;	}wxDouble MoneyBook::GetHouseFeeSameCountPlusTax(wxDouble totalcnt,wxDouble monthrate,wxInt16 terms){	return totalcnt *(monthrate*pow((1+monthrate),terms))/(pow((1+monthrate),terms)-1);}wxDouble MoneyBook::GetHouseFeeSameCountOnly(wxDouble totalcnt,wxDouble monthrate,wxInt16 terms, int monthindex){	if ((monthindex<=0) || (monthindex>terms)) return 0;	return (totalcnt / terms) + (totalcnt - totalcnt / terms * (monthindex-1)) * (monthrate);}

⌨️ 快捷键说明

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