// YtvAlarmDoc.cpp : implementation of the CYtvAlarmDoc class
//

#include "stdafx.h"
#include "YtvAlarm.h"
#include "YtvAlarmDoc.h"
#include "YtvClockAlarmView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CYtvAlarmDoc

IMPLEMENT_DYNCREATE(CYtvAlarmDoc, CDocument)

BEGIN_MESSAGE_MAP(CYtvAlarmDoc, CDocument)
	//{{AFX_MSG_MAP(CYtvAlarmDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_FILE_SEND_MAIL, OnFileSendMail)
	ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, OnUpdateFileSendMail)
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CYtvAlarmDoc, CDocument)
	//{{AFX_DISPATCH_MAP(CYtvAlarmDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//      DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IYtvAlarm to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {EFB33614-99EB-4ACB-83DD-4C9F7EC5CBA8}
static const IID IID_IYtvAlarm =
{ 0xefb33614, 0x99eb, 0x4acb, { 0x83, 0xdd, 0x4c, 0x9f, 0x7e, 0xc5, 0xcb, 0xa8 } };

BEGIN_INTERFACE_MAP(CYtvAlarmDoc, CDocument)
	INTERFACE_PART(CYtvAlarmDoc, IID_IYtvAlarm, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CYtvAlarmDoc construction/destruction

CYtvAlarmDoc::CYtvAlarmDoc()
{
	// TODO: add one-time construction code here
   
	EnableAutomation();

	AfxOleLockApp();
}

CYtvAlarmDoc::~CYtvAlarmDoc()
{
	AfxOleUnlockApp();
}

BOOL CYtvAlarmDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
    //m_szRegDbNodePath=YtvGetMainRegNode();
  	//SetTitle("Registry Database");
	//UpdateAllViews(NULL,IDC_DB_NAME);
	m_strPath.Empty();
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CYtvAlarmDoc serialization

void CYtvAlarmDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CYtvAlarmDoc diagnostics

#ifdef _DEBUG
void CYtvAlarmDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CYtvAlarmDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CYtvAlarmDoc commands

BOOL CYtvAlarmDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	
	// TODO: Add your specialized creation code here

	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// TODO: Add your specialized creation code here
	m_strPath=lpszPathName;
	return TRUE;

}

BOOL CYtvAlarmDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	// TODO: Add your specialized code here and/or call the base class

    BOOL b=FALSE;
    POSITION pos=GetFirstViewPosition();
	CYtvClockAlarmView* pv=(CYtvClockAlarmView*)GetNextView(pos);
	b=pv->m_ctrlClock.ExportSettings(lpszPathName);
	if(b)
	{
				b=TRUE;
                //SetTitle(lpszPathName);			
    }
	else
    {
				SetTitle("Error: Can not export Settings");			   
	}	
	return b;//CDocument::OnSaveDocument(lpszPathName);
	//return CDocument::OnSaveDocument(lpszPathName);
}
