/// <summary> /// 自动点名工作线程 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bgkReport_DoWork(object sender, DoWorkEventArgs e) { while (!bgkReport.CancellationPending) { Thread.Sleep(500); Application.DoEvents(); DateTime now = DateTime.Now; if ((now - mPrvReportTime).TotalSeconds < Settings.Default.AutoReportInterval) { continue; } mPrvReportTime = now; var vehicles = (this.dgvVechiles.DataSource as List <JsonLastPosition>).ToArray(); if (vehicles == null || vehicles.Length < 1) { continue; } foreach (var vehicle in vehicles) { if (bgkReport.CancellationPending) { // 系统取消退出 return; } var lastLocation = UrlApiHelper.GetLastLocation(vehicle.TerminalId); if (lastLocation != null && lastLocation.Status == 0) { this.dgvVechiles.Invoke(new Action <JsonLastPosition>(AddVehicle), lastLocation); } } } }
/// <summary> /// 点名, 获取最新位置信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuRequest_Click(object sender, EventArgs e) { var selVehicle = GetSelectedVehicle(); if (selVehicle == null) { return; } var task = Task.Factory.StartNew(() => { var lastLocation = UrlApiHelper.GetLastLocation(selVehicle.TerminalId); if (lastLocation == null) { GuiHelper.MsgBox("服务器连接异常..."); } else if (lastLocation.Status != 0) { GuiHelper.MsgBox("点名失败: " + lastLocation.Message); } else { this.dgvVechiles.Invoke(new Action <JsonLastPosition>(AddVehicle), lastLocation); mParent.LocatedVehicle(lastLocation); } }); }
/// <summary> /// 开启视频预览 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, EventArgs e) { string terminalId = this.txtTerminalId.Text.Trim(); if (string.IsNullOrEmpty(terminalId)) { errPrv.SetError(this.txtTerminalId, "终端编号不能为空..."); this.txtTerminalId.Focus(); return; } ValueString <AVChannel> selChn = this.cboChn.SelectedItem as ValueString <AVChannel>; if (selChn == null) { errPrv.SetError(this.cboChn, "请选择有效的预览通道..."); this.cboChn.Focus(); return; } string svrIp = this.txtSvrIp.Text.Trim(); if (string.IsNullOrEmpty(svrIp)) { errPrv.SetError(this.txtSvrIp, "视频服务器IP地址不能为空..."); this.txtSvrIp.Focus(); return; } ushort svrPort = (ushort)this.nudPort.Value; this.btnOk.Enabled = false; this.TerminalId = null; var task = Task.Factory.StartNew(() => { var result = UrlApiHelper.ControlVideo(terminalId, selChn.Value, VedioControlType.RealTime); if (result == null) { GuiHelper.MsgBox("服务器连接异常..."); } else if (result.Status != 0) { GuiHelper.MsgBox("实时预览开启失败: " + result.Message); } else { this.TerminalId = terminalId; this.Channel = selChn.Value; Settings.Default.DVRSvrIp = svrIp; Settings.Default.DVRSvrPort = svrPort; } }); task.Wait(); this.btnOk.Enabled = true; if (!string.IsNullOrEmpty(this.TerminalId)) { this.DialogResult = DialogResult.OK; this.Close(); } }
/// <summary> /// 登陆验证后台工作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; if (e.Argument is string[] loginArgs) { // FIXME: 目前是通过获取终端编号的位置信息模拟登陆过程, 后期将通过用户名密码验证API进行登陆 string loginName = loginArgs[0]; string loginPwd = loginArgs[1]; LastLocation = UrlApiHelper.GetLastLocation(loginName); if (LastLocation == null) { worker.ReportProgress(-1, "服务器连接异常..."); return; } else if (LastLocation.Status != 0) { worker.ReportProgress(-1, LastLocation.Message); return; } // 登陆成功 UpdateLoginProgress(50, "登陆成功, 正在载入界面..."); mParentFrm.InvokeIfRequired(frm => frm.LoadUI()); worker.ReportProgress(100); } else { // 失败 worker.ReportProgress(-1, "参数错误"); } }
/// <summary> /// 停止播放流媒体 /// </summary> public void StopPlay() { this.btnPlay.Enabled = false; if (ChannelId > 0) { if (this.btnRecord.Checked) { // 正在录制则进行停止 LogAppend("正在停止视频录制..."); // 停止录像 this.btnRecord.Checked = false; PlayerMethods.CarEyePlayer_StopManuRecording(ChannelId); LogAppend("视频录制已停止."); } // 预览停止代码 PlayerMethods.CarEyePlayer_CloseStream(ChannelId); UrlApiHelper.ControlVideo(Token.TerminalId, Token.LogicChn, VedioControlType.Stop); ChannelId = -1; } LinkToken(null); mImagePath = null; mVideoPath = null; UpdateDisplayStatus(); }
/// <summary> /// 进行查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, EventArgs e) { DateTime startTime = this.dtpStart.Value; DateTime endTime = this.dtpEnd.Value; if (startTime > endTime) { errPrv.SetError(this.dtpStart, "开始时间不能晚于结束时间..."); return; } string terminalId = this.txtTerminalId.Text.Trim(); if (string.IsNullOrEmpty(terminalId)) { errPrv.SetError(this.txtTerminalId, "终端编号不能为空..."); this.txtTerminalId.Focus(); return; } this.History = null; this.btnOk.Enabled = false; var task = Task.Factory.StartNew(() => { var history = UrlApiHelper.GetHistory(terminalId, startTime, endTime); if (history == null) { GuiHelper.MsgBox("服务器连接异常..."); } else if (history.Status != 0) { GuiHelper.MsgBox("轨迹查询失败: " + history.Message); } else if (history.Count < 1 || history.Items.Count < 1) { GuiHelper.MsgBox($"终端[{terminalId}]在该时间段内没有历史轨迹记录..."); } else { this.History = history; } }); task.Wait(); this.btnOk.Enabled = true; if (this.History != null) { this.DialogResult = DialogResult.OK; this.Close(); } }