黄学彪
2020-07-20 2029e64ec0491f7e511dc15bffaf821bfbabe2de
ZigbeeApp/Shared/Phone/UserCenter/Residence/LookRoomSettionForm.cs
@@ -20,6 +20,10 @@
        /// 桌布控件
        /// </summary>
        private NormalFrameLayout frameTable = null;
        /// <summary>
        /// 设备列表
        /// </summary>
        private List<CommonDevice> listDevice = new List<CommonDevice>();
        #endregion
@@ -161,21 +165,15 @@
                frameBack.AddChidren(listView);
                var dicData = new Dictionary<string, DeviceRowInfo>();
                var listGwId = new List<string>();
                foreach (var textId in dicGroupDevice.Keys)
                foreach (var strText in dicGroupDevice.Keys)
                {
                    //添加设备行
                    this.AddDeviceRow(dicGroupDevice[textId], textId, listView);
                    foreach (var deviceKey in dicGroupDevice[textId].listDeviceKeys)
                    this.AddDeviceRow(dicGroupDevice[strText], strText, listView);
                    foreach (var deviceKey in dicGroupDevice[strText].listDeviceKeys)
                    {
                        var device = Common.LocalDevice.Current.GetDevice(deviceKey);
                        if (listGwId.Contains(device.CurrentGateWayId) == false)
                        {
                            //网关ID
                            listGwId.Add(device.CurrentGateWayId);
                        }
                        //以回路作为索引去指定对象
                        dicData[deviceKey] = dicGroupDevice[textId];
                        dicData[deviceKey] = dicGroupDevice[strText];
                    }
                }
                listView.AdjustRealHeight(Application.GetRealHeight(23));
@@ -183,7 +181,7 @@
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    //开启设备在线监测
                    this.StartCheckDeviceOnline(listView, listGwId, dicData);
                    this.StartCheckDeviceOnline(listView, dicData);
                }
            });
        }
@@ -196,9 +194,9 @@
        /// 添加设备行
        /// </summary>
        /// <param name="rowInfo"></param>
        /// <param name="TextId"></param>
        /// <param name="strText"></param>
        /// <param name="listView"></param>
        private void AddDeviceRow(DeviceRowInfo rowInfo, int TextId, VerticalListControl listView)
        private void AddDeviceRow(DeviceRowInfo rowInfo, string strText, VerticalListControl listView)
        {
            var frameRow = new FrameRowControl(listView.rowSpace / 2);
            frameRow.LeftOffset = Application.GetRealWidth(46) - ControlCommonResourse.XXLeft;
@@ -209,7 +207,7 @@
            btnIcon.UnSelectedImagePath = rowInfo.IconPath;
            //名称
            var btnView = frameRow.AddLeftCaption(string.Empty, 600);
            btnView.TextID = TextId;
            btnView.Text = strText;
            btnView.TextSize = 15;
            //右箭头
            frameRow.AddRightArrow();
@@ -221,7 +219,7 @@
            frameRow.ButtonClickEvent += (sender, e) =>
            {
                var form = new LookRoomDeviceListForm();
                form.AddForm(lookRoom.Name, Language.StringByID(TextId), rowInfo.listDeviceKeys);
                form.AddForm(lookRoom.Name, strText, rowInfo.listDeviceKeys);
            };
        }
@@ -233,25 +231,25 @@
        /// 获取分组后的设备
        /// </summary>
        /// <returns></returns>
        private Dictionary<int, DeviceRowInfo> GetAllGroupDevice()
        private Dictionary<string, DeviceRowInfo> GetAllGroupDevice()
        {
            //全部的设备
            var listDevice = HdlRoomLogic.Current.GetRoomListDevice(lookRoom);
            var dic = new Dictionary<int, DeviceRowInfo>();
            this.listDevice = HdlRoomLogic.Current.GetRoomListDevice(lookRoom);
            var dic = new Dictionary<string, DeviceRowInfo>();
            foreach (var device in listDevice)
            {
                var typeInfo = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device);
                //按所属ID分组
                if (dic.ContainsKey(typeInfo.BeloneTextId) == false)
                if (dic.ContainsKey(typeInfo.BeloneText) == false)
                {
                    dic[typeInfo.BeloneTextId] = new DeviceRowInfo();
                    dic[typeInfo.BeloneText] = 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.BeloneText].IconPath = path1;
                }
                dic[typeInfo.BeloneTextId].listDeviceKeys.Add(Common.LocalDevice.Current.GetDeviceMainKeys(device));
                dic[typeInfo.BeloneText].listDeviceKeys.Add(Common.LocalDevice.Current.GetDeviceMainKeys(device));
            }
            return dic;
        }
@@ -264,53 +262,48 @@
        /// 开启设备在线监测
        /// </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)
        private void StartCheckDeviceOnline(VerticalListControl listView, Dictionary<string, DeviceRowInfo> dicData)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                var listCheck = new HashSet<string>();
                for (int i = 0; i < listGwId.Count; i++)
                var dicCheck = new Dictionary<string, bool>();
                for (int i = 0; i < this.listDevice.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)
                    var localDevice = this.listDevice[i];
                    if (dicCheck.ContainsKey(localDevice.DeviceAddr) == false)
                    {
                        //只需要检测一路
                        var deviceInfo = Common.LocalDevice.Current.ReadDeviceEpointDeviceInfo(localDevice);
                        if (deviceInfo != null)
                        {
                            localDevice.IsOnline = deviceInfo.IsOnline;
                            dicCheck[localDevice.DeviceAddr] = Common.LocalDevice.Current.CheckDeviceIsOnline(localDevice, false);
                        }
                    }
                    if (dicCheck.ContainsKey(localDevice.DeviceAddr) == false
                      || dicCheck[localDevice.DeviceAddr] == false)
                    {
                        //网关没有回复,或者不在线
                        continue;
                    }
                    string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(localDevice);
                    if (dicData.ContainsKey(mainkeys) == true)
                    {
                        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);
                            dicData[mainkeys].OnlineCount += 1;
                            dicData[mainkeys].btnOnline.Text = dicData[mainkeys].OnlineCount + "/" + dicData[mainkeys].listDeviceKeys.Count;
                                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;
                                }
                            }
                        });
                        }, ShowErrorMode.NO);
                    }
                    System.Threading.Thread.Sleep(30);
                }
            });
            }, ShowErrorMode.NO);
        }
        #endregion