// ProductDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ProductDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CProductDlg dialog
CProductDlg::CProductDlg(CWnd* pParent /*=NULL*/)
	: CaplResizableDialog(CProductDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CProductDlg)
	m_pdf_id = _T("");
	m_pdf_descr = _T("");
	m_prd_id = _T("");
	m_prd_name = _T("");
	m_prd_descr = _T("");
	m_nauo_descr = _T("");
	m_nauo_id = _T("");
	m_nauo_name = _T("");
	m_nauo_count = 1.0;
	m_ranking = 0;
	m_ranking_rationale = _T("");
	m_prd_code = _T("");
	m_pdf_code = _T("");
	m_nauo_count2 = 1.0;
	m_pdf_code1 = _T("");
	m_pdf_code2 = _T("");
	m_ref_des = _T("");
	//}}AFX_DATA_INIT
	m_pdf=NULL; m_prd=NULL;
	m_base_pdf=0; m_base_prd=0;m_base_nauo=0;m_parent_pdf=0;
	m_nauo=0;
	m_subst=0;
	m_mode=aplModeEdit;
	m_add_mode=false; m_ok_end=false; m_context_changed=false;
	m_api = NULL;

	m_new_clasif_level=0; m_old_clasif_level=0;


	m_pdf_first_usage=0;

	m_csAccessString	=_T("");

	m_bOpenPrdCode=false;
	m_bOpenPdfCode=false;
	m_bOpenPdfCode1=false;
	m_bOpenPdfCode2=false;

	m_bDizableEditPrd=false;
	m_bDizableEditPdf=false;
	m_bDizableEditNAUO=false;

	m_bIsCreatingCopy = false;

	m_changed_prd = false;
	m_changed_pdf = false;
}


void CProductDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplResizableDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProductDlg)
	DDX_Control(pDX, IDC_PDF_FIRST_USAGE_BTN, m_pdf_first_usage_btn);
	DDX_Control(pDX, IDC_STATIC_PDF_FIRST_USAGE_ST, m_pdf_first_usage_st);
	DDX_Control(pDX, IDC_FORMATION_FIRST_USAGE_EDT, m_pdf_first_usage_edt);
	DDX_Control(pDX, IDC_PRD_NAME_CNG, m_prd_name_cng_btn);
	DDX_Control(pDX, IDC_REF_DES_STATIC, m_ref_des_static_ctrl);
	DDX_Control(pDX, IDC_REF_DES, m_ref_des_ctrl);
	DDX_Control(pDX, IDC_STATIC_PDF_CODE2, m_st_pdf_code2);
	DDX_Control(pDX, IDC_STATIC_PDF_CODE1, m_st_pdf_code1);
	DDX_Control(pDX, IDC_PDF_CODE2, m_pdf_code2_ctrl);
	DDX_Control(pDX, IDC_PDF_CODE1, m_pdf_code1_ctrl);
	DDX_Control(pDX, IDC_PDF_CODE2_CNG, m_pdf_code2_cng_btn);
	DDX_Control(pDX, IDC_PDF_CODE1_CNG, m_pdf_code1_cng_btn);
	DDX_Control(pDX, IDC_PDF_CODE_CNG, m_pdf_code_cng_btn);
	DDX_Control(pDX, IDC_PRD_CODE_CNG, m_prd_code_cng_btn);
	DDX_Control(pDX, IDC_PRD_ID_CNG, m_prd_id_cng_btn);
	DDX_Control(pDX, IDC_PDF_ID_CNG, m_pdf_id_cng_btn);
	DDX_Control(pDX, IDC_PDF_UNIT, m_pdf_unit);
	DDX_Control(pDX, IDC_STATIC_PDF_UNIT, m_st_pdf_unit);
	DDX_Control(pDX, IDC_REL_PROPERTY, m_rel_property_btn);
	DDX_Control(pDX, IDC_ST_CONTEXT, m_st_contexts);
	DDX_Control(pDX, IDC_CONTEXTS_NAMES, m_context_names);
	DDX_Control(pDX, IDC_CONTEXT_SELECT, m_context_sel);
	DDX_Control(pDX, IDC_NAUO_COUNT2, m_nauo_count2_ctrl);
	DDX_Control(pDX, IDC_NAUO_UNIT2, m_nauo_unit2);
	//	DDX_Control(pDX, IDC_NAUO_SORTAMENT, m_sortament);
	//	DDX_Control(pDX, IDC_STATIC_SORTAMENT, m_st_sort);
	DDX_Control(pDX, IDC_STATIC_COUNT2, m_st_count2);
	DDX_Control(pDX, IDC_ADD_PRODUCT, m_btn_add);
	DDX_Control(pDX, IDC_PDF_CODE, m_pdf_code_ctrl);
	DDX_Control(pDX, IDC_PRODUCT_CODE, m_prd_code_ctrl);
	DDX_Control(pDX, IDC_SETUP_UNIT_CONVERTIONS, m_setup_unit_convertions_btn);
	DDX_Control(pDX, IDC_STATIC_PDF_CODE, m_st_pdf_code);
	DDX_Control(pDX, IDC_ST_RANK_RATIONALE, m_st_rank_rat);
	DDX_Control(pDX, IDC_NAUO_RANKING_RATIONALE, m_ranking_rationale_ctrl);
	DDX_Control(pDX, IDC_NAUO_RANKING, m_ranking_ctrl);
	DDX_Control(pDX, IDC_STATIC_RANKING_NAME, m_ranking_name_ctrl);
	DDX_Control(pDX, IDC_ST_NAME, m_st_header);
	DDX_Control(pDX, IDC_TEST, m_test_btn);
	DDX_Control(pDX, IDOK, m_btn_ok);
	DDX_Control(pDX, IDCANCEL, m_btn_cancel);
	DDX_Control(pDX, IDC_STATIC_PRD, m_st_prd);
	DDX_Control(pDX, IDC_PDF_STANDARD, m_pdf_std);
	DDX_Control(pDX, IDC_STATIC_PDF_V, m_s_pdf_v);
	DDX_Control(pDX, IDC_STATIC_PDF_TYPE, m_s_pdf_type);
	DDX_Control(pDX, IDC_STATIC_PDF_SOURCE, m_s_pdf_src);
	DDX_Control(pDX, IDC_STATIC_PDF_ID, m_s_pdf_id);
	DDX_Control(pDX, IDC_STATIC_PDF_DESCR, m_s_pdf_descr);
	DDX_Control(pDX, IDC_NAUO_COUNT, m_nauo_count_ctrl);
	DDX_Control(pDX, IDC_NAUO_UNIT, m_nauo_unit_ctrl);
	DDX_Control(pDX, IDC_STATIC_NAME, m_st_name);
	DDX_Control(pDX, IDC_STATIC_POS, m_st_pos);
	DDX_Control(pDX, IDC_STATIC_DESCR, m_st_descr);
	DDX_Control(pDX, IDC_STATIC_ASM, m_st_asm);
	DDX_Control(pDX, IDC_STATIC_COUNT, m_st_count);
	DDX_Control(pDX, IDC_NAUO_DESCR, m_nauo_descr_ctrl);
	DDX_Control(pDX, IDC_NAUO_NAME, m_nauo_name_ctrl);
	DDX_Control(pDX, IDC_NAUO_ID, m_nauo_id_ctrl);
	DDX_Control(pDX, IDC_SOURCE, m_source_ctrl);
	DDX_Control(pDX, IDC_TYPE, m_type_ctrl);
	DDX_Control(pDX, IDC_PRODUCT_DESCRIPTION, m_prd_descr_ctrl);
	DDX_Control(pDX, IDC_PRODUCT_NAME, m_prd_name_ctrl);
	DDX_Control(pDX, IDC_PRODUCT_ID, m_prd_id_ctrl);
	DDX_Control(pDX, IDC_FORMATION_DESCRIPTION, m_pdf_descr_ctrl);
	DDX_Control(pDX, IDC_FORMATION_ID, m_pdf_id_ctrl);
	DDX_Text(pDX, IDC_FORMATION_ID, m_pdf_id);
	DDX_Text(pDX, IDC_FORMATION_DESCRIPTION, m_pdf_descr);
	DDX_Text(pDX, IDC_PRODUCT_ID, m_prd_id);
	DDX_Text(pDX, IDC_PRODUCT_NAME, m_prd_name);
	DDX_Text(pDX, IDC_PRODUCT_DESCRIPTION, m_prd_descr);
	DDX_Text(pDX, IDC_NAUO_DESCR, m_nauo_descr);
	DDX_Text(pDX, IDC_NAUO_ID, m_nauo_id);
	DDX_Text(pDX, IDC_NAUO_NAME, m_nauo_name);
	DDX_Text(pDX, IDC_NAUO_COUNT, m_nauo_count);
	DDX_Text(pDX, IDC_NAUO_RANKING, m_ranking);
	DDX_Text(pDX, IDC_NAUO_RANKING_RATIONALE, m_ranking_rationale);
	DDX_Text(pDX, IDC_PRODUCT_CODE, m_prd_code);
	DDX_Text(pDX, IDC_PDF_CODE, m_pdf_code);
	DDX_Text(pDX, IDC_PDF_CODE1, m_pdf_code1);
	DDX_Text(pDX, IDC_PDF_CODE2, m_pdf_code2);
	DDX_Text(pDX, IDC_NAUO_COUNT2, m_nauo_count2);
	DDX_Text(pDX, IDC_REF_DES, m_ref_des);
	DDX_Control(pDX, IDC_TAB1, m_Tab);
	DDX_Control(pDX, IDC_B_PROPS_PROPS, m_bPropsProps);
	DDX_Control(pDX, IDC_B_PROPS_DEL, m_bPropsDel);
	DDX_Control(pDX, IDC_B_PROPS_ADD, m_bPropsAdd);
	DDX_Control(pDX, IDC_RELEVANCE, m_relevance_ctrl);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProductDlg, CaplResizableDialog)
	//{{AFX_MSG_MAP(CProductDlg)
	ON_BN_CLICKED(IDC_TEST, OnTest)
	ON_BN_CLICKED(IDC_ST_NAME, OnStName)
	ON_BN_CLICKED(IDC_ADD_PRODUCT, OnAddProduct)
	ON_BN_CLICKED(IDC_CONTEXT_SELECT, OnContextSel)
	ON_BN_CLICKED(IDC_REL_PROPERTY, OnRelProperty)
	ON_CBN_SELCHANGE(IDC_TYPE, OnSelchangeType)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
	ON_BN_CLICKED(IDC_B_PROPS_ADD, OnBPropsAdd)
	ON_BN_CLICKED(IDC_B_PROPS_DEL, OnBPropsDel)
	ON_BN_CLICKED(IDC_B_PROPS_PROPS, OnBPropsProps)
	ON_BN_CLICKED(IDC_PRD_ID_CNG, OnPrdIdCng)
	ON_BN_CLICKED(IDC_PRD_CODE_CNG, OnPrdCodeCng)
	ON_BN_CLICKED(IDC_PDF_CODE1_CNG, OnPdfCode1Cng)
	ON_BN_CLICKED(IDC_PDF_CODE2_CNG, OnPdfCode2Cng)
	ON_BN_CLICKED(IDC_PDF_CODE_CNG, OnPdfCodeCng)
	ON_BN_CLICKED(IDC_PDF_ID_CNG, OnPdfIdCng)
	ON_BN_CLICKED(IDC_PRD_NAME_CNG, OnPrdNameCng)
	ON_BN_CLICKED(IDC_PDF_FIRST_USAGE_BTN, OnPdfFirstUsageBtn)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_SETUP_UNIT_CONVERTIONS, &CProductDlg::OnBnClickedSetupUnitConvertions)
	ON_EN_CHANGE(IDC_PRODUCT_ID, &CProductDlg::OnEnChangePrdAttrs)
	ON_EN_CHANGE(IDC_PRODUCT_CODE, &CProductDlg::OnEnChangePrdAttrs)
	ON_EN_CHANGE(IDC_PRODUCT_NAME, &CProductDlg::OnEnChangePrdAttrs)
	ON_EN_CHANGE(IDC_PRODUCT_DESCRIPTION, &CProductDlg::OnEnChangePrdAttrs)
	ON_EN_CHANGE(IDC_FORMATION_ID, &CProductDlg::OnEnChangePdfAttrs)
	ON_EN_CHANGE(IDC_PDF_CODE, &CProductDlg::OnEnChangePdfAttrs)
	ON_EN_CHANGE(IDC_FORMATION_DESCRIPTION, &CProductDlg::OnEnChangePdfAttrs)
	ON_EN_CHANGE(IDC_PDF_CODE1, &CProductDlg::OnEnChangePdfAttrs)
	ON_EN_CHANGE(IDC_PDF_CODE2, &CProductDlg::OnEnChangePdfAttrs)
	ON_CBN_SELCHANGE(IDC_PDF_UNIT, &CProductDlg::OnCbnSelchangePdfCombo)
	ON_CBN_SELCHANGE(IDC_SOURCE, &CProductDlg::OnCbnSelchangePdfCombo)
	ON_BN_CLICKED(IDC_PDF_STANDARD, &CProductDlg::OnBnClickedPdfStandard)
