From cf0bffdf072bae11bdb8c780d0a355818700f713 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期一, 18 五月 2020 15:42:45 +0800
Subject: [PATCH] 请合并代码,优化面板问题

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs |  268 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 229 insertions(+), 39 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
index c5cd1d6..9e71acc 100644
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
@@ -18,11 +18,16 @@
         /// <param name="device"></param>
         /// <param name="deviceBindType">1:鏂伴;2:娓╁害浼犳劅鍣�;3:婀垮害浼犳劅鍣�;4:PM2.5浼犳劅鍣�</param>
         /// <param name="bindDev">缁戝畾鐩爣 </param>
-        public PanelFangyueFreshAirTargetsForm(CommonDevice device, CommonDevice bindDev, int deviceBindType)
+        public PanelFangyueFreshAirTargetsForm(CommonDevice device, CommonDevice bindDev, List<BindListResponseObj> bindList, int deviceBindType)
         {
             this.curControlDev = device as FreshAir;
             this.curBindDevice = bindDev;
             this.curDeviceBindType = deviceBindType;
+            curControlDev.bindList = bindList;
+            if (bindList.Count == 0)
+            {
+                canReadBindList = true;
+            }
         }
         #endregion
 
@@ -106,7 +111,7 @@
         /// <summary>
         /// 鏄惁鑳界偣鍑讳繚瀛樻寜閽�
         /// </summary>
-        private bool canSave = true;
+        private bool canReadBindList = false;
         #endregion
 
         #region UI璁捐 
@@ -337,6 +342,19 @@
                     }
                 }
 
+                if (index == roomTempList.Count - 1 && index > 3)
+                {
+                    var btnRoomFrameLayoutEmpty = new FrameLayout
+                    {
+                        Height = Application.GetMinReal(159),
+                        Width = Application.GetMinReal(50),
+                        Y = Application.GetRealHeight(23),
+                        X = Application.GetRealWidth(5),
+                        BorderWidth = 1,
+                    };
+                    btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayoutEmpty);
+                }
+
                 EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) =>
                 {
                     if (!btnRoom.IsSelected)
@@ -362,7 +380,6 @@
                         curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
                     }
                     curRoom = room;
-                    curControlDev.RoomId = room.Id;
 
                     //鏂伴闈㈡澘淇濆瓨浣胯兘
                     btnFinifh.Enable = true;
@@ -476,12 +493,20 @@
                         break;
                     case 2:
                         devicePic.UnSelectedImagePath = "Device/SensorTemperature.png";
+                        if (device.Type == DeviceType.PMSensor)
+                        {
+                            btnBindName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device) + "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                        }
                         break;
                     case 3:
                         devicePic.UnSelectedImagePath = "Device/SensorHumidity.png";
+                        if (device.Type == DeviceType.PMSensor)
+                        {
+                            btnBindName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device) + "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
+                        }
                         break;
                     case 4:
-                        devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
+                        devicePic.UnSelectedImagePath = "Device/AirQualitySensorEpoint.png";
                         break;
                 }
                 #endregion
@@ -711,35 +736,39 @@
                     currentPanelSupportBindDeviceList = GetAllRoomSupportDeviceList();
 
                     //鑾峰彇闈㈡澘涓瓨鍦ㄧ殑缁戝畾鐩爣
-                    var panelBindListRes = await this.curControlDev.GetDeviceBindAsync();
-                    if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null)
+                    if (canReadBindList)
                     {
-                        curControlDev.bindList.Clear();
-                        foreach (var bDev in panelBindListRes.getAllBindResponseData.BindList)
+                        var panelBindListRes = await this.curControlDev.GetDeviceBindAsync();
+                        if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null)
                         {
-                            curControlDev.bindList.Add(bDev);
+                            curControlDev.bindList.Clear();
+                            foreach (var bDev in panelBindListRes.getAllBindResponseData.BindList)
+                            {
+                                curControlDev.bindList.Add(bDev);
+                            }
+                        }
+                        else
+                        {
+                            Application.RunOnMainThread(() =>
+                            {
+                                CommonPage.Loading.Hide();
+                                midVerticalScrolViewLayout.EndHeaderRefreshing();
+                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                            });
                         }
                     }
