Click here to Skip to main content
15,884,838 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 "FilDailyInput.h"
#include "../../BasicAdmin2_Utils/UtGlobals.h"
#include "../../BasicAdmin2_Model/ClsDailyInput.h"
#include "../../BasicAdmin2_Utils/GenDialog/GenTreeDialogView.h"
#include "../../BasicAdmin2_Utils/GenDialog/GenDialogView.h"
#include <afxcontrolbars.h>     // MFC support for ribbons and control bars

CFilDailyInput::CFilDailyInput(void)
{
}

CFilDailyInput::~CFilDailyInput(void)
{
}

void CFilDailyInput::CreateControls()
{
	dh.Initialize();

	dh.form = form;
	dh.phelper.IsVertical = FALSE;
	
	dh.Initialize();

	vector<CString> v;
	v.push_back(param->langdata.Item(L"Finance.FilDailyInput.From") + L":");
	v.push_back(param->langdata.Item(L"Finance.FilDailyInput.To") + L":");
	v.push_back(param->langdata.Item(L"Finance.FilDailyInput.Account"));
	v.push_back(param->langdata.Item(L"Finance.FilDailyInput.Oper") + L":");
	v.push_back(param->langdata.Item(L"Finance.FilDailyInput.All"));
	v.push_back(param->langdata.Item(L"System.Filter.Search") + L":");

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

	dh.CreateDate(IDCC_TXTDFROM,&EdtFrom,FALSE,0);
	dh.phelper.CurLeft += dh.phelper.fhelper.GetNumCharWidth(LDateEdit) + param->fuentes.ctSpaceVert;
		
	dh.CreateLabel(v[1],&Lbl[1],0);
	dh.CreateDate(IDCC_TXTDTO,&EdtTo,FALSE,0);
	dh.phelper.CurLeft += dh.phelper.fhelper.GetNumCharWidth(LDateEdit) + param->fuentes.ctSpaceVert;

	dh.CreateCheckBox(IDCA_CHKFILACC,&ChkFilAcc,v[2],FALSE);
	dh.phelper.CurLeft += dh.phelper.fhelper.GetLblWidth(v[2]) + CheckWidth;
	
	cboAccount.cbp = this;
	cboAccount.IdTxt = IDCA_CBOACCTXTFIL;
	cboAccount.IdBtn = IDCC_CBOACCBTNFIL;
	cboAccount.IdStatic = IDCC_CBOACCSTCFIL;

	cboAccount.dh = &dh;
	cboAccount.ControlSpace = param->fuentes.ctSpaceVert;
	cboAccount.arr = &(param->arrays);
	cboAccount.typecontrol = TypeCboAccount;
	dh.genman = 0;
	
	cboAccount.Create();
	cboAccount.Id = -1;
	cboAccount.RefreshCaption();
	cboAccount.EnableDisable(FALSE);
	
	dh.phelper.CurLeft += cboAccount.GetWidth() + param->fuentes.ctSpaceVert;

	dh.CreateLabel(v[3],&Lbl[3],0);
	dh.CreateComboBox(IDCC_CBOOPTYPE,&CboOpType, FALSE, 17);

	CboOpType.AddString(v[4]);
	CboOpType.SetItemData(0,-1);

	ClsDailyInput di;
	for (int i=0;i<=eDailyInputType::TdinAccountOp;i++)
	{
		di.OperType = (eDailyInputType)i;
		CboOpType.AddString(di.GetTypeDescription(*(param->langdata.GetCurLangInfo())));
		CboOpType.SetItemData(i+1,i);
	}
	CboOpType.SetCurSel(0);

	dh.phelper.CurLeft += dh.phelper.fhelper.GetNumCharWidth(17) + param->fuentes.ctSpaceVert * 4;

	dh.CreateLabel(v[5],&Lbl[4],0);
	dh.CreateTextBox(IDCC_TXTSEARCHF,&TxtDescripcion, 30,FALSE);
}

void CFilDailyInput::OnSize(int cx, int cy)
{
	CRect rect;
	TxtDescripcion.GetWindowRect(rect);
	form->ScreenToClient(rect);
	TxtDescripcion.MoveWindow(rect.left,rect.top,cx - param->fuentes.ctSpaceVert * 2 - param->fuentes.ctBtnWidth - rect.left,rect.bottom - rect.top);
}
CString CFilDailyInput::GetStrDate(CAMSDateEdit* edtdate)
{
	if (edtdate->IsValid())
		return FormatDate(edtdate->GetDate());
	else
		return L"";
}
void CFilDailyInput::Filter()
{
	TxtDescripcion.GetWindowTextW(cdif.strSearch);
	
	cdif.strFrom = GetStrDate(&EdtFrom);
	cdif.strTo = GetStrDate(&EdtTo);
	cdif.iOper = CboOpType.GetItemData(CboOpType.GetCurSel());
	cdif.iAcc = -1;
	cdif.param = param;
	if (ChkFilAcc.GetCheck() == 1) cdif.iAcc = cboAccount.Id;
	cdif.Init();

	con->grid->SetRedraw(FALSE);
	con->utils->visiblerecords = 0;
	for (int i=1;i<= con->grid->GetRowCount() - 1;i++)
	{
		if (cdif.FilterDaily(con->grid,i))
			con->utils->visiblerecords++;
	}
	con->grid->SetRedraw(TRUE, TRUE);
	con->utils->SelectFirstRow(con->grid);
	con->utils->RefreshButtons(con->btnModify,con->btnDelete,con->btnPrint);
	RefreshStatusBar();
}