END_MESSAGE_MAP()

BOOL CProductDlg::SetAnchors(void)
{
	AddAnchor(IDC_ST_NAME,TOP_CENTER);

	AddAnchor(IDC_B_PROPS_ADD,TOP_RIGHT);
	AddAnchor(IDC_B_PROPS_DEL,TOP_RIGHT);
	AddAnchor(IDC_B_PROPS_PROPS,TOP_RIGHT);

	AddAnchor(IDC_TAB1,TOP_LEFT,BOTTOM_RIGHT);


	AddAnchor(IDC_STATIC_PRD,TOP_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_T_PRD_ID,TOP_LEFT);
		AddAnchor(IDC_PRODUCT_ID,TOP_LEFT,TOP_RIGHT);
		AddAnchor(IDC_PRD_ID_CNG,TOP_RIGHT);
		AddAnchor(IDC_PRD_NAME_CNG,TOP_RIGHT);
		AddAnchor(IDC_T_PRD_CODE,TOP_RIGHT);
		AddAnchor(IDC_PRODUCT_CODE,TOP_RIGHT);
		AddAnchor(IDC_PRD_CODE_CNG,TOP_RIGHT);
		AddAnchor(IDC_T_PRD_NAME,TOP_LEFT);
		AddAnchor(IDC_PRODUCT_NAME,TOP_LEFT,TOP_RIGHT);
		AddAnchor(IDC_T_PRD_DESCR,TOP_LEFT);
		AddAnchor(IDC_PRODUCT_DESCRIPTION,TOP_LEFT,BOTTOM_RIGHT);
	
	AddAnchor(IDC_STATIC_PDF_V,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_ID,BOTTOM_LEFT);
		AddAnchor(IDC_FORMATION_ID,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_FORMATION_FIRST_USAGE_EDT,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_FIRST_USAGE_ST,BOTTOM_LEFT);
		AddAnchor(IDC_RELEVANCE,BOTTOM_RIGHT);
		AddAnchor(IDC_ST_RELEVANCE,BOTTOM_RIGHT);

		AddAnchor(IDC_PDF_FIRST_USAGE_BTN,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_ID_CNG,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_UNIT,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_UNIT,BOTTOM_RIGHT);
		AddAnchor(IDC_SETUP_UNIT_CONVERTIONS,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_CODE,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_CODE,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_CODE_CNG,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_DESCR,BOTTOM_LEFT);
		AddAnchor(IDC_FORMATION_DESCRIPTION,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_CODE1,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_CODE1,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_CODE1_CNG,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_CODE2,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_CODE2,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_CODE2_CNG,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_TYPE,BOTTOM_LEFT);
		AddAnchor(IDC_TYPE,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_PDF_SOURCE,BOTTOM_RIGHT);
		AddAnchor(IDC_SOURCE,BOTTOM_RIGHT);
		AddAnchor(IDC_PDF_STANDARD,BOTTOM_RIGHT);


	AddAnchor(IDC_STATIC_ASM,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_POS,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_ID,BOTTOM_LEFT);
		AddAnchor(IDC_STATIC_NAME,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_NAME,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_REF_DES_STATIC,BOTTOM_LEFT);
		AddAnchor(IDC_REF_DES,BOTTOM_LEFT);
		AddAnchor(IDC_STATIC_DESCR,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_DESCR,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_REL_PROPERTY,BOTTOM_RIGHT);
		AddAnchor(IDC_ST_CONTEXT,BOTTOM_LEFT);
		AddAnchor(IDC_CONTEXTS_NAMES,BOTTOM_LEFT,BOTTOM_RIGHT);
		AddAnchor(IDC_CONTEXT_SELECT,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_COUNT,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_COUNT,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_UNIT,BOTTOM_LEFT);
		AddAnchor(IDC_STATIC_COUNT2,BOTTOM_RIGHT);
		AddAnchor(IDC_NAUO_COUNT2,BOTTOM_RIGHT);
		AddAnchor(IDC_NAUO_UNIT2,BOTTOM_RIGHT);
		AddAnchor(IDC_STATIC_RANKING_NAME,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_RANKING,BOTTOM_LEFT);
		AddAnchor(IDC_ST_RANK_RATIONALE,BOTTOM_LEFT);
		AddAnchor(IDC_NAUO_RANKING_RATIONALE,BOTTOM_LEFT,BOTTOM_RIGHT);
//		AddAnchor(IDC_STATIC_SORTAMENT,BOTTOM_LEFT);
//		AddAnchor(IDC_NAUO_SORTAMENT,BOTTOM_LEFT,BOTTOM_RIGHT);

	AddAnchor(IDC_TEST,BOTTOM_LEFT);
	AddAnchor(IDC_ADD_PRODUCT,BOTTOM_LEFT);
	AddAnchor(IDOK,BOTTOM_RIGHT);
	AddAnchor(IDCANCEL,BOTTOM_RIGHT);

	return TRUE;
}

void CProductDlg::SetSize(int cy)
{
	CRect rt;
	CSize sz;

	GetWindowRect(rt);
	sz.cx=rt.right-rt.left;
	sz.cy=rt.bottom-rt.top-cy;
	SetMinTrackSize(sz);

	m_Tab.GetWindowRect(rt);
	ScreenToClient(rt);
	rt.bottom-=cy;
	m_Tab.MoveWindow(rt);
}

BOOL CProductDlg::InitViews(void)
{
	CaplCharactView*	pCharView	=NULL;
	CaplApprovalView*	pApprView	=NULL;
	CaplDocsView*		pDocsView	=NULL;
	CaplAccessView*		pAccView	=NULL;

	CWnd*				pWnd		=NULL;

	CArray<int,int>		caExcludes;

	CRect				rt;

	DWORD				dwStyles=WS_CHILD|WS_BORDER;

	CaplInstance*		cit			=NULL;

	#ifdef _MOMA_
	m_pdf_first_usage_st.SetWindowText(_T("Classification:"));
	#endif


	m_source_ctrl.ResetContent();
	m_source_ctrl.InsertString(0,APL_T("Не известно"));
	m_source_ctrl.InsertString(1,APL_T("Покупное"));
	m_source_ctrl.InsertString(2,APL_T("Изготовляемое"));
	m_source_ctrl.InsertString(3,APL_T("По кооперации"));
	#ifdef _MOMA_
		m_source_ctrl.InsertString(4,APL_T("Назначается"));
	#endif

	if(NULL!=m_pdf)
		cit=m_pdf;
	else
		cit=m_prd;

	m_Tab.SetImageList(aplGetTabCtrlImageList());

	m_Tab.InsertItem(0, APL_T("Свойства"),0);
	m_Tab.AddTab(0,NULL);
	m_Tab.SetCurSel(0);

	caExcludes.Add(IDC_ST_NAME);
	caExcludes.Add(IDC_B_PROPS_ADD);
	caExcludes.Add(IDC_B_PROPS_DEL);
	caExcludes.Add(IDC_B_PROPS_PROPS);
	m_Tab.AddExcludeIDs(caExcludes);

	//pWnd=GetDlgItem(IDC_T_VIEW_FRAME);
	//pWnd->GetClientRect(rt);
	//pWnd->ClientToScreen(rt);
	m_Tab.GetWindowRect(rt);
	rt.DeflateRect(8,75,8,8);
	ScreenToClient(rt);


	if(NULL!=m_prd || (NULL!=m_pdf && aplModeCreateProductIfNew!=m_mode))
	{
		m_Tab.InsertItem(1, APL_T("Характеристики"),1);
		pCharView=(CaplCharactView*)(RUNTIME_CLASS(CaplCharactView)->CreateObject());
		pCharView->Create(NULL,NULL,dwStyles,rt,this,0);
		pCharView->m_inst=cit;
		pCharView->m_api=m_api;

		pCharView->SetBtnsHandles(&m_bPropsAdd,&m_bPropsDel,&m_bPropsProps);
		pCharView->OnInitialUpdate();
		m_Tab.AddTab(1,pCharView);
		AddAnchor(pCharView->m_hWnd,TOP_LEFT,BOTTOM_RIGHT);

		m_Tab.InsertItem(2, APL_T("Документы"),2);
		pDocsView=(CaplDocsView*)(RUNTIME_CLASS(CaplDocsView)->CreateObject());
		pDocsView->Create(NULL,NULL,dwStyles,rt,this,0);
		pDocsView->m_inst=cit;
		pDocsView->m_api=m_api;

		pDocsView->SetBtnsHandles(&m_bPropsAdd,&m_bPropsDel,&m_bPropsProps);
		pDocsView->OnInitialUpdate();
		m_Tab.AddTab(2,pDocsView);
		AddAnchor(pDocsView->m_hWnd,TOP_LEFT,BOTTOM_RIGHT);

		m_Tab.InsertItem(3, APL_T("Электронные подписи"),3);
		pApprView=(CaplApprovalView*)(RUNTIME_CLASS(CaplApprovalView)->CreateObject());
		pApprView->Create(NULL,NULL,dwStyles,rt,this,0);
		pApprView->m_inst=cit;
		pApprView->m_api=m_api;

		pApprView->SetBtnsHandles(&m_bPropsAdd,&m_bPropsDel,&m_bPropsProps);
		pApprView->OnInitialUpdate();
		m_Tab.AddTab(3,pApprView);
		AddAnchor(pApprView->m_hWnd,TOP_LEFT,BOTTOM_RIGHT);
	}

	if(aplModeCreateProductIfNew!=m_mode){
		if(NULL==m_prd && NULL==m_pdf)
			m_Tab.InsertItem(1, APL_T("Доступ"),17);
		else
			m_Tab.InsertItem(4, APL_T("Доступ"),17);
		
		pAccView=(CaplAccessView*)(RUNTIME_CLASS(CaplAccessView)->CreateObject());
		pAccView->Create(NULL,NULL,dwStyles|LVS_NOSORTHEADER,rt,this,0);
		pAccView->m_inst=cit;
		pAccView->m_api=m_api;
		
		pAccView->SetBtnsHandles(&m_bPropsAdd,&m_bPropsDel,&m_bPropsProps);
		pAccView->OnInitialUpdate();
		if(NULL==m_prd && NULL==m_pdf)
			m_Tab.AddTab(1,pAccView);
		else
			m_Tab.AddTab(4,pAccView);
		if(NULL==m_prd || NULL==m_pdf)
		{
			CString	csAccPatName;
			
			CaplEntity* et=NULL;
			
			if(aplModeCreateProduct==m_mode && NULL==m_prd)
				et=m_api->m_prd_mgr.e_prd;
			if(aplModeCreateVersion==m_mode && NULL==m_pdf)
				et=m_api->m_prd_mgr.e_pdf;
			if(aplModeCreateSubProduct==m_mode && NULL==m_pdf)
				et=m_api->m_prd_mgr.e_pdf;
			if(aplModeCreateProductIfNew==m_mode)
				et=0;
			if(NULL!=et)
				if(true==m_api->m_prd_mgr.m_AutoUsurpire)
					if(TRUE==m_api->m_options_mgr.GetDefTmplName(et,csAccPatName))
						pAccView->SetDefaultTemplate(csAccPatName);
		}
		
		AddAnchor(pAccView->m_hWnd,TOP_LEFT,BOTTOM_RIGHT);
	}


	return TRUE;
}

void CProductDlg::ChangeViewBtnsState(BOOL bDis,BOOL bHide)
{
	CWnd*	pwnd	=NULL;

	int		iIDs[]={IDC_B_PROPS_ADD,IDC_B_PROPS_DEL,IDC_B_PROPS_PROPS};
	int		iShow=SW_SHOW;
	int		i;

	if(TRUE==bHide)
		iShow=SW_HIDE;

	for(i=0;i<sizeof(iIDs)/sizeof(int);i++)
	{
		pwnd=GetDlgItem(iIDs[i]);
		pwnd->EnableWindow(bDis);
		pwnd->ShowWindow(iShow);
	}
}

void CProductDlg::GetAccessString(void)
{
	CaplAccessView*	pAccView	=NULL;

	CWnd*			pwnd		=NULL;

	int				i;
	
	for(i=0;i<m_Tab.GetItemCount();i++)
	{
		m_Tab.GetTabView(i,pwnd);
		if(pwnd!=NULL)
			if(pwnd->IsKindOf(RUNTIME_CLASS(CaplAccessView)))
			{
				pAccView=(CaplAccessView*)pwnd;
				pAccView->GetAccessString(m_csAccessString);
			}
	}
}
/////////////////////////////////////////////////////////////////////////////
// CProductDlg message handlers

bool CProductDlg::SelectUnit(CComboBox &box, CaplInstance *inst)
{
	int i=0, j;
	while(1)
	{
		j=box.GetItemData(i);
		if(j==CB_ERR) break;
		if(j==(int)inst){box.SetCurSel(i); return true;}
		i++;
	}
	
	//если не нашли, а inst не задана
	if(inst && m_api->m_data.IsKindOf(inst, m_api->m_charact_mgr.e_apl_unit))
	{
		CString buf;
		m_api->m_charact_mgr.GetUnitName(inst, buf);
		int k= box.AddString(buf);
		box.SetItemData(k, (UINT)inst);
		box.SetCurSel(k); 
		return true;
	}
	
	return false;
}

