using HDL_ON.Entity;
|
using Shared;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace HDL_ON
|
{
|
/// <summary>
|
/// 楼层及房间的选择界面
|
/// </summary>
|
public class FloorRoomSelectPopupView
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 当前选择显示的UID(楼层,或者房间,或者全部)
|
/// </summary>
|
private string nowShowSelectId = DiySelectPopupDialog.ALLSELECT;
|
/// <summary>
|
/// 全部的功能(设备显示分支使用)
|
/// </summary>
|
private List<Function> listAllFun = null;
|
|
#endregion
|
|
#region ■ 场景显示___________________________
|
|
/// <summary>
|
/// 显示选择场景的界面
|
/// </summary>
|
/// <param name="btnFloor">楼层名字显示的控件,选择后,内部会自动变更显示文字,可以设置为null</param>
|
/// <param name="SelectEvent">根据选择的条件,筛选之后的场景列表(第一个参数是选择的UID,不管有没有用,总之先返回)</param>
|
/// <param name="i_defultSelectId">默认哪个为选择状态</param>
|
public void ShowSceneView(Button btnFloor, Action<string, List<Scene>> SelectEvent, string i_defultSelectId = null)
|
{
|
//清缓存
|
this.ClearMemory();
|
|
if (string.IsNullOrEmpty(i_defultSelectId) == true)
|
{
|
i_defultSelectId = DiySelectPopupDialog.ALLSELECT;
|
}
|
|
//返回的id是UID
|
new FloorSelectPopupDialog().ShowView((selectValue) =>
|
{
|
this.nowShowSelectId = selectValue;
|
//刷新楼层的显示名字
|
this.RefreshFloorShowName(btnFloor);
|
|
//获取可以显示的场景列表
|
var listScene = this.GetCanShowListScene();
|
SelectEvent?.Invoke(this.nowShowSelectId, listScene);
|
SelectEvent = null;
|
|
}, i_defultSelectId);
|
}
|
|
/// <summary>
|
/// 获取能够显示的场景
|
/// </summary>
|
/// <returns></returns>
|
public List<Scene> GetCanShowListScene()
|
{
|
var listScene = new List<Scene>();
|
|
//先看看当前选择的显示类型 1:全部 2:楼层 3:房间
|
var selectType = this.CheckSelectFloorIdType();
|
if (selectType == 1)
|
{
|
return FunctionList.List.scenes;
|
}
|
|
//房间的UID (key:uid value:roomId)
|
var dicRoomUid = new Dictionary<string, string>();
|
foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
|
{
|
dicRoomUid[roomInfo.uid] = roomInfo.roomId;
|
}
|
//房间
|
if (selectType == 3)
|
{
|
//用UID转换为roomId
|
string roomId = dicRoomUid.ContainsKey(this.nowShowSelectId) == true ? dicRoomUid[this.nowShowSelectId] : string.Empty;
|
foreach (var scene in FunctionList.List.scenes)
|
{
|
//判断这个场景是否是这个房间的
|
if (scene.roomIds.Contains(roomId) == true)
|
{
|
listScene.Add(scene);
|
}
|
}
|
}
|
//楼层
|
else if (selectType == 2)
|
{
|
//获取这个楼层下面的全部房间ID
|
var listRoomId = new List<string>();
|
foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
|
{
|
//判断是不是这个楼层的
|
if (roomInfo.parentId == this.nowShowSelectId)
|
{
|
listRoomId.Add(roomInfo.roomId);
|
}
|
}
|
foreach (var scene in FunctionList.List.scenes)
|
{
|
//判断这个场景是否是这个房间的
|
foreach (var roomid in listRoomId)
|
{
|
if (scene.roomIds.Contains(roomid) == true)
|
{
|
listScene.Add(scene);
|
}
|
}
|
}
|
}
|
return listScene;
|
}
|
|
#endregion
|
|
#region ■ 设备显示___________________________
|
|
/// <summary>
|
/// 显示选择场景的界面
|
/// </summary>
|
/// <param name="btnFloor">楼层名字显示的控件,选择后,内部会自动变更显示文字,可以设置为null</param>
|
/// <param name="i_listAllFun">全部的设备列表,需要手动指定</param>
|
/// <param name="SelectEvent">根据选择的条件,筛选之后的设备列表(第一个参数是选择的UID,不管有没有用,总之先返回)</param>
|
/// <param name="i_defultSelectId">默认哪个为选择状态</param>
|
public void ShowDeviceFunctionView(Button btnFloor, List<Function> i_listAllFun, Action<string, List<Function>> SelectEvent, string i_defultSelectId = null)
|
{
|
//清缓存
|
this.ClearMemory();
|
this.listAllFun = new List<Function>();
|
this.listAllFun.AddRange(i_listAllFun);
|
|
if (string.IsNullOrEmpty(i_defultSelectId) == true)
|
{
|
i_defultSelectId = DiySelectPopupDialog.ALLSELECT;
|
}
|
|
//返回的id是UID
|
new FloorSelectPopupDialog().ShowView((selectValue) =>
|
{
|
this.nowShowSelectId = selectValue;
|
//刷新楼层的显示名字
|
this.RefreshFloorShowName(btnFloor);
|
|
//获取可以显示的设备列表
|
var listDevice = this.GetCanShowListDevice();
|
SelectEvent?.Invoke(this.nowShowSelectId, listDevice);
|
SelectEvent = null;
|
|
}, i_defultSelectId);
|
}
|
|
/// <summary>
|
/// 获取能够显示的设备
|
/// </summary>
|
/// <returns></returns>
|
public List<Function> GetCanShowListDevice()
|
{
|
var listFunction = new List<Function>();
|
|
//先看看当前选择的显示类型 1:全部 2:楼层 3:房间
|
var selectType = this.CheckSelectFloorIdType();
|
if (selectType == 1)
|
{
|
return this.listAllFun;
|
}
|
|
//房间的UID (key:uid value:roomId)
|
var dicRoomUid = new Dictionary<string, string>();
|
foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
|
{
|
dicRoomUid[roomInfo.uid] = roomInfo.roomId;
|
}
|
//房间
|
if (selectType == 3)
|
{
|
//用UID转换为roomId
|
string roomId = dicRoomUid.ContainsKey(this.nowShowSelectId) == true ? dicRoomUid[this.nowShowSelectId] : string.Empty;
|
foreach (var func in this.listAllFun)
|
{
|
//判断这个场景是否是这个房间的
|
if (func.roomIds.Contains(roomId) == true)
|
{
|
listFunction.Add(func);
|
}
|
}
|
}
|
//楼层
|
else if (selectType == 2)
|
{
|
//获取这个楼层下面的全部房间ID
|
var listRoomId = new List<string>();
|
foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
|
{
|
//判断是不是这个楼层的
|
if (roomInfo.parentId == this.nowShowSelectId)
|
{
|
listRoomId.Add(roomInfo.roomId);
|
}
|
}
|
foreach (var func in this.listAllFun)
|
{
|
//判断这个场景是否是这个房间的
|
foreach (var roomid in listRoomId)
|
{
|
if (func.roomIds.Contains(roomid) == true)
|
{
|
listFunction.Add(func);
|
}
|
}
|
}
|
}
|
return listFunction;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 刷新楼层的显示名字
|
/// </summary>
|
/// <param name="btnFloorName"></param>
|
private void RefreshFloorShowName(Button btnFloorName)
|
{
|
if (btnFloorName == null)
|
{
|
return;
|
}
|
//先看看当前选择的显示类型 1:全部 2:楼层 3:房间
|
var selectType = this.CheckSelectFloorIdType();
|
if (selectType == 1)
|
{
|
//全部
|
btnFloorName.Text = Language.StringByID(StringId.All);
|
}
|
//房间
|
else if (selectType == 3)
|
{
|
foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
|
{
|
if (roomInfo.uid == this.nowShowSelectId)
|
{
|
btnFloorName.Text = roomInfo.floorName + roomInfo.roomName;
|
return;
|
}
|
}
|
}
|
//楼层
|
else if (selectType == 2)
|
{
|
foreach (var floorInfo in SpatialInfo.CurrentSpatial.FloorList)
|
{
|
if (floorInfo.uid == this.nowShowSelectId)
|
{
|
btnFloorName.Text = floorInfo.roomName;
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 判断当前所选的ID的类型 1:全部 2:楼层 3:房间
|
/// </summary>
|
/// <returns></returns>
|
private int CheckSelectFloorIdType()
|
{
|
if (this.nowShowSelectId == DiySelectPopupDialog.ALLSELECT)
|
{
|
//全部
|
return 1;
|
}
|
foreach (var floorInfo in SpatialInfo.CurrentSpatial.FloorList)
|
{
|
if (floorInfo.uid == this.nowShowSelectId)
|
{
|
//当前选择的是楼层ID
|
return 2;
|
}
|
}
|
//不出意外,应该是房间了
|
return 3;
|
}
|
|
/// <summary>
|
/// 清除缓存
|
/// </summary>
|
public void ClearMemory()
|
{
|
//初始值
|
this.nowShowSelectId = DiySelectPopupDialog.ALLSELECT;
|
this.listAllFun = null;
|
}
|
|
#endregion
|
}
|
}
|