📄 downloadbytime.cpp
字号:
// DownloadByTime.cpp : implementation file
//
#include "stdafx.h"
#include "netsdkdemo.h"
#include "DownloadByTime.h"
#include "NetSDKDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDownloadByTime dialog
CDownloadByTime::CDownloadByTime(CWnd* pParent /*=NULL*/)
: CDialog(CDownloadByTime::IDD, pParent)
{
//{{AFX_DATA_INIT(CDownloadByTime)
m_channelsel = 0;
m_enddate = 0;
m_endtime = 0;
m_startdate = 0;
m_starttime = 0;
//}}AFX_DATA_INIT
}
void CDownloadByTime::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDownloadByTime)
DDX_Control(pDX, IDC_DLBT_DEVICESEL, m_devicesel);
DDX_Control(pDX, IDC_DLBT_PROGRESS, m_download_pos);
DDX_Text(pDX, IDC_DLBT_CHANNELSEL, m_channelsel);
DDV_MinMaxUInt(pDX, m_channelsel, 1, 16);
DDX_DateTimeCtrl(pDX, IDC_DLBT_ENDDATE, m_enddate);
DDX_DateTimeCtrl(pDX, IDC_DLBT_ENDTIME, m_endtime);
DDX_DateTimeCtrl(pDX, IDC_DLBT_STARTDATE, m_startdate);
DDX_DateTimeCtrl(pDX, IDC_DLBT_STARTTIME, m_starttime);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDownloadByTime, CDialog)
//{{AFX_MSG_MAP(CDownloadByTime)
ON_BN_CLICKED(IDC_BTN_DOWNLOAD, OnBtnDownload)
ON_WM_TIMER()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDownloadByTime message handlers
int InitComboxCallback(const DeviceNode& node, DWORD dwUser)
{
CDownloadByTime* pThis = (CDownloadByTime*)dwUser;
if(!pThis)
{
return 1;
}
return pThis->InitComboxCallback_Imp(node);
}
int CDownloadByTime::InitComboxCallback_Imp(const DeviceNode& node)
{
//设备显示
CString strDev;
strDev.Format(" %s ",node.Name);
int nIndex = m_devicesel.GetCount();
m_devicesel.InsertString(nIndex,strDev);
m_devicesel.SetItemData(nIndex, (DWORD)&node); //设置保存当前设备指针值
return 0;
}
BOOL CDownloadByTime::OnInitDialog()
{
CDialog::OnInitDialog();
g_SetWndStaticText(this);
//DeviceNode *nDev;
//CString strDev;
//POSITION nPos;
CDevMgr::GetDevMgr().For_EachDev(InitComboxCallback, (DWORD)this);
/*
//初始化可选择的设备
nPos = g_ptrdevicelist->GetHeadPosition();
m_devicesel.Clear();
for(int i = 0; i < g_ptrdevicelist->GetCount(); i ++ )
{
//设备显示格式
nDev = (DeviceNode *)g_ptrdevicelist->GetNext(nPos);
//设备显示
strDev.Format(" %s ",nDev->Name);
m_devicesel.InsertString(i,strDev);
m_devicesel.SetItemData(i, (DWORD)nDev); //设置保存当前设备指针值
}
*/
if (m_devicesel.GetCount() > 0)
{
m_devicesel.SetCurSel(0);
}
CTime cur_time = CTime ::GetCurrentTime();
CTime time = CTime(cur_time.GetYear(),cur_time.GetMonth(), cur_time.GetDay(),
cur_time.GetHour(),cur_time.GetMinute(),cur_time.GetSecond());
m_enddate = time;
m_endtime = time;
m_startdate = time;
m_starttime = time;
m_pdownloadfile = 0;
m_channelsel = 1;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CALLBACK BTDownLoadPos(LONG lPlayHandle, DWORD dwTotalSize, DWORD dwDownLoadSize, int index, NET_RECORDFILE_INFO recordfileinfo, DWORD dwUser)
{
CDownloadByTime * dlg = (CDownloadByTime *)dwUser;
dlg->UpdateDownloadPos(lPlayHandle, dwTotalSize, dwDownLoadSize, index, recordfileinfo);
}
//更新下载进度
void CDownloadByTime::UpdateDownloadPos(LONG iHandle, DWORD dwTotal, DWORD dwDownload, int index, NET_RECORDFILE_INFO recordfileinfo)
{
if(m_pdownloadfile != iHandle)
{
MessageBox(MSG_SCHRECORD_DOWNLORD_CB_ERR);
return;
}
m_downloadtotal = dwTotal;
m_downloadsize = dwDownload;
CString nstr;
nstr.Format("%d", index);
GetDlgItem(IDC_EDIT_FILEINDEX)->SetWindowText(nstr);
nstr.Format("%d / %d",dwDownload, dwTotal);
GetDlgItem(IDC_EDIT_PROGRESS)->SetWindowText(nstr);
nstr.Format("channel: %d, driver no: %d, size: %d\r\nstart time: %d-%d-%d-%d-%d-%d\r\nend time: %d-%d-%d-%d-%d-%d"
,recordfileinfo.ch, recordfileinfo.driveno, recordfileinfo.size,
recordfileinfo.starttime.dwYear,
recordfileinfo.starttime.dwMonth,
recordfileinfo.starttime.dwDay,
recordfileinfo.starttime.dwHour,
recordfileinfo.starttime.dwMinute,
recordfileinfo.starttime.dwSecond,
recordfileinfo.endtime.dwYear,
recordfileinfo.endtime.dwMonth,
recordfileinfo.endtime.dwDay,
recordfileinfo.endtime.dwHour,
recordfileinfo.endtime.dwMinute,
recordfileinfo.endtime.dwSecond);
GetDlgItem(IDC_EDIT_FILEINFO)->SetWindowText(nstr);
if(-1 == m_downloadsize || m_downloadsize >= m_downloadtotal)
{
MessageBox(MSG_SCHRECORD_DOWNLOAD_FIN);
if (m_pdownloadfile)
{
BOOL b = CLIENT_StopDownload(m_pdownloadfile);
if (!b)
{
((CNetSDKDemoDlg *)GetParent())->LastError();//Zhengdh 06.11.24
}
m_pdownloadfile = NULL;
}
((CButton *)GetDlgItem(IDC_BTN_DOWNLOAD))->SetWindowText(MSG_SCHRECORD_DOWNLOAD);
}
}
void CDownloadByTime::OnBtnDownload()
{
if (!UpdateData(TRUE))
{
return;
}
if(m_devicesel.GetCount() <= 0 || m_devicesel.GetCurSel() < 0)
{
MessageBox(MSG_SCHRECORD_NODEVICE,MSG_SCHRECORD_CHOOSEDEVICE);
return;
}
if(m_pdownloadfile)
{
BOOL stopret = CLIENT_StopDownload(m_pdownloadfile);
if (!stopret)
{
((CNetSDKDemoDlg *)GetParent())->LastError();//Zhengdh 06.11.24
MessageBox(MSG_SCHRECORD_STOPDLFAILED);
}
else
{
MessageBox(MSG_SCHRECORD_CANCELED);
m_pdownloadfile = NULL;
((CButton *)GetDlgItem(IDC_BTN_DOWNLOAD))->SetWindowText(MSG_SCHRECORD_DOWNLOAD);
}
return;
}
SYSTEMTIME systime;
NET_TIME stime, etime;
CTime time = CTime(m_startdate.GetYear(),m_startdate.GetMonth(),m_startdate.GetDay(),
m_starttime.GetHour(), m_starttime.GetMinute(), m_starttime.GetSecond());
if(!time.GetAsSystemTime(systime) || !time.GetAsSystemTime(systime))
{
MessageBox(MSG_SCHRECORD_TIMEINPUT_ERR,MSG_SCHRECORD_TIMEINPUT);
return;
}
g_systimetodhtime(&systime,&stime);
time = CTime(m_enddate.GetYear(),m_enddate.GetMonth(),m_enddate.GetDay(),
m_endtime.GetHour(), m_endtime.GetMinute(), m_endtime.GetSecond());
if(!time.GetAsSystemTime(systime) || !time.GetAsSystemTime(systime))
{
MessageBox(MSG_SCHRECORD_TIMEINPUT_ERR,MSG_SCHRECORD_TIMEINPUT);
return;
}
g_systimetodhtime(&systime,&etime);
DeviceNode *pInfo = (DeviceNode *)m_devicesel.GetItemData(m_devicesel.GetCurSel());
CString strName = "download.dav";
CFileDialog dlg(FALSE,"*.dav","download.dav",OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,
"All File(*.dav)|*.*||",this);
if(dlg.DoModal() == IDOK)
{
strName = dlg.GetPathName();
}
m_pdownloadfile = CLIENT_DownloadByTime(pInfo->LoginID,
m_channelsel - 1,
0,
&stime,
&etime,
strName.GetBuffer(0),
BTDownLoadPos,
(DWORD)this);
if (m_pdownloadfile)
{
((CButton *)GetDlgItem(IDC_BTN_DOWNLOAD))->SetWindowText(MSG_SCHRECORD_CANCELDOWNLOAD);
SetTimer((UINT)this, 1000,NULL);
}
else
{
((CNetSDKDemoDlg *)GetParent())->LastError();//Zhengdh 06.11.24
MessageBox(MSG_SCHRECORD_STARTDLFAILED);
}
}
void CDownloadByTime::OnTimer(UINT nIDEvent)
{
if(m_pdownloadfile)
{
m_download_pos.SetPos(m_downloadsize * 100/m_downloadtotal);
}
CDialog::OnTimer(nIDEvent);
}
void CDownloadByTime::OnClose()
{
if(m_pdownloadfile)
{
BOOL b = CLIENT_StopDownload(m_pdownloadfile);
if (!b)
{
((CNetSDKDemoDlg *)GetParent())->LastError();//Zhengdh 06.11.24
}
m_pdownloadfile = NULL;
}
KillTimer((int)this);
CDialog::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -