// GenSpecDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GenSpecDlg.h"
#include "SpecGenerator.h"

// CGenSpecDlg dialog

IMPLEMENT_DYNAMIC(CGenSpecDlg, CDialog)

CGenSpecDlg::CGenSpecDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGenSpecDlg::IDD, pParent)
{
	m_SpecGenerator=0;
	m_b4change=false;
}

CGenSpecDlg::~CGenSpecDlg()
{
}

void CGenSpecDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDOK, m_ok_btn);
	DDX_Control(pDX, IDCANCEL, m_cancel_btn);
	DDX_Control(pDX, IDC_GET_FORMAT_FOR_PART, m_GetFormatForPartBtn);
	DDX_Control(pDX, IDC_SET_BCH_FOR_PART, m_SetBCHForPartBtn);
	DDX_Control(pDX, IDC_SET_EMPTY_POSITION, m_SetEmptyPositionBtn);
	DDX_Control(pDX, IDC_CLEAR_EXIST_POSITION, m_ClearExistPosBtn);
	DDX_Control(pDX, IDC_SAVE_SPEC_IN_DB, m_SaveToDBBtn);
	DDX_Control(pDX, ION_ACTIVE, m_SetNevVersinActiveBtn);
	DDX_Control(pDX, IDC_SUBSTITUTIONS, m_UserSubstBtn);
	DDX_Control(pDX, IDC_USE_OST4, m_use_ost4_btn);
	DDX_Control(pDX, IDC_BCH_ADD_MAT, m_bch_add_mat_btn);
	DDX_Control(pDX, IDC_USAGE, m_usage_btn);
	DDX_Control(pDX, IDC_USE_ASSEMBLY_DESCR, m_use_assembly_descr_btn);
}


BEGIN_MESSAGE_MAP(CGenSpecDlg, CDialog)
	ON_BN_CLICKED(IDC_SAVE_SPEC_IN_DB, &CGenSpecDlg::OnBnClickedSaveSpecInDb)
	ON_BN_CLICKED(IDC_SET_EMPTY_POSITION, &CGenSpecDlg::OnBnClickedSetEmptyPosition)
	ON_BN_CLICKED(IDC_GET_FORMAT_FOR_PART, &CGenSpecDlg::OnBnClickedGetFormatForPart)
END_MESSAGE_MAP()


// CGenSpecDlg message handlers

BOOL CGenSpecDlg::OnInitDialog()
{
	if(0==m_SpecGenerator) EndDialog(IDCANCEL);

	CDialog::OnInitDialog();

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

	m_SaveToDBBtn.SetCheck(m_SpecGenerator->m_bSaveAsDocument);
	m_SetNevVersinActiveBtn.SetCheck(m_SpecGenerator->m_bSetNewVersionActive);

	m_SetEmptyPositionBtn.SetCheck(m_SpecGenerator->m_bSetEmptyPosition);
	m_ClearExistPosBtn.SetCheck(m_SpecGenerator->m_bClearExistPos);

	m_GetFormatForPartBtn.SetCheck(m_SpecGenerator->m_bGetFormatForPart);
	m_SetBCHForPartBtn.SetCheck(m_SpecGenerator->m_bSetBCHForPart);

	m_UserSubstBtn.SetCheck(m_SpecGenerator->m_bUseSubst);
	m_use_ost4_btn.SetCheck(m_SpecGenerator->m_bUseOst4);
	m_bch_add_mat_btn.SetCheck(m_SpecGenerator->m_bBCHF_AddMat);
	m_usage_btn.SetCheck(m_SpecGenerator->m_bUsage);

	m_use_assembly_descr_btn.SetCheck(m_SpecGenerator->m_bUseAassemblyDescr4Notes);

	// Дизаблим контролы
	OnBnClickedSaveSpecInDb();	
	OnBnClickedSaveSpecInDb();
	OnBnClickedGetFormatForPart();

	if(m_b4change)
	{
		m_SaveToDBBtn.EnableWindow(FALSE);
		m_SetNevVersinActiveBtn.EnableWindow(FALSE);
	}

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

//*********************************************************************************
void CGenSpecDlg::OnBnClickedSaveSpecInDb()
{
	m_SetNevVersinActiveBtn.EnableWindow(m_SaveToDBBtn.GetCheck());
}

void CGenSpecDlg::OnBnClickedSetEmptyPosition()
{
	m_ClearExistPosBtn.EnableWindow(m_SetEmptyPositionBtn.GetCheck());
}

void CGenSpecDlg::OnBnClickedGetFormatForPart()
{
	m_SetBCHForPartBtn.EnableWindow(m_GetFormatForPartBtn.GetCheck());
}

//*********************************************************************************
void CGenSpecDlg::OnOK()
{
	m_SpecGenerator->m_bSaveAsDocument=m_SaveToDBBtn.GetCheck();
	m_SpecGenerator->m_bSetNewVersionActive=m_SetNevVersinActiveBtn.GetCheck();

	m_SpecGenerator->m_bSetEmptyPosition=m_SetEmptyPositionBtn.GetCheck();
	m_SpecGenerator->m_bClearExistPos=m_ClearExistPosBtn.GetCheck();

	m_SpecGenerator->m_bGetFormatForPart=m_GetFormatForPartBtn.GetCheck();
	m_SpecGenerator->m_bSetBCHForPart=m_SetBCHForPartBtn.GetCheck();

	m_SpecGenerator->m_bUseSubst=m_UserSubstBtn.GetCheck();
	m_SpecGenerator->m_bUseOst4=m_use_ost4_btn.GetCheck();
	m_SpecGenerator->m_bBCHF_AddMat=m_bch_add_mat_btn.GetCheck();
	m_SpecGenerator->m_bUsage=m_usage_btn.GetCheck();
	m_SpecGenerator->m_bUseAassemblyDescr4Notes=m_use_assembly_descr_btn.GetCheck();

	m_SpecGenerator->SaveOptions();

	CDialog::OnOK();
}