// Для того чтобы показывались значения отсутствующие в не moma версии
void CProductDlg::SetSource(CString &src)
{
	CString src1=src=CaplProductManager::StrConvertMakeOrBuy2Rus(src);
	int i=m_source_ctrl.FindString(0,src1);
	if(i<0 )  m_source_ctrl.InsertString(m_source_ctrl.GetCount(), src1);
	m_source_ctrl.SelectString(0,src1);
}


BOOL CProductDlg::OnInitDialog() 
{
	CaplResizableDialog::OnInitDialog();
	if(m_api==NULL)
	{
		EndDialog(0);
		return FALSE;
	}

	// предотвращаем потерю модальности после диалога с бочками из aplSocketTransport
	CORRECT_LOOSE_MODAL_ON_CLASS(&(m_api->m_data));
	
	ModifyStyleEx(0, WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT);   
	ModifyStyle(0, WS_MAXIMIZEBOX);   


	m_type_ctrl.Clear();
	while(m_type_ctrl.GetCount()>0) m_type_ctrl.DeleteString(0);
	
	m_type_ctrl.AddString(APL_T("Деталь"));
	m_type_ctrl.AddString(APL_T("Сборочная единица"));
	m_type_ctrl.AddString(APL_T("Материал"));
	m_type_ctrl.AddString(APL_T("Комплект"));
	m_type_ctrl.AddString(APL_T("Комплекс"));
	m_type_ctrl.AddString(APL_T("Зона"));
	m_type_ctrl.AddString(APL_T("Программный модуль"));
	m_type_ctrl.AddString(APL_T("Система"));
	#ifdef _MOMA_
		m_type_ctrl.AddString(APL_T("Прочее"));
	#endif

	// Атрибут для сербов
	#ifdef _MOMA_
		m_relevance_ctrl.Clear();
		while(m_relevance_ctrl.GetCount()>0) m_relevance_ctrl.DeleteString(0);
		m_relevance_ctrl.AddString(_T(""));
		m_relevance_ctrl.AddString(_T("active"));
		m_relevance_ctrl.AddString(_T("inactive"));
		m_relevance_ctrl.AddString(_T("in preparation"));
	#else
		m_relevance_ctrl.EnableWindow(FALSE);
		m_relevance_ctrl.ShowWindow(SW_HIDE);
		CWnd *st_relev_wnd=GetDlgItem(IDC_ST_RELEVANCE);
		if(0!=st_relev_wnd)st_relev_wnd->ShowWindow(SW_HIDE);
	#endif

	if(!m_api->m_data.IsConnected())
	{
		AfxMessageBox( APL_T("Соединение не установлено!"));
		EndDialog(0);
		return FALSE;
	}

	
	// Проверяем DLL для присвоения обозначений
	if(m_fItemAttrBuild!=0)
	{
		CString buf;
		// Задаем доступность кнопок
		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_prd_id,m_prd,buf,this))  m_prd_id_cng_btn.EnableWindow(TRUE);
		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_prd_name,m_prd,buf,this))  m_prd_name_cng_btn.EnableWindow(TRUE);
		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_prd_code,m_prd,buf,this))m_prd_code_cng_btn.EnableWindow(TRUE);

		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_pdf_id,m_pdf,buf,this)) m_pdf_id_cng_btn.EnableWindow(TRUE);
		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_pdf_code,m_pdf,buf,this)) m_pdf_code_cng_btn.EnableWindow(TRUE);
		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_pdf_code1,m_pdf,buf,this)) m_pdf_code1_cng_btn.EnableWindow(TRUE);
		if(m_fItemAttrBuild(true,m_api,m_api->m_prd_mgr.a_pdf_code2,m_pdf,buf,this)) m_pdf_code2_cng_btn.EnableWindow(TRUE);
	}

	////// мать мать мать! 2 года в OptionsEditor-е было "...изделия..." а здесь искалось "...изделий...". Теперь здесь правильное слово
	m_PrdUnikByIdAndName = m_api->m_options_mgr.GetIntOptionValueBN( APL_NO_T("Уникальность изделия проверять по комбинации обозначения и наименования"), 0);
	
	COLORMAP  cm;
	cm.from=RGB(192,192,192);
	cm.to=::GetSysColor(COLOR_BTNFACE);

	if(aplGetBitPerPixel(this)>8)
		m_name_bmp.LoadMappedBitmap(IDB_PRD_NAME,0,&cm,1);
	else
		m_name_bmp.LoadMappedBitmap(IDB_PRD_NAME_16,0,&cm,1);

	HBITMAP hBmpOld=m_st_header.SetBitmap(HBITMAP(m_name_bmp));	
	::DeleteObject(hBmpOld);

	m_btn_cancel.SetIcon(GetAplStdIco16(APLSTDICO_CANCEL));
	m_btn_cancel.SetFlat(FALSE);
	m_btn_ok.SetIcon(GetAplStdIco16(APLSTDICO_OK));
	m_btn_ok.SetFlat(FALSE);
	
	m_rel_property_btn.SetIcon(GetAplStdIco16(APL_STD_24CHARACTS));
	m_rel_property_btn.SetFlat(FALSE);
	m_test_btn.SetTooltipText( APL_T("Характеристики связи"));

	m_btn_add.SetIcon(GetAplStdIco16(APL_STD_24PLUS));
	m_btn_add.SetTooltipText( APL_T("Добавить входящее изделие"));
	m_btn_add.SetFlat(FALSE);
	m_btn_add.ShowWindow(SW_HIDE);
	m_test_btn.SetIcon(GetAplStdIco16(APLSTDICO_QUERY));
	m_test_btn.SetTooltipText( APL_T("Проверка уникальности обозначений"));
	m_test_btn.SetFlat(FALSE);

	m_bPropsAdd.SetIcon(GetAplStdIco16(APLSTDICO_PLUS));
	m_bPropsAdd.SetFlat(FALSE);
	m_bPropsDel.SetIcon(GetAplStdIco16(APLSTDICO_MINUS));
	m_bPropsDel.SetFlat(FALSE);
	m_bPropsProps.SetIcon(GetAplTableIco(APL_TABLE_PROP));
	m_bPropsProps.SetFlat(FALSE);

	m_setup_unit_convertions_btn.SetFlat(TRUE);
	m_setup_unit_convertions_btn.SetTooltipText( APL_T("Настроить коэффициенты пересчета единиц измерения..."));
	m_setup_unit_convertions_btn.SetIcon(GetAplStdIco16(APL_STD_24STAR));


	{	// Изменение Tab-а под текущее окно
		CRect rectTab,rectCancel;
		m_Tab.GetWindowRect(rectTab);
		m_btn_cancel.GetWindowRect(rectCancel);
		rectTab.bottom=rectCancel.top-5;
		rectTab.right=rectCancel.right;
		ScreenToClient(rectTab);
		m_Tab.MoveWindow(rectTab);
	}

	InitViews();

	// Установка разрешений на изменение кода
	if(m_api->m_appr_mgr.IsAdmin())
	{
		m_bOpenPrdCode=true;
		m_bOpenPdfCode=true;
		m_bOpenPdfCode1=true;
		m_bOpenPdfCode2=true;
	}
	else
	{
		CString m_role;

		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Роли\\Роль для изменения кода изделия"),m_role);
		if(!m_role.IsEmpty())
		{
			if(m_api->m_appr_mgr.CheckPersonRole(0,m_role)) m_bOpenPrdCode=true;
		}

		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Роли\\Роль для изменения кода версии изделия"),m_role);
		if(!m_role.IsEmpty())
		{
			if(m_api->m_appr_mgr.CheckPersonRole(0,m_role)) m_bOpenPdfCode=true;
		}

		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Роли\\Роль для изменения кода1 версии изделия"),m_role);
		if(!m_role.IsEmpty())
		{
			if(m_api->m_appr_mgr.CheckPersonRole(0,m_role)) m_bOpenPdfCode1=true;
		}

		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Роли\\Роль для изменения кода2 версии изделия"),m_role);
		if(!m_role.IsEmpty())
		{
			if(m_api->m_appr_mgr.CheckPersonRole(0,m_role)) m_bOpenPdfCode2=true;
		}
	}

	// TODO: Add extra initialization here
	CString src,buf,buf1,scht;
	CString form_type;
	CaplInstance *pdf_unit=0;

	bool std_pdf=false;
	int i,j;

	// Установка источника по умолчанию
	if(0==m_pdf)
	{
		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Изделия\\Источник по умолчанию"),buf);
		if(!buf.IsEmpty()) m_source_ctrl.SelectString(0,buf);
	}

	//заполняем ед изм для базовой ед изм.
	aplExtent ext_unit_pdf;
	m_api->m_unit_exch_mgr.GetPrdUnits(ext_unit_pdf);
	if(ext_unit_pdf.GetSize()<=0) m_api->m_data.GetEntityExtent(m_api->m_charact_mgr.e_apl_step_unit, ext_unit_pdf);

	i=m_pdf_unit.AddString(_T(""));
	m_pdf_unit.SetItemData(i,0);
	m_pdf_unit.SelectString(-1,_T(""));

	for(i=0;i<ext_unit_pdf.Size;i++)
	{
		CaplInstance *unit=ext_unit_pdf[i];
		m_api->m_charact_mgr.GetUnitName(unit,buf);
		int k=m_pdf_unit.AddString(buf);
		m_pdf_unit.SetItemData(k,(UINT)unit);
	}

	aplExtent ext_unit;
	int option_ed_izm=0;
	m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Изделия\\Ограничить выбор единиц измерения таблицей преобразования"),option_ed_izm,1);
	if(1==option_ed_izm) m_api->m_charact_mgr.GetPossiblePdfUnits(m_pdf,ext_unit);
	if(ext_unit.Size<=0)m_api->m_unit_exch_mgr.GetPrdUnits(ext_unit);
	if(ext_unit.GetSize()<=0) m_api->m_data.GetEntityExtent(m_api->m_charact_mgr.e_apl_step_unit, ext_unit);

	//заполняем ед изм исходного кол-ва
	for(i=0;i<ext_unit.Size;i++)
	{
		CaplInstance *unit=ext_unit[i];
		m_api->m_charact_mgr.GetUnitName(unit,buf);
		int k=m_nauo_unit_ctrl.AddString(buf);
		m_nauo_unit_ctrl.SetItemData(k,(UINT)unit);
		
		buf1=buf;
		buf1.MakeLower();
		if(buf1.GetLength()>=2)	{if((buf1[0]==_T('ш'))&&(buf1[1]==_T('т')))scht=buf;}
	}
	if(scht!=_T(""))m_nauo_unit_ctrl.SelectString(-1,scht);
	else {
		// единицы измерения "штука" нет! Вставляем пустую строчку для констатации сего скорбного факта
		i=m_nauo_unit_ctrl.AddString(_T(""));
		m_nauo_unit_ctrl.SetItemData(i,0);
		m_nauo_unit_ctrl.SelectString(-1,_T(""));
	}

	//заполняем ед. изм. получаемого кол-ва
	aplExtent ext_unit2;
	if(1==option_ed_izm)
	{
		CaplInstance *par_pdf=m_parent_pdf; // новая переменная чтобы не дай бог не сломать логику
		if(0==par_pdf && 0!=m_nauo) m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ting, par_pdf);
		m_api->m_charact_mgr.GetPossiblePdfUnits(par_pdf,ext_unit2);
	}
	if(ext_unit2.Size<=0)m_api->m_unit_exch_mgr.GetPrdUnits(ext_unit2);
	if(ext_unit2.GetSize()<=0) m_api->m_data.GetEntityExtent(m_api->m_charact_mgr.e_apl_step_unit, ext_unit2);

	scht=_T("");
	for(i=0;i<ext_unit2.Size;i++)
	{
		CaplInstance *unit=ext_unit2[i];
		m_api->m_charact_mgr.GetUnitName(unit,buf);
		int k=m_nauo_unit2.AddString(buf);
		m_nauo_unit2.SetItemData(k,(UINT)unit);

		buf1=buf;
		buf1.MakeLower();
		if(buf1.GetLength()>=2)	{if((buf1[0]==_T('ш'))&&(buf1[1]==_T('т')))scht=buf;}
	}
	if(scht!=_T(""))m_nauo_unit2.SelectString(-1,scht);
	else{
		// единицы измерения "штука" нет! Вставляем пустую строчку для констатации сего скорбного факта
		i=m_nauo_unit2.AddString(_T(""));
		m_nauo_unit2.SetItemData(i,0);
		m_nauo_unit2.SelectString(-1,_T(""));
	}

