// OfficialPropDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OfficialPropDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COfficialPropDlg dialog


COfficialPropDlg::COfficialPropDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(COfficialPropDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COfficialPropDlg)
	m_Owner = _T("");
	m_Person = _T("");
	//}}AFX_DATA_INIT
	m_id = _T("");
	m_descr = _T("");
	m_data = 0;
	inst = 0;
}


void COfficialPropDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COfficialPropDlg)
	DDX_Control(pDX, IDCANCEL, m_cancel_btn);
	DDX_Text(pDX, IDC_ID, m_id);
	DDX_Text(pDX, IDC_DESCRIPTION, m_descr);
	DDX_Text(pDX, IDC_OWNER_TITLE, m_Owner);
	DDX_Text(pDX, IDC_ACT_PERSON_TITLE, m_Person);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COfficialPropDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(COfficialPropDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COfficialPropDlg message handlers

BOOL COfficialPropDlg::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();
	
	if(m_data==0 || inst == 0) 
	{
		SendMessage(WM_CLOSE);
		return FALSE;
	}

	m_cancel_btn.SetFlat(FALSE);
	m_cancel_btn.SetIcon(GetAplStdIco16(APLSTDICO_CANCEL));

	m_data->GetAttrBN(inst,_T("id"),m_id);
	m_data->GetAttrBN(inst,_T("description"),m_descr);
	CaplInstance *owner=0, *person=0;
	m_data->GetAttrBN(inst,_T("owner"),owner);
	m_data->GetAttrBN(inst,_T("actual_person"),person);
	CString fname, lname, name;
	CaplAggr aggr;
	if(person!=0)
	{
		m_data->GetAttrBN(person,_T("first_name"),fname);
		m_data->GetAttrBN(person,_T("last_name"),lname);
		m_data->GetAttrBN(person,_T("middle_names"),aggr);
		aggr.GetByIndex(0,name);
		m_Person = lname+_T(" ")+fname.Left(1)+_T(". ")+name.Left(1)+_T(".");
	}
	if(owner!=0)
	{
		m_data->GetAttrBN(owner,_T("first_name"),fname);
		m_data->GetAttrBN(owner,_T("last_name"),lname);
		m_data->GetAttrBN(owner,_T("middle_names"),aggr);
		aggr.GetByIndex(0,name);
		m_Owner = lname+_T(" ")+fname.Left(1)+_T(". ")+name.Left(1)+_T(".");
	}
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
