From 2450c12c825ad4d78d1572da2fa421706db2df2f Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 18 六月 2020 16:01:14 +0800
Subject: [PATCH] 新代码

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs | 1472 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 1,008 insertions(+), 464 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
index 8da0a5c..b996092 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelFangyueFreshAirTargetsForm.cs
@@ -16,27 +16,29 @@
         /// 鏋勯�犲嚱鏁�
         /// </summary>
         /// <param name="device"></param>
-        /// <param name="deviceBindType">1:鏂伴;2:娓╁害浼犳劅鍣�;3:婀垮害浼犳劅鍣�</param>
-        public PanelFangyueFreshAirTargetsForm(CommonDevice device, int deviceBindType)
+        /// <param name="deviceBindType">1:鏂伴;2:娓╁害浼犳劅鍣�;3:婀垮害浼犳劅鍣�;4:PM2.5浼犳劅鍣�</param>
+        /// <param name="bindDev">缁戝畾鐩爣 </param>
+        public PanelFangyueFreshAirTargetsForm(CommonDevice device, CommonDevice bindDev, int deviceBindType)
         {
             this.curControlDev = device as FreshAir;
+            this.curBindDevice = bindDev;
             this.curDeviceBindType = deviceBindType;
         }
         #endregion
 
-        #region  鍙橀噺鐢虫槑
-        /// <summary>
-        /// 褰撳墠鎺у埗璁惧
-        /// </summary>
-        //CommonDevice currentControlDevice;
+        #region  鍙橀噺鐢虫槑 
         /// <summary>
         /// 褰撳墠鏂伴闈㈡澘銆愭帶鍒惰澶囥��
         /// </summary>
         FreshAir curControlDev;
         /// <summary>
+        /// 褰撳墠琚粦璁惧
+        /// </summary>
+        CommonDevice curBindDevice;
+        /// <summary>
         /// 鏄剧ず琚粦瀹氳澶囨垨鍦烘櫙鐨剉iew
         /// </summary>
-        VerticalFrameRefreshControl midVerticalScrolViewLayout;
+        VerticalRefreshLayout midVerticalScrolViewLayout;
         /// <summary>
         /// 鏄剧ず鎴块棿鐨剉iew
         /// </summary>
@@ -62,10 +64,6 @@
         /// </summary>
         List<Room> supportRoomList = new List<Room>();
         /// <summary>
-        /// 褰撶粦瀹氳〃鍙樺寲鍚庣殑鍥炶皟
-        /// </summary>
-        public Action<List<BindListResponseObj>> action;
-        /// <summary>
         /// 淇濆瓨瀹屾垚鎸夐挳
         /// </summary>
         Button btnFinifh;
@@ -89,6 +87,23 @@
         /// 闈㈡澘涓瓨鍦ㄧ殑閿��
         /// </summary>
         List<String> panelBindListKey = null;
+        /// <summary>
+        /// 鏂伴缁戝畾鐩爣鍥炶皟
+        /// </summary>
+        public Action<string> actionFreshAirTarget = null;
+        /// <summary>
+        /// 娓╁害缁戝畾鐩爣鍥炶皟
+        /// </summary>
+        public Action<string> actionTemperatureTarget = null;
+        /// <summary>
+        /// 婀垮害缁戝畾鐩爣鍥炶皟
+        /// </summary>
+        public Action<string> actionHumidityTarget = null;
+        /// <summary>
+        /// PM缁戝畾鐩爣鍥炶皟
+        /// </summary>
+        public Action<string> actionPMTarget = null;
+
         #endregion
 
         #region UI璁捐 
@@ -119,7 +134,7 @@
             {
                 RemoveFromParent();
             };
-            this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 200 - 58);
+            this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300);
             this.btnBack.MouseUpEventHandler += eHandlerBack;
             this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
             this.MidFrameLayout(this);
@@ -140,14 +155,13 @@
         {
             var btnAddFrameLayout = new FrameLayout
             {
-                X = Application.GetRealWidth(830),
+                X = Application.GetRealWidth(619),
             };
             this.titleFrameLayout.AddChidren(btnAddFrameLayout);
 
             btnFloorText = new Button
             {
-                Width = Application.GetRealWidth(110),
-                X = Application.GetRealWidth(15),
+                Width = Application.GetRealWidth(300 - 69 - 58),
                 Text = Language.StringByID(R.MyInternationalizationString.FirstFloor),
                 TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                 TextSize = 14,
@@ -156,26 +170,35 @@
             };
             btnAddFrameLayout.AddChidren(btnFloorText);
 
+            var btnBindDownFrameLayout = new FrameLayout
+            {
+                Width = Application.GetMinReal(69 + 58),
+                X = Application.GetRealWidth(300 - 69 - 58),
+            };
+            btnAddFrameLayout.AddChidren(btnBindDownFrameLayout);
+
             var btnBindDown = new Button
             {
                 Height = Application.GetMinReal(69),
                 Width = Application.GetMinReal(69),
-                X = Application.GetRealWidth(200 - 77),
                 UnSelectedImagePath = "BindPic/BindDown.png",
                 Gravity = Gravity.CenterVertical,
             };
-            btnAddFrameLayout.AddChidren(btnBindDown);
-            btnBindDown.MouseDownEventHandler += (sender, e) =>
+            btnBindDownFrameLayout.AddChidren(btnBindDown);
+
+            EventHandler<MouseEventArgs> eHandlerBindDown = (sender, e) =>
             {
                 SideslipFramelayout();
             };
+            btnBindDown.MouseDownEventHandler += eHandlerBindDown;
+            btnBindDownFrameLayout.MouseDownEventHandler += eHandlerBindDown;
             if (Common.Config.Instance.Home.FloorDics.Count == 0)
             {
                 btnAddFrameLayout.Width = 0;
             }
             else
             {
-                btnAddFrameLayout.Width = Application.GetRealWidth(200);
+                btnAddFrameLayout.Width = Application.GetRealWidth(300);
             }
         }
 
@@ -198,12 +221,17 @@
             btnMidTopLayout.AddChidren(btnHorizontalScrolViewLayout);
 
             //璁惧鏍�
-            midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
+            midVerticalScrolViewLayout = new VerticalRefreshLayout()
             {
                 Y = btnMidTopLayout.Bottom,
                 Height = Application.GetRealHeight(1145),
             };
             this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
+            midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
+            {
+                midVerticalScrolViewLayout.BeginHeaderRefreshing();
+                InitData();
+            };
 
             //搴曢儴淇濆瓨鏍�
             var bottomFrameLayout = new FrameLayout()
@@ -237,8 +265,9 @@
         /// </summary>
         /// <param name="gateway">Gateway.</param>
         /// <param name="key">Key.</param>
-        void RefreshRoomList(Room curRoom, ref int index2)
+        void RefreshRoomList()
         {
+            Room curRoom = null;
             if (supportRoomList.Count == 0)
             {
                 return;
@@ -247,10 +276,18 @@
             Button curentOldRoom = null;
             FrameLayout curentOldRoomFrameLayout = null;
             int index = 0;
-            var roomTempList = GetSupportRoomList(curRoom);
+            var roomTempList = GetSupportRoomList();
+            Room slectedRoom = null;
+
             for (int i = 0; i < roomTempList.Count; i++)
             {
                 var room = roomTempList[i];
+                bool canSelect = false;
+                if (curControlDev.currentSelectRoomId == room.Id)
+                {
+                    slectedRoom = room;
+                    canSelect = true;
+                }
                 //鎴块棿
                 var btnRoomFrameLayout = new FrameLayout
                 {
@@ -277,16 +314,41 @@
                 btnRoomFrameLayout.AddChidren(btnRoom);
 
                 btnRoom.IsSelected = false;
-                if (index == 0)
+                if (canSelect)
                 {
                     btnRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
                     btnRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
                     curentOldRoom = btnRoom;
                     curentOldRoomFrameLayout = btnRoomFrameLayout;
                 }
+
+                //琚粦瀹氱殑鐩爣杩樻湭鍒嗛厤鍖哄煙锛岄粯璁ゆ槸绗竴涓�
+                if (string.IsNullOrEmpty(curControlDev.currentSelectRoomId))
+                {
+                    if (index == 0)
+                    {
+                        btnRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+                        btnRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+                        curentOldRoom = btnRoom;
+                        curentOldRoomFrameLayout = btnRoomFrameLayout;
+                    }
+                }
+
+                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) =>
                 {
-                    //ChangeRoom(curRoom, room, btnRoom, curentOldRoom, btnRoomFrameLayout, curentOldRoomFrameLayout);
                     if (!btnRoom.IsSelected)
                     {
                         if (curentOldRoom != null)
@@ -310,27 +372,11 @@
                         curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
                     }
                     curRoom = room;
-                    curControlDev.RoomId = room.Id;
-                    if (curRoom.ListSceneId.Count == 0)
-                    {
-                        btnFinifh.Enable = false;
-                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-                    }
-                    else
-                    {
-                        btnFinifh.Enable = true;
-                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                    }
-                    if (targetList.Count == 0)
-                    {
-                        btnFinifh.Enable = false;
-                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-                    }
-                    else
-                    {
-                        btnFinifh.Enable = true;
-                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                    }
+
+                    //鏂伴闈㈡澘淇濆瓨浣胯兘
+                    btnFinifh.Enable = true;
+                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+
                     RefreshDeviceList(curRoom);
                 };
                 btnRoom.MouseUpEventHandler += eHandlerRoom;
@@ -338,6 +384,24 @@
                 index++;
             }
             BindInfo.FinishDisplay(roomTempList, btnFinifh);
+
+            if (roomTempList.Count == 0)
+            {
+                curRoom = new Shared.Common.Room();
+            }
+            else
+            {
+                if (slectedRoom == null)
+                {
+                    curRoom = roomTempList[0];
+                }
+                else
+                {
+                    curRoom = slectedRoom;
+                }
+            }
+
+            RefreshDeviceList(curRoom);
         }
 
         /// <summary>
@@ -409,33 +473,39 @@
                 };
                 rowLayout.AddChidren(line2);
 
-                if (curIndex == currentPanelSupportBindDeviceList.Count - 1)
+                if (curIndex == currentRoomSupportBindDeviceList.Count - 1)
                 {
                     line2.Visible = false;
                 }
 
+                switch (curDeviceBindType)
+                {
+                    case 1:
+                        devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
+                        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/AirQualitySensorEpoint.png";
+                        break;
+                }
                 #endregion
 
                 string mianKey = device.DeviceAddr + device.DeviceEpoint;
                 if (targetList.Count != 0)
                 {
-                    //    if(curControlDev!=null)
-                    //    {
-                    //        foreach (var bindedSc in curControlDev.bindList)
-                    //        {
-                    //            if (bindedSc.BindMacAddr + bindedSc.BindEpoint == mianKey)
-                    //            {
-                    //                btnChoose.IsSelected = true;
-                    //                btnChoose.Visible = true;
-                    //                oldDevice = btnChoose;
-                    //                targetList.Add(device);
-                    //            }
-                    //        }
-                    //    }
-
-                    //}
-                    //else
-                    //{
                     foreach (var bindedDev in targetList)
                     {
                         if (bindedDev.DeviceAddr + bindedDev.DeviceEpoint == mianKey)
@@ -448,57 +518,43 @@
                 }
 
                 EventHandler<MouseEventArgs> hander = (sender, e) =>
-               {
-                   //ChangeTarget(device, btnChoose, oldDevice);
-                   if (curControlDev.bindList.Count != 0)
-                   {
-                       if (btnChoose.IsSelected)
-                       {
-                           new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindExist), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
-                           return;
-                       }
-                   }
+                {
+                    btnChoose.IsSelected = !btnChoose.IsSelected;
+                    if (!btnChoose.IsSelected)
+                    {
+                        if (oldDevice != null)
+                        {
+                            oldDevice.IsSelected = false;
+                            oldDevice.Visible = false;
+                        }
+                        oldDevice = btnChoose;
+                        oldDevice.IsSelected = false;
+                        oldDevice.Visible = false;
+                        targetList.Clear();
+                    }
+                    else
+                    {
+                        if (oldDevice != null)
+                        {
+                            oldDevice.IsSelected = false;
+                            oldDevice.Visible = false;
+                        }
+                        oldDevice = btnChoose;
+                        oldDevice.IsSelected = true;
+                        oldDevice.Visible = true;
+                        targetList.Clear();
+                        targetList.Add(device);
+                    }
 
-                   if (!btnChoose.IsSelected)
-                   {
-                       if (oldDevice != null)
-                       {
-                           oldDevice.IsSelected = false;
-                           oldDevice.Visible = false;
-                       }
-                       oldDevice = btnChoose;
-                       oldDevice.IsSelected = true;
-                       oldDevice.Visible = true;
-                       targetList.Clear();
-                       targetList.Add(device);
-                   }
-                   if (targetList.Count == 0)
-                   {
-                       btnFinifh.Enable = false;
-                       btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-                   }
-                   else
-                   {
-                       btnFinifh.Enable = true;
-                       btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                   }
-               };
+                    //鏂伴闈㈡澘锛氱敱浜庣洰鏍囨病鏈夋彁渚涘垹闄ゆ帴鍙o紝鎵�浠ュ彲浠ュ彇娑堥�変腑鑳戒繚瀛�
+                    btnFinifh.Enable = true;
+                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                };
                 rowLayout.MouseUpEventHandler += hander;
                 devicePic.MouseUpEventHandler += hander;
                 btnBindName.MouseUpEventHandler += hander;
                 btnChoose.MouseUpEventHandler += hander;
                 curIndex++;
-            }
-
-            if (targetList.Count == 0)
-            {
-                btnFinifh.Enable = false;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-            }
-            else
-            {
-                btnFinifh.Enable = true;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
             }
         }
 
@@ -521,7 +577,6 @@
 
             var sidelipFrameLayout = new FrameLayout()
             {
-                Height = Application.GetMinReal(783),
                 Width = Application.GetMinReal(449),
                 Y = Application.GetRealHeight(161),
                 X = Application.GetRealWidth(596),
@@ -545,18 +600,19 @@
 
             var sidelipVerticalScrolViewLayout = new VerticalScrolViewLayout()
             {
+                Y = btnSelectFloor.Bottom + Application.GetRealHeight(45),
                 Height = Application.GetRealHeight(600),
-                Y = btnSelectFloor.Bottom,
             };
             sidelipFrameLayout.AddChidren(sidelipVerticalScrolViewLayout);
 
             Button oldbutton = null;
             Button oldbuttonText = null;
+            int count = 0;
             foreach (var floorId in dicFloorList.Keys)
             {
                 var rowFrameLayout = new RowLayout()
                 {
-                    Height = Application.GetRealHeight(150),
+                    Height = Application.GetRealHeight(152),
                     LineColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                     X = Application.GetRealWidth(81),
                 };
@@ -566,9 +622,9 @@
                 {
                     Width = Application.GetMinReal(81),
                     Height = Application.GetMinReal(81),
-                    Y = Application.GetRealHeight(55),
                     UnSelectedImagePath = "Floor/Floor.png",
                     SelectedImagePath = "Floor/FloorSelected.png",
+                    Gravity = Gravity.CenterVertical,
                 };
                 rowFrameLayout.AddChidren(btnAllMethod);
 
@@ -577,7 +633,7 @@
                     Width = Application.GetRealWidth(311),
                     Height = Application.GetRealHeight(58),
                     X = Application.GetRealWidth(92),
-                    Y = Application.GetRealHeight(69),
+                    Gravity = Gravity.CenterVertical,
                     TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                     TextSize = 14,
                     TextAlignment = TextAlignment.CenterLeft,
@@ -592,36 +648,18 @@
                     btnMethodText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                 }
 
+                string curFloorId = floorId;
                 EventHandler<MouseEventArgs> hander = (sender, e) =>
                 {
-                    //ChangeFloor(dialog, floorId, btnMethodText, oldbuttonText, oldbutton);
-                    var curFloorId = floorId;
-                    curControlDev.currentSelectFloorId = curFloorId;
-                    btnFloorText.Text = dicFloorList[curFloorId];
                     if (curControlDev.currentSelectFloorId == curFloorId)
                     {
                         return;
                     }
                     curControlDev.currentSelectFloorId = curFloorId;
-                    btnFloorText.Text = dicFloorList[curFloorId];
+                    btnFloorText.Text = dicFloorList[floorId];
 
                     //鑾峰彇妤煎眰涓埧闂村垪琛� 
                     supportRoomList = GetFloorRoomList();
-                    if (supportRoomList.Count == 0)
-                    {
-                        return;
-                    }
-                    var curRoom = new Room();
-                    if (supportRoomList.Count != 0)
-                    {
-                        curRoom = supportRoomList[0];
-                    }
-                    else
-                    {
-                        curRoom = new Shared.Common.Room();
-                        supportRoomList.Add(curRoom);
-                    }
-
                     if (!btnMethodText.IsSelected)
                     {
                         if (oldbutton != null)
@@ -640,23 +678,26 @@
                     }
 
                     int index = 0;
-                    RefreshRoomList(curRoom, ref index);
-
-                    if (targetList.Count == 0)
-                    {
-                        btnFinifh.Enable = false;
-                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-                    }
-                    else
-                    {
-                        btnFinifh.Enable = true;
-                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                    }
+                    RefreshRoomList();
                     dialog.Close();
                 };
                 btnAllMethod.MouseUpEventHandler += hander;
                 rowFrameLayout.MouseUpEventHandler += hander;
                 btnMethodText.MouseUpEventHandler += hander;
+                count++;
+            }
+
+            if (count == 0)
+            {
+                sidelipFrameLayout.Height = 0;
+            }
+            else if (count <= 4 && count > 0)
+            {
+                sidelipFrameLayout.Height = Application.GetRealHeight(180) + count * Application.GetRealHeight(150);
+            }
+            else
+            {
+                sidelipFrameLayout.Height = Application.GetMinReal(780);
             }
         }
         #endregion
@@ -675,28 +716,19 @@
                     {
                         CommonPage.Loading.Start("");
                     });
+                    //鑾峰彇琚粦鐩爣绛変俊鎭�
+                    BindDevInfo(curBindDevice);
 
                     //鑾峰彇妤煎眰
                     dicFloorList = HdlRoomLogic.Current.GetFloorSortList();
-                    curControlDev.currentSelectFloorId = BindInfo.GetCurrentSelectFloorId();
-                    if (BindInfo.GetCurrentSelectFloorIdName() != null)
-                    {
-                        btnFloorText.Text = BindInfo.GetCurrentSelectFloorIdName();
-
-                    }
-
                     //鑾峰彇妤煎眰涓埧闂村垪琛�
                     supportRoomList = GetFloorRoomList();
-                    if (supportRoomList.Count == 0)
-                    {
-                        return;
-                    }
 
                     //鑾峰彇鎵�鏈夋埧闂翠腑鍖归厤鐨勮兘缁戠殑鐩爣
                     currentPanelSupportBindDeviceList = GetAllRoomSupportDeviceList();
 
                     //鑾峰彇闈㈡澘涓瓨鍦ㄧ殑缁戝畾鐩爣
-                    var panelBindListRes = await this.curControlDev.GetDeviceBindAsync();
+                    var panelBindListRes = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
                     if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null)
                     {
                         curControlDev.bindList.Clear();
@@ -714,228 +746,163 @@
                             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)
                                 {
-                                    //鑾峰彇璁惧绫诲瀷鐨�
-                                    var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
-                                    //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
-                                    if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                                    switch (curDeviceBindType)
                                     {
-                                        continue;
+                                        case 1:
+                                            //鑾峰彇璁惧绫诲瀷鐨�
+                                            var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
+                                            //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
+                                            if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                                            {
+                                                continue;
+                                            }
+                                            if (device.Type == DeviceType.FreshAir)
+                                            {
+                                                targetList.Add(device);
+                                                oldTargetList.Add(device);
+                                            }
+                                            break;
+                                        case 2:
+                                            if (device.Type == DeviceType.TemperatureSensor)
+                                            {
+                                                var bDev = device as TemperatureSensor;
+                                                if (bDev.SensorDiv == 1)
+                                                {
+                                                    targetList.Add(device);
+                                                    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)
+                                            {
+                                                var bDev = device as TemperatureSensor;
+                                                if (bDev.SensorDiv == 2)
+                                                {
+                                                    targetList.Add(device);
+                                                    oldTargetList.Add(device);
+                                                }
+                                            }
+                                            if (device.Type == DeviceType.FreshAirHumiditySensor)
+                                            {
+                                                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;
                                     }
-                                    if (device.Type == DeviceType.FreshAir)
-                                    {
-                                        targetList.Add(device);
-                                        oldTargetList.Add(device);
-                                    }
-                                }
 
+                                }
                             }
                         }
                     }
                 }
-                catch { }
+                catch (Exception ex)
+                {
+                    var mess = ex.Message;
+                }
                 finally
                 {
                     Application.RunOnMainThread(() =>
                     {
+
+                        //棣栨鏄惁鑳界偣鍑讳繚瀛�
+                        if (targetList.Count == 0)
+                        {
+                            curControlDev.currentSelectFloorId = BindInfo.GetCurrentSelectFloorId();
+                            curControlDev.currentSelectRoomId = null;
+                            if (BindInfo.GetCurrentSelectFloorIdName() != null)
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    btnFloorText.Text = BindInfo.GetCurrentSelectFloorIdName();
+                                });
+                            }
+                            btnFinifh.Enable = false;
+                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
+                        }
+                        else
+                        {
+                            foreach (var dev in targetList)
+                            {
+                                //鑾峰彇鏈湴璁惧鍒楄〃 
+                                var localDeviceList = Shared.Common.LocalDevice.Current.listAllDevice;
+                                var tempDev = localDeviceList.Find(obj => obj.DeviceAddr == dev.DeviceAddr && obj.DeviceEpoint == dev.DeviceEpoint);
+                                if (tempDev != null)
+                                {
+                                    //鑾峰彇璁惧鎵�灞炴埧闂�
+                                    var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
+                                    if (tempDevRoom != null)
+                                    {
+                                        curControlDev.currentSelectRoomId = tempDevRoom.Id;
+                                        curControlDev.currentSelectFloorId = tempDevRoom.FloorId;
+                                    }
+                                }
+                            }
+                            if (!string.IsNullOrEmpty(curControlDev.currentSelectFloorId))
+                            {
+                                if (BindInfo.GetBindTargetsFloorIdName(curControlDev.currentSelectFloorId) != null)
+                                {
+                                    btnFloorText.Text = BindInfo.GetBindTargetsFloorIdName(curControlDev.currentSelectFloorId);
+                                }
+                            }
+
+                            btnFinifh.Enable = true;
+                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                        }
+
+
+                        //鑾峰彇妤煎眰涓埧闂村垪琛�
                         if (supportRoomList.Count != 0)
                         {
-                            Shared.Common.Room curRoom = supportRoomList[0];
-                            int index = 0;
-                            RefreshRoomList(curRoom, ref index);
-                            RefreshDeviceList(curRoom);
-
-                            if (curRoom.ListDevice.Count == 0 || targetList.Count == 0)
-                            {
-                                btnFinifh.Enable = false;
-                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-                            }
-                            else
-                            {
-                                btnFinifh.Enable = true;
-                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                            }
+                            RefreshRoomList();
                         }
+
                         CommonPage.Loading.Hide();
+                        midVerticalScrolViewLayout.EndHeaderRefreshing();
                     });
                 }
             });
-        }
-
-        /// <summary>
-        /// 鍒囨崲妤煎眰
-        /// </summary>
-        /// <param name="dialog"></param>
-        /// <param name="curFloorId"></param>
-        /// <param name="btnMethodText"></param>
-        /// <param name="oldbuttonText"></param>
-        /// <param name="oldbutton"></param>
-        void ChangeFloor(Dialog dialog, string curFloorId, Button btnMethodText, Button oldbuttonText, Button oldbutton)
-        {
-            if (curControlDev.currentSelectFloorId == curFloorId)
-            {
-                return;
-            }
-            curControlDev.currentSelectFloorId = curFloorId;
-            btnFloorText.Text = dicFloorList[curFloorId];
-
-            //鑾峰彇妤煎眰涓埧闂村垪琛� 
-            supportRoomList = GetFloorRoomList();
-            if (supportRoomList.Count == 0)
-            {
-                return;
-            }
-            var curRoom = new Room();
-            if (supportRoomList.Count != 0)
-            {
-                curRoom = supportRoomList[0];
-            }
-            else
-            {
-                curRoom = new Shared.Common.Room();
-                supportRoomList.Add(curRoom);
-            }
-
-            if (!btnMethodText.IsSelected)
-            {
-                if (oldbutton != null)
-                {
-                    oldbutton.IsSelected = false;
-                }
-                if (oldbuttonText != null)
-                {
-                    oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
-                }
-                oldbutton = btnMethodText;
-                oldbuttonText = btnMethodText;
-                btnMethodText.IsSelected = true;
-                oldbuttonText.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                oldbuttonText.IsBold = true;
-            }
-
-            int index = 0;
-            RefreshRoomList(curRoom, ref index);
-
-            if (targetList.Count == 0)
-            {
-                btnFinifh.Enable = false;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-            }
-            else
-            {
-                btnFinifh.Enable = true;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-            }
-            dialog.Close();
-        }
-
-        /// <summary>
-        /// 鍒囨崲鎴块棿
-        /// </summary>
-        /// <param name="curRoom"></param>
-        /// <param name="room"></param>
-        /// <param name="btnRoom"></param>
-        /// <param name="curentOldRoom"></param>
-        /// <param name="btnRoomFrameLayout"></param>
-        /// <param name="curentOldRoomFrameLayout"></param>
-        void ChangeRoom(Room curRoom, Room room, Button btnRoom, Button curentOldRoom, FrameLayout btnRoomFrameLayout, FrameLayout curentOldRoomFrameLayout)
-        {
-            if (!btnRoom.IsSelected)
-            {
-                if (curentOldRoom != null)
-                {
-                    curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
-                }
-                curentOldRoom = btnRoom;
-                curentOldRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
-            }
-
-            if (btnRoomFrameLayout.BorderWidth == 1)
-            {
-                if (curentOldRoomFrameLayout != null)
-                {
-                    curentOldRoomFrameLayout.BorderWidth = 1;
-                    curentOldRoomFrameLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
-                    curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
-                }
-                curentOldRoomFrameLayout = btnRoomFrameLayout;
-                curentOldRoomFrameLayout.BorderWidth = 0;
-                curentOldRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
-            }
-            curRoom = room;
-            curControlDev.RoomId = room.Id;
-            if (curRoom.ListSceneId.Count == 0)
-            {
-                btnFinifh.Enable = false;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-            }
-            else
-            {
-                btnFinifh.Enable = true;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-            }
-            if (targetList.Count == 0)
-            {
-                btnFinifh.Enable = false;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-            }
-            else
-            {
-                btnFinifh.Enable = true;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-            }
-            RefreshDeviceList(curRoom);
-        }
-
-        /// <summary>
-        /// 鍒囨崲缁戝畾鐩爣
-        /// </summary>
-        void ChangeTarget(CommonDevice device, Button btnChoose, Button oldDevice)
-        {
-            if (curControlDev.bindList.Count != 0)
-            {
-                if (btnChoose.IsSelected)
-                {
-                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindExist), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
-                    return;
-                }
-            }
-
-            if (!btnChoose.IsSelected)
-            {
-                if (oldDevice != null)
-                {
-                    oldDevice.IsSelected = false;
-                    oldDevice.Visible = false;
-                }
-                oldDevice = btnChoose;
-                oldDevice.IsSelected = true;
-                oldDevice.Visible = true;
-                targetList.Clear();
-                targetList.Add(device);
-            }
-            if (targetList.Count == 0)
-            {
-                btnFinifh.Enable = false;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
-            }
-            else
-            {
-                btnFinifh.Enable = true;
-                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-            }
         }
 
         /// <summary>
