New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.Safety
|
| | | {
|
| | | /// <summary>
|
| | | /// 添加报警目标菜单列表的画面
|
| | | /// </summary>
|
| | | public class AlarmTargetAddMenuForm : EditorCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 防区ID(这个东西似乎是唯一的)
|
| | | /// </summary>
|
| | | private int zoonID = 0;
|
| | | /// <summary>
|
| | | /// 列表控件
|
| | | /// </summary>
|
| | | private VerticalListControl listView = null;
|
| | | /// <summary>
|
| | | /// 全部的数据(keys1:房间ID Keys2:R文件的数值)
|
| | | /// </summary>
|
| | | private Dictionary<string, Dictionary<int, uRowInformation>> dicAllData = new Dictionary<string, Dictionary<int, uRowInformation>>();
|
| | | /// <summary>
|
| | | /// 当前选择的楼层ID
|
| | | /// </summary>
|
| | | private string nowSelectFloorId = string.Empty;
|
| | | /// <summary>
|
| | | /// 当前选择的房间
|
| | | /// </summary>
|
| | | private Common.Room nowSelectRoom = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
| | | /// </summary>
|
| | | /// <param name="i_zoonID">防区ID</param>
|
| | | public void ShowForm(int i_zoonID)
|
| | | {
|
| | | this.zoonID = i_zoonID;
|
| | |
|
| | | //设置头部信息
|
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddAlarmTarget));
|
| | |
|
| | | //初始化右上角的控件
|
| | | this.InitTopRightMenuControl();
|
| | |
|
| | | //初始化中部信息
|
| | | this.InitMiddleFrame();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化中部信息
|
| | | /// </summary>
|
| | | private void InitMiddleFrame()
|
| | | {
|
| | | //清空bodyFrame
|
| | | this.ClearBodyFrame();
|
| | | this.nowSelectRoom = null;
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //获取设备的所有类型,并整理成每一行的数据
|
| | | this.dicAllData = this.GetAllListData();
|
| | | if (dicAllData.Count == 0)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //没有可以添加的目标
|
| | | this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget));
|
| | | });
|
| | | return;
|
| | | }
|
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //初始化房间和设备控件
|
| | | this.InitRoomAndDeviceControl();
|
| | | });
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化房间和设备控件
|
| | | /// </summary>
|
| | | private void InitRoomAndDeviceControl()
|
| | | {
|
| | | var listRoom = new List<Common.Room>();
|
| | | foreach (string roomId in this.dicAllData.Keys)
|
| | | {
|
| | | listRoom.Add(HdlRoomLogic.Current.GetRoomById(roomId));
|
| | | }
|
| | |
|
| | | //初始化房间菜单控件
|
| | | var frameBack = new FrameLayout();
|
| | | frameBack.Height = Application.GetRealHeight(204);
|
| | | bodyFrameLayout.AddChidren(frameBack);
|
| | | var roomMuneContr = new RoomDeviceGroupMenuControl(listRoom);
|
| | | roomMuneContr.Gravity = Gravity.CenterVertical;
|
| | | frameBack.AddChidren(roomMuneContr);
|
| | | roomMuneContr.SelectRoomEvent += (selectRoom) =>
|
| | | {
|
| | | //记录当前选择的房间
|
| | | this.nowSelectRoom = selectRoom;
|
| | | //还原列表高度
|
| | | listView.Height = bodyFrameLayout.Height - frameBack.Bottom;
|
| | | //初始化行控件
|
| | | this.InitRowControl(dicAllData[selectRoom.Id]);
|
| | | };
|
| | |
|
| | | this.listView = new VerticalListControl(29);
|
| | | listView.Y = frameBack.Bottom;
|
| | | listView.Height = bodyFrameLayout.Height - frameBack.Bottom;
|
| | | listView.BackgroundColor = UserCenterColor.Current.White;
|
| | | bodyFrameLayout.AddChidren(this.listView);
|
| | |
|
| | | //开始初始化房间控件,然后它会根据默认值调用回调函数
|
| | | roomMuneContr.InitControl();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化右上角的控件
|
| | | /// </summary>
|
| | | private void InitTopRightMenuControl()
|
| | | {
|
| | | //获取楼层
|
| | | var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
|
| | | if (dicFloor.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | var btnIconContr = new MostRightIconControl(69, 69);
|
| | | btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
|
| | | topFrameLayout.AddChidren(btnIconContr);
|
| | | btnIconContr.InitControl();
|
| | |
|
| | | var btnFloor = new NormalViewControl(300, 69, true);
|
| | | btnFloor.Gravity = Gravity.CenterVertical;
|
| | | btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
|
| | | btnFloor.TextAlignment = TextAlignment.CenterRight;
|
| | | btnFloor.IsBold = true;
|
| | | topFrameLayout.AddChidren(btnFloor);
|
| | |
|
| | | foreach (var floorId in dicFloor.Keys)
|
| | | {
|
| | | //第一个楼层
|
| | | this.nowSelectFloorId = floorId;
|
| | | btnFloor.Text = dicFloor[floorId];
|
| | | break;
|
| | | }
|
| | |
|
| | | btnIconContr.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //楼层菜单
|
| | | var contr = new TopRightFloorMenuControl(dicFloor.Count, 2, Language.StringByID(R.MyInternationalizationString.SelectFloor));
|
| | | foreach (var floorId in dicFloor.Keys)
|
| | | {
|
| | | contr.AddRowMenu(floorId, () =>
|
| | | {
|
| | | //记录起选择的ID
|
| | | this.nowSelectFloorId = floorId;
|
| | | btnFloor.Text = dicFloor[this.nowSelectFloorId];
|
| | | //初始化中部信息
|
| | | this.InitMiddleFrame();
|
| | | });
|
| | | }
|
| | | };
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 添加行_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化行控件
|
| | | /// </summary>
|
| | | /// <param name="dicRowData"></param>
|
| | | private void InitRowControl(Dictionary<int, uRowInformation> dicRowData)
|
| | | {
|
| | | this.listView.RemoveAll();
|
| | | HdlThreadLogic.Current.RunMainInThread(() =>
|
| | | {
|
| | | int count = 0;
|
| | | foreach (var textId in dicRowData.Keys)
|
| | | {
|
| | | count++;
|
| | | var rowData = dicRowData[textId];
|
| | |
|
| | | var rowlayout = new FrameRowControl(listView.rowSpace / 2);
|
| | | listView.AddChidren(rowlayout);
|
| | | //图标
|
| | | var btnIcon = rowlayout.AddLeftIcon(81);
|
| | | btnIcon.UnSelectedImagePath = rowData.IconPath;
|
| | |
|
| | | //设备名
|
| | | var txtDevice = rowlayout.AddLeftCaption(Language.StringByID(textId), 750);
|
| | | txtDevice.TextSize = 15;
|
| | | //向右图标
|
| | | rowlayout.AddRightArrow();
|
| | | if (count != dicRowData.Count)
|
| | | {
|
| | | //底线
|
| | | rowlayout.AddBottomLine();
|
| | | }
|
| | |
|
| | | //单击事件
|
| | | rowlayout.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | if (rowData.listScene == null)
|
| | | {
|
| | | //设备的一览
|
| | | var form = new AlarmTargetAddDeviceForm();
|
| | | form.AddForm(this.zoonID, txtDevice.Text, rowData.listDevice);
|
| | | }
|
| | | else
|
| | | {
|
| | | //场景的一览
|
| | | var form = new AlarmTargetAddSceneForm();
|
| | | form.AddForm(this.zoonID, rowData.listScene);
|
| | | }
|
| | | };
|
| | | }
|
| | | //调整真实高度
|
| | | this.listView.AdjustRealHeight(Application.GetRealHeight(23));
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取数据___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备的所有类型,并整理成每一行的数据(keys1:房间ID Keys2:R文件的数值)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private Dictionary<string, Dictionary<int, uRowInformation>> GetAllListData()
|
| | | {
|
| | | var dicData = new Dictionary<string, Dictionary<int, uRowInformation>>();
|
| | | //获取本地安防的场景
|
| | | Dictionary<int, string> dicScene = HdlSafeguardLogic.Current.GetLocalSceneByZoneID(this.zoonID);
|
| | | var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(this.nowSelectFloorId);
|
| | |
|
| | | for (int i = 0; i < listRoom.Count; i++)
|
| | | {
|
| | | //获取房间的设备和场景数据
|
| | | var dicRoomData = this.GetRoomDeviceAndSceneData(listRoom[i], dicScene);
|
| | | if (dicRoomData.Count > 0)
|
| | | {
|
| | | dicData[listRoom[i].Id] = dicRoomData;
|
| | | }
|
| | | }
|
| | | return dicData;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取房间里面的设备和场景数据
|
| | | /// </summary>
|
| | | /// <param name="i_room"></param>
|
| | | /// <param name="dicScene"></param>
|
| | | /// <returns></returns>
|
| | | private Dictionary<int, uRowInformation> GetRoomDeviceAndSceneData(Common.Room i_room, Dictionary<int, string> dicScene)
|
| | | {
|
| | | if (dicScene == null)
|
| | | {
|
| | | //获取本地安防的场景
|
| | | dicScene = HdlSafeguardLogic.Current.GetLocalSceneByZoneID(this.zoonID);
|
| | | }
|
| | | var dicRoomData = new Dictionary<int, uRowInformation>();
|
| | |
|
| | | for (int j = 0; j < i_room.ListDevice.Count; j++)
|
| | | {
|
| | | var device = Common.LocalDevice.Current.GetDevice(i_room.ListDevice[j]);
|
| | | //如果那个设备已经添加了,则不再显示
|
| | | if (device == null || 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 unSelectPath = string.Empty;
|
| | | string selectPath = string.Empty;
|
| | |
|
| | | var typeInfo = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device);
|
| | | //获取图片
|
| | | Common.LocalDevice.Current.GetDeviceObjectIcon(typeInfo.ConcreteType, ref unSelectPath, ref selectPath);
|
| | | if (dicRoomData.ContainsKey(typeInfo.BeloneTextId) == false)
|
| | | {
|
| | | dicRoomData[typeInfo.BeloneTextId] = new uRowInformation();
|
| | | dicRoomData[typeInfo.BeloneTextId].IconPath = unSelectPath;
|
| | | }
|
| | | dicRoomData[typeInfo.BeloneTextId].listDevice.Add(device);
|
| | | }
|
| | | }
|
| | | for (int j = 0; j < i_room.ListSceneId.Count; j++)
|
| | | {
|
| | | //如果那个场景已经添加了,则不再显示
|
| | | if (dicScene.ContainsKey(i_room.ListSceneId[j]) == true)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | var sceneUi = HdlSceneLogic.Current.GetSceneUIBySceneId(i_room.ListSceneId[j]);
|
| | | if (sceneUi == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | if (dicRoomData.ContainsKey(R.MyInternationalizationString.uScence) == false)
|
| | | {
|
| | | dicRoomData[R.MyInternationalizationString.uScence] = new uRowInformation();
|
| | | dicRoomData[R.MyInternationalizationString.uScence].IconPath = "Scene/SceneIcon.png";
|
| | | dicRoomData[R.MyInternationalizationString.uScence].listScene = new List<Common.SceneUI>();
|
| | | }
|
| | | dicRoomData[R.MyInternationalizationString.uScence].listScene.Add(sceneUi);
|
| | | }
|
| | | return dicRoomData;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 界面重新激活事件___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
|
| | | /// </summary>
|
| | | public override int FormActionAgainEvent()
|
| | | {
|
| | | //重新获取房间数据
|
| | | var dicData = this.GetRoomDeviceAndSceneData(this.nowSelectRoom, null);
|
| | | if (dicAllData.Count == 1 && dicData.Count == 0)
|
| | | {
|
| | | //这个房间,已经没有可选择的东西了
|
| | | dicAllData.Remove(this.nowSelectRoom.Id);
|
| | |
|
| | | //没有可以添加的目标
|
| | | this.ClearBodyFrame();
|
| | | this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget));
|
| | | return 1;
|
| | | }
|
| | | if (dicData.Count > 0)
|
| | | {
|
| | | //覆盖缓存
|
| | | dicAllData[this.nowSelectRoom.Id] = dicData;
|
| | | //重新刷新这个房间的设备列表
|
| | | this.InitRowControl(dicData);
|
| | | }
|
| | | else
|
| | | {
|
| | | //这个房间,已经没有可选择的东西了
|
| | | dicAllData.Remove(this.nowSelectRoom.Id);
|
| | | //清空bodyFrame
|
| | | this.ClearBodyFrame();
|
| | | //切换到别的房间
|
| | | this.InitRoomAndDeviceControl();
|
| | | }
|
| | |
|
| | | return 1;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 自定义结构体_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 每一行的行数据
|
| | | /// </summary>
|
| | | private class uRowInformation
|
| | | {
|
| | | /// <summary>
|
| | | /// 图标地址
|
| | | /// </summary>
|
| | | public string IconPath = string.Empty;
|
| | | /// <summary>
|
| | | /// 设备列表信息
|
| | | /// </summary>
|
| | | public List<CommonDevice> listDevice = new List<CommonDevice>();
|
| | | /// <summary>
|
| | | /// 场景
|
| | | /// </summary>
|
| | | public List<Common.SceneUI> listScene = null;
|
| | | }
|
| | | #endregion
|
| | | }
|
| | | }
|