#if !defined(AFX_FINDQUERYNIIAO_H__EE4C5B33_7F59_4EC1_8AA5_E5D9D5C9A10B__INCLUDED_)
#define AFX_FINDQUERYNIIAO_H__EE4C5B33_7F59_4EC1_8AA5_E5D9D5C9A10B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FindQueryNiiao.h : header file
//
#include "FindQueryDlg.h"

#define STD_HEADER_FIND_QUERY_NIAO _T("FindQueryNIAO v1.0\0")


enum TypeFindObjectNIIAO{FindObjectNIAO_ProductVer=0,
FindObjectNIAO_ProductInst=1,FindObjectNIAO_BPInst=2
};

enum TypeFOAttrNIIAO{
	TFO_NIAO_Id=0,// - обозначение объекта
		TFO_NIAO_Name=1,// - наименование оъекта (или серийный номер экземпляра)
		TFO_NIAO_Descr=2,// - описание объекта
		TFO_NIAO_Type=3,// - тип объекта
		TFO_NIAO_Code=4,// - код объекта
		TFO_NIAO_Source=5,// - источник
		TFO_NIAO_Ver=6// - обозначение версии ихделия
};


////////////////////////////////////////////////////////
// Структуры для хранения:
// Характеристик

struct SParam
{
	SParam(){
		m_state_id=0;m_state_name=0;m_state_descr=0;m_state_type=0;
		m_state_code=0;m_state_source=0;m_state_ver=0;
		m_id=_T("");m_name=_T("");m_descr=_T("");m_type=_T("");m_type_id=0;
		m_code=_T("");m_source=0;m_ver=_T("");
	}
	void GetCount(){
		m_count=0;
		if(m_state_id!=0 && m_id != _T(""))m_count++;
		if(m_state_name!=0 && m_name != _T(""))m_count++;
		if(m_state_descr!=0 && m_descr != _T(""))m_count++;
		if(m_state_type!=0 )m_count++;
		if(m_state_code!=0 && m_code != _T(""))m_count++;
		if(m_state_source!=0 )m_count++;
		if(m_state_ver!=0 && m_ver != _T(""))m_count++;
	}
	int m_state_id;
	int m_state_name;		
	int m_state_descr;	
	int m_state_type;	
	int m_state_code;		
	int m_state_source;
	int m_state_ver;
	CString m_id;
	CString m_name;		
	CString m_descr;	
	CString m_type;		
	int m_type_id;		
	CString m_code;		
	int m_source;
	CString m_ver;
	int m_count;	
};



/////////////////////////////////////////////////////////////////////////////
// CFindQueryNiiao dialog

class CFindQueryNiiao : public CaplTranslateDialog
{
// Construction
public:
	CFindQueryNiiao(CWnd* pParent = NULL);   // standard constructor
	~CFindQueryNiiao();

	// этот тип объектов искали в последний раз
	TypeFindObjectNIIAO m_mode;
	CString m_mode_text;
	// если true - можно показывать галочку "Отобразить результаты в таблице"
	bool m_can_make_table;
	// если true - доступна функция "сохранить запрос в БД"
	bool m_can_save;
	
	CaplAPI *m_api;
	CaplInstance *m_instance;

	// если true - используется как вспомогательный запрос (без инстансы, имени запроса и без иаблицы)
	bool m_mode_slave;

	
	TypeFindObjectNIIAO m_page_num;
	TypeFindObjectNIIAO m_old_page_num;
	
	bool m_is_adjustment;
	bool m_read_only;
	bool m_changed;
	int m_cur_ext_num;
	// Окончательный запрос
	CString m_QL_query;
	// Строки для заполнения экcтентов и полей (fields)
	CString m_extents;
	CString m_fields;
	
	CString	m_StringSource;
	CString	m_StringType;

