// PlaybackSampleDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PlaybackSample.h"
#include "PlaybackSampleDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

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

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPlaybackSampleDlg dialog

CPlaybackSampleDlg::CPlaybackSampleDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPlaybackSampleDlg::IDD, pParent),
    m_DisplayStartTime(_T("")),
    m_IsOpenRecordSuccess(FALSE)
{
	//{{AFX_DATA_INIT(CPlaybackSampleDlg)
	m_FontName = _T("Tahoma");
	m_FontSize = 9;
	m_FontG = 0;
	m_FontR = 0;
	m_FontB = 0;
	m_BackG = 0;
	m_BackB = 0;
	m_Transparency = 0;
	m_bHasEdge = FALSE;
	m_bTime = FALSE;
	m_bDate = FALSE;
	m_bCameraName = FALSE;
	m_bBold = FALSE;
	m_BackR = 0;
	m_IPAddress = _T("localhost:5160");
	m_Password = _T("");
	m_UserName = _T("admin");
	m_View = 0;
	m_RecordEndTime = _T("20001231246060");
	m_RecordStartTime = _T("20001231246060");
	m_SaveEndTime = _T("20001231246060"); 
	m_SaveStartTime = _T("20001231246060");
	m_ExportAudio = FALSE;
	m_ExportOSD = FALSE;
	m_Message = _T("");
	m_CameraIndex = 0;
	m_CameraLow = 0;
	m_CameraHigh = 0;
	m_SeekTime = _T("20001231246060");
	m_Path = _T("c:\\");
	m_Height = 0;
	m_Width = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPlaybackSampleDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPlaybackSampleDlg)
	DDX_Control(pDX, IDC_COMBO_PROFILE, m_Profile);
	DDX_Control(pDX, IDC_RPBACTIVEXCTRL1, m_RPBActiveX);
	DDX_Text(pDX, IDC_EDIT_FONTNAME, m_FontName);
	DDX_Text(pDX, IDC_EDIT_FONTSIZE, m_FontSize);
	DDX_Text(pDX, IDC_EDIT_FONTG, m_FontG);
	DDX_Text(pDX, IDC_EDIT_FONTR, m_FontR);
	DDX_Text(pDX, IDC_EDIT_FONTB, m_FontB);
	DDX_Text(pDX, IDC_EDIT_BACKG, m_BackG);
	DDX_Text(pDX, IDC_EDIT_BACKB, m_BackB);
	DDX_Text(pDX, IDC_EDIT_TRANSPARANCY, m_Transparency);
	DDX_Check(pDX, IDC_CHECK_EDGE, m_bHasEdge);
	DDX_Check(pDX, IDC_CHECK_TIME, m_bTime);
	DDX_Check(pDX, IDC_CHECK_DATE, m_bDate);
	DDX_Check(pDX, IDC_CHECK_CAMERANAME, m_bCameraName);
	DDX_Check(pDX, IDC_CHECK_BOLD, m_bBold);
	DDX_Text(pDX, IDC_EDIT_BACKR, m_BackR);
	DDX_Text(pDX, IDC_EDIT_IPADDRESS, m_IPAddress);
	DDX_Text(pDX, IDC_EDIT_PASS, m_Password);
	DDX_Text(pDX, IDC_EDIT_USER, m_UserName);
	DDX_Text(pDX, IDC_EDIT_CAMERAVIEW, m_View);
	DDX_Text(pDX, IDC_EDIT_RECORDEND, m_RecordEndTime);
	DDX_Text(pDX, IDC_EDIT_RECORDSTART, m_RecordStartTime);
	DDX_Text(pDX, IDC_EDIT_SAVEEND, m_SaveEndTime);
	DDX_Text(pDX, IDC_EDIT_SAVESTART, m_SaveStartTime);
	DDX_Check(pDX, IDC_CHECK_EXPORTAUDIO, m_ExportAudio);
	DDX_Check(pDX, IDC_CHECK_EXPORTOSD, m_ExportOSD);
	DDX_Text(pDX, IDC_STATIC_MESSAGE, m_Message);
	DDX_Text(pDX, IDC_EDIT_CAMERAINDEX, m_CameraIndex);
	DDX_Text(pDX, IDC_EDIT_CAMERALOW, m_CameraLow);
	DDX_Text(pDX, IDC_EDIT_CAMERA_HIGH, m_CameraHigh);
	DDX_Text(pDX, IDC_EDIT_SEEKTIME, m_SeekTime);
	DDX_Text(pDX, IDC_EDIT_PATH, m_Path);
	DDX_Text(pDX, IDC_EDIT_REOLUTION_WEIGHT, m_Width);
	DDX_Text(pDX, IDC_EDIT_REOLUTION_HEIGHT, m_Height);

	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPlaybackSampleDlg, CDialog)
	//{{AFX_MSG_MAP(CPlaybackSampleDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_CONNECT, OnButtonConnect)
	ON_BN_CLICKED(IDC_BUTTON_OpenRecord, OnBUTTONOpenRecord)
	ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, OnButtonDisconnect)
	ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
	ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_BN_CLICKED(IDC_BUTTON_SPEEDUP, OnButtonSpeedup)
	ON_BN_CLICKED(IDC_BUTTON_SPEEDDOWN, OnButtonSpeeddown)
	ON_BN_CLICKED(IDC_BUTTON_SEEK, OnButtonSeek)
	ON_BN_CLICKED(IDC_BUTTON_STEPFORWARD, OnButtonStepforward)
	ON_BN_CLICKED(IDC_BUTTON_STEPBACKWARD, OnButtonStepbackward)
	ON_BN_CLICKED(IDC_BUTTON_CAMERACOUNT, OnButtonCameracount)
	ON_BN_CLICKED(IDC_BUTTON_CAMERANAME, OnButtonCameraname)
	ON_BN_CLICKED(IDC_BUTTON_SAVEIMAGE, OnButtonSaveimage)
	ON_BN_CLICKED(IDC_BUTTON_SAVEAVI, OnButtonSaveavi)
	ON_BN_CLICKED(IDC_BUTTON_SAVEASF, OnButtonSaveasf)
	ON_BN_CLICKED(IDC_BUTTON_SETOSD, OnButtonSetosd)
	ON_BN_CLICKED(IDC_BUTTON_GETACTIVEVIEW, OnButtonGetactiveview)
	ON_BN_CLICKED(IDC_BUTTON_SETACTIVEVIEW, OnButtonSetactiveview)
	ON_BN_CLICKED(IDC_BUTTON_DISPLAYTIME, OnButtonGetDisplayTime)
	ON_BN_CLICKED(IDC_BUTTON_CHANGE_RESOLUTION, OnButtonChangeResoluton)
    ON_BN_CLICKED(IDC_BUTTON_PREVIOUS, &CPlaybackSampleDlg::OnButtonPrevious)
    ON_BN_CLICKED(IDC_BUTTON_NEXT, &CPlaybackSampleDlg::OnButtonNext)
    ON_BN_CLICKED(IDC_BUTTON_GET_PLAYER_STATE, &CPlaybackSampleDlg::OnButtonGetPlayerState)
    ON_BN_CLICKED(IDC_BUTTON_GET_SCHEDULE_LOGS, &CPlaybackSampleDlg::OnButtonGetScheduleLogs)
    ON_BN_CLICKED(IDC_BUTTON_GET_RECORD_LOGS, &CPlaybackSampleDlg::OnButtonGetRecordLogs)
    ON_BN_CLICKED(IDC_BUTTON_QUERY_EVENTS, &CPlaybackSampleDlg::OnButtonQueryEvents)
    ON_BN_CLICKED(IDC_BUTTON_GET_RECORD_DATE_LIST, &CPlaybackSampleDlg::OnButtonGetRecordDateList)
    ON_BN_CLICKED(IDC_BUTTON_SAVEORIGAVI, &CPlaybackSampleDlg::OnBnClickedButtonSaveorigavi)    
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPlaybackSampleDlg message handlers