LRESULT CFilDailyInput::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message != WM_COMMAND) return FALSE;

	if (wParam == IDCC_CBOACCBTNFIL)
	{
		SwitchToTree(&cboAccount);
		return TRUE;
	}
	if (wParam == IDCA_CHKFILACC)
	{
		cboAccount.EnableDisable(ChkFilAcc.GetCheck() == 1);
		Filter();
		return TRUE;
	}
	if (IsWindow(TxtDescripcion.GetSafeHwnd()) && HIWORD(wParam) == EN_CHANGE)
	{
		int ctrlid = LOWORD(wParam);
		switch(ctrlid)
		{
			case IDCC_TXTDFROM:
			case IDCC_TXTDTO:
			case IDCC_TXTSEARCHF:
				Filter();
				return TRUE;
		}
	}
	if (IsWindow(CboOpType.GetSafeHwnd()) && HIWORD(wParam) == CBN_SELCHANGE)
	{
		int id = LOWORD(wParam);
		if (id == IDCC_CBOOPTYPE)
		{
			Filter();
			return TRUE;
		}
	}

	return FALSE;
}
void CFilDailyInput::SwitchToTree(CCboTreeControl* cbo)
{
	::SetWindowLong(form->m_hWnd, GWL_ID, 0);
	CGenDialogView* gendiag = (CGenDialogView*)handles->m_WndDialog;
	CGenTreeDialogView* gentree = (CGenTreeDialogView*)handles->m_WndDialogTreeSearch;

 	gentree->cbo = cbo;
	gentree->frmreturn = form;

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

	gentree->mtree.SelectItem(gentree->titem);
	gentree->SetFocus();
	gentree->mtree.SetFocus();
}
void CFilDailyInput::RefreshColors()
{
	for (int i=0; i<=4; i++)
		Lbl[i].SetBkColor(DarColor(param->settings.m_nAppLook));

	ChkFilAcc.SetBkColor(DarColor(param->settings.m_nAppLook));
}
void CFilDailyInput::AfterTree()
{
	if (!IsWindow(TxtDescripcion.GetSafeHwnd())) return;
	Filter();
}
void CDIFilterData::Init()
{
	chkdFrom =	(strFrom.GetLength() > 0);
	chkdTo =	(strTo.GetLength() > 0);
	chkSearch = (strSearch.GetLength() > 0);
	chkOper =	(iOper != -1);
	chkAcc =	(iAcc != -1);

	if (!chkdFrom)	OkdFrom = TRUE;
	if (!chkdTo)	OkdTo = TRUE;
	if (!chkSearch) OkSearch = TRUE;
	if (!chkOper)	OkOper = TRUE;
	if (!chkAcc)	OkAcc = TRUE;
}
BOOL CDIFilterData::CheckRow(CGridCtrl* grid, int irow)
{
	CString strdate = grid->GetCell(irow,1)->GetText();
	CString stroper = grid->GetCell(irow,2)->GetText();

	if (chkdFrom)	OkdFrom = strdate >= strFrom;
	if (chkdTo)		OkdTo	= strdate <= strTo;

	if (!OkdFrom || !OkdTo) return FALSE;

	if (chkOper)
	{
		ClsDailyInput di;
		di.OperType = (eDailyInputType)iOper;
		OkOper = (di.GetTypeDescription(*(param->langdata.GetCurLangInfo())) == stroper);

		if (!OkOper) return FALSE;
	}
	if (chkSearch)
	{
		OkSearch = FALSE;
		CString strvalue;
		for (int j=1;j<=grid->GetColumnCount() - 1;j++)
		{
			strvalue = grid->GetCell(irow, j)->GetText();
			if (IsInText(strvalue,strSearch))
			{
				OkSearch = TRUE;
				break;
			}
		}
		if (!OkSearch) return FALSE;
	}
	if (chkAcc)
	{
		ClsAccount* accsearch = (ClsAccount*)param->arrays.arrAccounts[this->iAcc];
		CString strfind = accsearch->GetPath();
		int slen = strfind.GetLength();
		
		int idfrom = _wtoi(grid->GetCell(irow,7)->GetText());
		ClsAccount* accfrom = (ClsAccount*)param->arrays.arrAccounts[idfrom];
		CString strfrom = accfrom->GetPath();

		OkAcc = FALSE;
		if (strfrom.Left(slen) == strfind)
			OkAcc = TRUE;
		else
		{
			CString strto = grid->GetCell(irow,8)->GetText();
			if (strto != L"")
			{
				int idto = _wtoi(strto);
				ClsAccount* accto = (ClsAccount*)param->arrays.arrAccounts[idto];
				CString straccto = accto->GetPath();

				if (straccto.Left(slen) == strfind) OkAcc = TRUE;
			}
		}
		
		if (!OkAcc) return FALSE;
	}
	return TRUE;
}
BOOL CDIFilterData::FilterDaily(CGridCtrl* grid, int irow)
{
	BOOL showgrid = CheckRow(grid,irow);
	if (showgrid)
		grid->SetRowHeight(irow, grid->GetDefCellHeight());
	else
		grid->SetRowHeight(irow, 0);

	return showgrid;
}

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