	bool SetDataBuf(CaplDataBuf &dbuf);
	bool GetDataBuf(CaplDataBuf &dbuf);
	bool TestNameQuery();


// Dialog Data
	//{{AFX_DATA(CFindQueryNiiao)
	enum { IDD = IDD_FIND_QUERY_NIIAO };
	CEdit	m_edt_name_query;
	CButton	m_ChkSaveQuery;
	CComboBox	m_SelectFindType;
	CComboBox	m_CmbxStId;
	CComboBox	m_CmbxStName;
	CComboBox	m_CmbxStDescr;
	CComboBox	m_CmbxStType;
	CComboBox	m_CmbxStCode;
	CComboBox	m_CmbxStSource;
	CComboBox	m_CmbxStVer;
	CEdit	m_EditId;
	CEdit	m_EditName;
	CEdit	m_EditDescr;
	CComboBox	m_EditType;
	CEdit	m_EditCode;
	CComboBox	m_EditSource;
	CEdit	m_EditVer;
//	CButton	m_ctrl_find_version;
	CButton	m_adj_edit;
	CButton	m_adj_del;
	CButton	m_adj_add;
	CListCtrl	m_ListAdjust;
	CTabCtrl	m_TabAttr;
	CButton	m_Chk_StId;
	CButton	m_Chk_StName;
	CButton	m_Chk_StDescr;
	CButton	m_Chk_StType;
	CButton	m_Chk_StCode;
	CButton	m_Chk_StSource;
	CButton	m_Chk_StVer;
	CaplButton	m_BtnFind;
	CaplButton	m_BtnCancel;
	CaplButton	m_BtnShowStepQl;
	CButton	m_CtrlMakeTableResult;
	BOOL	m_IsMakeTableResult;
	CString	m_StringNameQuery;
	BOOL	m_StateSaveQuery;
	int		m_StateFindType;	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFindQueryNiiao)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	bool MakeObjectIdentify(SParam	*active_attr,TypeFindObjectNIIAO mode,CString &object_condition);
	//BOOL OnToolTipShow( UINT id, NMHDR * pNMHDR, LRESULT * pResult ); ЯАИ:  Перенесено в CaplTranslateDialog
	
	void MakeQueryChar(CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> *active_list_char,
								TypeFindObjectNIIAO mode,CString char_object_identify,CString object_identify,CString res_ent);
	void MakeQueryDoc ();
	void MakeQueryAppr();
	
	bool SaveDataToBuf();
	bool SaveCharacteristikToBuf(CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> *list_char);
	bool SaveAttrToBuf(SParam *active_attr,TypeFindObjectNIIAO mode);
	bool LoadDataFromBuf();
	bool LoadCharacteristikFromBuf(CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> *list_char);
	bool LoadAttrFromBuf(SParam *active_attr,TypeFindObjectNIIAO mode);
	
	CString FillDateCompare(CString name_attr,CaplQLQuery::aplQLLogRelation log_relation,COleDateTime* dtt);
	CString FillCharValue(ElValChar* el_ch,CaplEntity** base_entity);

	void DrawTabPage();
	void SetStateName(CString id,CString name,CString descr,CString type,CString code,CString source,CString ver);
	bool GenerateStepQL();
	void SetEditComboState();	
	bool SelchangeTabAttr();

	void FillTabAdjust();
	
	CBitmap m_name_bmp;
	CImageList imagelist_tab;
	CImageList imagelist_but;
	bool m_is_load_bmp;
	
	HICON m_adj_add_icon;
	HICON m_adj_del_icon;
	HICON m_adj_edit_icon;
	
	SParam	m_attr_pdf;
	SParam	m_attr_pi;
	SParam	m_attr_bpi;
	SParam	*m_active_attr;
	CaplDataBuf *m_dbuf;
	
	// Generated message map functions
	//{{AFX_MSG(CFindQueryNiiao)
	afx_msg void OnSelchangeTabAttr(NMHDR* pNMHDR, LRESULT* pResult);
	virtual BOOL OnInitDialog();
	afx_msg void OnSelchangeSelectFindType();
	afx_msg void OnAdjustAdd();
	afx_msg void OnAdjustDel();
	afx_msg void OnAdjustEdit();
	afx_msg void OnDblclkListAdjust(NMHDR* pNMHDR, LRESULT* pResult);
//	afx_msg void OnChkFindVersion();
	afx_msg void OnExecuteFind();
	afx_msg void OnRclickListAdjust(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnShowStepql();
	afx_msg void OnSelchangeComboState();
	afx_msg void OnChkSaveQuery();
	afx_msg void OnChangeEdit();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
		
	int m_num_ext_pdf;
	int m_num_ext_pi;
	int m_num_ext_bpi;	
	
	
	CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> m_list_char_pdf;
	CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> m_list_char_pi;
	CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> m_list_char_bpi;
	CaplTAggr<ElValChar*,ElValChar*,APLAGGR_UNIQUE|APLAGGR_LIST|APLAGGR_AUTOKILLREF> *m_active_list_char;

};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FINDQUERYNIIAO_H__EE4C5B33_7F59_4EC1_8AA5_E5D9D5C9A10B__INCLUDED_)
