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

📄 moneybook.cpp

📁 理财小工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////////// File:        moneybook.cpp// Purpose:     xml data file proc// Maintainer:  wesley.wang// Created:     2004-04-02// RCS-ID:      $Id: moneybook.cpp,v 1.13 2004/04/25 13:54:17 wq1977 Exp $// Copyright:   (c) wesley.wang// Licence:     wxWindows licence////////////////////////////////////////////////////////////////////////////////wxString temp(wxConvUTF8.cMB2WC(UserInfo.UserName),*wxConvCurrent);//wxString temp(wxConvCurrent->cWX2WC("小莉莉"),wxConvUTF8);//----------------------------------------------------------------------------// information//----------------------------------------------------------------------------//----------------------------------------------------------------------------// headers//----------------------------------------------------------------------------// For compilers that support precompilation, includes <wx/wx.h>.#include <wx/wxprec.h>#ifdef __BORLANDC__    #pragma hdrstop#endif// for all others, include the necessary headers (this file is usually all you// need because it includes almost all 'standard' wxWindows headers)#ifndef WX_PRECOMP    #include <wx/wx.h>#endif#include <math.h>#include "moneybook.h"   //----------------------------------------------------------------------------// resources//----------------------------------------------------------------------------//============================================================================// declarations//============================================================================//============================================================================// implementation//============================================================================#include <wx/listimpl.cpp>WX_DEFINE_LIST(MoneytypeCountList);//----------------------------------------------------------------------------// moneybook//----------------------------------------------------------------------------MoneyBook::MoneyBook(const wxChar *sfilename, wxTreeCtrl *Tree){	xmlNodePtr cur;		UserInfo = NULL;	ContentInfo = NULL;	InComingNode = NULL;	OutGoingNode = NULL;	HouseFeeNode = NULL;	enableAutoSave = TRUE;	uiTree = Tree;	wxString temp(_("lilimoney"),*wxConvCurrent);	rootitem=uiTree->AddRoot(temp,2, 2,NULL);		filename.assign(sfilename);		doc = xmlParseFile(sfilename);	if (doc == NULL ) {		wxLogError(_("Document not parsed successfully. \n"));		return;	}	cur = xmlDocGetRootElement(doc);		if (cur == NULL) {		wxLogError(_("empty document\n"));		xmlFreeDoc(doc);		return;	}		if (xmlStrcmp(cur->name, (const xmlChar *) _T("lilimoney"))) {		wxLogError(_("document of the wrong type, root node != story"));		xmlFreeDoc(doc);		return;	}	cur = cur->xmlChildrenNode;	while (cur != NULL) {		if ((!xmlStrcmp(cur->name, (const xmlChar *)_T("User")))){			UserInfo = cur;		}		else if ((!xmlStrcmp(cur->name, (const xmlChar *)_T("body")))){			ContentInfo = cur;		}		if ((UserInfo != NULL) &&(ContentInfo != NULL))		{			break;		}	cur = cur->next;	}	cur = ContentInfo->xmlChildrenNode;	while (cur != NULL) {		if ((!xmlStrcmp(cur->name, (const xmlChar *)_T("InComing")))){			InComingNode = cur;			xmlSetProp(InComingNode,(const xmlChar*)"Type", (const xmlChar*)"Folder");			incomingitem = 	uiTree->AppendItem(rootitem,_("InComing"),2, 2,				new xmlnodeTreeItemData(InComingNode));			RecursionInitUi(&incomingitem);		}		else if ((!xmlStrcmp(cur->name, (const xmlChar *)_T("OutGoing")))){			OutGoingNode = cur;			xmlSetProp(OutGoingNode, (const xmlChar*)"Type", (const xmlChar*)"Folder");			outgoingitem = 	uiTree->AppendItem(rootitem,_("OutGoing"),2, 2,				new xmlnodeTreeItemData(OutGoingNode));			RecursionInitUi(&outgoingitem);		}		else if ((!xmlStrcmp(cur->name, (const xmlChar *)_T("HouseFee")))){			HouseFeeNode = cur;		}		if ((InComingNode != NULL) &&(OutGoingNode != NULL) &&(HouseFeeNode != NULL))		{			break;		}	cur = cur->next;	}}MoneyBook::~MoneyBook(){	if (doc != NULL)	{		xmlFreeDoc(doc);		xmlCleanupParser();	}}long MoneyBook::GetFolderIndex(void){	long ret=0;	if (ContentInfo == NULL)	{		return 0;	}	xmlChar *nodeprop = xmlGetProp(ContentInfo, (const xmlChar*)"Index");	if (nodeprop==NULL)	{		xmlNewProp(ContentInfo, (const xmlChar*)"Index", (const xmlChar*)"1");		ret = 1;	}	else	{		wxString temp(nodeprop);		temp.ToLong(&ret);		ret+=1;		xmlChar tmp[100];		xmlStrPrintf(tmp, 100, (const xmlChar*)"%d",ret);		xmlSetProp(ContentInfo, (const xmlChar*)"Index", tmp);			}	savetofile();	xmlFree(nodeprop);	return ret;}xmlChar *MoneyBook::GetNodeXPath(xmlNodePtr nodeitem){#define MAX_NODE_DEPTH 10	#define MAX_XPATH_LENGTH 255	xmlChar tmpret[MAX_XPATH_LENGTH]="";	xmlChar ret[MAX_XPATH_LENGTH]="";	int depth=0;	while ((nodeitem!=ContentInfo)&&(depth<MAX_NODE_DEPTH))	{		strcpy((char*)tmpret,(const char*)ret);		xmlStrPrintf(ret,MAX_XPATH_LENGTH,(const xmlChar*)"//%s%s",nodeitem->name,tmpret);		nodeitem = nodeitem->parent;		depth++;	}	xmlStrPrintf(tmpret,MAX_XPATH_LENGTH,(const xmlChar*)"//body%s",ret);			if (depth>=MAX_NODE_DEPTH)	{		return NULL;	}	else	{		return xmlStrdup(tmpret);	}}xmlXPathObjectPtr MoneyBook::getnodeset (xmlDocPtr doc, xmlChar *xpath){		xmlXPathContextPtr context;	xmlXPathObjectPtr result;	context = xmlXPathNewContext(doc);	result = xmlXPathEvalExpression(xpath, context);	if(xmlXPathNodeSetIsEmpty(result->nodesetval)){		return NULL;	}	xmlXPathFreeContext(context);	return result;}bool MoneyBook::SetUserInfo(MB_UserInfo *pUserInfo){		if ((UserInfo == NULL) || (pUserInfo == NULL))	{		return FALSE;	}		xmlNodeSetContent(UserInfo,pUserInfo->UserName);	savetofile();	return TRUE;}bool MoneyBook::GetUserInfo(MB_UserInfo *pUserInfo){	if ((UserInfo == NULL) || (pUserInfo == NULL))	{		return FALSE;	}		xmlStrPrintf (pUserInfo->UserName, 100, (xmlChar*)"%s",xmlNodeGetContent(UserInfo));	return TRUE;}bool MoneyBook::SetDefault(wxTreeItemId *pid){	if (!pid->IsOk())	{		wxLogError(_("data file error, can not found base node!"));		return FALSE;	}	xmlnodeTreeItemData* itemdata = (xmlnodeTreeItemData*)uiTree->GetItemData(*pid);	if (itemdata != NULL)	{		xmlChar *nodeprop = xmlGetProp(itemdata->xmlNode, (const xmlChar*)"Type");		if ((xmlStrcmp(nodeprop,(const xmlChar*)"Folder"))==0)		{			if (NULL == ContentInfo) return FALSE;			xmlSetProp(ContentInfo, (const xmlChar*)"Default", itemdata->xmlNode->name);			savetofile();			xmlFree(nodeprop);			return TRUE;		}		xmlFree(nodeprop);	}	return FALSE;}bool MoneyBook::DeleteMoneyType(wxTreeItemId *pid){	if (!pid->IsOk())	{		wxLogError(_("data file error, can not found base node!"));		return FALSE;	}	xmlnodeTreeItemData* itemdata = (xmlnodeTreeItemData*)uiTree->GetItemData(*pid);	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)		{			xmlUnlinkNode(itemdata->xmlNode);			xmlFreeNode(itemdata->xmlNode);			savetofile();			xmlFree(nodeprop);			uiTree->Delete(*pid);			return TRUE;		}		xmlFree(nodeprop);	}	return FALSE;	}wxString* MoneyBook::GetFolderDesc(xmlNodePtr node){	xmlChar* desc= xmlGetProp(node, (const xmlChar*)"Desc");	if (desc!=NULL)	{		return new wxString(wxConvUTF8.cMB2WC((const char*)desc),*wxConvCurrent);	}	return new wxString(_("No Desc"));}bool MoneyBook::GetMonthTotalCnt(xmlNodePtr parentnode, wxDouble *pret, wxDateTime adate, MoneytypeCountList *retlist){	xmlNodePtr node = parentnode->xmlChildrenNode;	while (node != NULL)	{		xmlChar*nodeprop = xmlGetProp(node, (const xmlChar*)"Type");		if (xmlStrcmp(nodeprop, (const xmlChar*)"Folder")==0)		{			GetMonthTotalCnt(node,pret,adate,retlist);		}		xmlFree(nodeprop);		if (xmlStrcmp(node->name, (const xmlChar*)"MoneyRecs")==0)		{			xmlNodePtr monthnode = GetMonthFolder(parentnode, &adate);			if (NULL !=monthnode)			{				xmlChar *total = xmlGetProp(monthnode, (const xmlChar*)"Total");				if (NULL !=total)				{					wxString tmpstr(total);					wxDouble tmpdb;					tmpstr.ToDouble(&tmpdb);					(*pret)+=tmpdb;					if (retlist != NULL)					{						retlist->Append(new MoneytypeCountNode(node->parent,tmpdb));					}											xmlFree(total);				}			}		}				node=node->next;	}	return TRUE;}bool MoneyBook::SetBaseAcount(wxTreeItemId *id, wxDouble base){	if (!id->IsOk())	{		wxLogError(_("data file error, can not found base node!"));		return FALSE;	}	xmlnodeTreeItemData* itemdata = (xmlnodeTreeItemData*)uiTree->GetItemData(*id);	if ((itemdata->xmlNode != InComingNode)		&&(itemdata->xmlNode != OutGoingNode))	{		wxLogError(_("Node can not doing this operate!"));		return FALSE;	}		if (itemdata != NULL)	{		xmlSetProp(itemdata->xmlNode,(const xmlChar*)"Base",(const xmlChar*)(wxString::Format("%.2f",base).mb_str()));		savetofile();		return TRUE;	}	return FALSE;}bool MoneyBook::AddMoneyType(wxTreeItemId *id, MB_ClassInInfo *pClassInfo){	if (!id->IsOk())	{		wxLogError(_("data file error, can not found base node!"));		return FALSE;	}	xmlnodeTreeItemData* itemdata = (xmlnodeTreeItemData*)uiTree->GetItemData(*id);	if (itemdata != NULL)	{		xmlChar folename[255]="";		xmlStrPrintf(folename, 255, (const xmlChar*)"Folder%d",GetFolderIndex());		xmlNode* nodeitem = xmlNewTextChild (itemdata->xmlNode, NULL, folename, NULL);		wxString temp(wxConvCurrent->cWX2WC(pClassInfo->Desc),wxConvUTF8);		xmlSetProp(nodeitem, (const xmlChar*)"Desc", (const xmlChar*)temp.mb_str());		xmlSetProp(nodeitem, (const xmlChar*)"Type", (const xmlChar*)"Folder");		uiTree->AppendItem(*id,pClassInfo->Desc,2, 2,new xmlnodeTreeItemData(nodeitem));		uiTree->Expand(*id);		//init data node		nodeitem = xmlNewTextChild (nodeitem, NULL, (const xmlChar*)"MoneyRecs", NULL);				savetofile();					return TRUE;	}	return FALSE;}void MoneyBook::savetofile(bool Force){	if ((Force) || (enableAutoSave))		xmlSaveFormatFile(filename,doc,0);}bool MoneyBook::DeleteRec(xmlNodePtr node){	xmlChar *acountstr = xmlGetProp(node,(const xmlChar*)"Acount");	if (acountstr==NULL)	{		wxLogError(_("This is not a rec node!"));		return FALSE;	}	wxDouble acount;	wxString tmp(acountstr);	tmp.ToDouble(&acount);	UpdateTotalCount(node,acount,FALSE);	xmlFree(acountstr);	xmlUnlinkNode(node);	xmlFreeNode(node);	savetofile();		return TRUE;}bool MoneyBook::ModifyMoneyRec(xmlnodeGNode* oldNode,wxDateTime *pdate, wxDouble acount, wxString memo){	if (NULL ==oldNode)	{		return FALSE;	}	if (oldNode->xmlNode)	{		DeleteRec(oldNode->xmlNode);

⌨️ 快捷键说明

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