-                    else
-                    {
-                        Application.RunOnMainThread(() =>
-                        {
-                            CommonPage.Loading.Hide();
-                            midVerticalScrolViewLayout.EndHeaderRefreshing();
-                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
-                        });
-                    }
+
                     targetList.Clear();
                     //閫変腑鐩爣鍒楄〃 targetList
                     if (currentPanelSupportBindDeviceList.Count != 0 && curControlDev.bindList.Count != 0)
                     {
-                        foreach (var bindDev in currentPanelSupportBindDeviceList)
+                        foreach (var bindDev in curControlDev.bindList)
                         {
-                            var mainKey = bindDev.DeviceAddr + bindDev.DeviceEpoint;
-                            var dev = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey));
+                            var mainKey = bindDev.BindMacAddr + bindDev.BindEpoint;
+                            var dev = currentPanelSupportBindDeviceList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == mainKey));
                             if (dev != null)
                             {
-                                var device = LocalDevice.Current.GetDevice(bindDev.DeviceAddr, bindDev.DeviceEpoint);
+                                var device = LocalDevice.Current.GetDevice(dev.DeviceAddr, dev.DeviceEpoint);
                                 if (device != null)
                                 {
                                     switch (curDeviceBindType)
@@ -768,6 +797,14 @@
                                                     oldTargetList.Add(device);
                                                 }
                                             }
+                                            if (device.Type == DeviceType.PMSensor)
+                                            {
+                                                if (bindDev.BindCluster == 1026)
+                                                {
+                                                    targetList.Add(device);
+                                                    oldTargetList.Add(device);
+                                                }
+                                            }
                                             break;
                                         case 3:
                                             if (device.Type == DeviceType.TemperatureSensor)
@@ -784,9 +821,25 @@
                                                 targetList.Add(device);
                                                 oldTargetList.Add(device);
                                             }
+                                            if (device.Type == DeviceType.PMSensor)
+                                            {
+                                                if (bindDev.BindCluster == 1029)
+                                                {
+                                                    targetList.Add(device);
+                                                    oldTargetList.Add(device);
+                                                }
+                                            }
                                             break;
                                         case 4:
                                             //PM2.5
+                                            if (device.Type == DeviceType.PMSensor)
+                                            {
+                                                if (bindDev.BindCluster == 1066)
+                                                {
+                                                    targetList.Add(device);
+                                                    oldTargetList.Add(device);
+                                                }
+                                            }
                                             break;
                                     }
 
@@ -903,6 +956,7 @@
                                         break;
                                     case 4:
                                         //PM2.5
+                                        removeDevice.BindCluster = 1066;
                                         break;
                                 }
                                 removeDevice.BindMacAddr = bd.DeviceAddr;
@@ -949,6 +1003,12 @@
                                             btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                             this.RemoveFromParent();
                                         });
+                                        var mainKey = delDevice.DeviceAddr + delDevice.Epoint;
+                                        var dev1 = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey));
+                                        if (dev1 != null)
+                                        {
+                                            curControlDev.bindList.Remove(dev1);
+                                        }
                                     }
                                     else
                                     {
@@ -961,6 +1021,17 @@
                                         });
                                         return;
                                     }
+                                }
+                                else
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.OperrateFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                        btnFinifh.Enable = true;
+                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                        CommonPage.Loading.Hide();
+                                    });
+                                    return;
                                 }
                             }
                         }
@@ -1025,6 +1096,17 @@
                                 var delDevice = DelBindDevice(bd);
                                 var delResult = new DelDeviceBindResponseAllData();
                                 delResult = await curControlDev.DelDeviceBindAsync(delDevice);
+                                if (delResult == null || delResult.removeBindResultResponseData == null)
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                        btnFinifh.Enable = true;
+                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                        CommonPage.Loading.Hide();
+                                    });
+                                    return;
+                                }
                                 if (delResult != null && delResult.removeBindResultResponseData != null)
                                 {
                                     if (delResult.removeBindResultResponseData.Result != 0)
@@ -1039,6 +1121,12 @@
                                         return;
                                     }
                                 }
+                                var mainKey = delDevice.DeviceAddr + delDevice.Epoint;
+                                var dev2 = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey));
+                                if (dev2 != null)
+                                {
+                                    curControlDev.bindList.Remove(dev2);
+                                }
                             }
                         }
                         else
@@ -1050,6 +1138,17 @@
                                 var delDevice = DelBindDevice(curBindDevice);
                                 var delResult = new DelDeviceBindResponseAllData();
                                 delResult = await curControlDev.DelDeviceBindAsync(delDevice);
+                                if (delResult == null || delResult.removeBindResultResponseData == null)
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                        btnFinifh.Enable = true;
+                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                        CommonPage.Loading.Hide();
+                                    });
+                                    return;
+                                }
                                 if (delResult != null && delResult.removeBindResultResponseData != null)
                                 {
                                     if (delResult.removeBindResultResponseData.Result != 0)
@@ -1063,6 +1162,12 @@
                                         });
                                         return;
                                     }
+                                }
+                                var mainKey = delDevice.DeviceAddr + delDevice.Epoint;
+                                var dev3 = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey));
+                                if (dev3 != null)
+                                {
+                                    curControlDev.bindList.Remove(dev3);
                                 }
                             }
                         }
@@ -1088,13 +1193,30 @@
                                     break;
                                 case 4:
                                     //PM2.5
+                                    addBindInfo.BindCluster = 1066;
                                     break;
                             }
                             addBindInfo.BindType = 0;
                             addBindInfo.BindMacAddr = de.DeviceAddr;
                             addBindInfo.BindEpoint = de.DeviceEpoint;
                             addBindeDev.BindList.Add(addBindInfo);
-                            bindName = de.DeviceEpointName;
+                            addBindeDev.BindName = de.DeviceEpointName;
+
+                            switch (curDeviceBindType)
+                            {
+                                case 2:
+                                    if (de.Type == DeviceType.PMSensor)
+                                    {
+                                        addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de) + "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                                    }
+                                    break;
+                                case 3:
+                                    if (de.Type == DeviceType.PMSensor)
+                                    {
+                                        addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de) + "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
+                                    }
+                                    break;
+                            }
                         }
 
                         var dev = new AddedDeviceBindResponseAllData();
@@ -1114,33 +1236,31 @@
                         {
                             if (dev.addedDeviceBindResponseData.Result == 0)
                             {
-                                curControlDev.bindList = dev.addedDeviceBindResponseData.BindList;
                                 targetList.Clear();
-
                                 switch (curDeviceBindType)
                                 {
                                     case 1:
                                         if (actionFreshAirTarget != null)
                                         {
-                                            actionFreshAirTarget(bindName);
+                                            actionFreshAirTarget(addBindeDev.BindName);
                                         }
                                         break;
                                     case 2:
                                         if (actionTemperatureTarget != null)
                                         {
-                                            actionTemperatureTarget(bindName);
+                                            actionTemperatureTarget(addBindeDev.BindName);
                                         }
                                         break;
                                     case 3:
                                         if (actionHumidityTarget != null)
                                         {
-                                            actionHumidityTarget(bindName);
+                                            actionHumidityTarget(addBindeDev.BindName);
                                         }
                                         break;
                                     case 4:
                                         if (actionPMTarget != null)
                                         {
-                                            actionPMTarget(bindName);
+                                            actionPMTarget(addBindeDev.BindName);
                                         }
                                         break;
                                 }
@@ -1152,6 +1272,13 @@
                                     btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                     this.RemoveFromParent();
                                 });
+
+                                var mainKey = addBindeDev.DeviceAddr + addBindeDev.Epoint;
+                                var dev4 = curControlDev.bindList.Find(obj => (obj != null) && (obj.BindMacAddr + obj.BindEpoint == mainKey));
+                                if (dev4 != null)
+                                {
+                                    curControlDev.bindList.Add(dev4);
+                                }
                             }
                             else if (dev.addedDeviceBindResponseData.Result == 1)
                             {
@@ -1275,6 +1402,7 @@
                     break;
                 case 4:
                     //PM2.5
+                    removeDevice.BindCluster = 1066;
                     break;
             }
             removeDevice.BindMacAddr = bd.DeviceAddr;