BOOL CPlaybackSampleDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	

    int i = 0;
    m_Profile.InsertString(i++,_T("Windows Media Video 8 (256kbps)"));
    m_Profile.InsertString(i++,_T("Windows Media Video 8 (384kbps)"));
    m_Profile.InsertString(i++,_T("Windows Media Video 8 (768kbps)"));
    m_Profile.InsertString(i++,_T("Windows Media 8 Fair Quality"));
    m_Profile.InsertString(i++,_T("Windows Media 8 High Quality"));
    m_Profile.InsertString(i++,_T("Windows Media 8 Best Quality"));
    m_Profile.SetCurSel(0);

    // Change Z-order of the activeX control to be below all other controls, to prevent covering others after changing to larger resolution
    CWnd* pChild = GetTopWindow();
    while(pChild->GetNextWindow() != NULL)
    {
        pChild = pChild->GetNextWindow();
    }
    if((HWND)(*pChild) != (HWND)m_RPBActiveX)
    {
        m_RPBActiveX.SetWindowPos(pChild, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
    }
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPlaybackSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CPlaybackSampleDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPlaybackSampleDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPlaybackSampleDlg::OnButtonConnect() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
    m_RPBActiveX.SetIPAddress(m_IPAddress);
    m_RPBActiveX.SetUserName(m_UserName);
    m_RPBActiveX.SetPassword(m_Password);
	m_RPBActiveX.Connect();
}

