// DlgCutStartpos1.cpp : implementation file
//

#include "stdafx.h"
#include "netplayx.h"
#include "DlgCutStartpos.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgCutStartpos dialog


CDlgCutStartpos::CDlgCutStartpos(UINT nIDTemplate/*=CDlgCutStartpos::IDD*/,CWnd* pParent /*=NULL*/)
	: CDialog(nIDTemplate, pParent)
{
	//{{AFX_DATA_INIT(CDlgCutStartpos)
	m_cutStartTime = COleDateTime::GetCurrentTime();
	m_cutStartDate = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
	m_language = 1;
	m_type     = 0;			/*0为剪切，1为播放定位*/
}


void CDlgCutStartpos::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgCutStartpos)
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_STARTTIME, m_cutStartTime);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_STARTDATE, m_cutStartDate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgCutStartpos, CDialog)
	//{{AFX_MSG_MAP(CDlgCutStartpos)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgCutStartpos message handlers
void CDlgCutStartpos::OnOK()
{
	if(UpdateData(TRUE))
	{
		CTime	cutStartTime(m_cutStartDate.GetYear(),
							 m_cutStartDate.GetMonth(),
							 m_cutStartDate.GetDay(),
							 m_cutStartTime.GetHour(),
							 m_cutStartTime.GetMinute(),
							 m_cutStartTime.GetSecond());

		CTime	allFileTime(m_allFileTime.GetYear(),
							m_allFileTime.GetMonth(),
							m_allFileTime.GetDay(),
							m_allFileTime.GetHour(),
							m_allFileTime.GetMinute(),
							m_allFileTime.GetSecond());

		if (GetCutStartTime() < m_filecreatetime)
		{
			if (m_type == 0)
			{
				if (m_language) 
					AfxMessageBox(IDS_STRING263);
				else		
					AfxMessageBox(IDS_STRING264);
			}
			else
			{
				if (m_language) 
					AfxMessageBox(IDS_STRING261);
				else		
					AfxMessageBox(IDS_STRING262);
			}
			return;
		}

		if (cutStartTime >= allFileTime )
		{
			if (m_type == 0)
			{
				if (m_language) 
					AfxMessageBox(IDS_STRING235);
				else		
					AfxMessageBox(IDS_STRING250);
			}
			else
			{
				if (m_language) 
					AfxMessageBox(IDS_STRING257);
				else		
					AfxMessageBox(IDS_STRING258);
			}
			return;
		}
		else
		{
			CDialog::OnOK();
		}
	}
}

DWORD CDlgCutStartpos::GetCutStartTime()
{
	LONG	iRet;
	struct tm cutStartTime;
	cutStartTime.tm_year = m_cutStartDate.GetYear() - 1900;
	cutStartTime.tm_mon  = m_cutStartDate.GetMonth() - 1;
	cutStartTime.tm_mday = m_cutStartDate.GetDay();
	cutStartTime.tm_wday = m_cutStartDate.GetDayOfWeek();
	cutStartTime.tm_yday = m_cutStartDate.GetDayOfWeek();
	cutStartTime.tm_hour = m_cutStartTime.GetHour();
	cutStartTime.tm_min  = m_cutStartTime.GetMinute();
	cutStartTime.tm_sec  = m_cutStartTime.GetSecond();
	iRet = mktime(&cutStartTime);
	TRACE("Get Cut Start Time:%d.\n",iRet);
	return iRet;

//	return (m_cutStartTime.GetHour()  * 60 * 60 + m_cutStartTime.GetMinute() * 60 + m_cutStartTime.GetSecond())*1000;
}