@@ -1349,6 +1477,17 @@
                             }
                             break;
                         case 4:
+                            foreach (var de in room.ListDevice)
+                            {
+                                var device = LocalDevice.Current.GetDevice(de);
+                                if (device != null)
+                                {
+                                    if (device.Type == DeviceType.PMSensor)
+                                    {
+                                        roomIncludeMatchDevice.Add(device);
+                                    }
+                                }
+                            }
                             break;
                     }
 
@@ -1385,19 +1524,30 @@
             foreach (var de in room.ListDevice)
             {
                 var device = LocalDevice.Current.GetDevice(de);
-                //鐢垫睜璁惧涓嶆敮鎸佺粦瀹�
-                if (device.ZigbeeType != 1)
-                {
-                    continue;
-                }
                 if (device != null)
                 {
+                    //鐢垫睜璁惧涓嶆敮鎸佺粦瀹�
+                    if (device.ZigbeeType != 1)
+                    {
+                        continue;
+                    }
                     if (device.Type == DeviceType.TemperatureSensor)
                     {
                         var dev = device as TemperatureSensor;
                         if (dev.SensorDiv == 1)
                         {
                             roomIncludeMatchTempDevice.Add(device);
+                        }
+                    }
+                    else if (device.Type == DeviceType.PMSensor)
+                    {
+                        var dev = device as PMSensor;
+                        foreach (var clu in dev.InClusterList)
+                        {
+                            if (clu.InCluster == 1026)
+                            {
+                                roomIncludeMatchTempDevice.Add(device);
+                            }
                         }
                     }
                 }
@@ -1415,19 +1565,30 @@
             foreach (var de in room.ListDevice)
             {
                 var device = LocalDevice.Current.GetDevice(de);
-                //鐢垫睜璁惧涓嶆敮鎸佺粦瀹�
-                if (device.ZigbeeType != 1)
-                {
-                    continue;
-                }
                 if (device != null)
                 {
+                    //鐢垫睜璁惧涓嶆敮鎸佺粦瀹�
+                    if (device.ZigbeeType != 1)
+                    {
+                        continue;
+                    }
                     if (device.Type == DeviceType.TemperatureSensor)
                     {
                         var dev = device as TemperatureSensor;
                         if (dev.SensorDiv == 2)
                         {
                             roomIncludeMatchHumpDevice.Add(device);
+                        }
+                    }
+                    else if (device.Type == DeviceType.PMSensor)
+                    {
+                        var dev = device as PMSensor;
+                        foreach (var clu in dev.InClusterList)
+                        {
+                            if (clu.InCluster == 1029)
+                            {
+                                roomIncludeMatchHumpDevice.Add(device);
+                            }
                         }
                     }
                 }
@@ -1551,6 +1712,24 @@
                     }
                     break;
                 case 4:
+                    foreach (var r in supportRoomList)
+                    {
+                        if (r.ListDevice.Count == 0)
+                        {
+                            continue;
+                        }
+                        foreach (var deviceKeys in r.ListDevice)
+                        {
+                            var device = LocalDevice.Current.GetDevice(deviceKeys);
+                            if (device != null)
+                            {
+                                if (device.Type == DeviceType.PMSensor)
+                                {
+                                    currentPanelBindSupportDeviceListTemp.Add(device);
+                                }
+                            }
+                        }
+                    }
                     break;
             }
             return currentPanelBindSupportDeviceListTemp;
@@ -1604,6 +1783,17 @@
                     }
                     break;
                 case 4:
+                    foreach (var deviceKeys in curRoom.ListDevice)
+                    {
+                        var device = LocalDevice.Current.GetDevice(deviceKeys);
+                        if (device != null)
+                        {
+                            if (device.Type == DeviceType.PMSensor)
+                            {
+                                curRoomDeviceListTemp.Add(device);
+                            }
+                        }
+                    }
                     break;
             }
             return curRoomDeviceListTemp;

--
Gitblit v1.8.0