// RetryErrorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LocalErrors.h"
#include "RetryErrorDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRetryErrorDlg dialog

CRetryErrorDlg::CRetryErrorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRetryErrorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRetryErrorDlg)
	m_csCorrectiveAction = _T("");
	m_csWhatHappened = _T("");
	m_csRetryReport = _T("");
	//}}AFX_DATA_INIT
	m_nTimeout = 15;
	m_csCaption = _T("");
	m_csCaption_WhatHappened = _T("");
	m_csCaption_CorrectiveAction = _T("");
}

void CRetryErrorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRetryErrorDlg)
	DDX_Control(pDX, IDD_WHAT_HAPPENED, m_btnWhatHappened);
	DDX_Control(pDX, IDD_CORRECTIVE_ACTION, m_btnCorrectiveAction);
	DDX_Control(pDX, IDC_RETRY_PROGRESS, m_ProgressCtrl);
	DDX_Text(pDX, IDC_CORRECTIVE_ACTION, m_csCorrectiveAction);
	DDX_Text(pDX, IDC_WHAT_HAPPENED, m_csWhatHappened);
	DDX_Text(pDX, IDC_RETRY_REPORT, m_csRetryReport);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRetryErrorDlg, CDialog)
	//{{AFX_MSG_MAP(CRetryErrorDlg)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRetryErrorDlg message handlers

BOOL CRetryErrorDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	if( ! m_csCaption_WhatHappened.IsEmpty() )
		m_btnWhatHappened.SetWindowText( m_csCaption_WhatHappened );
	if( ! m_csCaption_CorrectiveAction.IsEmpty() )
		m_btnCorrectiveAction.SetWindowText( m_csCaption_CorrectiveAction );
	if( ! m_csCaption.IsEmpty() )
		SetWindowText( m_csCaption );
	if( m_nTimeout < 10 ) m_nTimeout = 15;

	SetTimer( 1, 1000, NULL );
	m_ProgressCtrl.SetRange( 0, m_nTimeout );
	m_ProgressCtrl.SetStep( 1 );
	m_csRetryReport.Format( "System will retry in %d seconds", m_nTimeout );
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRetryErrorDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	m_csRetryReport.Format( "System will retry in %d seconds", m_nTimeout );
	SetDlgItemText( IDC_RETRY_REPORT, m_csRetryReport );
//	SetDlgItemText( IDC_TIMEOUT_PROGRESS, m_csRetryReport );
	m_ProgressCtrl.StepIt();
	if( --m_nTimeout < 0 )
	{
		KillTimer( 1 );
		PostMessage( WM_COMMAND, IDOK, 0L );
	}
	CDialog::OnTimer(nIDEvent);
}