/*
	int k=m_sortament.AddString(_T(" "));
	m_sortament.SetItemData(k,0);

	aplExtent ext0;
	m_api->m_data.GetEntityExtent(m_api->m_prd_mgr.e_assortment, ext0);
	for(i=0;i<ext0.Size;i++)
	{
		m_api->m_data.GetAttr(ext0[i], m_api->m_prd_mgr.a_assortment_name, buf);
		if(buf.IsEmpty())
			m_api->m_data.GetAttr(ext0[i], m_api->m_prd_mgr.a_assortment_id, buf);
		buf+=_T(" ");
		m_api->m_data.GetAttr(ext0[i], m_api->m_prd_mgr.a_assortment_std, buf1);
		buf+=buf1;
		int k=m_sortament.AddString(buf);
		m_sortament.SetItemData(k,(UINT)ext0[i]);
	}
*/

	if(m_base_prd!=0)
	{
		m_api->m_data.GetAttr(m_base_prd, m_api->m_prd_mgr.a_prd_id, m_prd_id);
		m_api->m_data.GetAttr(m_base_prd, m_api->m_prd_mgr.a_prd_name, m_prd_name);
		m_api->m_data.GetAttr(m_base_prd, m_api->m_prd_mgr.a_prd_descr, m_prd_descr);
	}
	if(m_base_pdf!=0)
	{
		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_pdf_prd, m_base_prd);
		m_api->m_data.GetAttr(m_base_prd, m_api->m_prd_mgr.a_prd_id, m_prd_id);
		m_api->m_data.GetAttr(m_base_prd, m_api->m_prd_mgr.a_prd_name, m_prd_name);
		m_api->m_data.GetAttr(m_base_prd, m_api->m_prd_mgr.a_prd_descr, m_prd_descr);
		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_pdf_id, m_pdf_id);
		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_pdf_descr, m_pdf_descr);

		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_apl_pdf_unit, pdf_unit);
		SelectUnit(m_pdf_unit,pdf_unit);

		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_pdfwss_source, src);
		//src=CaplProductManager::StrConvertMakeOrBuy2Rus(src);
		//m_source_ctrl.SelectString(0,src);
		SetSource(src); // Для того чтобы показывались значения отсутствующие в не moma версии

		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_apl_pdf_type, form_type);
		form_type=CaplProductManager::StrConvertPdfType2Rus(form_type);
		m_type_ctrl.SelectString(0,form_type);

		m_api->m_data.GetAttr(m_base_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, std_pdf);
		m_pdf_std.SetCheck(std_pdf ? 1 : 0);

	}
	if(m_base_nauo!=0)
	{
		m_api->m_data.GetAttr(m_base_nauo, m_api->m_prd_mgr.a_pdr_id, m_nauo_id);
		m_api->m_data.GetAttr(m_base_nauo, m_api->m_prd_mgr.a_pdr_name, m_nauo_name);
		m_api->m_data.GetAttr(m_base_nauo, m_api->m_prd_mgr.a_pdr_descr, m_nauo_descr);

		CaplInstance *inst1;
		double count;

		if(m_api->m_data.IsKindOf(m_base_nauo, m_api->m_prd_mgr.e_apl_qacu))
		{
			m_api->m_data.GetAttr(m_base_nauo, m_api->m_prd_mgr.a_acu_ref_des, m_ref_des);
			m_api->m_data.GetAttr(m_base_nauo, m_api->m_prd_mgr.a_apl_qacu_value, count);
			m_nauo_count=count;
			m_api->m_data.GetAttr(m_base_nauo, m_api->m_prd_mgr.a_apl_qacu_unit, inst1);
			SelectUnit(m_nauo_unit_ctrl,inst1);
		}
	}
	// чтобы данные точно прочитались с сервера!
	m_api->m_data.ClearLastQuery();
	if(m_pdf!=0)
	{
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_prd, m_prd);
		m_api->m_prd_mgr.LoadPrdInfo(m_pdf);
	}
	else if(m_prd!=0)
		m_api->m_prd_mgr.LoadPrdInfo(m_prd);
	
	if(m_prd!=0)
	{
		if(m_prd->GetAccessmode()<aplNO)
		{
			m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_id, m_prd_id);
			m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_name, m_prd_name);
			m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_descr, m_prd_descr);
			m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_code, m_prd_code);
			m_prev_prd_code=m_prd_code;
		}
	}
	if(m_pdf!=0)
	{
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_id, m_pdf_id);
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_descr, m_pdf_descr);
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code, m_pdf_code);
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code1, m_pdf_code1);
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code2, m_pdf_code2);

		#ifndef _MOMA_
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_first_usage, m_pdf_first_usage);
		#else
			m_old_clasif_level=0;	
			aplExtent ext_classifiers, ext_assoc_ext;
			m_api->m_classifier_mgr.FindClassifiersContained(m_pdf,ext_classifiers, &ext_assoc_ext);
			if(0!=ext_classifiers.GetSize()) m_old_clasif_level=ext_classifiers[0];
		#endif


		m_prev_pdf_code=m_pdf_code;
		m_prev_pdf_code1=m_pdf_code1;
		m_prev_pdf_code2=m_pdf_code2;

		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_unit,pdf_unit);
		SelectUnit(m_pdf_unit,pdf_unit);

		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdfwss_source, src);
		//src=CaplProductManager::StrConvertMakeOrBuy2Rus(src0);
		//m_source_ctrl.SelectString(0,src);
		SetSource(src); // Для того чтобы показывались значения отсутствующие в не moma версии

		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_type, form_type);
		form_type=CaplProductManager::StrConvertPdfType2Rus(form_type);
		m_type_ctrl.SelectString(0,form_type);

		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, std_pdf);
		m_pdf_std.SetCheck(std_pdf ? 1:0);

		CString sRelevance;
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevance);
		m_relevance_ctrl.SelectString(0,sRelevance);
	}
	if(m_nauo!=0)
	{
		m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_id, m_nauo_id);
		m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_name, m_nauo_name);
		m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_descr, m_nauo_descr);

		m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_frames_of_reference,m_nauo_contexts);
		m_api->m_prd_mgr.PrintItemContextInString(m_nauo_contexts, buf);
		
		m_context_names.SetWindowText(buf);

		CaplInstance *inst1 = NULL;
		double count, count2;

		if(m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_apl_qacu))
		{
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_acu_ref_des, m_ref_des);
			m_st_pos.SetWindowText( APL_T("Позиция:"));
			m_st_count.SetWindowText( APL_T("Количество:"));
			HideMFU();

			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_value, count);
			m_nauo_count=count;
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_unit, inst1);
			SelectUnit(m_nauo_unit_ctrl,inst1);
		}
		else if(m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_design_make_from))
		{
			m_st_asm.SetWindowText( APL_T("Материал "));
			m_st_count.ShowWindow(SW_HIDE);
			HideMFU();
			HideRefDes();
			m_nauo_count_ctrl.ShowWindow(SW_HIDE);
			m_nauo_unit_ctrl.ShowWindow(SW_HIDE);

		}
		else if(m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_make_from))
		{
			HideRefDes();
			m_st_asm.SetWindowText( APL_T("Норма расхода "));
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_ranking, m_ranking);
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_ranking_rationale, m_ranking_rationale);
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_value, count);
			m_nauo_count=count;
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_derive_value, count2);
			m_nauo_count2=count2;
//#ifdef _STUPINO
			m_st_pos.SetWindowText( APL_T("Размер заготов."));
			m_st_name.SetWindowText( APL_T("Техн.треб."));
