// ExpandAllDlg.cpp : implementation file
//

#include "stdafx.h"
#include "psm.h"
#include "ExpandAllDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CExpandAllDlg dialog


CExpandAllDlg::CExpandAllDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(CExpandAllDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CExpandAllDlg)
	m_doc = TRUE;
	m_mater = FALSE;
	m_contents = TRUE;
	m_charact = TRUE;
	m_lot = FALSE;
	m_prdinst = FALSE;
	m_appr = TRUE;
	m_levels = 3;
	m_res = FALSE;
	m_act = FALSE;
	m_subst = FALSE;
	m_req = FALSE;
	//}}AFX_DATA_INIT
	m_show_time=false;
}


void CExpandAllDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExpandAllDlg)
	DDX_Control(pDX, IDC_LEVELS, m_levels_ctrl);
	DDX_Check(pDX, IDC_EXPAND_DOC, m_doc);
	DDX_Check(pDX, IDC_EXPAND_MATERIAL, m_mater);
	DDX_Check(pDX, IDC_EXPAND_CONTENTS, m_contents);
	DDX_Check(pDX, IDC_EXPAND_CHARACTERISTIC, m_charact);
	DDX_Check(pDX, IDC_EXPAND_LOT, m_lot);
	DDX_Check(pDX, IDC_EXPAND_PRDINSTANCE, m_prdinst);
	DDX_Check(pDX, IDC_EXPAND_APPR, m_appr);
	DDX_Text(pDX, IDC_LEVELS, m_levels);
	DDX_Check(pDX, IDC_EXPAND_RES, m_res);
	DDX_Check(pDX, IDC_EXPAND_BP, m_act);
	DDX_Check(pDX, IDC_EXPAND_SUBST, m_subst);
	DDX_Check(pDX, IDC_EXPAND_REQ, m_req);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CExpandAllDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(CExpandAllDlg)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExpandAllDlg message handlers

void CExpandAllDlg::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	*pResult = 0;
	CString buf;
	m_levels_ctrl.GetWindowText(buf);
	int i=_atoi(buf);
	i-=pNMUpDown->iDelta;
	if(i<1) i=1;
	buf.Format(_T("%i"),i);
	m_levels_ctrl.SetWindowText(buf);

}

BOOL CExpandAllDlg::OnInitDialog() 
{
	CString params,param;
	int i1=0,i2=0;

	params=AfxGetApp()->GetProfileString(_T("options"),_T("RecursivePasrams"));
	if(params.IsEmpty()==FALSE)
	{
		i1=params.Find(_T("LEV:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_levels = _atoi(param);
		}
		i1=params.Find(_T("DOC:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_doc = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("MAT:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_mater = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("CON:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_contents = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("CHA:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_charact = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("LOT:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_lot = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("PRI:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_prdinst = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("APR:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_appr = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("RES:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_res = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("ACT:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_act = _atoi(param)>0?TRUE:FALSE;
		}
		i1=params.Find(_T("SUB:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_subst = _atoi(param)>0?TRUE:FALSE;
		}		
		i1=params.Find(_T("REQ:"));
		if(i1!=-1){
			i2=params.Find(_T(";"),i1);
			param=params.Mid(i1+4,i2-i1-4);
			m_req = _atoi(param)>0?TRUE:FALSE;
		}
	}

	CaplTranslateDialog::OnInitDialog();
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CExpandAllDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString params;
	short state=GetKeyState(VK_LCONTROL);
	if((state & 0xff00)!=0)
	{
		m_show_time=true;
	}
	else
	{
	}

	CaplTranslateDialog::OnOK();
	
	params.Format(_T("LEV:%i;DOC:%i;MAT:%i;CON:%i;CHA:%i;LOT:%i;PRI:%i;APR:%i;RES:%i;ACT:%i;SUB:%i;REQ:%i;"),
		m_levels,m_doc == TRUE?1:0,m_mater == TRUE?1:0,m_contents == TRUE?1:0,
		m_charact == TRUE?1:0,m_lot== TRUE?1:0,m_prdinst == TRUE?1:0,
		m_appr == TRUE?1:0,m_res == TRUE?1:0,m_act == TRUE?1:0,m_subst == TRUE?1:0,m_req == TRUE?1:0);
	AfxGetApp()->WriteProfileString(_T("options"),_T("RecursivePasrams"),params);
	
}
