前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BaseDisplayVedio.aspx.cs" Inherits="舟山物联.ZS_Site.BaseMonitor.BaseDisplayVedio" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" /> <meta http-equiv="Expires" content="0" /> <title>视频信息</title> <link href="/CSS/demo.css" rel="stylesheet" /> <link href="/CSS/basic.css" rel="stylesheet" /> <link href="/CSS/style.css" rel="stylesheet" /> <script type="text/javascript"> document.write("<link type=‘text/css‘ href=‘/CSS/demo.css?version=" + new Date().getTime() + "‘ rel=‘stylesheet‘ />"); </script> </head> <body style="padding: 0;"> <form runat="server"> <div class="bg_bg" style=" padding:0 10px;"><span class="fl" style="display:block;">视频 </span><a class="fr" style="display:block;cursor:pointer; font-size:26px;" onclick="clickStopRealPlay(0);" >×</a></div> <div > <div class="yujingk_main"> <ul class="mt10 ml10 pc_overflow fl"> <li class="yujingk_main_ti fl ml10">方向控制:</li> <li class="ship fl ml10"><a href="#" onmousedown="mouseDownPTZControl(1);" onmouseup="mouseUpPTZControl();">上</a></li> <li class="ship fl ml10"><a href="#" onmousedown="mouseDownPTZControl(2);" onmouseup="mouseUpPTZControl();">下</a></li> <li class="ship fl ml10"><a href="#" onmousedown="mouseDownPTZControl(3);" onmouseup="mouseUpPTZControl();">左</a></li> <li class="ship fl ml10"><a href="#" onmousedown="mouseDownPTZControl(4);" onmouseup="mouseUpPTZControl();">右</a></li> <li class="ship fl ml10"><a href="#" onmousedown="PTZZoomIn()" onmouseup="PTZZoomStop()">放大</a></li> <li class="ship fl ml10"><a href="#" onmousedown="PTZZoomout()" onmouseup="PTZZoomStop()">缩小</a></li> </ul> <span style=" margin-top:10px; margin-right:10px;display: none;" id="lnkCtrl" class="fr pc_overflow"> <a href="/js/WebComponents.exe"><img src="/images/k_icon.png" /></a></span> <img id="next" src="/images/l-btn.png" style="z-index:9999;left: -674px;top: 400px; position: relative; background-color:#343434; width: 35px; height: 35px;" onclick="ImgFront();" /> <img id="front" src="/images/r-btn.png" style="z-index:99999; position:relative;top: 400px;left:283px; background-color:#343434; width: 35px; height: 35px;" onclick="ImgNext();" /> <div class="clear"></div> <div id="tablist2" style="background:#343434;"> <%--视频翻页--%> <div class="m2yw_pic mt20" <%--style="height:683px;"--%>> <div id="divPlugin" class="plugin" > </div> </div> </div> </div> </div> </form> </body> <script src="/js/jquery-1.8.2.min.js"></script> <script src="/js/webVideoCtrl.js"></script> <script src="/js/demo.js"></script> <script type="text/javascript"> var sreenview = new Array(); var StrCurrentVideoIDs = ""; var BaseID = <%=BaseID%> // 登录 $(function () { changeWndNum(1) StrCurrentVideoIDs = ""; if (StrCurrentVideoIDs == "") { GetFrist(); } }); // 窗口分割数 function changeWndNum(iType) { iType = parseInt(iType, 10); WebVideoCtrl.I_ChangeWndNum(iType); } //视频的翻页 function BindData() { //if (0 < sreenview.length && sreenview.length <= 1) { // CountVedio = 1; //} else if (1 < sreenview.length && sreenview.length <= 4) { // CountVedio = 2; //} else if (4 < sreenview.length && sreenview.length <= 9) { // CountVedio = 3; //} else { // CountVedio = 4; //} //changeWndNum(CountVedio); if (sreenview.length > 0) { //判断显示在第几个窗口: for (var i = 0; i < sreenview.length; i++) { clickLoginPLay(sreenview[i].IP, sreenview[i].IPort, sreenview[i].CUserName, sreenview[i].CPassWord, i); } } else { //clickLoginPLay(‘192.168.0.65‘, 80, ‘admin‘, ‘qwer1234‘, 0); alert("没有更多的视频信息了!"); } } // 停止预览 function clickStopRealPlay(count) { var oWndInfo = WebVideoCtrl.I_GetWindowStatus(count), szInfo = ""; if (oWndInfo != null) { var iRet = WebVideoCtrl.I_Stop(); if (0 == iRet) { szInfo = "停止预览成功!"; } else { szInfo = "停止预览失败!"; } } //alert(parent.document.getElementById("myModa")); //关闭当前页面 window.parent.location.href = "BaseMonitor.aspx?BaseID=" + BaseID; //parent.document.getElementById("myModa").style.display = "none"; } //下一页 function ImgNext() { sreenview = new Array(); $.ajax({ type: ‘post‘, url: ‘/Ajax/Video.ashx?type=1&StrCurrentVideoIDs=‘ + StrCurrentVideoIDs + ‘&BaseID=‘ + BaseID, success: function (Data) { if (Data == "[]") { alert("没有更多的视频信息了!"); return; } else { var result = eval("(" + Data + ")"); StrCurrentVideoIDs = ""; for (var i = 0; i < result.length; i++) { if (i == result.length - 1) { StrCurrentVideoIDs += result[i].ID; } else { StrCurrentVideoIDs += result[i].ID + ","; } var temp = { IP: result[i].CDeviceIp, IPort: result[i].Port, CUserName: result[i].FName, CPassWord: result[i].Parameter }; sreenview.push(temp); } BindData(); } } }) } //上一页 function ImgFront() { sreenview = new Array(); $.ajax({ type: ‘post‘, url: ‘/Ajax/Video.ashx?type=2&StrCurrentVideoIDs=‘ + StrCurrentVideoIDs + ‘&BaseID=‘ + BaseID, success: function (Data) { if (Data == "[]") { alert("没有更多的视频信息了!"); return; } else { var result = eval("(" + Data + ")"); StrCurrentVideoIDs = ""; for (var i = 0; i < result.length; i++) { if (i == result.length - 1) { StrCurrentVideoIDs += result[i].ID; } else { StrCurrentVideoIDs += result[i].ID + ","; } var temp = { IP: result[i].CDeviceIp, IPort: result[i].Port, CUserName: result[i].FName, CPassWord: result[i].Parameter }; sreenview.push(temp); } BindData(); } } }) } function GetFrist() { sreenview = new Array(); $.ajax({ type: ‘post‘, url: ‘/Ajax/Video.ashx?type=0&StrCurrentVideoIDs=‘ + StrCurrentVideoIDs + ‘&BaseID=‘ + BaseID, success: function (Data) { if (Data == "没有视频信息!") { alert(Data); return; } else { var result = eval("(" + Data + ")"); for (var i = 0; i < result.length; i++) { if (i == result.length - 1) { StrCurrentVideoIDs += result[i].ID; } else { StrCurrentVideoIDs += result[i].ID + ","; } var temp = { IP: result[i].CDeviceIp, IPort: result[i].Port, CUserName: result[i].FName, CPassWord: result[i].Parameter }; sreenview.push(temp); } BindData(); } } }) } </script> </html>
后台代码:传值
Video.ashx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using FS.Extend; using LD_Model.DB; using LD_Logic.IOT; using Newtonsoft.Json; namespace 舟山物联.Ajax { /// <summary> /// Video 的摘要说明 /// </summary> public class Video : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int type = context.Request["type"].ConvertType(0); string StrCurrentVideoIDs = context.Request["StrCurrentVideoIDs"]; int BaseID = context.Request["BaseID"].ConvertType(0); DeviceControlLogic vedio = new DeviceControlLogic(); //获取当前基地下并且状态=视频选出来,不重复的controlID集合; List<int?> lstGetAllControlID = DeviceConfigDB.Data.Where(o => o.BaseID == BaseID && o.IDeviceType == DeviceControlDB.eumIDeviceType.Video).ToList().Select(o => o.ControlID).Distinct().ToList(); if (lstGetAllControlID.Count > 0) { List<DeviceControlDB> lstGetControl = new List<DeviceControlDB>(); switch (type) { //首页 case 0: { lstGetControl = vedio.GetVideo(lstGetAllControlID, 1); break; } //下一页 case 1: { lstGetControl = vedio.GetVedioPageNext(1, StrCurrentVideoIDs, lstGetAllControlID); break; } //上一页 case 2: { lstGetControl = vedio.GetVedioPageFront(1, StrCurrentVideoIDs, lstGetAllControlID); break; } } var result = JsonConvert.SerializeObject(lstGetControl); context.Response.Write(result); } else { context.Response.Write("没有视频信息!"); } } public bool IsReusable { get { return false; } } } }
model层写的sql语句
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using LD_Model.DB; using System.Data; using System.Reflection; using System.Data.SqlClient; namespace LD_Logic.IOT { public partial class DeviceControlLogic { public DeviceControlLogic() {} /// <summary> /// 添加修改气象站 /// </summary> /// <param name="info"></param> /// <returns></returns> public bool Save(DeviceControlDB info) { if (info.ID > 0) { return DeviceControlDB.Data.Update(info); } else { return DeviceControlDB.Data.Insert(info); } } /// <summary> /// 根据ID删除气象站 /// </summary> /// <param name="ID"></param> /// <returns></returns> public bool Delete(int ID) { return DeviceControlDB.Data.Delete(ID); } /// <summary> /// 根据ID获取一个实体 /// </summary> /// <param name="ID"></param> /// <returns></returns> public DeviceControlDB GetModel(int ID) { return DeviceControlDB.Data.Where(o => o.ID == ID).ToInfo(); } /// <summary> /// 获取所有信息 /// </summary> /// <returns></returns> public List<DeviceControlDB> GetList() { return DeviceControlDB.Data.Where(o => o.IDeviceType == LD_Model.DB.DeviceControlDB.eumIDeviceType.Sensor).ToList(); } /// <summary> /// 视频 /// </summary> /// <param name="lstGetControlID"></param> /// <param name="count"></param> /// <returns></returns> public List<DeviceControlDB> GetVideo(List<int?> lstGetControlID, int count) { StringBuilder strSql = new StringBuilder(); string StrIDs = string.Join(",",lstGetControlID.ToArray()); strSql.AppendFormat(" select top {1} * from dbo.TB_Device_Control where ID in ({0}) order by ID desc ", StrIDs,count); var dataset = LD_Logic.IOT.Common.CommonDAL.Query(strSql.ToString()); return DataSetToIList<DeviceControlDB>(dataset, 0); } /// <summary> /// 视频翻页(下一页) /// ids当前视频的ID,lstGetControlID为当前基地下所有的视频ID /// </summary> public List<DeviceControlDB> GetVedioPageNext(int vedioCount, string StrIds, List<int?> lstGetControlID) { StringBuilder strSql = new StringBuilder(); //string StrIds = string.Join(",", ids.ToArray()); string StrControlIds = string.Join(",", lstGetControlID.ToArray()); strSql.AppendFormat(" select top {0} * from dbo.TB_Device_Control where ID in ({2}) and ID < (select MIN(ID) from dbo.TB_Device_Control where ID in ({1}) ) order by ID desc ", vedioCount, StrIds, StrControlIds); var dataset = LD_Logic.IOT.Common.CommonDAL.Query(strSql.ToString()); return DataSetToIList<DeviceControlDB>(dataset, 0); } /// <summary> /// 视频翻页(上一页) /// </summary> public List<DeviceControlDB> GetVedioPageFront(int vedioCount, string StrIds, List<int?> lstGetControlID) { StringBuilder strSql = new StringBuilder(); //string StrIds = string.Join(",", ids.ToArray()); string StrControlIds = string.Join(",", lstGetControlID.ToArray()); strSql.AppendFormat(" select top {0} * from dbo.TB_Device_Control where ID in ({2}) and ID > (select max(ID) from dbo.TB_Device_Control where ID in ({1})) order by ID asc ", vedioCount, StrIds, StrControlIds); var dataset = LD_Logic.IOT.Common.CommonDAL.Query(strSql.ToString()); return DataSetToIList<DeviceControlDB>(dataset, 0); } /// <summary> /// 右上角预警信息浮动同一传感器只显示最新一条数据 /// </summary> public List<AlarmLogDB> lstAlarmInfo(int CID) { StringBuilder strSql = new StringBuilder(); strSql.AppendFormat("select * from dbo.TB_AlarmLog a where exists(select * from (select DeviceID,max(AlarmAt) as FTime from dbo.TB_AlarmLog group by DeviceID) x where x.DeviceID=a.DeviceID and a.AlarmAt=x.FTime and CID= {0} )", CID); var dataset = LD_Logic.IOT.Common.CommonDAL.Query(strSql.ToString()); return DataSetToIList<AlarmLogDB>(dataset, 0); } /// <summary> /// DataSet装换为泛型集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="p_DataSet">DataSet</param> /// <param name="p_TableIndex">待转换数据表索引</param> /// <returns></returns> public static List<T> DataSetToIList<T>(DataSet p_DataSet, int p_TableIndex) { if (p_DataSet == null || p_DataSet.Tables.Count < 0) return null; if (p_TableIndex > p_DataSet.Tables.Count - 1) return null; if (p_TableIndex < 0) p_TableIndex = 0; DataTable p_Data = p_DataSet.Tables[p_TableIndex]; // 返回值初始化 List<T> result = new List<T>(); for (int j = 0; j < p_Data.Rows.Count; j++) { T _t = (T)Activator.CreateInstance(typeof(T)); PropertyInfo[] propertys = _t.GetType().GetProperties(); foreach (PropertyInfo pi in propertys) { for (int i = 0; i < p_Data.Columns.Count; i++) { // 属性与字段名称一致的进行赋值 (枚举类型无法转换,单独拎出来) if (pi.Name.Equals(p_Data.Columns[i].ColumnName)) { if (pi.Name == "IDeviceType") { pi.SetValue(_t, DeviceControlDB.eumIDeviceType.Video, null); } else if (pi.Name == "Status") { if (p_Data.Rows[j][i] != DBNull.Value) { if (Convert.ToInt32(p_Data.Rows[j][i]) == 0) { pi.SetValue(_t, DeviceControlDB.eumStatusType.Error, null); } else if (Convert.ToInt32(p_Data.Rows[j][i]) == 2) { pi.SetValue(_t, DeviceControlDB.eumStatusType.Warning, null); } else { pi.SetValue(_t, DeviceControlDB.eumStatusType.Normal, null); } } } else if (pi.Name == "AlarmType") { pi.SetValue(_t, LD_Entity.enums.eumAlarmType.Warning, null); } else if (pi.Name == "AlarmStatus") { pi.SetValue(_t, LD_Entity.enums.eumAlarmStatusType.High, null); } else { // 数据库NULL值单独处理 if (p_Data.Rows[j][i] != DBNull.Value) pi.SetValue(_t, p_Data.Rows[j][i], null); else pi.SetValue(_t, null, null); } break; } } } result.Add(_t); } return result; } } }
时间: 2024-10-31 06:32:13