/// <summary> /// click the query button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnQuery_Click(object sender, EventArgs e) { #region << image operation >> int channelID = 0; RECORD_FILE_TYPE rfType = RECORD_FILE_TYPE.ALLRECORDFILE; if (txtChannelID.Text.Trim().Length == 0) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("please input the channel number!"), StringUtil.ConvertString(strMsgTitle)); return; } else { channelID = int.Parse(txtChannelID.Text); } if (txtDevName.Text.Trim().Length == 0) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("please input the name of the equipment!"), StringUtil.ConvertString(strMsgTitle)); return; } if (cmbChannelSelect.SelectedIndex == -1) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("please choose the type of the file!"), StringUtil.ConvertString(strMsgTitle)); return; } else { switch (cmbRecordFileTypeSelect.SelectedIndex) { case 0: rfType = RECORD_FILE_TYPE.ALLRECORDFILE; break; case 1: rfType = RECORD_FILE_TYPE.OUTALARM; break; case 2: rfType = RECORD_FILE_TYPE.DYNAMICSCANALARM; break; case 3: rfType = RECORD_FILE_TYPE.ALLALARM; break; case 4: rfType = RECORD_FILE_TYPE.CARDNOSEACH; break; case 5: rfType = RECORD_FILE_TYPE.COMBINEDSEACH; break; } } string strTmStart = dtpStart.Text + " " + txtTimeStart.Text; string strTmEnd = dtpEnd.Text + " " + txtTimeEnd.Text; DateTime tmStart; DateTime tmEnd; try { tmStart = DateTime.Parse(strTmStart); tmEnd = DateTime.Parse(strTmEnd); } catch (System.Exception ex) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("please input the correct format of time!"), StringUtil.ConvertString(strMsgTitle)); return; } if (tmStart >= tmEnd) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("the starting date is not before the ending date!"), StringUtil.ConvertString(strMsgTitle)); return; } #endregion #region << query operation >> nriFileInfo = new NET_RECORDFILE_INFO[intFilesMaxCount]; string strTimeFormatStyle = "on mm dd,yyyy hh:MM:ss";// the ToSting of the structure NET_TIME gives the detailed definition of the formating characters of the date and time int intFileCount = 0; bool blnQueryRecordFile = false; blnQueryRecordFile = NETClient.NETQueryRecordFile(gLoginID, channelID, rfType, tmStart, tmEnd, null, ref nriFileInfo, intFilesMaxCount * Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out intFileCount, 5000, false); if (blnQueryRecordFile == true) { lsvFiles.Items.Clear(); if (0 == intFileCount) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("no video file is available!"), StringUtil.ConvertString(strMsgTitle)); return; } ListViewItem lvi; for (int i = 0; i < intFileCount; i++) { lvi = new ListViewItem(); lvi.SubItems[0].Text = txtDevName.Text + nriFileInfo[i].ch.ToString(); lvi.SubItems.Add(nriFileInfo[i].starttime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].endtime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].size.ToString()); lsvFiles.Items.Add(lvi); } return; } else { btnOK.Enabled = false; } return; #endregion }
/// <summary> /// 查询按钮单击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnQuery_Click(object sender, EventArgs e) { #region << 画面操作 >> int channelID = 0; RECORD_FILE_TYPE rfType = RECORD_FILE_TYPE.ALLRECORDFILE; if (txtChannelID.Text.Trim().Length == 0) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("请输入通道号!"), StringUtil.ConvertString(strMsgTitle)); return; } else { channelID = int.Parse(txtChannelID.Text); } if (txtDevName.Text.Trim().Length == 0) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("请输入设备名!"), StringUtil.ConvertString(strMsgTitle)); return; } if (cmbChannelSelect.SelectedIndex == -1) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("请选择文件类型!"), StringUtil.ConvertString(strMsgTitle)); return; } else { switch (cmbRecordFileTypeSelect.SelectedIndex) { case 0: rfType = RECORD_FILE_TYPE.ALLRECORDFILE; break; case 1: rfType = RECORD_FILE_TYPE.OUTALARM; break; case 2: rfType = RECORD_FILE_TYPE.DYNAMICSCANALARM; break; case 3: rfType = RECORD_FILE_TYPE.ALLALARM; break; case 4: rfType = RECORD_FILE_TYPE.CARDNOSEACH; break; case 5: rfType = RECORD_FILE_TYPE.COMBINEDSEACH; break; } } string strTmStart = dtpStart.Text + " " + txtTimeStart.Text; string strTmEnd = dtpEnd.Text + " " + txtTimeEnd.Text; DateTime tmStart; DateTime tmEnd; try { //tmStart = DateTime.Parse(strTmStart); //tmEnd = DateTime.Parse(strTmEnd); tmStart = DateTime.Now.AddDays(-4); tmEnd = DateTime.Now; } catch (System.Exception ex) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("请输入正确的时间格式!"), StringUtil.ConvertString(strMsgTitle)); return; } if (tmStart >= tmEnd) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("开始日期不在结束日期前!"), StringUtil.ConvertString(strMsgTitle)); return; } #endregion #region << 查询操作 >> nriFileInfo = new NET_RECORDFILE_INFO[intFilesMaxCount]; string strTimeFormatStyle = "yyyy年mm月dd日 hh:MM:ss";//日期时间格式化字符,具体定义请参见NET_TIME结构的ToSting方法说明 int intFileCount = 0; bool blnQueryRecordFile = false; blnQueryRecordFile = DHClient.DHQueryRecordFile(gLoginID, channelID, rfType, tmStart, tmEnd, null, ref nriFileInfo, intFilesMaxCount * Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out intFileCount, 5000, false); if (blnQueryRecordFile == true) { lsvFiles.Items.Clear(); if (0 == intFileCount) { MessageUtil.ShowMsgBox(StringUtil.ConvertString("未查询到录像文件!"), StringUtil.ConvertString(strMsgTitle)); return; } ListViewItem lvi; for (int i = 0; i < intFileCount; i++) { lvi = new ListViewItem(); lvi.SubItems[0].Text = txtDevName.Text + nriFileInfo[i].ch.ToString(); lvi.SubItems.Add(nriFileInfo[i].starttime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].endtime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].size.ToString()); lsvFiles.Items.Add(lvi); } return; } else { btnOK.Enabled = false; } return; #endregion }
/// <summary> /// Query the video file /// </summary> /// <param name="lLoginID">Device handles user login</param> /// <param name="nChannelId">channelID</param> /// <param name="nRecordFileType">Video file type </param> /// <param name="tmStart">Recording start time</param> /// <param name="tmEnd">Recording end time</param> /// <param name="pchCardid">card number,Only for card number query effectively,In other cases you can fill NULL</param> /// <param name="nriFileinfo">Return to video file information,Structure is a NET_RECORDFILE_INFO[Only one video file information]</param> /// <param name="maxlen">nriFileinfoThe maximum length of the buffer;[Sizeof size in bytes(NET_RECORDFILE_INFO)]</param> /// <param name="filecount">The number of documents returned,Maximum output parameters are only found in video recording until the buffer is full</param> /// <param name="waittime">waiting time</param> /// <param name="bTime">Whether by time(Currently inactive)</param> /// <returns>true:success;false:failure</returns> public static bool NETQueryRecordFile(int lLoginID, int nChannelId, RECORD_FILE_TYPE nRecordFileType, DateTime tmStart, DateTime tmEnd, string pchCardid, ref NET_RECORDFILE_INFO nriFileinfo, int maxlen, out int filecount, int waittime, bool bTime) { bool returnValue = false; filecount = 0; NET_RECORDFILE_INFO[] ntFileInfo = new NET_RECORDFILE_INFO[1]; returnValue = NETQueryRecordFile(lLoginID, nChannelId, nRecordFileType, tmStart, tmEnd, pchCardid, ref ntFileInfo, maxlen, out filecount, waittime, bTime); nriFileinfo = ntFileInfo[0]; NETThrowLastError(returnValue); return returnValue; }
/// <summary> /// Query video files /// </summary> /// <param name="lLoginID">Device handles user login</param> /// <param name="nChannelId">channelID</param> /// <param name="nRecordFileType">Video file types </param> /// <param name="tmStart">Recording start time</param> /// <param name="tmEnd">Recording end time</param> /// <param name="pchCardid">card number,Only for card number query effectively,In other cases you can fill NULL</param> /// <param name="nriFileinfo">Return to video file information,Is an array of structures NET_RECORDFILE_INFO[Video file information for the specified bar]</param> /// <param name="maxlen">nriFileinfoThe maximum length of the buffer;[Unit of byte,Dimensional structure of an array of size number*sizeof(NET_RECORDFILE_INFO),Victoria is the size of the array is equal to 1,Recommend less than 200]</param> /// <param name="filecount">The number of documents returned,Maximum output parameters are only found in video recording until the buffer is full</param> /// <param name="waittime">Waiting Time</param> /// <param name="bTime">Whether by time(Currently inactive)</param> /// <returns>true:success;false:failure</returns> public static bool NETQueryRecordFile(int lLoginID, int nChannelId, RECORD_FILE_TYPE nRecordFileType, DateTime tmStart, DateTime tmEnd, string pchCardid, ref NET_RECORDFILE_INFO[] nriFileinfo, int maxlen, out int filecount, int waittime, bool bTime) { bool returnValue = false; filecount = 0; IntPtr pBoxInfo = IntPtr.Zero; try { NET_TIME timeStart = ToNetTime(tmStart); NET_TIME timeEnd = ToNetTime(tmEnd); pBoxInfo = Marshal.AllocHGlobal(maxlen);//Allocation of fixed specified the size of the memory space int fileCountMin = 0; if (pBoxInfo != IntPtr.Zero) { returnValue = CLIENT_QueryRecordFile(lLoginID, nChannelId, (int)nRecordFileType, ref timeStart, ref timeEnd, pchCardid, pBoxInfo, maxlen, out filecount, waittime, bTime); fileCountMin = (filecount <= nriFileinfo.Length ? filecount : nriFileinfo.Length); for (int dwLoop = 0; dwLoop < fileCountMin; dwLoop++) { // specify the memory space of the data is copied to the purpose in the array in the specified format nriFileinfo[dwLoop] = (NET_RECORDFILE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pBoxInfo + Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)) * dwLoop), typeof(NET_RECORDFILE_INFO)); } } NETThrowLastError(returnValue); } catch (Exception e) { NETThrowLastError(e); returnValue= false; } finally { Marshal.FreeHGlobal(pBoxInfo);//Release the fixed memory allocation pBoxInfo = IntPtr.Zero; } return returnValue; }
private void btnQuery_Click(object sender, EventArgs e) { #region << 画面操作 >> int channelID = 0; RECORD_FILE_TYPE rfType = RECORD_FILE_TYPE.ALLRECORDFILE; if (txtChannelID.Text.Trim().Length == 0) { MessageBox.Show("Por favor ingrese el número de canal", strMsgTitle); return; } else { channelID = int.Parse(txtChannelID.Text); } if (txtDevName.Text.Trim().Length == 0) { MessageBox.Show("Por favor ingrese el nombre del dispositivo", strMsgTitle); return; } if (cmbChannelSelect.SelectedIndex == -1) { MessageBox.Show("Por favor seleccione el tipo de archivo", strMsgTitle); return; } else { switch (cmbRecordFileTypeSelect.SelectedIndex) { case 0: rfType = RECORD_FILE_TYPE.ALLRECORDFILE; break; case 1: rfType = RECORD_FILE_TYPE.OUTALARM; break; case 2: rfType = RECORD_FILE_TYPE.DYNAMICSCANALARM; break; case 3: rfType = RECORD_FILE_TYPE.ALLALARM; break; case 4: rfType = RECORD_FILE_TYPE.CARDNOSEACH; break; case 5: rfType = RECORD_FILE_TYPE.COMBINEDSEACH; break; } } string timeFormating = ""; timeFormating = dtpStart.Value.Day.ToString() + "/" + dtpStart.Value.Month.ToString() + "/" + dtpStart.Value.Year.ToString() + " " + dtpTimeStart.Value.Hour.ToString() + ":" + dtpTimeStart.Value.Minute.ToString() + ":" + dtpTimeStart.Value.Second.ToString(); dtpStart.Value = DateTime.Parse(timeFormating); timeFormating = dtpTimeEnd.Value.Day.ToString() + "/" + dtpTimeEnd.Value.Month.ToString() + "/" + dtpTimeEnd.Value.Year.ToString() + " " + dtpTimeEnd.Value.Hour.ToString() + ":" + dtpTimeEnd.Value.Minute.ToString() + ":" + dtpTimeEnd.Value.Second.ToString(); dtpEnd.Value = DateTime.Parse(timeFormating); DateTime tmStart = dtpStart.Value; DateTime tmEnd = dtpEnd.Value; if (tmStart.Date > tmEnd.Date) { MessageBox.Show("La fecha desde no puede ser posterior a la fecha hasta", ": Atención !"); return; } else { if (tmStart.Date == tmEnd.Date && dtpTimeStart.Value.TimeOfDay >= dtpTimeEnd.Value.TimeOfDay) { MessageBox.Show("La hora hasta debe ser mayor que la hora desde cuando la busqueda es en el mísmo día", ": Atención !"); return; } } #endregion #region << 查询操作 >> nriFileInfo = new NET_RECORDFILE_INFO[intFilesMaxCount]; string strTimeFormatStyle = "hh:MM:ss dd/mm/yyyy"; int intFileCount = 0; bool blnQueryRecordFile = false; this.progressBar1.Visible = true; this.progressBar1.Value = 50; this.lblInfoSearch.Visible = true; this.Refresh(); blnQueryRecordFile = DHClient.DHQueryRecordFile(gLoginID, channelID, rfType, tmStart, tmEnd, null, ref nriFileInfo, intFilesMaxCount * Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out intFileCount, 5000, false); if (blnQueryRecordFile == true) { lsvFiles.Items.Clear(); if (intFileCount > 0) { this.progressBar1.Maximum = intFileCount; ListViewItem lvi; for (int i = 0; i < intFileCount; i++) { lvi = new ListViewItem(); lvi.SubItems[0].Text = txtDevName.Text + " / " + nriFileInfo[i].ch.ToString(); lvi.SubItems.Add(nriFileInfo[i].starttime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].endtime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].size.ToString()); lsvFiles.Items.Add(lvi); this.progressBar1.Increment(1); this.lblInfoSearch.Text = "" + i.ToString() + "/" + intFileCount.ToString(); } this.progressBar1.Visible = false; this.lblInfoSearch.Visible = false; return; } else { MessageBox.Show("No se encontraron registros", ": Atención!"); } } else { MessageBox.Show("No se pudo acceder al disco del dispositivo", "Error"); } this.progressBar1.Visible = false; this.lblInfoSearch.Visible = false; return; #endregion }
/// <summary> /// Click Search Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnQuery_Click(object sender, EventArgs e) { #region << Screen Operation>> int channelID = 0; RECORD_FILE_TYPE rfType = RECORD_FILE_TYPE.ALLRECORDFILE; if (txtChannelID.Text.Trim().Length == 0) { MessageBox.Show("Please type in the channel#!", strMsgTitle); return; } else { channelID = int.Parse(txtChannelID.Text); } if (txtDevName.Text.Trim().Length == 0) { MessageBox.Show("Please type in the device name!", strMsgTitle); return; } if (cmbChannelSelect.SelectedIndex == -1) { MessageBox.Show("Please select the file type!", strMsgTitle); return; } else { switch (cmbRecordFileTypeSelect.SelectedIndex) { case 0: rfType = RECORD_FILE_TYPE.ALLRECORDFILE; break; case 1: rfType = RECORD_FILE_TYPE.OUTALARM; break; case 2: rfType = RECORD_FILE_TYPE.DYNAMICSCANALARM; break; case 3: rfType = RECORD_FILE_TYPE.ALLALARM; break; case 4: rfType = RECORD_FILE_TYPE.CARDNOSEACH; break; case 5: rfType = RECORD_FILE_TYPE.COMBINEDSEACH; break; } } DateTime tmStart = dtpStart.Value; DateTime tmEnd = dtpEnd.Value; string[] strTemp = txtTimeStart.Text.ToString().Split(':'); if (3 == strTemp.Length) { tmStart = tmStart.AddHours(double.Parse(strTemp[0])); tmStart = tmStart.AddMinutes(double.Parse(strTemp[1])); tmStart = tmStart.AddSeconds(double.Parse(strTemp[2])); } string[] strTempEnd = txtTimeEnd.Text.ToString().Split(':'); if (3 == strTempEnd.Length) { tmEnd = tmEnd.AddHours(double.Parse(strTempEnd[0])); tmEnd = tmEnd.AddMinutes(double.Parse(strTempEnd[1])); tmEnd = tmEnd.AddSeconds(double.Parse(strTempEnd[2])); } if (tmStart >= tmEnd) { MessageBox.Show("Start period is not before the end period!", strMsgTitle); return; } #endregion #region << Search Operation >> nriFileInfo = new NET_RECORDFILE_INFO[intFilesMaxCount]; string strTimeFormatStyle = "yyyy year mm month dd day hh:MM:ss";//Date time format character, detailed definition please refer to ToSting instruction of NET_TIME struct. int intFileCount = 0; bool blnQueryRecordFile = false; //Search Recoder blnQueryRecordFile = NETClient.NETQueryRecordFile(gLoginID, channelID, rfType, tmStart, tmEnd, null, ref nriFileInfo, intFilesMaxCount * Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)), out intFileCount, 5000, false); if (blnQueryRecordFile == true) { lsvFiles.Items.Clear(); ListViewItem lvi; for (int i = 0; i < intFileCount; i++) { lvi = new ListViewItem(); lvi.SubItems[0].Text = txtDevName.Text + nriFileInfo[i].ch.ToString(); lvi.SubItems.Add(nriFileInfo[i].starttime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].endtime.ToString(strTimeFormatStyle)); lvi.SubItems.Add(nriFileInfo[i].size.ToString()); lsvFiles.Items.Add(lvi); } return; } else { btnOK.Enabled = false; } return; #endregion }
/// <summary> /// 查询录像文件 /// </summary> /// <param name="lLoginID">设备用户登录句柄</param> /// <param name="nChannelId">通道ID</param> /// <param name="nRecordFileType">录像文件类型 </param> /// <param name="tmStart">录像开始时间</param> /// <param name="tmEnd">录像结束时间</param> /// <param name="pchCardid">卡号,只针对卡号查询有效,其他情况下可以填NULL</param> /// <param name="nriFileinfo">返回的录像文件信息,是一个NET_RECORDFILE_INFO结构数组[录像文件信息为指定条]</param> /// <param name="maxlen">nriFileinfo缓冲的最大长度;[单位字节,大小为结构数组维数*sizeof(NET_RECORDFILE_INFO),数组维为大小等于1,建议小于200]</param> /// <param name="filecount">返回的文件个数,属于输出参数最大只能查到缓冲满为止的录像记录</param> /// <param name="waittime">等待时间</param> /// <param name="bTime">是否按时间查(目前无效)</param> /// <returns>true:成功;false:失败</returns> public static bool DHQueryRecordFile(int lLoginID, int nChannelId, RECORD_FILE_TYPE nRecordFileType, DateTime tmStart, DateTime tmEnd, string pchCardid, ref NET_RECORDFILE_INFO[] nriFileinfo, int maxlen, out int filecount, int waittime, bool bTime) { bool returnValue = false; filecount = 0; IntPtr pBoxInfo = IntPtr.Zero; try { NET_TIME timeStart = ToNetTime(tmStart); NET_TIME timeEnd = ToNetTime(tmEnd); pBoxInfo = Marshal.AllocHGlobal(maxlen);//分配固定的指定大小的内存空间 int fileCountMin = 0; if (pBoxInfo != IntPtr.Zero) { returnValue = CLIENT_QueryRecordFile(lLoginID, nChannelId, (int)nRecordFileType, ref timeStart, ref timeEnd, pchCardid, pBoxInfo, maxlen, out filecount, waittime, bTime); fileCountMin = (filecount <= nriFileinfo.Length ? filecount : nriFileinfo.Length); for (int dwLoop = 0; dwLoop < fileCountMin; dwLoop++) { //将指定内存空间的数据按指定格式复制到目的数组中 nriFileinfo[dwLoop] = (NET_RECORDFILE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pBoxInfo + Marshal.SizeOf(typeof(NET_RECORDFILE_INFO)) * dwLoop), typeof(NET_RECORDFILE_INFO)); } } DHThrowLastError(returnValue); } catch (Exception e) { DHThrowLastError(e); returnValue= false; } finally { Marshal.FreeHGlobal(pBoxInfo);//释放固定内存分配 pBoxInfo = IntPtr.Zero; } return returnValue; }