New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.Residence
|
| | | {
|
| | | /// <summary>
|
| | | /// 查看房间配置的界面
|
| | | /// </summary>
|
| | | public class LookRoomSettionForm : EditorCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 查看的房间对象
|
| | | /// </summary>
|
| | | private Common.Room lookRoom = null;
|
| | | /// <summary>
|
| | | /// 桌布控件
|
| | | /// </summary>
|
| | | private NormalFrameLayout frameTable = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
| | | /// </summary>
|
| | | /// <param name="i_room">查看的房间对象</param>
|
| | | public void ShowForm(Common.Room i_room)
|
| | | {
|
| | | this.lookRoom = i_room;
|
| | |
|
| | | //设置头部信息
|
| | | base.SetTitleText(lookRoom.Name);
|
| | |
|
| | | //初始化中部信息
|
| | | this.InitMiddleFrame();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化中部信息
|
| | | /// </summary>
|
| | | private void InitMiddleFrame()
|
| | | {
|
| | | //清空bodyFrame
|
| | | this.ClearBodyFrame();
|
| | |
|
| | | //初始化桌布控件
|
| | | this.frameTable = new NormalFrameLayout();
|
| | | frameTable.Y = Application.GetRealHeight(187);
|
| | | frameTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(187);
|
| | | bodyFrameLayout.AddChidren(frameTable);
|
| | |
|
| | | //初始化分支控件
|
| | | this.InitSwitchControl();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化分支控件
|
| | | /// </summary>
|
| | | private void InitSwitchControl()
|
| | | {
|
| | | var tabControl = new SceneFunctionSwitchControl();
|
| | | tabControl.Y = Application.GetRealHeight(40);
|
| | | bodyFrameLayout.AddChidren(tabControl);
|
| | | tabControl.SelectTabEvent += (tabIndex) =>
|
| | | {
|
| | | if (tabIndex == 0)
|
| | | {
|
| | | //显示场景列表
|
| | | this.ShowSceneList();
|
| | | }
|
| | | else
|
| | | {
|
| | | //显示功能列表
|
| | | this.ShowFunctionList();
|
| | | }
|
| | | };
|
| | | var listTitle = new List<string>();
|
| | | //场景,功能
|
| | | listTitle.Add(Language.StringByID(R.MyInternationalizationString.uScence));
|
| | | listTitle.Add(Language.StringByID(R.MyInternationalizationString.uFunction));
|
| | | tabControl.InitControl(listTitle);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 场景显示___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 显示场景列表
|
| | | /// </summary>
|
| | | private void ShowSceneList()
|
| | | {
|
| | | //清空桌布
|
| | | this.frameTable.RemoveAll();
|
| | | HdlThreadLogic.Current.RunMainInThread(() =>
|
| | | {
|
| | | if (lookRoom.ListSceneId.Count == 0)
|
| | | {
|
| | | //还没有添加场景哦
|
| | | this.ShowNotDataImage(frameTable, Language.StringByID(R.MyInternationalizationString.uDoNotHadAddScenceMsg));
|
| | | return;
|
| | | }
|
| | | var listView = new VerticalFrameControl(3);
|
| | | listView.Height = frameTable.Height;
|
| | | frameTable.AddChidren(listView);
|
| | |
|
| | | foreach (var dataId in lookRoom.ListSceneId)
|
| | | {
|
| | | var data = HdlSceneLogic.Current.GetSceneUIBySceneId(dataId);
|
| | | if (data == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | //场景控件
|
| | | var frameContr = new ScenePictrueControl();
|
| | | listView.AddChidren(frameContr);
|
| | | frameContr.InitControl(data);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 功能显示___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 显示功能列表
|
| | | /// </summary>
|
| | | private void ShowFunctionList()
|
| | | {
|
| | | //清空桌布
|
| | | this.frameTable.RemoveAll();
|
| | |
|
| | | HdlThreadLogic.Current.RunMainInThread(() =>
|
| | | {
|
| | | //获取分组后的设备列表
|
| | | var dicGroupDevice = this.GetAllGroupDevice();
|
| | | if (dicGroupDevice.Count == 0)
|
| | | {
|
| | | //还没有添加设备哦
|
| | | this.ShowNotDataImage(frameTable, Language.StringByID(R.MyInternationalizationString.uDoNotHadAddDeviceMsg));
|
| | | return;
|
| | | }
|
| | |
|
| | | var frameBack = new FrameLayout();
|
| | | frameBack.X = ControlCommonResourse.XXLeft;
|
| | | frameBack.BackgroundColor = UserCenterColor.Current.White;
|
| | | frameBack.Width = bodyFrameLayout.Width;
|
| | | frameBack.Height = Application.GetRealHeight(1650);
|
| | | frameBack.Radius = (uint)Application.GetRealHeight(58);
|
| | | frameTable.AddChidren(frameBack);
|
| | |
|
| | | var listView = new VerticalListControl(23);
|
| | | listView.Y = Application.GetRealHeight(23);
|
| | | listView.Height = Application.GetRealHeight(1549 - 23);
|
| | | frameBack.AddChidren(listView);
|
| | |
|
| | | var dicData = new Dictionary<string, DeviceRowInfo>();
|
| | | var listGwId = new List<string>();
|
| | | foreach (var textId in dicGroupDevice.Keys)
|
| | | {
|
| | | //添加设备行
|
| | | this.AddDeviceRow(dicGroupDevice[textId], textId, listView);
|
| | | foreach (var deviceKey in dicGroupDevice[textId].listDeviceKeys)
|
| | | {
|
| | | var device = Common.LocalDevice.Current.GetDevice(deviceKey);
|
| | | if (listGwId.Contains(device.CurrentGateWayId) == false)
|
| | | {
|
| | | //网关ID
|
| | | listGwId.Add(device.CurrentGateWayId);
|
| | | }
|
| | | //以回路作为索引去指定对象
|
| | | dicData[deviceKey] = dicGroupDevice[textId];
|
| | | }
|
| | | }
|
| | | listView.AdjustRealHeight(Application.GetRealHeight(23));
|
| | | //如果不是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | //开启设备在线监测
|
| | | this.StartCheckDeviceOnline(listView, listGwId, dicData);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 添加设备行_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 添加设备行
|
| | | /// </summary>
|
| | | /// <param name="rowInfo"></param>
|
| | | /// <param name="TextId"></param>
|
| | | /// <param name="listView"></param>
|
| | | private void AddDeviceRow(DeviceRowInfo rowInfo, int TextId, VerticalListControl listView)
|
| | | {
|
| | | var frameRow = new FrameRowControl(listView.rowSpace / 2);
|
| | | frameRow.LeftOffset = Application.GetRealWidth(46) - ControlCommonResourse.XXLeft;
|
| | | frameRow.RightOffset = -ControlCommonResourse.XXLeft;
|
| | | listView.AddChidren(frameRow);
|
| | | //图标
|
| | | var btnIcon = frameRow.AddLeftIcon(81);
|
| | | btnIcon.UnSelectedImagePath = rowInfo.IconPath;
|
| | | //名称
|
| | | var btnView = frameRow.AddLeftCaption(string.Empty, 600);
|
| | | btnView.TextID = TextId;
|
| | | btnView.TextSize = 15;
|
| | | //右箭头
|
| | | frameRow.AddRightArrow();
|
| | | //在线数
|
| | | var btnOnline = frameRow.AddMostRightView(rowInfo.OnlineCount + "/" + rowInfo.listDeviceKeys.Count, 300);
|
| | | rowInfo.btnOnline = btnOnline;
|
| | | //底线
|
| | | frameRow.AddBottomLine();
|
| | | frameRow.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | var form = new LookRoomDeviceListForm();
|
| | | form.AddForm(lookRoom.Name, Language.StringByID(TextId), rowInfo.listDeviceKeys);
|
| | | };
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 整合设备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取分组后的设备
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private Dictionary<int, DeviceRowInfo> GetAllGroupDevice()
|
| | | {
|
| | | //全部的设备
|
| | | var listDevice = HdlRoomLogic.Current.GetRoomListDevice(lookRoom);
|
| | | var dic = new Dictionary<int, DeviceRowInfo>();
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | var typeInfo = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device);
|
| | | //按所属ID分组
|
| | | if (dic.ContainsKey(typeInfo.BeloneTextId) == false)
|
| | | {
|
| | | dic[typeInfo.BeloneTextId] = new DeviceRowInfo();
|
| | | string path1 = string.Empty;
|
| | | string path2 = string.Empty;
|
| | | //获取图片
|
| | | Common.LocalDevice.Current.GetDeviceFunctionTypeMenuIcon(typeInfo.ConcreteType, ref path1, ref path2);
|
| | | dic[typeInfo.BeloneTextId].IconPath = path1;
|
| | | }
|
| | | dic[typeInfo.BeloneTextId].listDeviceKeys.Add(Common.LocalDevice.Current.GetDeviceMainKeys(device));
|
| | | }
|
| | | return dic;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设备在线___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 开启设备在线监测
|
| | | /// </summary>
|
| | | /// <param name="listView">判断退出时使用</param>
|
| | | /// <param name="listGwId">网关ID</param>
|
| | | /// <param name="dicData">以回路作为索引去指定对象</param>
|
| | | private void StartCheckDeviceOnline(VerticalListControl listView, List<string> listGwId, Dictionary<string, DeviceRowInfo> dicData)
|
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var listCheck = new HashSet<string>();
|
| | | for (int i = 0; i < listGwId.Count; i++)
|
| | | {
|
| | | if (listView.Parent == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //这里主要只是获取在线状态
|
| | | var zbway = HdlGatewayLogic.Current.GetLocalGateway(listGwId[i]);
|
| | | int statu = 0;
|
| | | var list = Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO);
|
| | | if (statu != -1)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | for (int j = 0; j < list.Count; j++)
|
| | | {
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(list[j]);
|
| | | if (listView.Parent == null || dicData.ContainsKey(mainkeys) == false || listCheck.Contains(mainkeys) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | listCheck.Add(mainkeys);
|
| | |
|
| | | var localDevice = Common.LocalDevice.Current.GetDevice(mainkeys);
|
| | | if (localDevice != null && localDevice.IsOnline != list[j].IsOnline)
|
| | | {
|
| | | //在线状态一样的话,不需要刷新
|
| | | localDevice.IsOnline = list[j].IsOnline;
|
| | | localDevice.ReSave();
|
| | | }
|
| | | if (Common.LocalDevice.Current.CheckDeviceIsOnline(list[j]) == true)
|
| | | {
|
| | | dicData[mainkeys].OnlineCount += 1;
|
| | | dicData[mainkeys].btnOnline.Text = dicData[mainkeys].OnlineCount + "/" + dicData[mainkeys].listDeviceKeys.Count;
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 结构体_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设备行信息
|
| | | /// </summary>
|
| | | private class DeviceRowInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 图标
|
| | | /// </summary>
|
| | | public string IconPath = string.Empty;
|
| | | /// <summary>
|
| | | /// 设备回路主键
|
| | | /// </summary>
|
| | | public List<string> listDeviceKeys = new List<string>();
|
| | | /// <summary>
|
| | | /// 设备在线数
|
| | | /// </summary>
|
| | | public int OnlineCount = 0;
|
| | | /// <summary>
|
| | | /// 在线控件
|
| | | /// </summary>
|
| | | public NormalViewControl btnOnline = null;
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|