//			m_st_descr.SetWindowText(APL_T("ГОСТ на сортамент"));
//			m_st_count.SetWindowText(APL_T("Масса заготовки"));
//			m_st_rank_rat.SetWindowText(APL_T("Кол-во из 1 заг."));
//#endif
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_unit, inst1);
			SelectUnit(m_nauo_unit_ctrl,inst1);
			
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_derive_unit, inst1);
			SelectUnit(m_nauo_unit2,inst1);

			//m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_assortment, inst1);
			//SelectUnit(m_sortament,inst1);
		}
		else
		{
			HideRefDes();
			HideMFU();
			m_st_count.ShowWindow(SW_HIDE);
			m_nauo_count_ctrl.ShowWindow(SW_HIDE);
			m_nauo_unit_ctrl.ShowWindow(SW_HIDE);
		}
	}
	else if(m_subst!=0)
	{
		HideRefDes();
		m_st_asm.SetWindowText( APL_T("Сборка (замена)"));
		m_st_name.SetWindowText( APL_T("Обозначение:"));
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_id, m_nauo_id);
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_name, m_nauo_name);
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_description, m_nauo_descr);
		CaplInstance *inst1;
		double count;

		m_st_pos.SetWindowText( APL_T("Позиция:"));
		m_st_count.SetWindowText( APL_T("Количество:"));
		HideMFU();

		m_context_names.SetWindowText( APL_T("Все контексты"));
		m_context_sel.EnableWindow(false);

		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_value, count);
		m_nauo_count=count;
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_unit, inst1);
		if(inst1!=0)
		{
			i=0;
			while(1)
			{
				j=m_nauo_unit_ctrl.GetItemData(i);
				if(j==CB_ERR) break;
				if(j==(int)inst1){m_nauo_unit_ctrl.SetCurSel(i);break;}
				i++;
			}
		}
	}

	if(0 == m_pdf)
		m_setup_unit_convertions_btn.EnableWindow(FALSE);

	if(m_mode==aplModeCreateVersion)
	{
		if(m_base_prd!=0){
			m_prd=m_base_prd;
		}else if(m_base_pdf!=0){
			m_api->m_data.GetAttr(m_base_pdf,m_api->m_prd_mgr.a_pdf_prd,m_prd);
		}
		if(m_prd!=NULL)
		{
			m_prd_id_ctrl.SetReadOnly(TRUE);
			m_prd_name_ctrl.SetReadOnly(TRUE);
			m_prd_descr_ctrl.SetReadOnly(TRUE);
			m_bOpenPrdCode=false;						
		}
		HideNAUO();
	}
	else if(m_mode==aplModeCreateProduct)
	{
		HideNAUO();
	}
	else if(m_mode==aplModeEdit)
	{
		if(m_nauo==0 && m_subst==0) HideNAUO();
		if(m_pdf==0) HidePDF();
	}
	else if(m_mode==aplModeCreateSubProduct)
	{
		m_st_pos.SetWindowText( APL_T("Позиция:"));
		m_st_count.SetWindowText( APL_T("Количество:"));
		//if(m_base_pdf==0) return FALSE;
		m_btn_add.ShowWindow(SW_SHOW);
		HideMFU();

		m_pdf_first_usage=m_parent_pdf;
		
	}
	else if(m_mode==aplModeCreateProductIfNew)
	{
		HideNAUO();
	}
	else
	{
		if(m_pdf==0) HidePDF();
	}
	UpdateData(FALSE);

	#ifdef _MOMA_
		if(0!=m_old_clasif_level)
		{
			CString sName;
			m_api->m_classifier_mgr.GetItemName(m_old_clasif_level,sName);
			m_pdf_first_usage_edt.SetWindowText(sName);
		}
	#else
		if(m_pdf_first_usage!=0)
		{
			CaplInstance *ciPrd = NULL;
			m_api->m_data.GetAttr(m_pdf_first_usage, m_api->m_prd_mgr.a_pdf_prd, ciPrd);
			m_api->GetItemName(ciPrd, buf);
			m_pdf_first_usage_edt.SetWindowText(buf);
		}
	#endif

	if(m_prd_id!=_T("")) m_prd_id_ctrl.SetWindowText(m_prd_id);


	m_Tab.InitStates();
	SetAnchors();

	CString state;

	// Проверяем права
	
	/* ЯАИ В ГРПЗ сказали что все кроме обозначения можно менять
	if(m_api->m_prd_mgr.bNoCreateAndChangePDF)
	{
		m_bDizableEditPrd=true;
		m_bDizableEditPdf=true;
	}
	else*/
	{
		if(m_prd!=0)
		{
			if(m_prd->GetAccessmode()>=aplRO)
			{
				m_bDizableEditPrd=true;
				m_bOpenPrdCode=false;
			}

			// ЯАИ: Проверяем - если есть версия в нередактируемом состоянии, то править нельзя (по просьбе ЦКБА)
			aplExtent ext_pdf;
			m_api->m_prd_mgr.GetAllProductVersion(m_prd,ext_pdf);
			int i;
			for(i=0;i<ext_pdf.GetSize();i++)
			{
				CaplInstance *pdf_i=ext_pdf[i];
				if(pdf_i->GetAccessmode()>aplRO) continue;
				m_api->m_data.GetAttr(pdf_i, m_api->m_prd_mgr.a_apl_pdf_state, state);
				if( ! ( (state==_T("")  || state==_T("working")  || state==_T("changing"))))
					m_bDizableEditPrd=true; 
			}
		}

		if(m_pdf!=0)
		{
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_state, state);

			if( ! ( (m_pdf->GetAccessmode()<=aplRW) && (state==_T("")  || state==_T("working")  || state==_T("changing")) ) && (!m_bIsCreatingCopy) )
			{
				m_bDizableEditPdf=true;
				m_bDizableEditPrd=true;  // За компанию :-)
			}

			if(m_pdf->GetAccessmode()>=aplRO)
			{
				m_bOpenPdfCode=false;
				m_bOpenPdfCode1=false;
				m_bOpenPdfCode2=false;
			}
		}
	}

	if(m_pdf!=0)
	{
		CString sSprav4Right;
		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Изделия\\Справочники ограничивающие права на атрибуты изделий"), sSprav4Right, _T(""));
		if(sSprav4Right!=_T("") && !m_api->m_data.IsAdmin())
		{
			sSprav4Right.MakeLower(); sSprav4Right.Insert(0,_T('|'));sSprav4Right+=_T('|'); // Для простоты поиска
			aplExtent ext_classif_level;
			m_api->m_classifier_mgr.FindClassifiersContained(m_pdf,ext_classif_level);
			if(ext_classif_level.GetSize()>0)m_api->m_classifier_mgr.LoadClassifierInfo(ext_classif_level);

			bool bRO=false;
			int i;
			CString sId;
			for(i=0;i<ext_classif_level.GetSize();i++)
			{
				CaplInstance *system,*level=ext_classif_level[i];
				m_api->m_data.GetAttr(level,m_api->m_classifier_mgr.a_apl_classifier_level_system,system);
				m_api->m_data.GetAttr(system,m_api->m_classifier_mgr.a_apl_classifier_system_id,sId);
				sId.MakeLower(); sId.Insert(0,_T('|'));sId+=_T('|');
				if(sSprav4Right.Find(sId)<0) continue;
				// справочник есть в списке
				if(system->GetAccessmode()>aplRW) bRO=true; 
				else {bRO=false; break;}  // Среди справочников есть тот к которому есть доступ
			}
			if(bRO){m_bDizableEditPdf=true; m_bDizableEditPrd=true;}

		}
	}



	if(m_nauo!=0)
	{
		CaplInstance *pdf1;
		m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ting, pdf1);
		if(pdf1!=0)
		{
			
			m_api->m_data.GetAttr(pdf1, m_api->m_prd_mgr.a_apl_pdf_state, state);

			if( ! ( (pdf1->GetAccessmode()<=aplRW) && (state==_T("")  || state==_T("working")  || state==_T("changing")) ))
			{
				m_bDizableEditNAUO=true;

				// Для ВНИИС
				if(m_api->m_data.IsKindOf(m_nauo,m_api->m_prd_mgr.e_design_make_from) || m_api->m_data.IsKindOf(m_nauo,m_api->m_prd_mgr.e_make_from))
				{
					CString sRoleName;
					m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Роли\\Роль для редактирования норм расхода у утвержденных изделий"), sRoleName, _T(""));
					if(sRoleName!=_T(""))
					{
						if(m_api->m_appr_mgr.CheckPersonRole(0,sRoleName)) m_bDizableEditNAUO=false;
					}
				}
			}
		}
	}
	else if(m_subst!=0)
	{
		// Проверяем доступ по состоянию подительской сборки
		CaplInstance *par_nauo, *par_pdf;
		CString state;
		m_bDizableEditNAUO=true;
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_pdr, par_nauo);
		if(0!=par_nauo)
		{
			m_api->m_data.GetAttr(par_nauo,m_api->m_prd_mgr.a_pdr_r_ting,par_pdf);
			if(0!=par_pdf)
			{
				m_api->m_data.GetAttr(par_pdf,m_api->m_prd_mgr.a_apl_pdf_state,state);
				if((par_pdf->GetAccessmode()<=aplRW) && ( state==_T("working") || state==_T("changing") || state==_T("")))
				{
					m_bDizableEditNAUO=false;
				}
			}
		}
	}
	else
	{
		if(m_mode!=aplModeCreateSubProduct) m_bDizableEditNAUO=true;
	}

	TestPdfType(); // Дизейблить ед. изм. по типу версии


	// Проверяем роли для структуры
	if(0!=m_nauo)
	{
		if(m_api->m_data.IsKindOf(m_nauo,m_api->m_prd_mgr.e_nauo))
		{
			if(!m_api->m_appr_mgr.CheckPersonRoleByOption(0,APL_NO_T("Роли\\Роль для редактирования структуры изделия"),false))
				m_bDizableEditNAUO=true;
		}
		else  if(m_api->m_data.IsKindOf(m_nauo,m_api->m_prd_mgr.e_make_from))
		{
			if(!m_api->m_appr_mgr.CheckPersonRoleByOption(0,APL_NO_T("Роли\\Роль для редактирования норм расхода для изделия"),false))
			m_bDizableEditNAUO=true;
		}
		else if(m_api->m_data.IsKindOf(m_nauo,m_api->m_prd_mgr.e_design_make_from))
		{
			if(!m_api->m_appr_mgr.CheckPersonRoleByOption(0,APL_NO_T("Роли\\Роль для редактирования материала изделия"),false))
			m_bDizableEditNAUO=true;
		}
	}

	if(m_bDizableEditPrd)
	{
		m_prd_id_ctrl.SetReadOnly(TRUE);
		m_prd_name_ctrl.SetReadOnly(TRUE);
		m_prd_descr_ctrl.SetReadOnly(TRUE);
		m_prd_code_ctrl.SetReadOnly(TRUE);
		m_prd_code_cng_btn.EnableWindow(FALSE);
	}

	if(m_bDizableEditPdf)
	{
		m_pdf_id_ctrl.SetReadOnly(TRUE);
		m_pdf_descr_ctrl.SetReadOnly(TRUE);
		m_type_ctrl.EnableWindow(FALSE);
		m_pdf_std.EnableWindow(FALSE);
		m_source_ctrl.EnableWindow(FALSE);
		m_pdf_first_usage_btn.EnableWindow(FALSE);

		m_pdf_unit.EnableWindow(FALSE);
		//m_setup_unit_convertions_btn.EnableWindow(FALSE); ЯАИ: теперь открывается в режиме RO
		m_pdf_id_cng_btn.EnableWindow(FALSE);

		m_pdf_code_cng_btn.EnableWindow(FALSE);
		m_pdf_code1_cng_btn.EnableWindow(FALSE);
		m_pdf_code2_cng_btn.EnableWindow(FALSE);

		m_pdf_code_ctrl.SetReadOnly(TRUE);
		m_pdf_code1_ctrl.SetReadOnly(TRUE);
		m_pdf_code2_ctrl.SetReadOnly(TRUE);

		m_test_btn.EnableWindow(FALSE);
	}

	if(m_bDizableEditNAUO)
	{
		m_nauo_id_ctrl.SetReadOnly(TRUE);
		m_ref_des_ctrl.SetReadOnly(TRUE);
		m_nauo_name_ctrl.SetReadOnly(TRUE);
		m_nauo_descr_ctrl.SetReadOnly(TRUE);
		m_nauo_count_ctrl.SetReadOnly(TRUE);
		m_nauo_unit_ctrl.EnableWindow(FALSE);
		m_nauo_unit2.EnableWindow(FALSE);
		m_ranking_ctrl.SetReadOnly(TRUE);
		m_ranking_rationale_ctrl.SetReadOnly(TRUE);
		m_nauo_count2_ctrl.SetReadOnly(TRUE);
		//m_sortament.EnableWindow(FALSE);
		m_context_sel.EnableWindow(FALSE);
	}

	if(m_bOpenPrdCode)	m_prd_code_ctrl.SetReadOnly(FALSE);
	if(m_bOpenPdfCode)	m_pdf_code_ctrl.SetReadOnly(FALSE);
	if(m_bOpenPdfCode1) m_pdf_code1_ctrl.SetReadOnly(FALSE);
	if(m_bOpenPdfCode2) m_pdf_code2_ctrl.SetReadOnly(FALSE);

	if(m_api->m_prd_mgr.bNoCreateAndChangePDF)
	{
		m_pdf_code2_ctrl.SetReadOnly(TRUE); // В ГРПЗ никто не может править код 2
		if(m_api->m_data.IsAdmin())
		{
			if(m_bDizableEditPrd) m_prd_code_ctrl.SetReadOnly(TRUE);
			if(m_bDizableEditPdf)
			{
				m_pdf_code_ctrl.SetReadOnly(TRUE);
				m_pdf_code1_ctrl.SetReadOnly(TRUE);
				m_pdf_code2_ctrl.SetReadOnly(TRUE);
			}
		}
		else
		{
			m_prd_id_ctrl.SetReadOnly(TRUE);
			m_prd_name_ctrl.SetReadOnly(TRUE);
			m_pdf_id_ctrl.SetReadOnly(TRUE);
			m_prd_code_ctrl.SetReadOnly(TRUE);
			m_pdf_code_ctrl.SetReadOnly(TRUE);
			m_pdf_code1_ctrl.SetReadOnly(TRUE);
			m_pdf_code2_ctrl.SetReadOnly(TRUE);
		}
	}

	if(m_bDizableEditPrd && m_bDizableEditPdf && m_bDizableEditNAUO)
	{
		m_btn_ok.EnableWindow(FALSE);
	}

	{ //Проверяем возможность редактирования справочников
		CString role;

		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Изделия\\Роль для создания стандартных"),role);
		if(!role.IsEmpty())
		{
			if(!m_api->m_appr_mgr.CheckPersonRole(0,role))
			{
				if(0==m_pdf)m_pdf_std.SetCheck(0);
				m_pdf_std.EnableWindow(FALSE);
			}
		}
		
		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Изделия\\Роль для создания материалов"),role);
		if(!role.IsEmpty())
		{
			if(!m_api->m_appr_mgr.CheckPersonRole(0,role))
			{
				m_type_ctrl.GetWindowText(buf);

				bool bRemove=true;

				if(0==m_pdf)
				{
					if(buf==APL_T("Материал")) m_type_ctrl.SetCurSel(-1);
				}
				else
				{
					if(buf==APL_T("Материал")) bRemove=false;
				}
				if(bRemove)
				{
					int i=m_type_ctrl.FindString(0, APL_T("Материал"));
					if(i>=0) m_type_ctrl.DeleteString(i);
				}
			}
		}	
		m_api->m_options_mgr.GetOptionValueBN( APL_NO_T("Изделия\\Роль для создания покупных"),role);
		if(!role.IsEmpty())
		{
			if(!m_api->m_appr_mgr.CheckPersonRole(0,role))
			{
				bool  bRemoveBuy=true;
				if(0!=m_pdf)
				{
					m_source_ctrl.GetWindowText(buf);
					if(buf== APL_T("Покупное")) bRemoveBuy=false;
				}
				if(bRemoveBuy)
				{
					int i=m_source_ctrl.FindString(0, APL_T("Покупное"));
					if(i>=0) m_source_ctrl.DeleteString(i);
				}
			}
		}
	}

	m_changed_prd = false;
	m_changed_pdf = false;

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