void CPlaybackSampleDlg::OnButtonDisconnect() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.DisConnect();
}

void CPlaybackSampleDlg::OnBUTTONOpenRecord() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_RPBActiveX.OpenRecordByDateTime(m_RecordStartTime,m_RecordEndTime,m_CameraLow,m_CameraHigh);
    m_DisplayStartTime = m_RecordStartTime;
}



void CPlaybackSampleDlg::OnButtonPlay() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.Play();
}

void CPlaybackSampleDlg::OnButtonPause() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.Pause();
}

void CPlaybackSampleDlg::OnButtonStop() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.Stop();
}

void CPlaybackSampleDlg::OnButtonSpeedup() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.SpeedUp();
}

void CPlaybackSampleDlg::OnButtonSpeeddown() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.SpeedDown();
}

void CPlaybackSampleDlg::OnButtonSeek() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_RPBActiveX.Seek(m_SeekTime);
	m_Message = m_SeekTime;
	UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonStepforward() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.StepForward();
}

void CPlaybackSampleDlg::OnButtonStepbackward() 
{
	// TODO: Add your control notification handler code here
	m_RPBActiveX.StepBackward();
}

void CPlaybackSampleDlg::OnButtonCameracount() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_Message.Format(_T("Camera Count : %d "),m_RPBActiveX.GetCameraCount());
    UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonCameraname() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_Message = m_RPBActiveX.GetCameraName(m_CameraIndex);
    UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonSaveimage() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
    BOOL SaveSuccess = m_RPBActiveX.SaveImage(m_View, m_Path);
    if (SaveSuccess)
    {
        m_Message.Format(_T("Save Image Success"));
    }
    else
    {
        m_Message.Format(_T("Save Image Failed"));
    }
    UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonSaveavi() 
{
	// TODO: Add your control notification handler code here :"20080825145030","20080825145100"
    UpdateData(TRUE);
    BOOL SaveSuccess =FALSE;
	SaveSuccess = m_RPBActiveX.SaveAvi(m_View,m_SaveStartTime,m_SaveEndTime,m_ExportAudio,m_ExportOSD, m_Path);
    if (SaveSuccess)
    {
        m_Message.Format(_T("Saving AVI File"));
    }
    else
    {
        m_Message.Format(_T("Saving AVI Failed"));
    }
    UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonSaveasf() 
{
	// TODO: Add your control notification handler code here :"20080825145030","20080825145100"

    UpdateData(TRUE);
    BOOL SaveSuccess =FALSE;
	SaveSuccess = m_RPBActiveX.SaveASF(m_View,m_SaveStartTime,m_SaveEndTime,m_ExportAudio,m_ExportOSD,m_Profile.GetCurSel(),m_Path);
    if (SaveSuccess)
    {
        m_Message.Format(_T("Saving ASF File"));
    }
    else
    {
        m_Message.Format(_T("Saving ASF Failed"));
    }
    UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonSetosd() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
    int icmd = 0;
    if (m_bDate)
    {
        icmd +=1;
    }
    if (m_bTime)
    {
        icmd +=2;
    }
    if (m_bCameraName)
    {
        icmd +=8;
    }
    //int View = m_RPBActiveX.GetActiveView();
	m_RPBActiveX.SetOSDConfig(icmd,m_FontName,m_FontSize,m_FontR,m_FontG,m_FontB,m_BackR,m_BackG,m_BackB,m_bHasEdge,m_bBold,m_Transparency);	
}

void CPlaybackSampleDlg::OnButtonGetactiveview() 
{
	// TODO: Add your control notification handler code here
	m_Message.Format(_T("Camera View : %d"),m_RPBActiveX.GetActiveView());
    UpdateData(FALSE);

}

void CPlaybackSampleDlg::OnButtonSetactiveview() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	m_RPBActiveX.SetActiveView(m_View);
}

