#if !defined(AFX_PROJECTDLG_H__F7E38792_CE65_4A66_8E17_E1E1956BF40C__INCLUDED_)
#define AFX_PROJECTDLG_H__F7E38792_CE65_4A66_8E17_E1E1956BF40C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ProjectDlg.h : header file
//
#include "resource.h"
#include "aplProjectMgr.h"
#include <apl_gui.h>
#include "afxwin.h"
#include "afxcmn.h"
#include "afxdtctl.h"
/////////////////////////////////////////////////////////////////////////////
// CProjectDlg dialog

class CProjectDlg : public CaplResizableDialog
{
// Construction
public:
	void RecalcActualDlit();
	//void RecalcPlannedDlit();
	bool RecalcPercentage();
	bool RecalcLaborActual();
	bool RecalcLaborPlanned();
	void UpdateActualLaborUnitCtrl();
	void UpdateLaborOfItemUnitCtrl();
	CProjectDlg(CWnd* pParent = NULL);   // standard constructor

	CaplInstance *m_project;
	aplExtent m_executors;
	aplExtent m_co_executors,co_executors,m_co_customers;
	CaplInstance *m_kurator;
	CaplInstance *m_customer;
	CaplInstance *m_labor_unit;
	//CaplInstance *m_labor_unit_actual;
	CaplInstance *m_prd_labor_unit_planned;
	CaplInstance *m_prd_labor_unit_actual;
	CaplInstance *m_labor_of_item_unit;
	CaplInstance *m_parent;
	CaplProjectManager *m_project_mgr;
	CaplAPI *m_api;
	CString m_cur_state; 
	bool m_read_only;
	bool m_read_only_ver;
	bool m_can_check_out;
	CBitmap m_name_bmp;
	bool m_bHaveChildren;
	int m_check_dates;//иерархический контроль сроков проекта
	int m_forbid_overproducing;//запретить перевыполнение плана
	int m_auto_complete;//присвоение статуса "выполнено" при выполнении 100% и более
	int m_auto_complete_parent; //присвоение статуса "выполнено" родительскому проекту при присвоении статуса "выполнено" данному
	int m_forbinen_future_fact_dates;
	CString m_max_actual_date_end;
	CString m_min_actual_date_begin;
	CString m_max_planned_date_end;
	CString m_min_planned_date_begin;

	COleDateTime m_odt_min_planed, m_odt_max_planed;

	CToolTipCtrl m_toolTipCtrl;

	void SetFromInst();
	void SetDefaults();
	void SetStates();
	void SetReadOnlyItems();
	bool SaveChanges();
	void UpdateCoCutomersCtrl();
	void UpdateExecutorsCtrl();
	void UpdateCoExecutorsCtrl();
	void UpdateLaborUnitCtrl();
	void UpdateKuratorCtrl();
	void UpdateCustomerCtrl();
	void UpdateRelation(int item);
// Dialog Data
	//{{AFX_DATA(CProjectDlg)
	enum { IDD = IDD_PROJECT_DLG };
	CComboBox	m_date_control_ctrl;
	CEdit	m_dlit_plan_ctrl;
	CEdit	m_dlit_actual_ctrl;
	CButton	m_select_labor_of_item_unit_btn;
	//CButton	m_select_actual_labor_unit_btn;
	CEdit	m_prd_unit_planned_ctrl;
	CEdit	m_prd_unit_actual_ctrl;
	CEdit	m_prd_amount_planned_ctrl;
	CEdit	m_prd_amount_actual_ctrl;
	CEdit	m_labor_of_item_unit_ctrl;
	CEdit	m_labor_of_item_ctrl;
	CButton	m_calc_by_amount_ctrl;
	//CEdit	m_actual_labor_unit_ctrl;
	CEdit	m_actual_labor_ctrl;
	CButton	m_select_customer_btn;
	CEdit	m_customer_ctrl;
	CStatic	m_st_project_name;
	CDateTimeCtrl	m_date_begin_planned_ctrl;
	CaplButton	m_check_in_ctrl;
	CaplButton	m_check_out_ctrl;
	CaplButton	m_undo_check_out_ctrl;
	CComboBox	m_project_type_ctrl;
	CButton	m_check_planned_end_ctrl;
	CButton	m_check_planned_begin_ctrl;
	CComboBox	m_state_ctrl;
	CButton	m_select_labunit_btn;
	CButton	m_select_executors_btn;
	CButton	m_select_kurator_btn;
	CaplButton	m_cancel_btn;
	CaplButton	m_ok_btn;
	CEdit	m_kurator_ctrl;
	CButton	m_check_fact_end_ctrl;
	CButton	m_check_fact_begin_ctrl;
	CEdit	m_executors_ctrl;
	CDateTimeCtrl	m_date_end_planned_ctrl;
	CDateTimeCtrl	m_date_end_fact_ctrl;
	CDateTimeCtrl	m_date_begin_fact_ctrl;
	CEdit	m_descr_ctrl;
	CEdit	m_name_ctrl;
	CEdit	m_id_ctrl;
	CDateTimeCtrl	m_time_end_planned_ctrl;
	CDateTimeCtrl	m_time_end_planned2_ctrl;
	CDateTimeCtrl	m_time_end_fact_ctrl;
	CDateTimeCtrl	m_time_begin_planned_ctrl;
	CDateTimeCtrl	m_time_begin_fact_ctrl;
	CEdit	m_persentage_ctrl;
	CEdit	m_labor_value_ctrl;
	CEdit	m_labor_unit_ctrl;
	CTabCtrl	m_tab_ctrl;
	CString	m_id;
	//COleDateTime	m_time_begin_fact;
	//COleDateTime	m_time_begin_planned;
	//COleDateTime	m_time_end_fact;
	//COleDateTime	m_time_end_planned;
	CString	m_sName;
	//}}AFX_DATA


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

// Implementation
protected:
	// предотвращаем потерю модальности после диалога с бочками из aplSocketTransport
	CaplParentWndProcesser m_pwp;