void CProductDlg::OnOK() 
{
	// TODO: Add extra validation here
	if(!UpdateData()) return;

	m_prd_id.TrimLeft();
	m_prd_id.TrimRight();
	m_prd_name.TrimLeft();
	m_prd_name.TrimRight();
	m_pdf_id.TrimLeft();
	m_pdf_id.TrimRight();

	CString buf;

	m_nauo_count_ctrl.GetWindowText(buf);
	buf.Replace(_T(','),_T('.'));
	m_nauo_count=__atof(LPCTSTR(buf));

	m_nauo_count2_ctrl.GetWindowText(buf);
	buf.Replace(_T(','),_T('.'));
	m_nauo_count2=__atof(LPCTSTR(buf));

	CString sRelevanceNew;
	m_relevance_ctrl.GetWindowText(sRelevanceNew);

	UpdateData(FALSE);

	//Проверка уникальности
	CaplAttrValue tst_values[5];

	if(m_changed_prd || 0==m_prd || 0==m_pdf)
	{
		if(m_prd_id==_T(""))
		{
			AfxMessageBox( APL_T("Обозначение не может быть пустым!"),MB_OK|MB_ICONSTOP);return;
		}
		
		int count_val=1;
		tst_values[0].value.Set((LPCTSTR)m_prd_id);
		tst_values[0].attr=m_api->m_prd_mgr.a_prd_id;

		if(m_PrdUnikByIdAndName)
		{
			tst_values[1].value.Set((LPCTSTR)m_prd_name);
			tst_values[1].attr=m_api->m_prd_mgr.a_prd_name;
			count_val=2;
		}

		if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_prd, m_prd, count_val, &tst_values[0]))
		{
			if(m_mode==aplModeCreateProductIfNew && m_changed_prd==false)
			{
				m_prd=m_base_prd;
			}else{
				AfxMessageBox( APL_T("Изделие с таким обозначением уже есть в базе !!!"),MB_OK|MB_ICONSTOP);return;
			}
		}

		if(m_bOpenPrdCode)
		{
			if(!m_prd_code.IsEmpty() && m_prev_prd_code!=m_prd_code)
			{

				int no_chek = m_api->m_options_mgr.GetIntOptionValueBN( APL_NO_T("Изделия\\Не проверять уникальность кода изделия"), 0);
				if(0==no_chek)
				{
					tst_values[0].value.Set((LPCTSTR)m_prd_code);
					tst_values[0].attr=m_api->m_prd_mgr.a_prd_code;

					if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_prd, m_prd, 1, &tst_values[0]))
					{
						AfxMessageBox( APL_T("Код изделия не уникален !!!"),MB_OK|MB_ICONSTOP);return;
					}
				}
			}
		}
	}

	if(m_changed_pdf || (m_mode==aplModeCreateVersion)) // aplModeCreateVersion Для обработки создания версии с параметрами по умолчанию
	{
		if(m_bOpenPdfCode)
		{
			if(!m_pdf_code.IsEmpty() && m_prev_pdf_code!=m_pdf_code)
			{
				int no_chek = m_api->m_options_mgr.GetIntOptionValueBN( APL_NO_T("Изделия\\Не проверять уникальность кода версии изделия"), 0);
				if(no_chek==0)
				{
					tst_values[0].value.Set((LPCTSTR)m_pdf_code);
					tst_values[0].attr=m_api->m_prd_mgr.a_pdf_code;

					if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_apl_pdf, m_pdf, 1, &tst_values[0]))
					{
						AfxMessageBox( APL_T("Код версии изделия не уникален !!!"),MB_OK|MB_ICONSTOP);return;
					}
				}
			}
		}

		if(m_bOpenPdfCode1)
		{
			if(!m_pdf_code1.IsEmpty() && m_prev_pdf_code1!=m_pdf_code1)
			{
				int no_chek = m_api->m_options_mgr.GetIntOptionValueBN( APL_NO_T("Изделия\\Не проверять уникальность кода 1 версии изделия"), 0);
				if(0==no_chek)
				{
					tst_values[0].value.Set((LPCTSTR)m_pdf_code1);
					tst_values[0].attr=m_api->m_prd_mgr.a_pdf_code1;

					if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_apl_pdf, m_pdf, 1, &tst_values[0]))
					{
						AfxMessageBox( APL_T("Код 1 версии изделия не уникален !!!"),MB_OK|MB_ICONSTOP);return;
					}
				}
			}
		}

		if(m_bOpenPdfCode2)
		{
			if(!m_pdf_code2.IsEmpty() && m_prev_pdf_code2!=m_pdf_code2)
			{
				int no_chek = m_api->m_options_mgr.GetIntOptionValueBN( APL_NO_T("Изделия\\Не проверять уникальность кода 2 версии изделия"), 0);
				if(0==no_chek)
				{
					tst_values[0].value.Set((LPCTSTR)m_pdf_code2);
					tst_values[0].attr=m_api->m_prd_mgr.a_pdf_code2;

					if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_apl_pdf, m_pdf, 1, &tst_values[0]))
					{
						AfxMessageBox( APL_T("Код 2 версии изделия не уникален !!!"),MB_OK|MB_ICONSTOP);return;
					}
				}
			}
		}

		bool f=true;
		if(!( (m_pdf==0)&&(m_mode==aplModeEdit) ))
		{
			if(m_prd!=0)
			{
				tst_values[0].value.Set((LPCTSTR)m_pdf_id);
				tst_values[0].attr=m_api->m_prd_mgr.a_pdf_id;
				tst_values[1].value.Set(m_prd);
				tst_values[1].attr=m_api->m_prd_mgr.a_pdf_prd;
				
				if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_pdf, m_pdf, 2, &tst_values[0]))
				{
					AfxMessageBox( APL_T("Версия с таким обозначением уже существует!!!"),MB_OK|MB_ICONSTOP);
					return;
				}
			}
		}
	}

	if(m_nauo!=0 && m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_acu))
	{
		if(m_nauo_id.Find(_T("*"))<0 && m_nauo_id.Find(_T("-"))<0) // так выделяются подборные - их не проверяем
		{
			CaplInstance *p1,*p2;
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ting, p1);
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ted, p2);

			tst_values[0].value.Set(p1);
			tst_values[0].attr=m_api->m_prd_mgr.a_pdr_r_ting;
			tst_values[1].value.Set(p2);
			tst_values[1].attr=m_api->m_prd_mgr.a_pdr_r_ted;
			tst_values[2].value.Set(m_nauo_id);
			tst_values[2].attr=m_api->m_prd_mgr.a_pdr_id;

			if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_pdr, m_nauo, 3, &tst_values[0]))
			{
				AfxMessageBox( APL_T("Связь данных изделий с такой позицией уже есть в базе !!!"),MB_OK|MB_ICONSTOP);
				return;
			}
		}
	}
	else if(m_subst)
	{
		CaplInstance *p1,*p2;
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_pdr, p1);
		m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_pdf, p2);
		
		tst_values[0].value.Set(p1);
		tst_values[0].attr=m_api->m_prd_mgr.a_pdf_subst_pdr;
		tst_values[1].value.Set(p2);
		tst_values[1].attr=m_api->m_prd_mgr.a_pdf_subst_pdf;
		tst_values[2].value.Set(m_nauo_id);
		tst_values[2].attr=m_api->m_prd_mgr.a_pdf_subst_id;
		if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_pdf_subst, m_subst, 3, &tst_values[0]))
		{
			AfxMessageBox( APL_T("Связь данных изделий с такой позицией уже есть в базе !!!"),MB_OK|MB_ICONSTOP);return;
		}	
	}
	int iCur = -1;
	// Чтение вспомогательных атрибутов
	CString src;
	m_source_ctrl.GetWindowText(src);
	src=CaplProductManager::StrConvertRus2MakeOrBuy(src);

	CString form_type;
	m_type_ctrl.GetWindowText(form_type);
	form_type=CaplProductManager::StrConvertRus2PdfType(form_type);

	bool std_pdf=false;
	if(m_pdf_std.GetCheck()==1)std_pdf=true;

	CaplInstance *pdf_unit=(CaplInstance*)m_pdf_unit.GetItemData(m_pdf_unit.GetCurSel());
	if((int)pdf_unit==-1)pdf_unit=0;

	if((m_mode==aplModeCreateVersion || m_mode==aplModeCreateProductIfNew) && m_prd!=NULL)
	{
		CaplAttrValue tst_values[2];
		
		m_pdf=m_api->m_data.CreateInstance(m_api->m_prd_mgr.e_apl_pdf);
		m_aeCreatedInsts.Add(m_pdf);
		if(!m_pdf_first_usage) 
		{
			if(m_base_pdf) m_pdf_first_usage = m_base_pdf;
			else m_pdf_first_usage = m_pdf;
		}
		
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_id, m_pdf_id);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_descr, m_pdf_descr);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_prd, m_prd);

		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdfwss_source, src);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_type, form_type);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, std_pdf);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_state, _T("working"));
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_first_usage, m_pdf_first_usage);

		CString sRelevanceOld;
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceOld);
		if(sRelevanceNew!=sRelevanceOld) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceNew);

		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_unit, pdf_unit);

		if(m_bOpenPdfCode)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code, m_pdf_code);
		if(m_bOpenPdfCode1)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code1, m_pdf_code1);
		if(m_bOpenPdfCode2)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code2, m_pdf_code2);

	}
	else if(m_mode==aplModeCreateProduct || ((m_mode==aplModeCreateVersion || m_mode==aplModeCreateProductIfNew) && m_prd==NULL))
	{
		// Определение атрибутов

		m_prd=m_api->m_data.CreateInstance(m_api->m_prd_mgr.e_prd);
		m_pdf=m_api->m_data.CreateInstance(m_api->m_prd_mgr.e_apl_pdf);
		m_aeCreatedInsts.Add(m_prd);
		m_aeCreatedInsts.Add(m_pdf);
		if(!m_pdf_first_usage) m_pdf_first_usage = m_pdf;
		
		m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_id, m_prd_id);
		m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_descr, m_prd_descr);
		m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_name, m_prd_name);

		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_id, m_pdf_id);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_descr, m_pdf_descr);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_prd, m_prd);
		
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdfwss_source, src);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_type, form_type);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, std_pdf);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_state, _T("working"));
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_first_usage, m_pdf_first_usage);

		CString sRelevanceOld;
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceOld);
		if(sRelevanceNew!=sRelevanceOld) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceNew);

		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_unit, pdf_unit);
		
		if(m_bOpenPrdCode)	m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_code, m_prd_code);
		if(m_bOpenPdfCode)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code, m_pdf_code);
		if(m_bOpenPdfCode1)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code1, m_pdf_code1);
		if(m_bOpenPdfCode2)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code2, m_pdf_code2);

	}
	else if(m_mode==aplModeCreateSubProduct)
	{
		// скопировать характеристики?
		aplExtent char_prd_ext, char_pdf_ext;
		if(m_bIsCreatingCopy)
		{
			if(m_prd != NULL)
				m_api->m_charact_mgr.FindAssociatedCharacteristics(m_prd, char_prd_ext);
			if(m_pdf != NULL)
				m_api->m_charact_mgr.FindAssociatedCharacteristics(m_pdf, char_pdf_ext);
			if((char_prd_ext.Size > 0 || char_pdf_ext.Size > 0 )&& AfxMessageBox(APL_T("Скопировать характеристики?"), MB_YESNO|MB_ICONQUESTION) != IDYES)
			{
				char_prd_ext.Clear();
				char_pdf_ext.Clear();
			}
		}
			
		// создание изделия	
		m_prd=m_api->m_data.CreateInstance(m_api->m_prd_mgr.e_prd);
		m_pdf=m_api->m_data.CreateInstance(m_api->m_prd_mgr.e_apl_pdf);
		m_aeCreatedInsts.Add(m_prd);
		m_aeCreatedInsts.Add(m_pdf);

		// копирование характеристик
		for(int i = 0; i < char_prd_ext.Size; ++i)
		{
			CaplInstance *inst = m_api->m_charact_mgr.CreateCopyCharacteristicVal(char_prd_ext[i]);
			m_api->m_data.PutAttr(inst, m_api->m_charact_mgr.a_apl_charact_val_item, m_prd);
		}
		for(int i = 0; i < char_pdf_ext.Size; ++i)
		{
			CaplInstance *inst = m_api->m_charact_mgr.CreateCopyCharacteristicVal(char_pdf_ext[i]);
			m_api->m_data.PutAttr(inst, m_api->m_charact_mgr.a_apl_charact_val_item, m_pdf);
		}

		
		m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_id, m_prd_id);
		m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_descr, m_prd_descr);
		m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_name, m_prd_name);
		
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_id, m_pdf_id);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_descr, m_pdf_descr);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_prd, m_prd);
		
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdfwss_source, src);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_type, form_type);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, std_pdf);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_state, _T("working"));
		
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_unit, pdf_unit);
		m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_first_usage, m_pdf_first_usage);

		CString sRelevanceOld;
		m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceOld);
		if(sRelevanceNew!=sRelevanceOld) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceNew);
		
		if(m_bOpenPrdCode)	m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_code, m_prd_code);
		if(m_bOpenPdfCode)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code, m_pdf_code);
		if(m_bOpenPdfCode1)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code1, m_pdf_code1);
		if(m_bOpenPdfCode2)	m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code2, m_pdf_code2);

		
		// Создание сборки
		m_nauo=m_api->m_data.CreateInstance(m_api->m_prd_mgr.e_qacu_nauo);
		m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_id, m_nauo_id);
		m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_acu_ref_des,m_ref_des);
		m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_name, m_nauo_name);
		m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_descr, m_nauo_descr);
		if(!m_bIsCreatingCopy) // при копировании изделия связь не создавать
		{
			m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ting, m_parent_pdf);
			m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ted, m_pdf);
		}		
		m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_value, m_nauo_count);

		if(m_context_changed)
		{
			if(m_nauo_contexts.GetSize()>0)
				m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_frames_of_reference, m_nauo_contexts);
		}

		iCur = m_nauo_unit_ctrl.GetCurSel();
		CaplInstance *inst2=NULL;
		if(iCur>-1){
			inst2=(CaplInstance*)m_nauo_unit_ctrl.GetItemData(iCur);
		}
		if(inst2==(CaplInstance*)-1){
			inst2=0;
		}
		m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_unit, inst2);

	}
	else if(m_mode==aplModeEdit)
	{
		CString o1,o2;
		CaplAttrValue tst_values[2];
		
		m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_id, o1);
		m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_name, o2);
		if((m_prd_id!=o1)||(m_prd_name!=o2))
		{
			if(m_prd_id!=o1) m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_id,m_prd_id);
			if(m_prd_name!=o2) m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_name,m_prd_name);
		}
		
		if(m_bOpenPrdCode)
		{
			m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_code, o2);
			if(o2!=m_prd_code)
				m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_code, m_prd_code);
		}
		
		m_api->m_data.GetAttr(m_prd, m_api->m_prd_mgr.a_prd_descr, o1);
		if(o1!=m_prd_descr)
			m_api->m_data.PutAttr(m_prd, m_api->m_prd_mgr.a_prd_descr, m_prd_descr);
		
		if(m_pdf!=0)
		{
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_id, o1);
			if(m_pdf_id!=o1)
			{
				m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_id, m_pdf_id);
			}
		
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_descr, o1);
			if(m_pdf_descr!=o1) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_descr, m_pdf_descr);

			if(m_bOpenPdfCode)
			{
				m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code, o2);
				if(o2!=m_pdf_code) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code, m_pdf_code);
			}

			if(m_bOpenPdfCode1)
			{
				m_api->m_data.GetAttr(m_pdf,m_api->m_prd_mgr.a_pdf_code1, o2);
				if(o2!=m_pdf_code1) m_api->m_data.PutAttr(m_pdf,m_api->m_prd_mgr.a_pdf_code1, m_pdf_code1);
			}

			if(m_bOpenPdfCode2)
			{
				m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code2, o2);
				if(o2!=m_pdf_code2) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdf_code2, m_pdf_code2);
			}
			

			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_pdfwss_source, o1);
			if(src!=o1)m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_pdfwss_source, src);

			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_type, o1);
			if(form_type!=o1)m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_type, form_type);
		
			bool o_std_pdf;
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, o_std_pdf);
			if(std_pdf!=o_std_pdf)m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_standard, std_pdf);

			CaplInstance *o_pdf_unit;
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_unit, o_pdf_unit);
			if(o_pdf_unit!=pdf_unit)m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_unit, pdf_unit);

			CaplInstance *o_pdf_first_usage;
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_first_usage, o_pdf_first_usage);
			if(o_pdf_first_usage!=m_pdf_first_usage)
				m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_first_usage, m_pdf_first_usage);

			CString sRelevanceOld;
			m_api->m_data.GetAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceOld);
			if(sRelevanceNew!=sRelevanceOld) m_api->m_data.PutAttr(m_pdf, m_api->m_prd_mgr.a_apl_pdf_relevance, sRelevanceNew);

			if(0!=m_new_clasif_level && m_old_clasif_level!=m_new_clasif_level) // значение изменилось
			{
				if(0!=m_old_clasif_level) 
				{
					m_api->m_classifier_mgr.DeleteClassifierAssociation(m_pdf,m_old_clasif_level);
				}
				m_api->m_classifier_mgr.CreateClassifierAssociation(m_pdf,m_new_clasif_level);
			}

		}
		if(m_nauo!=0)
		{
			if(m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_make_from))
			{
				CaplInstance *pd1=0;
				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_r_ting, pd1);
				tst_values[0].value.Set(pd1);
				tst_values[0].attr=m_api->m_prd_mgr.a_pdr_r_ting;
				tst_values[1].value.Set(m_ranking);
				tst_values[1].attr=m_api->m_prd_mgr.a_make_from_ranking;
				if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_make_from, m_nauo, 2, &tst_values[0]))
				{
					AfxMessageBox( APL_T("Связь с таким приоритетом уже есть в базе !!!"),MB_OK|MB_ICONSTOP);
					return;
				}
			}

			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_id, o1);
			if(m_nauo_id!=o1) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_id, m_nauo_id);
			
			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_acu_ref_des, o1);
			if(m_ref_des!=o1) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_acu_ref_des, m_ref_des);

			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_name, o1);
			if(m_nauo_name!=o1) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_name, m_nauo_name);

			m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_pdr_descr, o1);
			if(m_nauo_descr!=o1) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_descr, m_nauo_descr);
		
			CaplInstance *inst, *inst2;
			double count;
			int ranking=0;
			CString buf;

			if(m_context_changed)
			{
				if(m_nauo_contexts.GetSize()>0)
					m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_frames_of_reference, m_nauo_contexts);
				else
				{
					CaplValue empty_val;
					m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_pdr_frames_of_reference, empty_val);
				}
			}

			if(m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_apl_qacu))
			{
				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_value, count);
				if(m_nauo_count!=count) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_value, m_nauo_count);

				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_unit, inst);
				inst2 = NULL;
				iCur = m_nauo_unit_ctrl.GetCurSel();
				if(iCur>-1) inst2=(CaplInstance*)m_nauo_unit_ctrl.GetItemData(iCur);
				if(inst2==(CaplInstance*)-1)inst2=0;
				if(inst2!=inst)m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_apl_qacu_unit, inst2);
			}
			else if(m_api->m_data.IsKindOf(m_nauo, m_api->m_prd_mgr.e_make_from))
			{
				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_value, count);
				if(m_nauo_count!=count) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_value, m_nauo_count);

				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_derive_value, count);
				if(m_nauo_count2!=count) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_derive_value, m_nauo_count2);
				
				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_unit, inst);
				inst2 = NULL;
				iCur = m_nauo_unit_ctrl.GetCurSel();
				if(iCur>-1) inst2=(CaplInstance*)m_nauo_unit_ctrl.GetItemData(iCur);
				if(inst2==(CaplInstance*)-1)inst2=0;
				if(inst2!=inst)m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_unit, inst2);

				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_derive_unit, inst);
				inst2 = NULL;
				iCur = m_nauo_unit2.GetCurSel();
				if(iCur>-1) inst2=(CaplInstance*)m_nauo_unit2.GetItemData(iCur);
				if(inst2==(CaplInstance*)-1)inst2=0;
				if(inst2!=inst)m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_derive_unit, inst2);

				/*m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_assortment, inst);
				inst2 = NULL;
				iCur = m_sortament.GetCurSel();
				if(iCur>-1) inst2=(CaplInstance*)m_sortament.GetItemData(iCur);
				if(inst2==(CaplInstance*)-1)inst2=0;
				if(inst2!=inst)m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_assortment, inst2);*/
				
				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_ranking, ranking);
				if(ranking!=m_ranking) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_ranking, m_ranking);

				m_api->m_data.GetAttr(m_nauo, m_api->m_prd_mgr.a_make_from_ranking_rationale, buf);
				if(buf!=m_ranking_rationale) m_api->m_data.PutAttr(m_nauo, m_api->m_prd_mgr.a_make_from_ranking_rationale, m_ranking_rationale);
			}
		}
		else if(m_subst)
		{
			m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_id, o1);
			if(m_nauo_id!=o1) m_api->m_data.PutAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_id, m_nauo_id);

			m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_name, o1);
			if(m_nauo_name!=o1) m_api->m_data.PutAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_name, m_nauo_name);

			m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_description, o1);
			if(m_nauo_descr!=o1) m_api->m_data.PutAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_description, m_nauo_descr);
		
			CaplInstance *inst, *inst2;
			double count;
			int ranking=0;
			CString buf;

			m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_value, count);
			if(m_nauo_count!=count) m_api->m_data.PutAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_value, m_nauo_count);
			m_api->m_data.GetAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_unit, inst);
			inst2 = NULL;
			iCur = m_nauo_unit_ctrl.GetCurSel();
			if(iCur>-1) inst2=(CaplInstance*)m_nauo_unit_ctrl.GetItemData(iCur);
			if(inst2==(CaplInstance*)-1)inst2=0;
			if(inst2!=inst)m_api->m_data.PutAttr(m_subst, m_api->m_prd_mgr.a_pdf_subst_unit, inst2);
		}
	}
	m_api->m_data.NET_SaveChanges();
	m_ok_end=true;
	GetAccessString();
	CaplResizableDialog::OnOK();
}
//********************************************************************************
//********************************************************************************
//********************************************************************************
void CProductDlg::HideNAUO()
{
	RECT rect,rect1;
	int cy;
	
	m_nauo_id_ctrl.ShowWindow(SW_HIDE);
	m_nauo_name_ctrl.ShowWindow(SW_HIDE);
	m_nauo_descr_ctrl.ShowWindow(SW_HIDE);
	m_nauo_count_ctrl.ShowWindow(SW_HIDE);
	m_nauo_unit_ctrl.ShowWindow(SW_HIDE);
	m_ranking_name_ctrl.ShowWindow(SW_HIDE);
	m_ranking_ctrl.ShowWindow(SW_HIDE);
	m_ranking_rationale_ctrl.ShowWindow(SW_HIDE);
	m_st_rank_rat.ShowWindow(SW_HIDE);
	m_rel_property_btn.ShowWindow(SW_HIDE);
	m_ref_des_ctrl.ShowWindow(SW_HIDE);
	m_ref_des_static_ctrl.ShowWindow(SW_HIDE);

	m_context_sel.ShowWindow(SW_HIDE);
	m_context_names.ShowWindow(SW_HIDE);
	m_st_contexts.ShowWindow(SW_HIDE);

	m_st_name.ShowWindow(SW_HIDE);
	m_st_pos.ShowWindow(SW_HIDE);
	m_st_descr.ShowWindow(SW_HIDE);
	m_st_asm.ShowWindow(SW_HIDE);
	m_st_count.ShowWindow(SW_HIDE);	
	m_st_rank_rat.ShowWindow(SW_HIDE);	
	m_st_count2.ShowWindow(SW_HIDE);
	m_nauo_unit2.ShowWindow(SW_HIDE);
	m_nauo_count2_ctrl.ShowWindow(SW_HIDE);
	//m_st_sort.ShowWindow(SW_HIDE);
	//m_sortament.ShowWindow(SW_HIDE);

	m_s_pdf_v.GetWindowRect(&rect);
	m_test_btn.GetWindowRect(&rect1);
	cy=-25+rect1.top-rect.bottom;
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_test_btn.MoveWindow(&rect1);

	m_btn_cancel.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_cancel.MoveWindow(&rect1);

	m_btn_ok.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_ok.MoveWindow(&rect1);

	m_btn_add.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_add.MoveWindow(&rect1);

	GetWindowRect(&rect);
	rect.bottom-=cy;

	SetSize(cy);

	MoveWindow(&rect);


}
//********************************************************************************
void CProductDlg::HideMFU()
{
	RECT rect,rect1;
	int cy;
	
	m_ranking_name_ctrl.ShowWindow(SW_HIDE);
	m_ranking_ctrl.ShowWindow(SW_HIDE);
	m_ranking_rationale_ctrl.ShowWindow(SW_HIDE);
	m_st_rank_rat.ShowWindow(SW_HIDE);	
	m_st_count2.ShowWindow(SW_HIDE);
	m_nauo_unit2.ShowWindow(SW_HIDE);
	m_nauo_count2_ctrl.ShowWindow(SW_HIDE);
	//m_st_sort.ShowWindow(SW_HIDE);
	//m_sortament.ShowWindow(SW_HIDE);

	//m_st_count2.GetWindowRect(&rect);
	m_st_rank_rat.GetWindowRect(&rect);
	m_st_asm.GetWindowRect(&rect1);
	cy=-25+rect1.bottom-rect.top;

	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_st_asm.MoveWindow(&rect1);

	m_test_btn.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_test_btn.MoveWindow(&rect1);
/*
	m_rel_property_btn.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_rel_property_btn.MoveWindow(&rect1);
*/
	m_btn_cancel.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_cancel.MoveWindow(&rect1);

	m_btn_ok.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_ok.MoveWindow(&rect1);

	m_btn_add.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_add.MoveWindow(&rect1);

	GetWindowRect(&rect);
	rect.bottom-=cy;

	SetSize(cy);

	MoveWindow(&rect);


}
void CProductDlg::HidePDF()
{
	HideNAUO();
	RECT rect,rect1;
	int cy;

	m_pdf_id_ctrl.ShowWindow(SW_HIDE);
	m_pdf_descr_ctrl.ShowWindow(SW_HIDE);

	m_pdf_std.ShowWindow(SW_HIDE);
	m_s_pdf_v.ShowWindow(SW_HIDE);
	m_s_pdf_type.ShowWindow(SW_HIDE);
	m_s_pdf_src.ShowWindow(SW_HIDE);
	m_s_pdf_id.ShowWindow(SW_HIDE);
	m_s_pdf_descr.ShowWindow(SW_HIDE);
	m_st_pdf_code.ShowWindow(SW_HIDE);
	m_pdf_code_ctrl.ShowWindow(SW_HIDE);

	m_pdf_first_usage_st.ShowWindow(SW_HIDE);
	m_pdf_first_usage_edt.ShowWindow(SW_HIDE);
	m_pdf_first_usage_btn.ShowWindow(SW_HIDE);

	m_source_ctrl.ShowWindow(SW_HIDE);
	m_type_ctrl.ShowWindow(SW_HIDE);

	m_setup_unit_convertions_btn.ShowWindow(SW_HIDE);
	m_pdf_unit.ShowWindow(SW_HIDE);
	m_st_pdf_unit.ShowWindow(SW_HIDE);
	m_pdf_id_cng_btn.ShowWindow(SW_HIDE);
	m_pdf_code_cng_btn.ShowWindow(SW_HIDE);
	m_pdf_code1_cng_btn.ShowWindow(SW_HIDE);
	m_pdf_code2_cng_btn.ShowWindow(SW_HIDE);
	m_pdf_code1_ctrl.ShowWindow(SW_HIDE);
	m_pdf_code2_ctrl.ShowWindow(SW_HIDE);
	m_st_pdf_code1.ShowWindow(SW_HIDE);
	m_st_pdf_code2.ShowWindow(SW_HIDE);

	m_st_prd.GetWindowRect(&rect);
	m_test_btn.GetWindowRect(&rect1);
	cy=-25+rect1.top-rect.bottom;
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_test_btn.MoveWindow(&rect1);

	m_btn_cancel.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_cancel.MoveWindow(&rect1);

	m_btn_ok.GetWindowRect(&rect1);
	rect1.top-=cy;
	rect1.bottom-=cy;
	ScreenToClient(&rect1);
	m_btn_ok.MoveWindow(&rect1);

	GetWindowRect(&rect);
	rect.bottom-=cy;

	SetSize(cy);

	MoveWindow(&rect);
}

