Click here to Skip to main content
15,884,739 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 38.9K   5.9K   32  
Utility to keep track of your finances
#include "StdAfx.h"
#include "ControlsNoteGroups.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/ManGroup.h"
#include "../../BasicAdmin2_Utils/GenView/GenGridView.h"
#include "../../Librerias/GraphParser/Globals.h"
#include "../../BasicAdmin2_Model/CustMessages.h"

ControlsNoteGroups::ControlsNoteGroups(void)
{
}

ControlsNoteGroups::~ControlsNoteGroups(void)
{
}

void ControlsNoteGroups::InitControls()
{
	dh.form = form;
	dh.param = param;
	dh.Initialize();
	dh.genman = (CWnd*)this;
}
void ControlsNoteGroups::CreateControls()
{
	vector<CString> v;
	v.push_back(param->langdata.Item(L"NoteGroup.Label.Parent") + L":");
	v.push_back(param->langdata.Item(L"NoteGroup.Label.Description") + L":");
	v.push_back(param->langdata.Item(L"NoteGroup.Label.Shortcut") + L":");
	v.push_back(param->langdata.Item(L"NoteGroup.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 = TypeNoteGroup;
	cboParent.Create();

	dh.AddRow();

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

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

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

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

}

void ControlsNoteGroups::LimpiarControles()
{	
	TxtDescrip.SetWindowText(L"");
	HtkShortCut.SetHotKey(0,0);
	TxtObs.SetWindowText(L"");

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

CString ControlsNoteGroups::Validar()
{
	CString cad;

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

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

	ClsGroup* grp = new ClsGroup();

	ManGroup mangrp;
	mangrp.dbAdmin = &(param->dbAdmin);

	LoadGrpFromForm(grp);
	
	CGenGridView* genv = (CGenGridView*)handles->m_WndGrid;
	
	if (ID == -1)
	{
		mangrp.AddGroup(*grp);
		arr->arrGroups[grp->ID] = (DWORD)grp;
		genv->genman->AddRow(genv->con->grid,(DWORD)grp);
		genv->genman->AfterNew();
	}
	else
	{
		mangrp.ModifyGroup(*grp);
		ClsGroup* grpaux = (ClsGroup*)arr->arrGroups[grp->ID];
		delete grpaux;
		arr->arrGroups[grp->ID] = (DWORD)grp;
		genv->genman->RefreshRow(genv->con->grid,0,(DWORD)grp);
	}

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

	int idimage = gentree->treeutils->ImagenDato;

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

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

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

	return L"";
}

void ControlsNoteGroups::LoadData()
{
	ManGroup mangrp;
	mangrp.dbAdmin = &(param->dbAdmin);

	ClsGroup* grp = new ClsGroup();
	grp->ID = ID;
	mangrp.GetGroup(*grp);
	LoadFormFromGrp(grp);
	
	delete grp;
}
void ControlsNoteGroups::LoadFormFromGrp(ClsGroup* grp)
{
	cboParent.Id = grp->IdParent;
	cboParent.RefreshCaption();
	TxtDescrip.SetWindowTextW(grp->Description);
	HtkShortCut.SetHotKey(grp->Shortcut1, grp->Shortcut2);
	TxtObs.SetWindowTextW(grp->Observations);
}

void ControlsNoteGroups::InitialFocus()
{
}
void ControlsNoteGroups::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message != WM_COMMAND) return;
	if (wParam == IDCC_CBOPARENTBTN)
	{
		SwitchToTree();
	}
}
void ControlsNoteGroups::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 ControlsNoteGroups::LoadGrpFromForm(ClsGroup* grp)
{
	CString cad;
	
	TxtDescrip.GetWindowTextW(cad);
	grp->Description = cad;
	grp->IdParent = cboParent.Id;
	if (!grp->IsParentRoot())
		grp->Parent = (ClsGroup*)arr->arrGroups[grp->IdParent];

	WORD virtualkeycode, modifiers;
	HtkShortCut.GetHotKey(virtualkeycode, modifiers);
	grp->Shortcut1 = virtualkeycode;
	grp->Shortcut2 = modifiers;
	
	grp->Type = eLeftTableType::eLeftTableNotes;

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

	grp->ID = ID;
}
void ControlsNoteGroups::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