// BPResDlg.cpp : implementation file
//

#include "stdafx.h"
#include "psm.h"
#include "BPResDlg.h"
#include "PSMDoc.h"
#include "aplguiex.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBPResDlg dialog


CBPResDlg::CBPResDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(CBPResDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBPResDlg)
	//}}AFX_DATA_INIT
	m_inst=0; m_bp=0; m_obj=0; m_base_pdr=0; m_base_res=0,m_bp_rev=0;
	m_doc=0;m_ReadOnly=false;
}


void CBPResDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBPResDlg)
	DDX_Control(pDX, IDC_RANKING, m_ranking_ctrl);
	DDX_Control(pDX, IDC_RANK_RAT, m_ranking_rationale_ctrl);
	//DDX_Control(pDX, IDC_SORTAMENT, m_sortament);
	DDX_Control(pDX, IDC_VALUE_DER, m_val_der_ctrl);
	DDX_Control(pDX, IDC_UNIT_DER, m_unit_der_ctrl);
	DDX_Control(pDX, IDC_VALUE, m_val_ctrl);
	DDX_Control(pDX, IDC_DESCR, m_descr_ctrl);
	DDX_Control(pDX, IDC_UNIT, m_unit_ctrl);
	DDX_Control(pDX, IDC_RES_TYPE, m_type_ctrl);
	DDX_Control(pDX, IDC_OBJ, m_obj_ctrl);
	DDX_Control(pDX, IDC_NAME, m_name_ctrl);
	DDX_Control(pDX, IDC_ID, m_id_ctrl);
	DDX_Control(pDX, IDCANCEL, m_cancel_btn);
	DDX_Control(pDX, IDOK, m_ok_btn);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBPResDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(CBPResDlg)
	ON_BN_CLICKED(IDC_OBJ_BROWSE, OnObjBrowse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBPResDlg message handlers
//****************************************************************************
BOOL CBPResDlg::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();

	// TODO: Add extra initialization here
	VERIFY(m_doc!=0);
	m_cancel_btn.SetIcon(GetAplStdIco16(APLSTDICO_CANCEL));
	m_cancel_btn.SetFlat(FALSE);
	m_ok_btn.SetIcon(GetAplStdIco16(APLSTDICO_OK));
	m_ok_btn.SetFlat(FALSE);

	int i,j;
	aplExtent ext;
	CString buf,buf1;
	CaplInstance *inst;

	bool b_use_values=false;
	CString id, name, descr,ranking_rationale;
	int ranking;
	CaplInstance *unit0=0, *unit1=0, *sort=0;
	double count0=1,count1=0;

	// Типы ресурсов
	m_doc_data.GetEntityExtent(m_doc->m_api.m_bp_mgr.e_bp_res_type,ext);
	for(i=0;i<ext.Size;i++)
	{
		m_doc_data.GetAttr(ext[i],m_doc->m_api.m_bp_mgr.a_bp_res_type_name,buf);
		j=m_type_ctrl.AddString(buf);
		m_type_ctrl.SetItemData(j,(int)ext[i]);
	}
	// Сортамент
	/*int k=m_sortament.AddString(_T(" "));
	m_sortament.SetItemData(k,0);

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

	//Единицы измерения
	CString scht;
	m_doc_data.GetEntityExtentBN(_T("step_unit"),ext);
	for(i=0;i<ext.Size;i++)
	{
		m_doc->m_api.m_charact_mgr.GetUnitName(ext[i],buf);
		j=m_unit_ctrl.AddString(buf);
		m_unit_ctrl.SetItemData(j,(UINT)ext[i]);
		buf1=buf;
		buf1.MakeLower();
		if(buf1.GetLength()>=2)	{if((buf1[0]==_T('ш'))&&(buf1[1]==_T('т')))scht=buf;}

		j=m_unit_der_ctrl.AddString(buf);
		m_unit_der_ctrl.SetItemData(j,(UINT)ext[i]);
	}
	j=m_unit_ctrl.AddString(_T(""));
	m_unit_ctrl.SetItemData(j,0);
	if(scht!=_T("")) m_unit_ctrl.SelectString(-1,scht);

	j=m_unit_der_ctrl.AddString(_T(""));
	m_unit_der_ctrl.SetItemData(j,0);

	if(m_base_res!=0)
	{
		b_use_values=true;
		m_doc_data.GetAttrBN(m_base_res,S::id,id);
		m_doc_data.GetAttrBN(m_base_res,S::name,name);
		m_doc_data.GetAttrBN(m_base_res,S::description,descr);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_unit,unit0);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_val,count0);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_derive_unit,unit1);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_derive_val,count1);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_assortment,sort);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_object,m_obj);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_ranking,ranking);
		m_doc_data.GetAttr(m_base_res,m_doc->m_api.m_bp_mgr.a_bp_res_ranking_rationale,ranking_rationale);
	}
	else if(m_base_pdr!=0)
	{
		b_use_values=true;

		m_doc_data.GetAttrBN(m_base_pdr,S::id,id);
		m_doc_data.GetAttrBN(m_base_pdr,S::name,name);
		m_doc_data.GetAttrBN(m_base_pdr,S::description,descr);

		if(m_doc_data.IsKindOfBN(m_base_pdr,S::apl_qacu))
		{
			m_doc_data.GetAttrBN(m_base_pdr,S::value_component,count0);
			m_doc_data.GetAttrBN(m_base_pdr,S::unit_component,unit0);
		}
		else if(m_doc_data.IsKindOfBN(m_base_pdr,_T("apl_make_from_usage_option")))
		{
			m_doc_data.GetAttrBN(m_base_pdr,S::value_component,count0);
			m_doc_data.GetAttrBN(m_base_pdr,_T("derive_value_component"),count1);
			m_doc_data.GetAttrBN(m_base_pdr,S::unit_component,unit0);
			m_doc_data.GetAttrBN(m_base_pdr,_T("derive_unit_component"),unit1);
			m_doc_data.GetAttrBN(m_base_pdr,_T("apl_assortment"),sort);
		}
	}
	
	// Чтение существующих данных
	if(m_inst!=0)
	{
		b_use_values=true;

		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_id,id);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_name,name);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_descr,descr);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_type,inst);
		if(inst!=0)
		{
			for(i=0;i<m_type_ctrl.GetCount();i++)
			{
				j=m_type_ctrl.GetItemData(i);
				if(j==(int)inst) { m_type_ctrl.SetCurSel(i); break;	}
			}
		}
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_unit,unit0);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_val,count0);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_derive_unit,unit1);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_derive_val,count1);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_assortment,sort);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_object,m_obj);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_ranking,ranking);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_ranking_rationale,ranking_rationale);
	}

	if(b_use_values)
	{
		m_id_ctrl.SetWindowText(id);
		m_name_ctrl.SetWindowText(name);
		m_descr_ctrl.SetWindowText(descr);
		m_ranking_rationale_ctrl.SetWindowText(ranking_rationale);

		if(ranking!=0)
		{	buf.Format(_T("%d"),ranking);
			m_ranking_ctrl.SetWindowText(buf);
		}

		if(count0!=0)
		{	buf.Format(_T("%f"),count0);
			m_val_ctrl.SetWindowText(buf);
		}
		if(count1!=0)
		{	buf.Format(_T("%f"),count1);
			m_val_der_ctrl.SetWindowText(buf);
		}
		if(unit0!=0)
		{
			for(i=0;i<m_unit_ctrl.GetCount();i++)
			{
				j=m_unit_ctrl.GetItemData(i);
				if(j==(int)unit0) { m_unit_ctrl.SetCurSel(i); break;	}
			}
		}
		if(unit1!=0)
		{
			for(i=0;i<m_unit_der_ctrl.GetCount();i++)
			{
				j=m_unit_der_ctrl.GetItemData(i);
				if(j==(int)unit1) { m_unit_der_ctrl.SetCurSel(i); break;	}
			}
		}
		/*if(sort!=0)
		{
			i=0;
			while(1)
			{
				j=m_sortament.GetItemData(i);
				if(j==CB_ERR) break;
				if(j==(int)sort){m_sortament.SetCurSel(i);break;}
				i++;
			}
		}*/
	}

	if(m_obj!=0)
	{
		m_doc->m_api.m_bp_mgr.GetItemName(m_obj,buf);
		m_obj_ctrl.SetWindowText(buf);

		/*if(!m_doc_data.IsKindOf(m_obj,m_doc->m_api.m_prd_mgr.e_pdf))
		{
			m_sortament.SelectString(0,_T(""));
			m_sortament.EnableWindow(FALSE);
		}
		else m_sortament.EnableWindow(TRUE);*/
	}
	if(m_inst)
		if(m_inst->GetAccessmode()>=aplRO)
			m_ReadOnly=true;
	if(m_ReadOnly)
	{
		//m_sortament.EnableWindow(FALSE);
		m_val_der_ctrl.SetReadOnly(TRUE);
		m_unit_der_ctrl.EnableWindow(FALSE);
		m_val_ctrl.SetReadOnly(TRUE);
		m_descr_ctrl.SetReadOnly(TRUE);
		m_unit_ctrl.EnableWindow(FALSE);
		m_type_ctrl.EnableWindow(FALSE);
		m_obj_ctrl.SetReadOnly(TRUE);
		m_name_ctrl.SetReadOnly(TRUE);
		m_id_ctrl.SetReadOnly(TRUE);
		m_ok_btn.EnableWindow(FALSE);
		m_ranking_rationale_ctrl.SetReadOnly(TRUE);
		m_ranking_ctrl.SetReadOnly(TRUE);

	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
//****************************************************************************
void CBPResDlg::OnOK() 
{
	// TODO: Add extra validation here
	int i;
	CString buf,buf1;
	double val=0,der_val=0;
	int ranking=0;
	m_val_ctrl.GetWindowText(buf1);
	buf1.TrimLeft();buf1.TrimRight();
	buf1.Replace(_T(','),_T('.'));
	if(!IsRealOrEmpty(buf1)) {AfxMessageBox( APL_T("В поле \"Количество\" должно быть указано число"));return;}
	if(buf1!=_T(""))val=__atof(buf1);

	m_val_der_ctrl.GetWindowText(buf1);
	buf1.TrimLeft();buf1.TrimRight();
	buf1.Replace(_T(','),_T('.'));
	if(!IsRealOrEmpty(buf1)) {AfxMessageBox( APL_T("В поле \"Количество\" должно быть указано число"));return;}
	if(buf1!=_T(""))der_val=__atof(buf1);

	m_ranking_ctrl.GetWindowText(buf1);
	buf1.TrimLeft();buf1.TrimRight();
	buf1.Replace(_T(','),_T('.'));
	if(!IsRealOrEmpty(buf1)) {AfxMessageBox( APL_T("В поле \"Приоритет\" должно быть указано число"));return;}
	if(buf1!=_T(""))ranking=_atoi(buf1);

	if(m_obj==0) {AfxMessageBox( APL_T("Объект не задан")); return;}

	if(m_inst==0)
	{
		if(m_bp)
		{
			CaplAggr aggr;
			if(m_doc->m_api.m_bp_mgr.m_bUseVersions)
			{
				CaplInstance *lock=0;
				m_doc_data.GetAttr(m_bp,m_doc->m_api.m_bp_mgr.a_bp_lock,lock);
				if(lock) m_doc_data.GetAttr(lock,m_doc->m_api.m_bp_mgr.a_bp_ver_res,aggr);
				
			}
			else
				m_doc_data.GetAttr(m_bp,m_doc->m_api.m_bp_mgr.a_bp_res,aggr);
		
			CaplInstance *res=0,*res_obj=0;
			for(i=0;i<aggr.GetSize();i++)
			{
				aggr.GetByIndex(i,res);
				if(!res) continue;if(res->GetAccessmode()>aplRO) continue;
				m_doc_data.GetAttr(res,m_doc->m_api.m_bp_mgr.a_bp_res_object,res_obj);
				if(res_obj==m_obj) 
				{
					if(IDYES!=AfxMessageBox( APL_T("Такой ресурс уже существует! Продолжить?"),MB_YESNO|MB_ICONWARNING)) return;
					break;
				}
			}
		}
	}

	CaplInstance *unit=0, *unit_der=0;

	i=m_unit_ctrl.GetCurSel();
	if(i>=0)unit=(CaplInstance*)m_unit_ctrl.GetItemData(i);
	else unit=0;
	
	if((unit!=0)&&(val==0)){AfxMessageBox( APL_T("Если задана единица измерения, то количество должно быть указано"));return;}

	i=m_unit_der_ctrl.GetCurSel();
	if(i>=0)unit_der=(CaplInstance*)m_unit_der_ctrl.GetItemData(i);
	else unit_der=0;
	
	if((unit_der!=0)&&(der_val==0)){AfxMessageBox( APL_T("Если задана единица измерения, то количество должно быть указано"));return;}

	CString id=_T(""),name=_T(""),descr=_T(""),ranking_rationale=_T("");
	CaplInstance *type=0;
	m_id_ctrl.GetWindowText(id);
	m_name_ctrl.GetWindowText(name);
	m_descr_ctrl.GetWindowText(descr);
	m_ranking_rationale_ctrl.GetWindowText(ranking_rationale);
	i=m_type_ctrl.GetCurSel();
	if(i>=0 )type=(CaplInstance*)m_type_ctrl.GetItemData(i);
	else type=0;
	/*CaplInstance *assortment=0;
	if(m_doc_data.IsKindOf(m_obj,m_doc->m_api.m_prd_mgr.e_pdf))
	{	
		assortment=(CaplInstance*)m_sortament.GetItemData(m_sortament.GetCurSel());
		if(assortment==(CaplInstance*)-1)assortment=0;
	}*/
	bool something_changed=true;
	bool create_new_version=false;
	if(m_inst==0)
	{
		m_inst=m_doc_data.CreateInstance(m_doc->m_api.m_bp_mgr.e_bp_res);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_process,m_bp);
		if(m_bp)
		{
			CaplAggr aggr;
			if(m_doc->m_api.m_bp_mgr.m_bUseVersions)
			{
				CaplInstance *lock=0;
				m_doc_data.GetAttr(m_bp,m_doc->m_api.m_bp_mgr.a_bp_lock,lock);
				if(lock)
				{
					m_doc_data.GetAttr(lock,m_doc->m_api.m_bp_mgr.a_bp_ver_res,aggr);
					aggr.Add(m_inst);
					m_doc_data.PutAttr(lock,m_doc->m_api.m_bp_mgr.a_bp_ver_res,aggr);
				}
			}
			else
			{
				m_doc_data.GetAttr(m_bp,m_doc->m_api.m_bp_mgr.a_bp_res,aggr);
				aggr.Add(m_inst);
				m_doc_data.PutAttr(m_bp,m_doc->m_api.m_bp_mgr.a_bp_res,aggr);
			}
		}
	}
	else
	{
		// Проверка измененности
		CaplInstance *m_old_obj=0,*old_unit=0,*old_der_unit=0,*old_type=0,*old_assortment=0;
		CString old_id=_T(""),old_name=_T(""),old_descr=_T(""),old_ranking_rationale=_T("");
		double old_val=0,old_der_val=0;
		int old_ranking;

		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_object,m_old_obj);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_unit,old_unit);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_derive_unit,old_der_unit);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_id,old_id);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_name,old_name);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_descr,old_descr);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_val,old_val);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_type,old_type);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_derive_val,old_der_val);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_assortment,old_assortment);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_ranking,old_ranking);
		m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_ranking_rationale,old_ranking_rationale);


		if(m_old_obj==m_obj)
			if(old_unit==unit) 
				if(old_der_unit==unit_der) 
					if(old_id==id)
						if(old_name==name)
							if(old_descr==descr)
								if(old_type==type) 
									if(old_val==val)
										if(old_der_val==der_val) 
											//if(assortment==old_assortment)
												if(ranking==old_ranking)
													if(ranking_rationale==old_ranking_rationale)
														something_changed=false;

		if(something_changed && m_doc->m_api.m_bp_mgr.m_bUseVersions)
		{
			CaplInstance *ver=0;
			if(m_bp_rev)
			{
				m_doc_data.GetAttr(m_bp_rev,m_doc->m_api.m_bp_mgr.a_bp_ver_bp,m_bp);
				m_doc->m_api.m_bp_mgr.LoadBPInfo(m_bp_rev);
				ver=m_bp_rev;
			}
			else
			{
				m_doc_data.GetAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_process,m_bp);
				ver=m_doc->m_api.m_bp_mgr.CheckMyLock(m_bp,true);
				if(!ver) return;
			}
			if(!m_bp) return;
				
			//проверка на вхождение в базовый список
			
			CaplAggr aggr0;
			CaplInstance *inst0=0;
			CaplInstance *base_bp=0;
			m_doc_data.GetAttr(ver,m_doc->m_api.m_bp_mgr.a_bp_ver_base,base_bp);
			if(base_bp)
			{
				m_doc->m_api.m_bp_mgr.LoadBPInfo(base_bp);
				m_doc_data.GetAttr(base_bp,m_doc->m_api.m_bp_mgr.a_bp_ver_res,aggr0);
			}
			else
				m_doc_data.GetAttr(m_bp,m_doc->m_api.m_bp_mgr.a_bp_res,aggr0);
			bool found_in_base_process=false;
			int i;
			CaplInstance *inst;
			for(i=0;i<aggr0.GetSize();i++)
			{
				aggr0.GetByIndex(i,inst);
				if(inst==m_inst)
				{
					found_in_base_process=true;
					break;
				}

			}
			
			CaplAggr aggr;
			if(found_in_base_process)
			{
				m_doc_data.GetAttr(ver,m_doc->m_api.m_bp_mgr.a_bp_ver_res,aggr);
				for(i=0;i<aggr.GetSize();i++)
				{
					aggr.GetByIndex(i,inst);
					if(inst==m_inst)
					{
						if(m_bp_rev)
						{
							CString msg=APL_T("Вы изменили данные ресурса версии бизнес-процесса!\n\n");
							msg+=APL_T("Создать новую версию ресурса ?");
							if(IDNO==AfxMessageBox(msg,MB_YESNO|MB_ICONQUESTION)) return;
						}
						create_new_version=true;
						aggr.Remove(i);
						m_inst=m_doc_data.CreateInstance(m_doc->m_api.m_bp_mgr.e_bp_res);
						m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_process,m_bp);
						CaplValue c_value;
						c_value.Set(m_inst);
						aggr.Insert(i,c_value);
						m_doc_data.PutAttr(ver,m_doc->m_api.m_bp_mgr.a_bp_ver_res,aggr);
						break;
					}
				}
			}
		}
	}
	if(something_changed)
	{
		if(m_bp_rev && !create_new_version)
			if(IDNO==AfxMessageBox( APL_T("Вы изменили данные ресурса версии бизнес-процесса!\n\nCохранить изменения?"),
				MB_YESNO|MB_ICONQUESTION)) return;
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_object,m_obj);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_unit,unit);	
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_derive_unit,unit_der);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_id,id);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_name,name);
	    m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_descr,descr);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_type,type);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_val,val);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_derive_val,der_val);
		//m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_assortment,assortment);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_ranking,ranking);
		m_doc_data.PutAttr(m_inst,m_doc->m_api.m_bp_mgr.a_bp_res_ranking_rationale,ranking_rationale);
	}
	
	CaplTranslateDialog::OnOK();
}
//****************************************************************************
void CBPResDlg::OnObjBrowse() 
{
	// TODO: Add your control notification handler code here
	CaplInstance *inst=m_doc->m_api.m_bp_mgr.SelectInstance(APL_MODE_SELECT_PRD|
		APL_MODE_SELECT_PDF|APL_MODE_SELECT_PRDINST|APL_MODE_SELECT_LOT|
		APL_MODE_SELECT_PERSON|APL_MODE_SELECT_ORG,
		 APL_T("Выберите объект"));
	if(inst!=0)
	{
		CString buf;
		m_doc->m_api.m_bp_mgr.GetItemName(inst,buf);
		m_obj_ctrl.SetWindowText(buf);
		m_obj=inst;

		/*if(!m_doc_data.IsKindOf(m_obj,m_doc->m_api.m_prd_mgr.e_pdf))
		{
			m_sortament.SelectString(0,_T(""));
			m_sortament.EnableWindow(FALSE);
		}
		else m_sortament.EnableWindow(TRUE);*/

	}
}