void CProductDlg::HideRefDes()
{
	CRect st_rect,rect,st_descr_rect,descr_rect;

	m_ref_des_static_ctrl.GetWindowRect(&st_rect);
	ScreenToClient(&st_rect);
	m_st_descr.GetWindowRect(&st_descr_rect);
	ScreenToClient(&st_descr_rect);
	st_descr_rect.left=st_rect.left;
	st_descr_rect.right=st_rect.right;
	m_st_descr.MoveWindow(&st_descr_rect);

	m_ref_des_ctrl.GetWindowRect(&rect);
	ScreenToClient(&rect);
	m_nauo_descr_ctrl.GetWindowRect(&descr_rect);
	ScreenToClient(&descr_rect);
	descr_rect.left=rect.left;
	m_nauo_descr_ctrl.MoveWindow(&descr_rect);

	m_ref_des_ctrl.ShowWindow(SW_HIDE);
	m_ref_des_static_ctrl.ShowWindow(SW_HIDE);
}

void CProductDlg::OnTest() 
{
	// TODO: Add your control notification handler code here
	if(UpdateData(TRUE)==0) return;
	m_prd_id.TrimLeft();
	m_prd_id.TrimRight();
	m_prd_name.TrimLeft();
	m_prd_name.TrimRight();
	m_pdf_id.TrimLeft();
	m_pdf_id.TrimRight();
	UpdateData(FALSE);
	
	if(m_prd_id==_T(""))
	{
		AfxMessageBox( APL_T("Обозначение не может быть пустым!"),MB_OK|MB_ICONSTOP);return;
	}

	CString buf;

	//Проверка уникальности
	CaplAttrValue tst_values[2];
	
	//if(m_prd!=0)
	{

		int count_val=1;
		buf=m_prd_id;
		buf.TrimLeft();
		buf.TrimRight();		tst_values[0].value.Set((LPCTSTR)buf);
		tst_values[0].attr=m_api->m_prd_mgr.a_prd_id;

		if(m_PrdUnikByIdAndName)
		{
			buf=m_prd_name;
			buf.TrimLeft();
			buf.TrimRight();
			tst_values[1].value.Set((LPCTSTR)buf);
			tst_values[1].attr=m_api->m_prd_mgr.a_prd_name;
			count_val=2;
		}

		if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_prd, m_prd, count_val, &tst_values[0]))
		{
			AfxMessageBox( APL_T("Изделие с таким обозначением уже существует в БД!"),MB_OK|MB_ICONSTOP);
			return;
		}

	}
	bool f=true;