	bool bIsSet3Check();
	bool RecalcPlanDate();
	void CalcMaxMinSubDates();
	void PrjRbuttonDown(MSG* pMsg);

	bool m_bNeedUndoCheckout;
	// Generated message map functions
	//{{AFX_MSG(CProjectDlg)
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	afx_msg void OnSelectLaborUnit();
	afx_msg void OnSelectExecutors();
	afx_msg void OnCheckFactBegin();
	afx_msg void OnCheckFactEnd();
	afx_msg void OnSelectKurator();
	afx_msg void OnSelchangeState();
	afx_msg void OnCheckPlannedBegin();
	afx_msg void OnCheckPlannedEnd();
	afx_msg void OnCheckOut();
	afx_msg void OnCheckIn();
	afx_msg void OnUndoCheckOut();
	afx_msg void OnSelectCustomer();
	afx_msg void OnCalcByAmount();
	afx_msg void OnSelectLaborOfItemUnit();
	//afx_msg void OnSelectActualLaborUnit();
	afx_msg void OnChangePrdAmoutPlanned();
	afx_msg void OnChangeLaborOfItem();
	afx_msg void OnChangePrdAmoutActual();
	afx_msg void OnChangeLabor();
	afx_msg void OnChangeActualLabor();
	afx_msg void OnSelchangeDateControl();
	afx_msg void OnChangeDlitPlan();
	afx_msg void OnChangeDlitActual();
	afx_msg void OnDatetimechangeDateBeginFact(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnDatetimechangeDateEndFact(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnDatetimechangeDateBeginPlanned(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnDatetimechangeDateEndPlanned(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnTransactions();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
public:
	CComboBox m_prd_amount_unit_ctrl;
	CEdit m_number_ctrl;
	afx_msg void OnBnClickedDeleteCustomer();
	afx_msg void OnBnClickedDeleteKurator();
	CButton m_delete_cust_btn;
	CButton m_delete_kur_btn;
	afx_msg void OnBnClickedDelLaborUnit();
	CButton m_check_planed_duration_set_btn;
	afx_msg void OnBnClickedCheckPlannedDuration();
	afx_msg void OnDtnDatetimechangeTimeBeginPlanned(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDtnDatetimechangeTimeEndPlanned(NMHDR *pNMHDR, LRESULT *pResult);
	CSortListCtrl m_prj_rel_list;
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	CDateTimeCtrl m_actual_labor_date_ctrl;
	afx_msg void OnNMDblclkPrjRelList(NMHDR *pNMHDR, LRESULT *pResult);
	CEdit m_coexecutors_ctrl;
	afx_msg void OnBnClickedSelectCoexecutors();
	CButton m_select_coexecutors_btn;
	CaplButton m_notes_btn;
	afx_msg void OnBnClickedNotes();
	afx_msg void OnBnClickedSelectCocustomers();
	CEdit m_cosustomers_ctrl;
	CButton m_select_cocostomers_btn;
	CButton m_auto_end_edit_ctrl;
protected:
	virtual void OnCancel();
public:
	afx_msg void OnDtnDatetimechangeTimeEndFact(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDtnDatetimechangeTimeBeginFact(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDtnDatetimechangeIdcActualLaborDate(NMHDR *pNMHDR, LRESULT *pResult);
};

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

#endif // !defined(AFX_PROJECTDLG_H__F7E38792_CE65_4A66_8E17_E1E1956BF40C__INCLUDED_)
