Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C

BasicAdmin - Personal Organizer

Rate me:
Please Sign up or sign in to vote.
4.94/5 (14 votes)
1 Aug 2009CPOL6 min read 50.9K   5.6K   60  
Finance, contacts, notes organizer
#include "stdafx.h"
#include "../../../BasicAdmin.h"
#include "FrmCatSearch.h"

IMPLEMENT_DYNAMIC(CFrmCatSearch, CDialog)

CFrmCatSearch::CFrmCatSearch(CWnd* pParent /*=NULL*/)
	: CDialog(CFrmCatSearch::IDD, pParent)
{

}

CFrmCatSearch::~CFrmCatSearch()
{

}

BEGIN_MESSAGE_MAP(CFrmCatSearch, CDialog)
	ON_BN_CLICKED(IDC_BTN_CANCEL, &CFrmCatSearch::OnBnClickedBtnCancel)
	ON_BN_CLICKED(IDC_BTN_OK, &CFrmCatSearch::OnBnClickedBtnOk)
	ON_WM_CTLCOLOR()
	ON_WM_ERASEBKGND()
	ON_NOTIFY(GVN_SELCHANGED, IDC_GRID, OnGridRowChange)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_ACC, OnTvnSelchangedTreeAcc)
	ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_ACC, OnTvnItemexpandingTreeAcc)
	ON_EN_CHANGE(IDC_ED_SEARCH, OnEnChangeEdSearch)
END_MESSAGE_MAP()

void CFrmCatSearch::OnBnClickedBtnCancel()
{
	OnCancel();
}

void CFrmCatSearch::OnBnClickedBtnOk()
{
	int irow = m_grid.GetSelectedCellRange().GetMinRow();
	int id = atoi(m_grid.GetCell(irow, 0)->GetText());
	m_treecbo->FindItemByID(id);
	OnOK();
	// TODO: Add your control notification handler code here
}
HBRUSH CFrmCatSearch::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	int nID = pWnd->GetDlgCtrlID();

	switch (nID)
    {
		case LBLSEARCH3:
			pDC->SetBkMode(OPAQUE);
			pDC->SetBkColor(DarColor());
			return (HBRUSH) GetStockObject(NULL_BRUSH);
	}
	return hbr;
}
BOOL CFrmCatSearch::OnEraseBkgnd(CDC* pDC)
{
	CRect rect;
	GetClientRect(&rect);
	pDC->FillSolidRect(0,0,rect.Width(),rect.Height(),DarColor());
	return TRUE;
}

void CFrmCatSearch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BTN_OK, BtnOK);
	DDX_Control(pDX, IDC_BTN_CANCEL, BtnCancel);
	DDX_Control(pDX, IDC_GRID, m_grid);
	DDX_Control(pDX, IDC_TREE_ACC, m_treeacc);
	DDX_Control(pDX, IDC_ED_SEARCH, EdtSearch);
}

BOOL CFrmCatSearch::OnInitDialog()
{
	CDialog::OnInitDialog();
	ut.FormatButtonsOKCancel(&BtnOK, &BtnCancel);
	ut.FormatGrid(&m_grid);
	switch(cattype)
	{
		case TCatTypeContacts:		uttree.pParent = (CTreeParams*)&con;
		case TCatTypeNotesFiles:	uttree.pParent = (CTreeParams*)&notecat;
		case TCatTypeCalendar:		uttree.pParent = (CTreeParams*)&calcat;
	}
	CString strsql;
	strsql.Format("SELECT * FROM CONTACTSCAT WHERE TYPE = %d ORDER BY ID", cattype);
	ut.AccLoadArrayWithParent("CONTACTSCAT", "DESCRIPTION", strsql);
	GridColumns();
	LoadGridData();
	
	uttree.Table = "CONTACTSCAT";
	uttree.type = cattype;
	uttree.LoadTree(&m_treeacc);

	ut.visiblerecords = 1;
	ut.SelectFirstRow(&m_grid);
	GridRowColChange(1,0);
	return TRUE;
}
void CFrmCatSearch::GridColumns()
{
	m_grid.SetColumnCount(3);
	m_grid.GetCell(0,0)->SetText("Id");
	m_grid.GetCell(0,1)->SetText("Categor�a");
	m_grid.GetCell(0,2)->SetText("Direcci�n Completa");

	m_grid.SetColumnWidth(0, 0);
	m_grid.SetColumnWidth(1, 80);
	m_grid.SetColumnWidth(2, 300);
}
void CFrmCatSearch::LoadGridData()
{
	m_grid.SetRedraw(FALSE);
	int irow = 1;
	CString strid;
	CString strsql;
	strsql.Format("SELECT * FROM CONTACTSCAT WHERE TYPE = %d", cattype);

	CppSQLite3Query q = dbAdmin.execQuery(strsql);
	while (!q.eof())
	{
		m_grid.SetRowCount(irow + 1);
		strid.Format("%d", q.getIntField("ID"));
		m_grid.GetCell(irow, 0)->SetText(strid);
		m_grid.GetCell(irow, 1)->SetText(q.getStringField("DESCRIPTION"));
		m_grid.GetCell(irow, 2)->SetText(ut.AccGetArrDescription(q.getIntField("ID"), 0));
		irow++;
		q.nextRow();
	}
	m_grid.SetRedraw(TRUE, TRUE);
}
void CFrmCatSearch::OnGridRowChange(NMHDR *pNotifyStruct, LRESULT* /*pResult*/)
{
	NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
	GridRowColChange(pItem->iRow, pItem->iColumn);
}
void CFrmCatSearch::GridRowColChange(int irow, int icol)
{
	if (irow <= 0 || icol < 0) return;
	int id = atoi(m_grid.GetCell(irow,0)->GetText());
	uttree.SelectNodeByID(&m_treeacc,id);
}
void CFrmCatSearch::OnTvnSelchangedTreeAcc(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
	// TODO: Add your control notification handler code here
	*pResult = 0;
	HTREEITEM item=m_treeacc.GetSelectedItem();
	if (item==NULL) return;
	
	int id = (DWORD)m_treeacc.GetItemData(item);
	int idgrid, irow;
	irow = 0;
	for (int i=0;i<=m_grid.GetRowCount() - 1;i++)
	{
		idgrid = atoi(m_grid.GetCell(i, 0)->GetText());
		if (id == idgrid)
		{
			irow = i;
			break;
		}
	}
	if (irow == 0) return;

	if (m_grid.GetRowHeight(irow) > 0)
	{
		m_grid.EnsureVisible(irow, 0);
		m_grid.SetFocusCell(irow,0);
		m_grid.SelectRows(m_grid.GetFocusCell(), 1,1);
	}

}
void CFrmCatSearch::OnTvnItemexpandingTreeAcc(NMHDR *pNMHDR, LRESULT *pResult)
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	
	if (pNMTreeView->action == TVE_COLLAPSE)
		m_treeacc.SetItemImage(pNMTreeView->itemNew.hItem,10,10);
	else
		m_treeacc.SetItemImage(pNMTreeView->itemNew.hItem,16,16);
	// TODO: Add your control notification handler code here
}
void CFrmCatSearch::OnEnChangeEdSearch()
{
	m_grid.SetRedraw(FALSE);
	CString strvalidar;
	EdtSearch.GetWindowTextA(strvalidar);
	for (int i=1;i<m_grid.GetRowCount();i++)
		ut.FilterGenerico(strvalidar, &m_grid, i);
	m_grid.SetRedraw(TRUE, TRUE);
}

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