#if _MSC_VER >= 1400
	if(!( (m_pdf==0)&&(m_mode==aplModeEdit) ))
#else
	if(!( (m_pdf==0)&&(m_mode==_T("Edit")) ))
#endif
	{
		if(m_prd!=0)
		{
			buf=m_pdf_id;
			buf.TrimLeft();
			buf.TrimRight();

			tst_values[0].value.Set((LPCTSTR)buf);
			tst_values[0].attr=m_api->m_prd_mgr.a_pdf_id;
			tst_values[1].value.Set(m_prd);
			tst_values[1].attr=m_api->m_prd_mgr.a_pdf_prd;
			
			if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_pdf, m_pdf, 2, &tst_values[0]))
			{
				AfxMessageBox( APL_T("Версия  с таким обозначением уже существует в БД!"));
				return;
			}
		}
	}
	if(m_api->m_appr_mgr.IsAdmin())
	{
		if(!m_prd_code.IsEmpty())
		{
			tst_values[0].value.Set((LPCTSTR)m_prd_code);
			tst_values[0].attr=m_api->m_prd_mgr.a_prd_code;

			if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_prd, m_prd, 1, &tst_values[0]))
			{
				AfxMessageBox( APL_T("Код изделия не уникален!"),MB_OK|MB_ICONSTOP);
				return;
			}
		}
		if(!m_pdf_code.IsEmpty())
		{
			tst_values[0].value.Set((LPCTSTR)m_pdf_code);
			tst_values[0].attr=m_api->m_prd_mgr.a_pdf_code;

			if(!m_api->m_data.TestUniqueAttrValues(m_api->m_prd_mgr.e_apl_pdf, m_pdf, 1, &tst_values[0]))
			{
				AfxMessageBox( APL_T("Код версии изделия не уникален!"),MB_OK|MB_ICONSTOP);return;
			}
		}
	}
	AfxMessageBox( APL_T("Обозначение уникально!"));
}

int state_undoc=0;
void CProductDlg::OnStName() 
{
	// TODO: Add your control notification handler code here
/*
	bool lShift,rShift,lCtrl,rCtrl,lAlt,rAlt;

	lShift=((GetKeyState(VK_LSHIFT) & 0xff00)!=0);
	rShift=((GetKeyState(VK_RSHIFT) & 0xff00)!=0);
	lCtrl=((GetKeyState(VK_LCONTROL) & 0xff00)!=0);
	rCtrl=((GetKeyState(VK_RCONTROL) & 0xff00)!=0);
	lAlt=((GetKeyState(VK_LMENU) & 0xff00)!=0);
	rAlt=((GetKeyState(VK_RMENU) & 0xff00)!=0);
*/
	CString text,buf;
	if(((GetKeyState(VK_LMENU) & 0xff00)!=0)&&((GetKeyState(VK_RMENU) & 0xff00)!=0)){
		text.Format( APL_T("Режим %s;\n"),m_mode);
		if(m_pdf!=0){buf.Format(_T("m_pdf->id %i;\n"),m_pdf->GetId());text+=buf;}
		if(m_prd!=0){buf.Format(_T("m_prd->id %i;\n"),m_prd->GetId());text+=buf;}
		if(m_base_pdf!=0){buf.Format(_T("m_base_pdf->id %i;\n"),m_base_pdf->GetId());text+=buf;}
		if(m_base_prd!=0){buf.Format(_T("m_base_prd->id %i;\n"),m_base_prd->GetId());text+=buf;}
		if(m_nauo!=0){buf.Format(_T("m_nauo->id %i;\n"),m_nauo->GetId());text+=buf;}

		AfxMessageBox(text);
	}
}

void CProductDlg::OnAddProduct() 
{
	OnOK();
	if(m_ok_end) m_add_mode=true;
}

void CProductDlg::OnContextSel() 
{
	if(m_api->m_prd_mgr.ChangeItemContext(m_nauo_contexts))
	{
		CString buf;
		m_api->m_prd_mgr.PrintItemContextInString(m_nauo_contexts,buf);
		m_context_names.SetWindowText(buf);
		m_context_changed=true;
	}
}

void CProductDlg::OnRelProperty() 
{
	if(m_nauo==0 && m_subst==0)
	{
		AfxMessageBox( APL_T("Связь еще не создана !!!"),MB_OK|MB_ICONSTOP);return;
	}
	if(m_nauo) m_api->m_charact_mgr.ShowItemProperties(m_nauo);
	else if(m_subst) m_api->m_charact_mgr.ShowItemProperties(m_subst);
}

void CProductDlg::TestPdfType()
{
	CString buf, buf2;
	m_type_ctrl.GetWindowText(buf2);
	buf = m_api->m_prd_mgr.StrConvertRus2PdfType(buf2);
	BOOL bRes = buf.CompareNoCase(_T("system"))==0 || buf.CompareNoCase(_T("zone"))==0 || buf.CompareNoCase(_T("module"))==0;
	
	//Дизаблим еденици измерения, сортамент и т.д.
	if(m_bDizableEditNAUO) bRes=TRUE;
	m_nauo_count_ctrl.EnableWindow(!bRes);
	m_nauo_unit_ctrl.EnableWindow(!bRes);
	m_nauo_unit2.EnableWindow(!bRes);
	m_nauo_count2_ctrl.EnableWindow(!bRes);
	m_ranking_ctrl.EnableWindow(!bRes);
	m_ranking_rationale_ctrl.EnableWindow(!bRes);
	//m_sortament.EnableWindow(!bRes);
}

void CProductDlg::OnSelchangeType() 
{
	TestPdfType();
	m_changed_pdf = true;
}

void CProductDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CaplPropsView* pView	=NULL;
	
	BOOL	bDis	=TRUE;
	BOOL	bHide	=FALSE;

	if(0==m_Tab.GetCurSel())
		bDis=FALSE;
	
	ChangeViewBtnsState(bDis,!bDis);

	m_Tab.GetTabView(m_Tab.GetCurSel(),(CWnd*&)pView);
	if(NULL!=pView)
	{
		pView->InitView();
		pView->ChangeCtrlsState();
	}
	
	*pResult = 0;
}

void CProductDlg::OnBPropsAdd() 
{
	CaplPropsView* pView	=NULL;

	if(0==m_Tab.GetCurSel())
		return;

	m_Tab.GetTabView(m_Tab.GetCurSel(),(CWnd*&)pView);
	pView->OnBAdd();
}

void CProductDlg::OnBPropsDel() 
{
	CaplPropsView* pView	=NULL;

	if(0==m_Tab.GetCurSel())
		return;

	m_Tab.GetTabView(m_Tab.GetCurSel(),(CWnd*&)pView);
	pView->OnBDel();
}

void CProductDlg::OnBPropsProps() 
{
	CaplPropsView* pView	=NULL;

	if(0==m_Tab.GetCurSel())
		return;

	m_Tab.GetTabView(m_Tab.GetCurSel(),(CWnd*&)pView);
	pView->OnBProps();
}

//************************************************



void CProductDlg::OnPrdIdCng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_prd_id_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_prd_id,m_prd,buf,this)) m_prd_id_ctrl.SetWindowText(buf);
	m_changed_prd = true;
}

void CProductDlg::OnPrdNameCng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_prd_name_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_prd_name,m_prd,buf,this)) m_prd_name_ctrl.SetWindowText(buf);
	m_changed_prd = true;
}

void CProductDlg::OnPrdCodeCng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_prd_code_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_prd_code,m_prd,buf,this)) m_prd_code_ctrl.SetWindowText(buf);
	m_changed_prd = true;
}


void CProductDlg::OnPdfIdCng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_pdf_id_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_pdf_id,m_pdf,buf,this)) m_pdf_id_ctrl.SetWindowText(buf);
	m_changed_pdf = true;
}


void CProductDlg::OnPdfCodeCng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_pdf_code_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_pdf_code,m_pdf,buf,this)) m_pdf_code_ctrl.SetWindowText(buf);
	m_changed_pdf = true;
}

void CProductDlg::OnPdfCode1Cng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_pdf_code1_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_pdf_code1,m_pdf,buf,this)) m_pdf_code1_ctrl.SetWindowText(buf);
	m_changed_pdf = true;
}

void CProductDlg::OnPdfCode2Cng() 
{
	if(m_fItemAttrBuild==0) return;
	CString buf;
	m_pdf_code2_ctrl.GetWindowText(buf);
	if(m_fItemAttrBuild(false,m_api,m_api->m_prd_mgr.a_pdf_code2,m_pdf,buf,this)) m_pdf_code2_ctrl.SetWindowText(buf);
	m_changed_pdf = true;
}




void CProductDlg::OnPdfFirstUsageBtn() 
{
	#ifdef _MOMA_

		CaplInstance *newClassLevel=m_old_clasif_level;
		if(!m_api->m_classifier_mgr.SelectItem(&newClassLevel,0,APL_SELECT_CLASSIFIER_LEVEL)) return;
		if(0==newClassLevel) return;
		if(m_old_clasif_level==newClassLevel)  return;

		m_new_clasif_level=newClassLevel;

		CString sName;
		m_api->m_classifier_mgr.GetItemName(newClassLevel,sName);
		m_pdf_first_usage_edt.SetWindowText(sName);

	#else

		CString buf;
		CaplInstance *newpdf=m_api->m_prd_mgr.SelectInstance(APL_MODE_SELECT_PDF, APL_T("Выбор первого применения"));
		if(newpdf!=0)
		{
			m_api->GetItemName(newpdf,buf);
			m_pdf_first_usage_edt.SetWindowText(buf);
			m_pdf_first_usage=newpdf;
		}

	#endif
}

void CProductDlg::OnBnClickedSetupUnitConvertions()
{
	int index = m_pdf_unit.GetCurSel();
	if(-1 == index)
	{
		AfxMessageBox( APL_T("Сначала необходимо выбрать единицу измерения."), MB_ICONSTOP);
		return;
	}

	CaplInstance *ciUnit = reinterpret_cast<CaplInstance*>(m_pdf_unit.GetItemData(index));
	if(0 == ciUnit)
	{
		AfxMessageBox( APL_T("Сначала необходимо выбрать единицу измерения."), MB_ICONSTOP);
		return;
	}

	m_api->m_charact_mgr.SetupUnitConvertion(m_pdf, ciUnit, m_nauo_count);
}

void CProductDlg::OnEnChangePrdAttrs()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CaplResizableDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
	m_changed_prd = true;
}

void CProductDlg::OnEnChangePdfAttrs()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CaplResizableDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
	m_changed_pdf = true;
}

void CProductDlg::OnCbnSelchangePdfCombo()
{
	// TODO: Add your control notification handler code here
	m_changed_pdf = true;
}

void CProductDlg::OnBnClickedPdfStandard()
{
	// TODO: Add your control notification handler code here
	m_changed_pdf = true;
}