@@ -944,24 +911,206 @@
         /// <param name="curControlDev"></param>
         void SaveTarget()
         {
-            bool isFinish = false;
-
-            //绌虹洰鏍�
+            btnFinifh.Enable = false;
             if (targetList.Count == 0)
             {
-                Application.RunOnMainThread(() =>
+                //绌虹洰鏍�
+                System.Threading.Tasks.Task.Run(async () =>
                 {
-                    var myTip = new Tip();
-                    myTip.Direction = AMPopTipDirection.None;
-                    myTip.CloseTime = 2;
-                    myTip.Text = Language.StringByID(R.MyInternationalizationString.BindDeviceTargetIsEmpty);
-                    myTip.Show(Common.CommonPage.Instance);
+                    try
+                    {
+                        Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
+
+                        if (oldTargetList.Count != 0)
+                        {
+                            //鍒犻櫎鍙栨秷鐨勭洰鏍�
+                            foreach (var bd in oldTargetList)
+                            {
+                                var delDevice = new DelDeviceBindData();
+                                delDevice.DeviceAddr = curControlDev.DeviceAddr;
+                                delDevice.Epoint = curControlDev.DeviceEpoint;
+
+                                var removeDevice = new RemoveBindListObj();
+                                removeDevice.BindType = 0;
+                                switch (curDeviceBindType)
+                                {
+                                    case 1:
+                                        removeDevice.BindCluster = 514;
+                                        break;
+                                    case 2:
+                                        removeDevice.BindCluster = 1026;
+                                        break;
+                                    case 3:
+                                        removeDevice.BindCluster = 1029;
+                                        break;
+                                    case 4:
+                                        //PM2.5
+                                        removeDevice.BindCluster = 1066;
+                                        break;
+                                }
+                                removeDevice.BindMacAddr = bd.DeviceAddr;
+                                removeDevice.BindEpoint = bd.DeviceEpoint;
+                                delDevice.RemoveBindList.Add(removeDevice);
+
+                                var delResult = new DelDeviceBindResponseAllData();
+                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
+                                if (delResult == 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;
+                                }
+                                else
+                                {
+                                    if (delResult.removeBindResultResponseData == null)
+                                    {
+                                        if (delResult.delDeviceBindResponseData != null)
+                                        {
+                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
+                                            {
+                                                if (d.Result == 1)
+                                                {
+                                                    switch (curDeviceBindType)
+                                                    {
+                                                        case 1:
+                                                            if (actionFreshAirTarget != null)
+                                                            {
+                                                                actionFreshAirTarget("");
+                                                            }
+                                                            break;
+                                                        case 2:
+                                                            if (actionTemperatureTarget != null)
+                                                            {
+                                                                actionTemperatureTarget("");
+                                                            }
+                                                            break;
+                                                        case 3:
+                                                            if (actionHumidityTarget != null)
+                                                            {
+                                                                actionHumidityTarget("");
+                                                            }
+                                                            break;
+                                                        case 4:
+                                                            if (actionPMTarget != null)
+                                                            {
+                                                                actionPMTarget("");
+                                                            }
+                                                            break;
+                                                    }
+                                                    Application.RunOnMainThread(() =>
+                                                    {
+                                                        CommonPage.Loading.Hide();
+                                                        btnFinifh.Enable = true;
+                                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                                        this.RemoveFromParent();
+                                                    });
+                                                }
+                                                else
+                                                {
+                                                    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;
+                                                }
+                                            }
+                                        }
+                                    }
+                                    else
+                                    {
+                                        if (delResult.removeBindResultResponseData.Result == 0)
+                                        {
+                                            switch (curDeviceBindType)
+                                            {
+                                                case 1:
+                                                    if (actionFreshAirTarget != null)
+                                                    {
+                                                        actionFreshAirTarget("");
+                                                    }
+                                                    break;
+                                                case 2:
+                                                    if (actionTemperatureTarget != null)
+                                                    {
+                                                        actionTemperatureTarget("");
+                                                    }
+                                                    break;
+                                                case 3:
+                                                    if (actionHumidityTarget != null)
+                                                    {
+                                                        actionHumidityTarget("");
+                                                    }
+                                                    break;
+                                                case 4:
+                                                    if (actionPMTarget != null)
+                                                    {
+                                                        actionPMTarget("");
+                                                    }
+                                                    break;
+                                            }
+                                            Application.RunOnMainThread(() =>
+                                            {
+                                                CommonPage.Loading.Hide();
+                                                btnFinifh.Enable = true;
+                                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                                this.RemoveFromParent();
+                                            });
+
+                                        }
+                                        else
+                                        {
+                                            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;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            //娌℃湁鐩爣鎻愮ず
+                            Application.RunOnMainThread(() =>
+                            {
+                                var myTip = new Tip();
+                                myTip.Direction = AMPopTipDirection.None;
+                                myTip.CloseTime = 2;
+                                myTip.Text = Language.StringByID(R.MyInternationalizationString.BindDeviceTargetIsEmpty);
+                                myTip.Show(Common.CommonPage.Instance);
+                                btnFinifh.Enable = true;
+                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                CommonPage.Loading.Hide();
+                            });
+                            return;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        var mess = ex.Message;
+                        Application.RunOnMainThread(() =>
+                        {
+                            CommonPage.Loading.Hide();
+                        });
+                        btnFinifh.Enable = true;
+                    }
                 });
-                return;
             }
             else
             {
-                //宸茬粡缁戝畾杩囩殑鐩爣
+                //閫変腑鐩爣
+                //1銆佸凡缁忕粦瀹氳繃鐨勭洰鏍�
                 if (checkExistDevice())
                 {
                     Application.RunOnMainThread(() =>
@@ -971,6 +1120,8 @@
                         myTip.CloseTime = 2;
                         myTip.Text = Language.StringByID(R.MyInternationalizationString.BindExist);
                         myTip.Show(Common.CommonPage.Instance);
+                        btnFinifh.Enable = true;
+                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                     });
                     return;
                 }
@@ -986,11 +1137,123 @@
                         {
                             foreach (var bd in oldTargetList)
                             {
-                                await RemoveTargets(bd);
+                                var delDevice = DelBindDevice(bd);
+                                var delResult = new DelDeviceBindResponseAllData();
+                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
+
+                                if (delResult == 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;
+                                }
+                                else
+                                {
+                                    if (delResult.removeBindResultResponseData == null)
+                                    {
+                                        if (delResult.delDeviceBindResponseData != null)
+                                        {
+                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
+                                            {
+                                                if (d.Result != 1)
+                                                {
+                                                    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)
+                                    {
+                                        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;
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            //妫�娴嬪凡缁忕粦瀹氱殑鐩爣鏄惁涓嶅湪鏈湴鎴栬�呮病鏈夊垎閰嶅埌浠讳綍鎴块棿涓�
+                            //姝ゆ椂闇�瑕佸垹闄ゅ凡缁忚缁戝畾鍒扮洰鏍囷紝鎵嶈兘缁х画缁戝畾鏂扮洰鏍�
+                            if (curBindDevice != null)
+                            {
+                                var delDevice = DelBindDevice(curBindDevice);
+                                var delResult = new DelDeviceBindResponseAllData();
+                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
+
+                                if (delResult == 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;
+                                }
+                                else
+                                {
+                                    if (delResult.removeBindResultResponseData == null)
+                                    {
+                                        if (delResult.delDeviceBindResponseData != null)
+                                        {
+                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
+                                            {
+                                                if (d.Result != 1)
+                                                {
+                                                    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)
+                                    {
+                                        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;
+                                    }
+                                }
                             }
                         }
 
-                        //娣诲姞鏂扮殑鐩爣
+                        //2銆佹坊鍔犳柊鐨勭洰鏍�
+                        string bindName = "";
                         var addBindeDev = new AddBindData();
                         addBindeDev.DeviceAddr = curControlDev.DeviceAddr;
                         addBindeDev.Epoint = curControlDev.DeviceEpoint;
@@ -1008,50 +1271,85 @@
                                 case 3:
                                     addBindInfo.BindCluster = 1029;
                                     break;
+                                case 4:
+                                    //PM2.5
+                                    addBindInfo.BindCluster = 1066;
+                                    break;
                             }
                             addBindInfo.BindType = 0;
                             addBindInfo.BindMacAddr = de.DeviceAddr;
                             addBindInfo.BindEpoint = de.DeviceEpoint;
+                            addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de);
+                            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;
+                            }
                             addBindeDev.BindList.Add(addBindInfo);
                         }
 
                         var dev = new AddedDeviceBindResponseAllData();
-                        dev = await curControlDev.AddDeviceBindAsync(addBindeDev);
-                        if (dev.addedDeviceBindResponseData == null)
+                        dev = HdlDeviceBindLogic.Current.AddDeviceBindAsync(addBindeDev);
+                        if (dev == null || dev.addedDeviceBindResponseData == null)
                         {
                             Application.RunOnMainThread(() =>
                             {
                                 CommonPage.Loading.Hide();
                                 new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                btnFinifh.Enable = true;
+                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                return;
                             });
-                            btnFinifh.Enable = true;
-                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
-                            return;
                         }
                         else
                         {
                             if (dev.addedDeviceBindResponseData.Result == 0)
                             {
-                                curControlDev.bindList = dev.addedDeviceBindResponseData.BindList;
                                 targetList.Clear();
-                                isFinish = true;
-                                if (isFinish)
+                                switch (curDeviceBindType)
                                 {
-                                    if (action != null)
-                                    {
-                                        action(curControlDev.bindList);
-                                    }
-                                    this.RemoveFromParent();
+                                    case 1:
+                                        if (actionFreshAirTarget != null)
+                                        {
+                                            actionFreshAirTarget(addBindeDev.BindName);
+                                        }
+                                        break;
+                                    case 2:
+                                        if (actionTemperatureTarget != null)
+                                        {
+                                            actionTemperatureTarget(addBindeDev.BindName);
+                                        }
+                                        break;
+                                    case 3:
+                                        if (actionHumidityTarget != null)
+                                        {
+                                            actionHumidityTarget(addBindeDev.BindName);
+                                        }
+                                        break;
+                                    case 4:
+                                        if (actionPMTarget != null)
+                                        {
+                                            actionPMTarget(addBindeDev.BindName);
+                                        }
+                                        break;
                                 }
-                                else
-                                {
-                                    this.RemoveFromParent();
-                                }
+
                                 Application.RunOnMainThread(() =>
                                 {
                                     CommonPage.Loading.Hide();
                                     btnFinifh.Enable = true;
                                     btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                    this.RemoveFromParent();
                                 });
                             }
                             else if (dev.addedDeviceBindResponseData.Result == 1)
@@ -1090,73 +1388,42 @@
                             }
                         }
                     }
-                    catch
+                    catch (Exception ex)
                     {
+                        Application.RunOnMainThread(() =>
+                        {
+                            CommonPage.Loading.Hide();
+                        });
+                        btnFinifh.Enable = true;
+                        var mess = ex.Message;
                     }
                 });
             }
         }
 
         /// <summary>
-        /// 鍒犻櫎瀛樺湪鐨勭洰鏍�
+        /// 褰撳墠琚粦瀹氳澶囨墍灞炴ゼ灞傚拰鎴块棿
         /// </summary>
-        /// <param name="bindDevice"></param>
-        /// <param name="btnDel"></param>
-        /// <returns></returns>
-        private async System.Threading.Tasks.Task<int> RemoveTargets(CommonDevice delDev)
+        /// <param name="bindDev"></param>
+        void BindDevInfo(CommonDevice bindDev)
         {
-            var delDevice = new DelDeviceBindData();
-            delDevice.DeviceAddr = curControlDev.DeviceAddr;
-            delDevice.Epoint = curControlDev.DeviceEpoint;
-
-            var removeDevice = new RemoveBindListObj();
-            removeDevice.BindType = 0;
-            switch (curDeviceBindType)
+            if (bindDev == null)
             {
-                case 1:
-                    removeDevice.BindCluster = 514;
-                    break;
-                case 2:
-                    removeDevice.BindCluster = 1026;
-                    break;
-                case 3:
-                    removeDevice.BindCluster = 1029;
-                    break;
+                return;
             }
-            removeDevice.BindMacAddr = delDev.DeviceAddr;
-            removeDevice.BindEpoint = delDev.DeviceEpoint;
-            delDevice.RemoveBindList.Add(removeDevice);
-
-            try
+            //鑾峰彇鏈湴璁惧鍒楄〃 
+            var localDeviceList = Shared.Common.LocalDevice.Current.listAllDevice;
+            var tempDev = localDeviceList.Find(obj => obj.DeviceAddr == bindDev.DeviceAddr && obj.DeviceEpoint == bindDev.DeviceEpoint);
+            if (tempDev != null)
             {
-                CommonPage.Loading.Start("");
-                var delResult = new DelDeviceBindResponseAllData();
-                delResult = await curControlDev.DelDeviceBindAsync(delDevice);
-                if (delResult != null && delResult.delDeviceBindResponseData != null)
+                //鑾峰彇璁惧鎵�灞炴埧闂�
+                var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
+                if (tempDevRoom != null)
                 {
-                    if (delResult.delDeviceBindResponseData?.RemoveBindList != null)
-                    {
-                        foreach (var re in delResult.delDeviceBindResponseData.RemoveBindList)
-                        {
-                            switch (re.Result)
-                            {
-                                case 0:
-                                    return 0;
-                                    break;
-                                case 1:
-                                    return 1;
-                                    break;
-                                case 2:
-                                    return 2;
-                                    break;
-                            }
-                        }
-                    }
+                    curControlDev.currentSelectRoomId = tempDevRoom.Id;
+                    curControlDev.currentSelectFloorId = tempDevRoom.FloorId;
                 }
             }
-            catch { }
-
-            return -1;
         }
 
         /// <summary>
@@ -1183,9 +1450,43 @@
         }
 
         /// <summary>
+        /// 妫�娴嬪凡缁忕粦瀹氱殑鐩爣鏄惁涓嶅湪鏈湴鎴栬�呮病鏈夊垎閰嶅埌浠讳綍鎴块棿涓�
+        /// </summary>
+        /// <returns></returns>
+        private DelDeviceBindData DelBindDevice(CommonDevice bd)
+        {
+            var delDevice = new DelDeviceBindData();
+            delDevice.DeviceAddr = curControlDev.DeviceAddr;
+            delDevice.Epoint = curControlDev.DeviceEpoint;
+
+            var removeDevice = new RemoveBindListObj();
+            removeDevice.BindType = 0;
+            switch (curDeviceBindType)
+            {
+                case 1:
+                    removeDevice.BindCluster = 514;
+                    break;
+                case 2:
+                    removeDevice.BindCluster = 1026;
+                    break;
+                case 3:
+                    removeDevice.BindCluster = 1029;
+                    break;
+                case 4:
+                    //PM2.5
+                    removeDevice.BindCluster = 1066;
+                    break;
+            }
+            removeDevice.BindMacAddr = bd.DeviceAddr;
+            removeDevice.BindEpoint = bd.DeviceEpoint;
+            delDevice.RemoveBindList.Add(removeDevice);
+            return delDevice;
+        }
+
+        /// <summary>
         /// 鑳芥樉绀虹殑鎴块棿鍒楄〃
         /// </summary>
-        private List<Room> GetSupportRoomList(Room curRoom)
+        private List<Room> GetSupportRoomList()
         {
             var roomTempList = new List<Room>();
             for (int i = 0; i < supportRoomList.Count; i++)
@@ -1202,14 +1503,169 @@
                 {
                     continue;
                 }
-
-                roomTempList.Add(room);
-                if (roomTempList.Count != 0)
+                else
                 {
-                    curRoom = roomTempList[0];
+                    List<CommonDevice> roomIncludeMatchDevice = new List<CommonDevice>();
+
+                    //鎴块棿涓病鏈夊搴旂殑鏀寔缁戝畾鐨勭洰鏍�
+                    switch (curDeviceBindType)
+                    {
+                        case 1:
+                            foreach (var de in room.ListDevice)
+                            {
+                                var device = LocalDevice.Current.GetDevice(de);
+
+                                if (device != null)
+                                {
+                                    //鑾峰彇璁惧绫诲瀷鐨�
+                                    var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
+                                    //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
+                                    if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                                    {
+                                        continue;
+                                    }
+                                    if (device.Type == DeviceType.FreshAir)
+                                    {
+                                        roomIncludeMatchDevice.Add(device);
+                                    }
+                                }
+                            }
+                            break;
+                        case 2:
+                            roomIncludeMatchDevice = GetMatchTemperatureSensorDevice(room);
+                            break;
+                        case 3:
+                            roomIncludeMatchDevice = GetMatchHumiditySensorDevice(room);
+                            foreach (var de in room.ListDevice)
+                            {
+                                var device = LocalDevice.Current.GetDevice(de);
+                                if (device != null)
+                                {
+                                    if (device.Type == DeviceType.FreshAirHumiditySensor)
+                                    {
+                                        roomIncludeMatchDevice.Add(device);
+                                    }
+                                }
+                            }
+                            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;
+                    }
+
+                    if (roomIncludeMatchDevice.Count == 0)
+                    {
+                        continue;
+                    }
+
+                    if (!string.IsNullOrEmpty(room.FloorId))
+                    {
+                        //鏈夋ゼ灞�
+                        if (room.FloorId == curControlDev.currentSelectFloorId)
+                        {
+                            roomTempList.Add(room);
+                        }
+                    }
+                    else
+                    {
+                        //娌℃湁妤煎眰
+                        roomTempList.Add(room);
+                    }
                 }
             }
             return roomTempList;
+        }
+
+        /// <summary>
+        /// 鍖归厤娓╁害浼犳劅鍣�
+        /// </summary>
+        /// <param name="room"></param>
+        List<CommonDevice> GetMatchTemperatureSensorDevice(Room room)
+        {
+            List<CommonDevice> roomIncludeMatchTempDevice = new List<CommonDevice>();
+            foreach (var de in room.ListDevice)
+            {
+                var device = LocalDevice.Current.GetDevice(de);
+                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);
+                            }
+                        }
+                    }
+                }
+            }
+            return roomIncludeMatchTempDevice;
+        }
+
+        /// <summary>
+        /// 鍖归厤婀垮害浼犳劅鍣�
+        /// </summary>
+        /// <param name="room"></param>
+        List<CommonDevice> GetMatchHumiditySensorDevice(Room room)
+        {
+            List<CommonDevice> roomIncludeMatchHumpDevice = new List<CommonDevice>();
+            foreach (var de in room.ListDevice)
+            {
+                var device = LocalDevice.Current.GetDevice(de);
+                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);
+                            }
+                        }
+                    }
+                }
+            }
+            return roomIncludeMatchHumpDevice;
         }
 
         /// <summary>
