private void DownloadByName()
        {
            if (m_DownLoadFileHandle > 0)
            {
                timerDownload.Stop();
                XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                m_DownLoadFileHandle         = 0;
                progressBarDownloadPos.Value = 0;

                btnDownload.Text = "Download";

                return;
            }

            string csFileName;

            //inCount;
            //if ( nSelected < 0 )
            //{
            //    MessageBox.Show("SelectFile !");
            //    return;
            //}


            H264_DVR_FILE_DATA FileInfo = (H264_DVR_FILE_DATA)listFile.FocusedItem.Tag;


            string strSaveName;
            //strSaveName.Format("c:\\record\\record.h264");
            int nSelectedIndex = comboDev.SelectedIndex;

            if (nSelectedIndex < 0)
            {
                MessageBox.Show("SelectDevice !");
                return;
            }
            DEV_INFO DevTemp = (DEV_INFO)((ComboxItem)comboDev.SelectedItem).Value;

            string strInitDir;

            strInitDir = Application.StartupPath;
            if (strInitDir.EndsWith("\\"))
            {
                strInitDir += "Download";
            }
            else
            {
                strInitDir += "\\Download";
            }

            DirectoryInfo dir = new DirectoryInfo(strInitDir);

            //if ( dir.Attributes )
            {
                dir.Create();
            }

            string strFileTpye = "h264";
            string strFileName = FileInfo.sFileName;

            if (strFileName.EndsWith(".h264"))
            {
                strFileTpye = "h264";
            }
            else
            {
                strFileTpye = "jpg";
            }
            strFileName = string.Format("{0}_{1}_{2}-{3}_{4}{5}{6}{7}.{8}",
                                        DevTemp.szDevName, FileInfo.ch + 1,
                                        FileInfo.stBeginTime.year, FileInfo.stBeginTime.month,
                                        FileInfo.stBeginTime.day, FileInfo.stBeginTime.hour,
                                        FileInfo.stBeginTime.minute, FileInfo.stBeginTime.second, strFileTpye);

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.AddExtension     = true;
            dlg.CheckPathExists  = true;
            dlg.DefaultExt       = ".h264";
            dlg.Filter           = "All File(*.h264;*.jpg)|*.*||";
            dlg.InitialDirectory = strInitDir;          //默认路径

            dlg.FileName = strFileName;
            int count = listFile.SelectedItems[0].Index;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                strSaveName = dlg.FileName;
                //m_lSaveHandle = H264_DVR_GetFileByName(m_lLoginID, pstrFileInfo,strSaveName.GetBuffer(0),SDKDownLoadPosCallback,(DWORD)this);
                m_DownLoadFileHandle = XMSDK.H264_DVR_GetFileByName(m_lLoginID, ref FileInfo, strSaveName, null, 0, null);
                if (m_DownLoadFileHandle >= 0)
                {
                    progressBarDownloadPos.Value = 0;
                    btnDownload.Text             = "Stop";
                    //update the progress control
                    //SetTimer(1,0,NULL);
                }
                else
                {
                    string sTemp = string.Format("dowload fail ERROR = {0}", XMSDK.H264_DVR_GetLastError());
                    MessageBox.Show(sTemp);
                }
            }
        }
        private void DownloadByTime()
        {
            if (m_DownLoadFileHandle > 0)
            {
                timerDownload.Stop();
                XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                m_DownLoadFileHandle         = 0;
                progressBarDownloadPos.Value = 0;

                btnDownload.Text = "Download";

                return;
            }

            string strSaveName = "";

            //strSaveName.Format("c:\\record");
            strSaveName = BrowseForFolder(this.Handle);

            if (strSaveName == "")  //未选择路径时退出
            {
                return;
            }

            H264_DVR_FINDINFO info = new H264_DVR_FINDINFO();

            info.nChannelN0         = comboChannel.SelectedIndex;    //channel No.
            info.nFileType          = comboRecordType.SelectedIndex; //file type
            info.startTime.dwYear   = beginDate.Value.Year;
            info.startTime.dwMonth  = beginDate.Value.Month;
            info.startTime.dwDay    = beginDate.Value.Day;
            info.startTime.dwHour   = beginTime.Value.Hour;
            info.startTime.dwMinute = beginTime.Value.Minute;
            info.startTime.dwSecond = beginTime.Value.Second;
            info.endTime.dwYear     = endDate.Value.Year;
            info.endTime.dwMonth    = endDate.Value.Month;
            info.endTime.dwDay      = endDate.Value.Day;
            info.endTime.dwHour     = endTime.Value.Hour;
            info.endTime.dwMinute   = endTime.Value.Minute;
            info.endTime.dwSecond   = endTime.Value.Second;
            int nRecordFileType = comboRecordType.SelectedIndex;

            info.nFileType = (nRecordFileType <= (int)PlayBackFileType.SDK_RECORD_MANUAL) ? nRecordFileType : ((int)PlayBackFileType.SDK_PIC_ALL + nRecordFileType - (int)PlayBackFileType.SDK_RECORD_MANUAL - 1);

            m_DownLoadFileHandle = XMSDK.H264_DVR_GetFileByTime(m_lLoginID, ref info, strSaveName, false, null, 0, null);
            if (m_DownLoadFileHandle > 0)
            {
                progressBarDownloadPos.Value = 0;

                btnDownload.Text = "Stop";

                //update the progress control
                timerDownload.Start();
            }
            else
            {
                string sTemp;
                sTemp = string.Format("dowload fail ERROR = {0}", XMSDK.H264_DVR_GetLastError());
                MessageBox.Show(sTemp);
            }
        }
        public void recordTime(object source, System.Timers.ElapsedEventArgs e)
        {
            if (!m_bPauseLocalPlay)
            {
                float pos = XMSDK.H264_DVR_GetPlayPos(m_nLocalplayHandle);

                if (InvokeRequired)
                {
                    BeginInvoke((MethodInvoker)(() => trackBarLocalPlayPos.Value = Convert.ToInt32(pos * 1000)));
                }
                else
                {
                    trackBarLocalPlayPos.Value = Convert.ToInt32(pos * 1000);
                }
            }

            if (!m_bPauseNetPlay)
            {
                float pos = XMSDK.H264_DVR_GetPlayPos(m_nNetPlayHandle);
                if (InvokeRequired)
                {
                    BeginInvoke((MethodInvoker)(() => trackBarNetPlayPos.Value = Convert.ToInt32(pos * 1000)));
                }
                else
                {
                    trackBarNetPlayPos.Value = Convert.ToInt32(pos * 1000);
                }
            }

            if (m_DownLoadFileHandle != 0)
            {
                int nPos = XMSDK.H264_DVR_GetDownloadPos(m_DownLoadFileHandle);
                if (nPos < 0)           //fail
                {
                    XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                    progressBarDownloadPos.Value = 0;
                    m_DownLoadFileHandle         = 0;
                    btnDownload.Text             = "Download";
                    MessageBox.Show("Get download process fail !");
                    timerDownload.Stop();
                }

                if (nPos == 100)                //download end
                {
                    XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                    m_DownLoadFileHandle = 0;

                    timerDownload.Stop();
                    if (InvokeRequired)
                    {
                        BeginInvoke((MethodInvoker)(() => progressBarDownloadPos.Value = 0));
                    }
                    else
                    {
                        progressBarDownloadPos.Value = 0;
                    }
                    btnDownload.Text = "Download";
                    MessageBox.Show("Download Finished");
                    return;
                }
                if (nPos > 100)         //abnormal
                {
                    XMSDK.H264_DVR_StopGetFile(m_DownLoadFileHandle);
                    m_DownLoadFileHandle = 0;
                    if (InvokeRequired)
                    {
                        BeginInvoke((MethodInvoker)(() => progressBarDownloadPos.Value = 0));
                    }
                    else
                    {
                        progressBarDownloadPos.Value = 0;
                    }
                    btnDownload.Text = "Download";
                    MessageBox.Show("Download Error");
                }
                else
                {
                    if (InvokeRequired)
                    {
                        BeginInvoke((MethodInvoker)(() => progressBarDownloadPos.Value = nPos));
                    }
                    else
                    {
                        progressBarDownloadPos.Value = nPos;
                    }
                }
            }
        }