Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / C++

BasicAdmin2 - Personal Finance Software

Rate me:
Please Sign up or sign in to vote.
4.58/5 (8 votes)
4 Nov 2011CPOL3 min read 39K   5.9K   33  
Utility to keep track of your finances
#include "StdAfx.h"
#include "ControlsAccounts.h"
#include "../../BasicAdmin2_Utils/GenDialog/GenDialogView.h"
#include "../../BasicAdmin2_Utils/GenDialog/GenTreeDialogView.h"
#include "../../BasicAdmin2_Utils/GenView/GenLeftTreeView.h"
#include <afxcontrolbars.h>     // MFC support for ribbons and control bars
#include "../../BasicAdmin2_Database/Managers/ManArrays.h"
#include "../../BasicAdmin2_Database/Managers/ManAccount.h"
#include "../../BasicAdmin2_Utils/GenView/GenGridView.h"
#include "../../Librerias/GraphParser/Globals.h"
#include "../../BasicAdmin2_Model/CustMessages.h"

ControlsAccounts::ControlsAccounts(void)
{
}

ControlsAccounts::~ControlsAccounts(void)
{
}

void ControlsAccounts::InitControls()
{
	dh.form = form;
	dh.param = param;
	dh.Initialize();
	dh.genman = (CWnd*)this;
}
void ControlsAccounts::CreateControls()
{
	vector<CString> v;
	v.push_back(param->langdata.Item(L"Account.Label.Parent") + L":");
	v.push_back(param->langdata.Item(L"Account.Label.Type") + L":");
	v.push_back(param->langdata.Item(L"Account.Label.Description") + L":");
	v.push_back(param->langdata.Item(L"Account.Label.Shortcut") + L":");
	v.push_back(param->langdata.Item(L"Account.Label.Currency") + L":");
	v.push_back(param->langdata.Item(L"Account.Label.Observations") + L":");

	dh.phelper.IsVertical = TRUE;
	dh.phelper.SetLeftAlign(0,&v);
	dh.phelper.SetTop();

	dh.CreateLabel(v[0],&(Lbl[0]));

	cboParent.IdTxt = IDCA_CBOPARENTTXT;
	cboParent.IdBtn = IDCC_CBOPARENTBTN;
	cboParent.IdStatic = IDCC_CBOPARENTSTC;

	cboParent.dh = &dh;
	cboParent.ControlSpace = param->fuentes.ctSpaceVert;
	cboParent.arr = arr;
	cboParent.typecontrol = TypeCboAccount;
	cboParent.Create();

	dh.AddRow();

	dh.CreateLabel(v[1],&(Lbl[1]));
	dh.CreateComboBox(IDCC_CBOTIPO,&CboTipo);

	ClsAccount acc;
	for (int i=0;i<=eAccountType::TaccCalculated;i++)
	{
		CString cad = acc.GetTypeDescription(*(param->langdata.GetCurLangInfo()), i);
		CboTipo.AddString(cad);
		CboTipo.SetItemData(i,i);
	}
	CboTipo.SetCurSel(0);
	dh.AddRow();

	dh.CreateLabel(v[2],&(Lbl[2]));
	dh.CreateTextBox(IDCC_CBOTXTDESC,&TxtDescrip, 50);
	dh.AddRow();

	dh.CreateLabel(v[3],&(Lbl[3]));
	dh.CreateShortCutBox(IDCC_CBOSHORTCUT,&HtkShortCut);
	dh.AddRow();

	dh.CreateLabel(v[4],&(Lbl[4]));
	dh.CreateComboBox(IDCC_CBOMONEDA,&CboMoneda);

	if (!arr->LoadedCur)
	{
		ManArrays arrman;
		arrman.dbAdmin = &(param->dbAdmin);
		arrman.LoadArrCurrencies(*arr);
	}

	ClsCurrency* curarr;
	int j=0;
	for (auto itr=arr->arrCurrencies.begin();itr!=arr->arrCurrencies.end();itr++)
	{
		 curarr = (ClsCurrency*)(*itr).second;
		 CboMoneda.AddString(curarr->Description);
		 CboMoneda.SetItemData(j,curarr->ID);
		 j++;
	}
	if (CboMoneda.GetCount() > 0) CboMoneda.SetCurSel(0);
	dh.AddRow();

	dh.CreateLabel(v[5],&(Lbl[5]));
	dh.CreateMultiEdit(IDCC_TXTOBS,&TxtObs,MultiEditHeight);
	dh.AddRow();

	dh.CreateGroupBox(dh.phelper.TopAlign,dh.phelper.TotalHeight + param->fuentes.ctSpaceVert * 2,&GroupBox);

}

void ControlsAccounts::LimpiarControles()
{	
	CboTipo.SetCurSel(0);
	TxtDescrip.SetWindowText(L"");
	HtkShortCut.SetHotKey(0,0);
	if (CboMoneda.GetCount() > 0) CboMoneda.SetCurSel(0);
	TxtObs.SetWindowText(L"");

	int id = GetIDFromTree();
	if (id == -1)
		cboParent.Clean();
	else
	{
		cboParent.Id = id;
		cboParent.RefreshCaption();
	}
}
int ControlsAccounts::GetIDFromTree()
{
	CGenLeftTreeView* gentreeview = (CGenLeftTreeView*)handles->m_WndTreeView;
	HTREEITEM titem = gentreeview->GetTreeCtrl().GetSelectedItem();
	if (titem == NULL)
		return -1;
	else
		return gentreeview->GetTreeCtrl().GetItemData(titem);
}

CString ControlsAccounts::Validar()
{
	CString cad;

	TxtDescrip.GetWindowTextW(cad);
	if (cad == "")
	{
		dh.SetLblError(&Lbl[2]);
		TxtDescrip.SetFocus();
		return param->langdata.Item(L"Account.Errors.EnterDescription");
	}

	CboMoneda.GetWindowTextW(cad);
	if (cad == "")
	{
		dh.SetLblError(&Lbl[4]);
		CboMoneda.SetFocus();
		return param->langdata.Item(L"Account.Errors.EnterCurrency");
	}

	return L"";
}

CString ControlsAccounts::SaveOK()
{
	CString cad;
	SetNoError();
		
	cad = Validar();
	if (cad != "") return cad;

	ClsAccount* acc = new ClsAccount();

	int id = CboTipo.GetItemData(CboTipo.GetCurSel());

	ManAccount manc;
	manc.dbAdmin = &(param->dbAdmin);

	LoadAccFromForm(acc);
	
	CGenGridView* genv = (CGenGridView*)handles->m_WndGrid;
	
	if (ID == -1)
	{
		manc.AddAccount(*acc);
		arr->arrAccounts[acc->ID] = (DWORD)acc;
		genv->genman->AddRow(genv->con->grid,(DWORD)acc);
		genv->genman->AfterNew();
	}
	else
	{
		manc.ModifyAccount(*acc);
		ClsAccount* accaux = (ClsAccount*)arr->arrAccounts[acc->ID];
		delete accaux;
		arr->arrAccounts[acc->ID] = (DWORD)acc;
		genv->genman->RefreshRow(genv->con->grid,0,(DWORD)acc);
	}

	CGenDialogView* gendiag = (CGenDialogView*)form;
	CGenTreeDialogView* gentree = (CGenTreeDialogView*)handles->m_WndDialogTreeSearch;
	CGenLeftTreeView* gentreeview = (CGenLeftTreeView*)handles->m_WndTreeView;

	gentree->treeutils->AddModifyTree(ID != -1,acc->ID, acc->Description, acc->IdParent,3,gentree->mtree);
	gentreeview->tutils.AddModifyTree(ID != -1,acc->ID, acc->Description, acc->IdParent,3,gentreeview->GetTreeCtrl());

	gentree->treeutils->CheckFolderImages(gentree->mtree, 3);
	gentreeview->tutils.CheckFolderImages(gentreeview->GetTreeCtrl(), 3);

	CWnd* pant = handles->m_WndDialog->GetParent()->GetParent()->GetParent();
	pant->SendMessage(MsgAccountChange,0,0);

	return L"";
}

void ControlsAccounts::LoadData()
{
	ManAccount manc;
	manc.dbAdmin = &(param->dbAdmin);

	ClsAccount* acc = new ClsAccount();
	acc->ID = ID;
	manc.GetAccount(*acc);
	LoadFormFromAcc(acc);
	
	delete acc;
}
void ControlsAccounts::LoadFormFromAcc(ClsAccount* acc)
{
	cboParent.Id = acc->IdParent;
	cboParent.RefreshCaption();
	PosCbo(&CboTipo, acc->AccountType);
	TxtDescrip.SetWindowTextW(acc->Description);
	HtkShortCut.SetHotKey(acc->Shortcut1, acc->Shortcut2);
	PosCbo(&CboMoneda, acc->IdCurrency);
	TxtObs.SetWindowTextW(acc->Observations);
}

void ControlsAccounts::InitialFocus()
{
}
void ControlsAccounts::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message != WM_COMMAND) return;
	if (wParam == IDCC_CBOPARENTBTN)
	{
		SwitchToTree();
	}
}
void ControlsAccounts::SwitchToTree()
{
	::SetWindowLong(form->m_hWnd, GWL_ID, 0);
	CGenDialogView* gendiag = (CGenDialogView*)form;
	CGenTreeDialogView* gentree = (CGenTreeDialogView*)handles->m_WndDialogTreeSearch;

 	gentree->cbo = &cboParent;

	::SetWindowLong(gentree->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);
	form->ShowWindow(SW_HIDE);
	gentree->ShowWindow(SW_SHOW);
	CMDIChildWndEx* frame = (CMDIChildWndEx*)form->GetParent();
	frame->RecalcLayout();

	gentree->mtree.SelectItem(gentree->titem);
	gentree->SetFocus();
	gentree->mtree.SetFocus();
	
}
void ControlsAccounts::LoadAccFromForm(ClsAccount* acc)
{
	CString cad;
	
	acc->AccountType = (eAccountType)CboTipo.GetItemData(CboTipo.GetCurSel());
	TxtDescrip.GetWindowTextW(cad);
	
	acc->Description = cad;
	acc->IdParent = cboParent.Id;
	if (!acc->IsParentRoot())
		acc->Parent = (ClsAccount*)arr->arrAccounts[acc->IdParent];

	acc->IdCurrency = CboMoneda.GetItemData(CboMoneda.GetCurSel());
	acc->currency = (ClsCurrency*)arr->arrCurrencies[acc->IdCurrency];
	
	WORD virtualkeycode, modifiers;
	HtkShortCut.GetHotKey(virtualkeycode, modifiers);
	acc->Shortcut1 = virtualkeycode;
	acc->Shortcut2 = modifiers;

	TxtObs.GetWindowTextW(cad);
	acc->Observations = cad;

	acc->ID = ID;
}
void ControlsAccounts::RefreshLabels()
{
	cboParent.RefreshColors();
	CGenDialogManager::RefreshLabels();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Argentina Argentina
System developer from Argentina.

Programmed in VB 5,6,.NET, C#, Java, PL-SQL, Transac-SQL, C, C++ and even some "calculator" language.

Love to build small, useful applications.
Usually building big and complicated apps based on solid, reliable components.

Hobbies: reading, photography, chess, paddle, running.

Comments and Discussions