BEGIN_EVENTSINK_MAP(CPlaybackSampleDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CPlaybackSampleDlg)
	ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 1 /* OnEvent */, OnOnEventRpbactivexctrl1, VTS_I4 VTS_I4)
	ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 2 /* OnEvent */, OnDisplayTime, VTS_BSTR)
    ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 3 /* OnRecordDate */, OnRecordDate, VTS_BSTR)
    ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 4 /* OnScheduleLog */, OnScheduleLog, VTS_I4  VTS_BSTR  VTS_BSTR  VTS_BSTR)
    ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 5 /* OnRecordLog */, OnRecordLog, VTS_I4  VTS_BSTR  VTS_BSTR)
    ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 6 /* OnEventLog */, OnEventLog, VTS_BSTR  VTS_I4  VTS_BSTR  VTS_BSTR  VTS_BSTR  VTS_BSTR)
    ON_EVENT(CPlaybackSampleDlg, IDC_RPBACTIVEXCTRL1, 7 /* OnExportFinish */, OnExportFinish, VTS_BSTR)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CPlaybackSampleDlg::OnOnEventRpbactivexctrl1(long iEventID, long iParameter) 
{
	// TODO: Add your control notification handler code here
    switch (iEventID)
    {
        case 0:
            m_Message.Format(_T("Event : OnConnectSuccess"));
            break;
        case 1:
            m_Message.Format(_T("Event : OnConnectFailed"));
            break;
        case 2:
            m_Message.Format(_T("Event : OnDisconnect"));
            break;
        case 3:
            m_Message.Format(_T("Event : OnOpenRecordSuccess"));
            m_IsOpenRecordSuccess = TRUE;
            break;
        case 4:
            m_Message.Format(_T("Event : SaveingSuccess"));
            break;
        case 5:
            m_Message.Format(_T("Event : SaveingFailed"));
            break;
        default:
            ASSERT(0);
            break;
    }
    UpdateData(FALSE);	
}

void CPlaybackSampleDlg::OnDisplayTime(BSTR DisplayTime)
{
	m_Message.Format(_T("%s"), (TCHAR*)DisplayTime);
	//UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnRecordDate(BSTR DateTime)
{
    if(0 == _tcslen(DateTime))
    {
        MessageBox(_T("End"), _T("Record Date"));
        return;
    }

    MessageBox(DateTime, _T("Record Date"));
}

void CPlaybackSampleDlg::OnScheduleLog(int iCameraIndex, BSTR Type, BSTR StartTime, BSTR EndTime)
{
    if(0 == _tcslen(StartTime) || 0 == _tcslen(EndTime))
    {
        MessageBox(_T("End"), _T("Schedule Log"));
        return;
    }

    CString log;
    log.Format(_T("Camera Index: %d\n\
                   Type: %s\n\
                   Start Time: %s\n\
                   End Time: %s"), iCameraIndex, Type, StartTime, EndTime);
    MessageBox(log, _T("Schedule Log"));
}

void CPlaybackSampleDlg::OnRecordLog(int iCameraIndex, BSTR StartTime, BSTR EndTime)
{
    if(0 == _tcslen(StartTime) || 0 == _tcslen(EndTime) )
    {
        MessageBox(_T("End"), _T("Record Log"));
        return;
    }

    CString log;
    log.Format(_T("Camera Index: %d\n\
                   Start Time: %s\n\
                   End Time: %s"), iCameraIndex, StartTime, EndTime);
    MessageBox(log, _T("Record Log"));
}

void CPlaybackSampleDlg::OnEventLog(BSTR DateTime, int iCameraIndex, BSTR EventType, BSTR auxiliaryCode, BSTR description, BSTR sourceName)
{
    if(0 == _tcslen(DateTime))
    {
        MessageBox(_T("End"), _T("Event Log"));
        return;
    }

    CString log;
    log.Format(_T("DateTime: %s\n\
                   Camera Index: %d\n\
                   EventType: %s\n\
                   Auxiliary Code: %s\n\
                   Description: %s\n\
                   Source Name: %s"), DateTime, iCameraIndex, EventType, auxiliaryCode, description, sourceName);
    MessageBox(log, _T("Event Log"));
}

void CPlaybackSampleDlg::OnExportFinish(BSTR Status)
{
    m_Message.Format(_T("Export %s"), (TCHAR*)Status);
    UpdateData(FALSE);	
}

void CPlaybackSampleDlg::OnButtonGetDisplayTime()
{
    if (!m_IsOpenRecordSuccess || !CheckDateTime(m_DisplayStartTime))
    {
        return ;
    }

    CString timeStamp = m_RPBActiveX.GetCurrDisplayTime();
    CTime currentTime(_ttoi(m_DisplayStartTime.Mid(0, 4).GetString()), 
        _ttoi(m_DisplayStartTime.Mid(4, 2).GetString()),
        _ttoi(m_DisplayStartTime.Mid(6, 2).GetString()), 
        _ttoi(m_DisplayStartTime.Mid(8, 2).GetString()),
        _ttoi(m_DisplayStartTime.Mid(10, 2).GetString()),
        _ttoi(m_DisplayStartTime.Mid(12, 2).GetString())
        );

    currentTime += (_ttoi(m_RPBActiveX.GetCurrDisplayTime().GetString())/1000);
    m_Message = currentTime.Format("%Y-%m-%d %H:%M:%S");
	UpdateData(FALSE);	
}

void CPlaybackSampleDlg::OnButtonChangeResoluton()
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
    m_RPBActiveX.ChangeResolution(m_Width,m_Height);
}
void CPlaybackSampleDlg::OnButtonPrevious()
{
    m_RPBActiveX.Previous();
}

