220 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			220 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using BLL; | |||
|  | using Newtonsoft.Json; | |||
|  | using Newtonsoft.Json.Linq; | |||
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Configuration; | |||
|  | using System.Data; | |||
|  | using System.Data.SqlClient; | |||
|  | using System.Linq; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.ProjectData | |||
|  | { | |||
|  |     public partial class ProjectMonitorList : PageBase | |||
|  |     { | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 定义项 | |||
|  |         /// </summary> | |||
|  |         public string ProjectCode | |||
|  |         { | |||
|  |             get | |||
|  |             { | |||
|  |                 return (string)ViewState["ProjectCode"]; | |||
|  |             } | |||
|  |             set | |||
|  |             { | |||
|  |                 ViewState["ProjectCode"] = value; | |||
|  |             } | |||
|  |         } | |||
|  |         public string Id | |||
|  |         { | |||
|  |             get | |||
|  |             { | |||
|  |                 return (string)ViewState["Id"]; | |||
|  |             } | |||
|  |             set | |||
|  |             { | |||
|  |                 ViewState["Id"] = value; | |||
|  |             } | |||
|  |         } | |||
|  |         public string Devices | |||
|  |         { | |||
|  |             get | |||
|  |             { | |||
|  | 				var sysSet16 = (from x in Funs.DB.Sys_Set where x.SetName == "视频监控地址" select x).ToList().FirstOrDefault();   | |||
|  | 				string url = sysSet16.SetValue; | |||
|  |                 string res = APIGetHttpService.Http(url + "api/v1/user/channellist?token=" + URLToken + "&id=" + Id + "&related=true"); | |||
|  |                 string devices = ""; | |||
|  |                 JObject jObject = (JObject)JsonConvert.DeserializeObject(res); | |||
|  |                 JArray channelList = jObject.Value<JArray>("ChannelList"); | |||
|  |                 HashSet<string> set = new HashSet<string>(); | |||
|  |                 foreach (var c in channelList) | |||
|  |                 { | |||
|  |                     set.Add(c["DeviceID"] + ":" + c["ID"]); | |||
|  |                 } | |||
|  |                 if (set.Count > 0) | |||
|  |                 { | |||
|  |                     devices = string.Join(",", set); | |||
|  |                 } | |||
|  |                 return devices; | |||
|  |             } | |||
|  |             set | |||
|  |             { | |||
|  |                 ViewState["Devices"] = value; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 定义项 | |||
|  |         /// </summary> | |||
|  |         public string URLToken | |||
|  |         { | |||
|  |             get | |||
|  |             { | |||
|  |                 return (string)ViewState["URLToken"]; | |||
|  |             } | |||
|  |             set | |||
|  |             { | |||
|  |                 ViewState["URLToken"] = value; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 加载 | |||
|  |         /// <summary> | |||
|  |         /// 加载页面 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 this.ProjectCode = Request.QueryString["ProjectCode"]; | |||
|  |                 this.URLToken = Request.QueryString["URLToken"]; | |||
|  |                 this.Id = Request.QueryString["Id"]; | |||
|  |                 Funs.DropDownPageSize(this.ddlPageSize); | |||
|  |                 if (this.CurrUser != null && this.CurrUser.PageSize.HasValue) | |||
|  |                 { | |||
|  |                     Grid1.PageSize = this.CurrUser.PageSize.Value; | |||
|  |                 } | |||
|  |                 this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); | |||
|  |                 // 绑定表格 | |||
|  |                 | |||
|  |                 this.BindGrid(); | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 绑定数据 | |||
|  |         /// <summary> | |||
|  |         /// 绑定数据 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid() | |||
|  | 		{ | |||
|  | 			var sysSet16 = (from x in Funs.DB.Sys_Set where x.SetName == "视频监控地址" select x).ToList().FirstOrDefault(); | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 			DataTable dt = new DataTable(); | |||
|  |             dt.Columns.Add("id"); | |||
|  |             dt.Columns.Add("name"); | |||
|  |             dt.Columns.Add("serial"); | |||
|  |             dt.Columns.Add("deviceName"); | |||
|  |             string url = sysSet16.SetValue; | |||
|  |             List<string> urls = new List<string>(); | |||
|  |             string res = APIGetHttpService.Http(url + "api/v1/device/channeltree?token=" + URLToken); | |||
|  | 
 | |||
|  |             List<Dictionary<string, string>> jsonNvr = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(res); | |||
|  |             foreach (Dictionary<string, string> nvr in jsonNvr) | |||
|  |             { | |||
|  |                 if (string.IsNullOrEmpty(txtProjectName.Text.Trim()) || nvr["customName"].Contains(txtProjectName.Text.Trim())) | |||
|  |                 { | |||
|  |                     string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?token=" + URLToken + "&serial=" + nvr["serial"]); | |||
|  |                     List<Dictionary<string, string>> jsonDiv = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jsonCameras); | |||
|  |                     foreach (Dictionary<string, string> div in jsonDiv) | |||
|  |                     { | |||
|  |                         var rowDiv = dt.NewRow(); | |||
|  |                         rowDiv["id"] = div["id"]; | |||
|  |                         rowDiv["deviceName"] = nvr["customName"]; | |||
|  |                         if (!string.IsNullOrEmpty(div["customName"])) | |||
|  |                         { | |||
|  |                             rowDiv["name"] = div["customName"]; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             rowDiv["name"] = div["name"]; | |||
|  |                         } | |||
|  |                         rowDiv["serial"] = div["code"]; | |||
|  | 
 | |||
|  |                         dt.Rows.Add(rowDiv); | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |             Grid1.RecordCount = dt.Rows.Count; | |||
|  |             Grid1.DataSource = this.GetPagedDataTable(Grid1, dt); | |||
|  |             Grid1.DataBind(); | |||
|  |             if (!string.IsNullOrEmpty(Devices)) | |||
|  |             { | |||
|  |                 Grid1.SelectedRowIDArray = Devices.Split(','); | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region Grid | |||
|  |         /// <summary> | |||
|  |         ///  | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         ///  | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  | 
 | |||
|  |             Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  | 
 | |||
|  |         protected void btnSearch_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  |         protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e) | |||
|  |         { | |||
|  | 			var sysSet16 = (from x in Funs.DB.Sys_Set where x.SetName == "视频监控地址" select x).ToList().FirstOrDefault(); | |||
|  | 			string url = sysSet16.SetValue; | |||
|  |             APIGetHttpService.Http(url + "api/v1/user/savechannels?token=" + URLToken + "&id=" + Id + "&channels[]=" + e.RowID);            | |||
|  |              | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         protected void Grid1_RowDeselect(object sender, GridRowSelectEventArgs e) | |||
|  |         { | |||
|  | 			var sysSet16 = (from x in Funs.DB.Sys_Set where x.SetName == "视频监控地址" select x).ToList().FirstOrDefault(); | |||
|  | 			string url = sysSet16.SetValue;			  | |||
|  |             APIGetHttpService.Http(url + "api/v1/user/removechannels?token=" + URLToken + "&id=" + Id + "&channels[]=" + e.RowID);            | |||
|  |         } | |||
|  |     } | |||
|  | } |