@@ -1238,24 +1694,21 @@
             }
             else
             {
-                // 鑾峰彇妤煎眰瀵瑰簲瀵规埧闂�
+                // 鑾峰彇鏀寔鐨勬埧闂�
                 foreach (var room in listAllRoom)
                 {
-                    if (room.FloorId == curControlDev.currentSelectFloorId)
+                    if (room.IsLove)
                     {
-                        if (room.IsLove)
-                        {
-                            continue;
-                        }
-                        supportRoomListTemp.Add(room);
+                        continue;
                     }
+                    supportRoomListTemp.Add(room);
                 }
             }
             return supportRoomListTemp;
         }
 
         /// <summary>
-        /// 鎴块棿涓尮閰嶇殑鏀寔缁戝畾鐨勬墍鏈夌洰鏍囧垪琛�
+        /// 鎵�鏈夋埧闂翠腑鍖归厤鐨勬敮鎸佺粦瀹氱殑鎵�鏈夌洰鏍囧垪琛�
         /// </summary>
         /// <returns></returns>
         List<CommonDevice> GetAllRoomSupportDeviceList()
@@ -1276,13 +1729,13 @@
                             var device = LocalDevice.Current.GetDevice(deviceKeys);
                             if (device != null)
                             {
-                                ////鑾峰彇璁惧绫诲瀷鐨�
-                                //var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
-                                ////鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
-                                //if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
-                                //{
-                                //    continue;
-                                //}
+                                //鑾峰彇璁惧绫诲瀷鐨�
+                                var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
+                                //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
+                                if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                                {
+                                    continue;
+                                }
                                 if (device.Type == DeviceType.FreshAir)
                                 {
                                     currentPanelBindSupportDeviceListTemp.Add(device);
@@ -1292,10 +1745,63 @@
                     }
                     break;
                 case 2:
+                    foreach (var r in supportRoomList)
+                    {
+                        if (r.ListDevice.Count == 0)
+                        {
+                            continue;
+                        }
+                        var deviceListTemp = GetMatchTemperatureSensorDevice(r);
+                        foreach (var dev in deviceListTemp)
+                        {
+                            currentPanelBindSupportDeviceListTemp.Add(dev);
+                        }
+                    }
                     break;
                 case 3:
+                    foreach (var r in supportRoomList)
+                    {
+                        if (r.ListDevice.Count == 0)
+                        {
+                            continue;
+                        }
+                        var deviceListTemp = GetMatchHumiditySensorDevice(r);
+                        foreach (var dev in deviceListTemp)
+                        {
+                            currentPanelBindSupportDeviceListTemp.Add(dev);
+                        }
+                        foreach (var deviceKeys in r.ListDevice)
+                        {
+                            var device = LocalDevice.Current.GetDevice(deviceKeys);
+                            if (device != null)
+                            {
+                                if (device.Type == DeviceType.FreshAirHumiditySensor)
+                                {
+                                    currentPanelBindSupportDeviceListTemp.Add(device);
+                                }
+                            }
+                        }
+                    }
                     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;
@@ -1314,16 +1820,16 @@
                 case 1:
                     foreach (var deviceKeys in curRoom.ListDevice)
                     {
-                        var device = LocalDevice.Current.GetDevice(deviceKeys);
+                        var device = LocalDevice.Current.GetDevice(deviceKeys);
                         if (device != null)
                         {
-                            ////鑾峰彇璁惧绫诲瀷鐨�
-                            //var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
-                            ////鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
-                            //if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
-                            //{
-                            //    continue;
-                            //}
+                            //鑾峰彇璁惧绫诲瀷鐨�
+                            var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
+                            //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
+                            if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                            {
+                                continue;
+                            }
                             if (device.Type == DeviceType.FreshAir)
                             {
                                 curRoomDeviceListTemp.Add(device);
@@ -1332,14 +1838,52 @@
                     }
                     break;
                 case 2:
+                    curRoomDeviceListTemp = GetMatchTemperatureSensorDevice(curRoom);
                     break;
                 case 3:
+                    curRoomDeviceListTemp = GetMatchHumiditySensorDevice(curRoom);
+                    foreach (var deviceKeys in curRoom.ListDevice)
+                    {
+                        var device = LocalDevice.Current.GetDevice(deviceKeys);
+                        if (device != null)
+                        {
+                            if (device.Type == DeviceType.FreshAirHumiditySensor)
+                            {
+                                curRoomDeviceListTemp.Add(device);
+                            }
+                        }
+                    }
                     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;
         }
-        #endregion 
+        #endregion
+
+        #region 绉婚櫎鏂规硶
+        /// <summary>
+        /// 閲嶅啓绉婚櫎鏂规硶
+        /// </summary>
+        public override void RemoveFromParent()
+        {
+            actionFreshAirTarget = null;
+            actionTemperatureTarget = null;
+            actionHumidityTarget = null;
+            actionPMTarget = null;
+            base.RemoveFromParent();
+        }
+        #endregion
     }
 }

--
Gitblit v1.8.0