void CPlaybackSampleDlg::OnButtonNext()
{
    m_RPBActiveX.Next();
}

void CPlaybackSampleDlg::OnButtonGetPlayerState()
{
    m_Message.Format(m_RPBActiveX.GetPlayerState());
    UpdateData(FALSE);
}

void CPlaybackSampleDlg::OnButtonGetRecordDateList()
{
    UpdateData(TRUE);
    m_RPBActiveX.GetRecordDateList(m_RecordStartTime, m_RecordEndTime);
}

void CPlaybackSampleDlg::OnButtonGetScheduleLogs()
{
    UpdateData(TRUE);
    m_RPBActiveX.GetScheduleLogs(m_RecordStartTime);
}

void CPlaybackSampleDlg::OnButtonGetRecordLogs()
{
    UpdateData(TRUE);
    m_RPBActiveX.GetRecordLogs(m_RecordStartTime);
}

void CPlaybackSampleDlg::OnButtonQueryEvents()
{
    UpdateData(TRUE);
    m_RPBActiveX.QueryEvents(m_RecordStartTime, m_RecordEndTime, NULL, -1, NULL);
}

void CPlaybackSampleDlg::OnBnClickedButtonSaveorigavi()
{
    UpdateData(TRUE);
    BOOL SaveSuccess =FALSE;
	SaveSuccess = m_RPBActiveX.SaveOriginalAvi(m_View,m_SaveStartTime,m_SaveEndTime,m_ExportAudio,m_ExportOSD, m_Path);
    if (SaveSuccess)
    {
        m_Message.Format(_T("Saving Original AVI File"));
    }
    else
    {
        m_Message.Format(_T("Saving Original AVI Failed"));
    }
    UpdateData(FALSE);
}

BOOL CPlaybackSampleDlg::CheckDateTime(const CString &dateTime)
{
    if (dateTime.GetLength() != 14)
    {
        return FALSE;
    }

    int iYear = _ttoi(dateTime.Mid(0, 4).GetString());
    int iMonth = _ttoi(dateTime.Mid(4, 2).GetString());
    int iDay = _ttoi(dateTime.Mid(6, 2).GetString());
    int iHour = _ttoi(dateTime.Mid(8, 2).GetString());
    int iMinute = _ttoi(dateTime.Mid(10, 2).GetString());
    int iSecond = _ttoi(dateTime.Mid(12, 2).GetString());

    if (iYear < 1900  ||
        iMonth < 1 || iMonth > 12 ||
        iDay < 1 || iDay > 31 ||
        iHour < 0 || iHour > 23 ||
        iMinute < 0 || iMinute > 59 ||
        iSecond < 0 || iSecond > 59)
    {
        return FALSE;
    }

    return TRUE;
}