// InstProperties.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "aplNetStepData.h"
#include "InstProperties.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInstProperties dialog


CInstProperties::CInstProperties(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(CInstProperties::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInstProperties)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_inst_data = 0;
	m_comments = 0;
	m_data = 0;	
}


void CInstProperties::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInstProperties)
	DDX_Control(pDX, IDC_LIST_INST, m_ListInst);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInstProperties, CaplTranslateDialog)
	//{{AFX_MSG_MAP(CInstProperties)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInstProperties message handlers

void CInstProperties::OnSize(UINT nType, int cx, int cy) 
{
/*
	CRect rect;
	m_ListInst.GetWindowRect(&rect);
	ScreenToClient(rect);
	CaplTranslateDialog::OnSize(nType, cx, cy);
	rect.bottom+=cy;
	rect.right+=cx;
	m_ListInst.MoveWindow(rect);
*/
	// TODO: Add your message handler code here
	
}

BOOL CInstProperties::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rect;
	CaplInstance *inst,*user;
	CString str;
	DATE date;
	COleDateTime dt;
	SInstInfo* el;
	int i,col = 0;

	HWND hWnd = ::GetDlgItem(m_hWnd, IDC_LIST_INST);
	ListView_SetExtendedListViewStyle(hWnd, 
		ListView_GetExtendedListViewStyle(hWnd) | LVS_EX_FULLROWSELECT /*| LVS_EX_GRIDLINES */);
	
	m_ListInst.GetClientRect(rect);
	if(m_inst_data== 0 || m_data== 0)
	{
		m_ListInst.InsertColumn(0,_T(""),LVCFMT_LEFT,rect.Width()*9/10);
		m_ListInst.InsertItem(0, APL_T("Данные не предоставлены!"));
	}
	m_ListInst.InsertColumn(col++,_T("id"),LVCFMT_LEFT,rect.Width()*2/20);
	m_ListInst.InsertColumn(col++,_T("type"),LVCFMT_LEFT,rect.Width()*3/20);
	m_ListInst.InsertColumn(col++,_T("create user"),LVCFMT_LEFT,rect.Width()*3/20);
	m_ListInst.InsertColumn(col++,_T("create date"),LVCFMT_LEFT,rect.Width()*3/20);
	m_ListInst.InsertColumn(col++,_T("update user"),LVCFMT_LEFT,rect.Width()*3/20);
	m_ListInst.InsertColumn(col++,_T("update date"),LVCFMT_LEFT,rect.Width()*3/20);
	m_ListInst.InsertColumn(col++,_T("comment"),LVCFMT_LEFT,rect.Width()*3/20);

	for(i = 0;i<m_inst_data->GetSize();i++)
	{
		el=m_inst_data->GetAt(i);
		if(el== 0)continue;
		inst=el->inst;
		// id
		if(inst== 0){str=_T("inst== 0");}else{str.Format(_T("%i"),inst->GetId());}
		m_ListInst.InsertItem(i,str);
		if(inst== 0)continue;
		// type
		if(inst->GetType()== 0){str= APL_T("неизвестно");}else{str=inst->GetType()->name;}
		m_ListInst.SetItemText(i,1,str);
		// create user 
		user=el->create_user;
		if(user== 0){
			str= APL_T("неизвестен");
		}else{
			m_data->GetAttr(user,m_data->m_attr_apl_user__name,str);
		}
		m_ListInst.SetItemText(i,2,str);
		// create date 
		date=el->create_date;
		if(date== 0){
			str= APL_T("неизвестно");
		}else{
			dt=date;
			str=dt.Format(_T("%m/%d/%Y %H:%M:%S"));
		}
		m_ListInst.SetItemText(i,3,str);
		// update user 
		user=el->update_user;
		if(user== 0){
			str= APL_T("неизвестен");
		}else{
			m_data->GetAttr(user,m_data->m_attr_apl_user__name,str);
		}
		m_ListInst.SetItemText(i,4,str);
		// update date 
		date=el->update_date;
		if(date== 0){
			str= APL_T("неизвестно");
		}else{
			dt=date;
			str=dt.Format(_T("%m/%d/%Y %H:%M:%S"));
		}
		m_ListInst.SetItemText(i,5,str);
		// comment
		if(m_comments== 0)continue;
		if(m_comments->GetSize()<=i)continue;
		str=m_comments->GetAt(i);
		m_ListInst.SetItemText(i,6,str);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
