Click here to Skip to main content
15,895,084 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
// FrmContactsCatData.cpp : implementation file
//

#include "stdafx.h"
#include "../../../BasicAdmin.h"
#include "../../../UtilsOp/BasicTables.h"
#include "../../../Globals.h"
#include "../../../UtilsOp/dbOpers.h"
#include "../../../Classes/Account.h"
#include "FrmContactsCatData.h"


// CFrmContactsCatData dialog

IMPLEMENT_DYNAMIC(CFrmContactsCatData, CDialog)

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

}

CFrmContactsCatData::~CFrmContactsCatData()
{
}

void CFrmContactsCatData::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BTN_OK, BtnOK);
	DDX_Control(pDX, IDC_BTN_CANCEL, BtnCancel);
	DDX_Control(pDX, IDC_CBO_PARENT, CboParent);
	DDX_Control(pDX, IDC_ED_DESCRIPTION, EdtDescription);
	DDX_Control(pDX, IDC_SHORTCUT, HtkShortCut);
	DDX_Control(pDX, IDC_ED_PREFIX4, EdtObservations);
	DDX_Control(pDX, IDC_CHK_ROOT, ChkRoot);
}


BEGIN_MESSAGE_MAP(CFrmContactsCatData, CDialog)
	ON_BN_CLICKED(IDC_BTN_OK, &CFrmContactsCatData::OnBnClickedBtnOk)
	ON_BN_CLICKED(IDC_BTN_CANCEL, &CFrmContactsCatData::OnBnClickedBtnCancel)
	ON_BN_CLICKED(IDC_CHK_ROOT, &CFrmContactsCatData::OnBnClickedChkRoot)
	ON_WM_CTLCOLOR()
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


// CFrmContactsCatData message handlers

void CFrmContactsCatData::OnBnClickedBtnOk()
{
	CString strverif = VerifyData();
	if (strverif != "")
	{
		MostrarMensaje(strverif);
		return;
	}
	CdbOpers dbop;
	dbop.TableObj = "CONTACTSCAT";
	CTreeObj obj;
	
	if (ChkRoot.GetCheck() != 0)
		obj.Parent = 0;
	else
		obj.Parent = CboParent.GetSelectedID();

	obj.Description = GetTextValue(&EdtDescription);
	
	WORD virtualkeycode, modifiers;
	HtkShortCut.GetHotKey(virtualkeycode, modifiers);
	
	obj.Shortcut1 = virtualkeycode;
	obj.Shortcut2 = modifiers;

	obj.Observations = GetTextValue(&EdtObservations);
	obj.Type = frm->cattype;
	
	int irow;
	if (ID==0)
	{
		dbop.AddTreeObj(&ID, &obj);
		frm->m_grid.SetRowCount(frm->m_grid.GetRowCount() + 1);
		frm->RefreshRow(frm->m_grid.GetRowCount() - 1, ID, obj.Parent, obj.Description, obj.Shortcut1, obj.Shortcut2, obj.Observations);
		irow = frm->m_grid.GetRowCount() - 1;
		frm->m_grid.SetRowHeight(irow,0);
	}
	else
	{
		irow = frm->m_grid.GetSelectedCellRange().GetMinRow();
		obj.ID = ID;
		dbop.ModifyTreeObj(&obj);
		frm->RefreshRow(irow, ID, obj.Parent, obj.Description, obj.Shortcut1, obj.Shortcut2, obj.Observations);
	}
	frm->ut.FilterGenerico(frm->strsearch,&(frm->m_grid),irow);
	if (irow == frm->m_grid.GetRowCount() - 1)
		frm->ut.SelectRow(&frm->m_grid,irow);
	frm->ut.RefreshMainRows();
	uttree.LoadTree(&frm->m_treeacc);
	OnOK();
}

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

void CFrmContactsCatData::OnBnClickedChkRoot()
{
	if (ChkRoot.GetCheck() != 0)
	{
		CboParent.SetWindowTextA("");
		CboParent.EnableWindow(FALSE);
	}
	else
	{
		CboParent.EnableWindow(TRUE);
	}
}
CString CFrmContactsCatData::VerifyData()
{
	if (ChkRoot.GetCheck() == 0)
	{
		if (GetTextValue(&CboParent).GetLength() == 0)
		{
			CboParent.SetFocus();
			return GetStringFromRes(IDACC_PARENTEMPTY);
		}
		if (CboParent.GetSelectedID() == this->ID)
		{
			CboParent.SetFocus();
			return GetStringFromRes(IDACC_PARENTITEM);
		}
	}

	if (GetTextValue(&EdtDescription).GetLength() == 0)
	{
		EdtDescription.SetFocus();
		return GetStringFromRes(IDACC_DESCEMPTY);
	}

	return "";
}


BOOL CFrmContactsCatData::OnInitDialog()
{
	CDialog::OnInitDialog();
	uttree.Table = "CONTACTSCAT";
	uttree.type = frm->cattype;
	
	switch (frm->cattype)
	{
		case TCatTypeContacts:		uttree.pParent = (CTreeParams*)&con;
		case TCatTypeNotesFiles:		uttree.pParent = (CTreeParams*)&notefilecat;
		case TCatTypeCalendar:		uttree.pParent = (CTreeParams*)&calendarcat;
	}

	uttree.LoadTree(CboParent.GetTree());
	uttree.LoadTreeKeys(&CboParent);
	
	if (frm->cattype==TCatTypeContacts)
		this->SetWindowTextA("Contacts Category Information");
	else
		this->SetWindowTextA("Notes/Files Category Information");

	if (ID != 0)
		LoadData();                 
	else
	{
		HTREEITEM item=frm->m_treeacc.GetSelectedItem();
		if (item!=NULL)
		{
			int id = (DWORD)frm->m_treeacc.GetItemData(item);
			CboParent.FindItemByID(id);
		}
	}


	ut.FormatButtonsOKCancel(&BtnOK, &BtnCancel);
	return TRUE;
}
void CFrmContactsCatData::LoadData()
{
	CdbOpers dbop;
	CUtils ut;

	CTreeObj con;
	con.ID = ID;
	dbop.TableObj = "CONTACTSCAT";
	dbop.GetTreeObj(&con);
	
	CboParent.FindItemByID(con.Parent);
	ChkRoot.SetCheck(con.Parent==0?1:0);
	OnBnClickedChkRoot();
	EdtDescription.SetWindowTextA(con.Description);
	HtkShortCut.SetHotKey(con.Shortcut1,con.Shortcut2);
	EdtObservations.SetWindowTextA(con.Observations);
}
HBRUSH CFrmContactsCatData::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	int nID = pWnd->GetDlgCtrlID();

	switch (nID)
    {
		case LBLCONCATPARENT: case LBLCONCATDESC:case LBLCONCATSHORT:case IDC_OBS_CAP:
		case IDC_CHK_ROOT:
			pDC->SetBkMode(OPAQUE);
			pDC->SetBkColor(DarColor());
			return (HBRUSH) GetStockObject(NULL_BRUSH);
	}
	return hbr;
}
BOOL CFrmContactsCatData::OnEraseBkgnd(CDC* pDC)
{
	CRect rect;
	GetClientRect(&rect);
	pDC->FillSolidRect(0,0,rect.Width(),rect.Height(),DarColor());
	return 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