using System; using System.Collections.Generic; using ZigBee.Device; namespace Shared.Phone.UserCenter.Safety { /// /// 添加报警目标菜单列表的画面 /// public class AddAlarmTargetTypeListForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 防区ID(这个东西似乎是唯一的) /// private int zoonID = 0; /// /// 列表控件 /// private VerticalListControl listView = null; /// /// 全部设备信息 /// private List listAllDeviceInfo = new List(); #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 防区ID public void ShowForm(int i_zoonID) { this.zoonID = i_zoonID; //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddAlarmTarget)); //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); //设置中间部分信息 this.SetMiddleInfo(); } /// /// 设置中间部分信息 /// private void SetMiddleInfo() { HdlThreadLogic.Current.RunThread(() => { //获取设备的所有类型,并整理成每一行的数据 this.GetAllListData(); if (listAllDeviceInfo.Count == 0) { return; } Application.RunOnMainThread(() => { int realHeight = (ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29)) * listAllDeviceInfo.Count + Application.GetRealHeight(23); if (realHeight > bodyFrameLayout.Height + Application.GetRealHeight(6)) { //计算真实高度 realHeight = bodyFrameLayout.Height + Application.GetRealHeight(6); } this.listView = new VerticalListControl(29); listView.Y = Application.GetRealHeight(-6); listView.Height = realHeight; listView.BackgroundColor = UserCenterColor.Current.White; bodyFrameLayout.AddChidren(this.listView); //添加设备的行 int count = listAllDeviceInfo.Count - 1; for (int i = 0; i < listAllDeviceInfo.Count; i++) { this.AddRowLaout(listAllDeviceInfo[i], i != count); } }); }); } #endregion #region ■ 添加行_____________________________ /// /// 添加行 /// /// /// private void AddRowLaout(uRowInformation uRow, bool addLine) { var rowlayout = new FrameRowControl(listView.rowSpace / 2); listView.AddChidren(rowlayout); //图标 var btnIcon = rowlayout.AddLeftIcon(81); btnIcon.UnSelectedImagePath = uRow.IconUnSelectPath; //设备名 var txtDevice = rowlayout.AddLeftCaption(uRow.TextName, 750); txtDevice.Text = uRow.TextName; txtDevice.TextSize = 15; //向右图标 rowlayout.AddRightArrow(); if (addLine == true) { //底线 rowlayout.AddBottomLine(); } //单击事件 rowlayout.ButtonClickEvent += (sender, e) => { if (uRow.listScene == null) { //设备的一览 var form = new AddDeviceAlarmTargetListForm(); form.AddForm(this.zoonID, uRow.TextName, uRow.listDevice); } else { //场景的一览 var form = new AddSceneAlarmTargetListForm(); form.AddForm(this.zoonID, uRow.listScene); } }; } #endregion #region ■ 一般方法___________________________ /// /// 获取设备的所有类型,并整理成每一行的数据 /// private void GetAllListData() { Dictionary dic = new Dictionary(); this.listAllDeviceInfo.Clear(); var listDevice = Common.LocalDevice.Current.listAllDevice; foreach (CommonDevice device in listDevice) { //如果那个设备已经添加了,则不再显示 if (HdlSafeguardLogic.Current.IsAlarmDeviceExist(this.zoonID, device) == true) { continue; } if (device.Type == DeviceType.AirSwitch//空气开关 || device.Type == DeviceType.DimmableLight//调光器 || device.Type == DeviceType.ColorDimmableLight//彩灯 || device.Type == DeviceType.OnOffOutput//继电器 || device.Type == DeviceType.WindowCoveringDevice)//窗帘 { //显示文本 string KeysName = Common.LocalDevice.Current.GetDeviceObjectText(new List() { device }); uRowInformation infoRow = null; if (dic.ContainsKey(KeysName) == false) { //图标地址:点亮 string IconSelect = string.Empty; //图标地址:未点亮 string IconUnSelect = string.Empty; Common.LocalDevice.Current.GetDeviceBeloneIcon(new List() { device }, ref IconUnSelect, ref IconSelect); //第一次时,设置它的显示文本及设置它的图标 infoRow = new uRowInformation(); dic[KeysName] = infoRow; infoRow.TextName = KeysName; infoRow.IconSelectPath = IconSelect; infoRow.IconUnSelectPath = IconUnSelect; this.listAllDeviceInfo.Add(infoRow); } infoRow = dic[KeysName]; //设备收集 var info = new uDeviceInfo { RoomName = Shared.Common.Room.CurrentRoom.GetRoomNameByDevice(device), Device = device, MainKeys = device.DeviceAddr + device.DeviceEpoint.ToString() }; infoRow.listDevice.Add(info); } } //获取场景 Common.SceneRoomUI.GetAllSceneRoomUIList(); List listScene = Common.SceneRoomUI.AllSceneRoomUIList; if (listScene.Count == 0) { return; } //获取本地安防的场景 Dictionary dicScene = HdlSafeguardLogic.Current.GetLocalSceneByZoneID(this.zoonID); var SceneInfo = new uRowInformation(); SceneInfo.listScene = new List(); foreach (var data in listScene) { //如果那个场景已经添加了,则不再显示 if (dicScene.ContainsKey(data.sceneUI.Id) == true) { continue; } SceneInfo.listScene.Add(data); } if (SceneInfo.listScene.Count > 0) { SceneInfo.TextName = Language.StringByID(R.MyInternationalizationString.uScence); SceneInfo.IconUnSelectPath = "Item/Scene.png"; this.listAllDeviceInfo.Add(SceneInfo); } } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// public override int FormActionAgainEvent() { //重新刷新界面 this.InitMiddleFrame(); return 1; } #endregion #region ■ 自定义结构体_______________________ /// /// 每一行的行数据 /// private class uRowInformation { /// /// 图标地址:未点亮 /// public string IconUnSelectPath = string.Empty; /// /// 图标地址:点亮 /// public string IconSelectPath = string.Empty; /// /// 显示的内容 /// public string TextName = string.Empty; /// /// 设备列表信息 /// public List listDevice = new List(); /// /// 场景 /// public List listScene = null; } #endregion } }