From 23420922845c9e77019a55c3b3e3271eb1ec261e Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 13 七月 2020 11:42:18 +0800
Subject: [PATCH] 新版本

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs |  608 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 328 insertions(+), 280 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs
index d7e25e7..7fdf549 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs
@@ -93,7 +93,7 @@
         /// <summary>
         /// 妤煎眰鍒楄〃
         /// </summary>
-        Dictionary<string, string> dicFloorList;
+        Dictionary<string, string> dicFloorList = new Dictionary<string, string> { };
         /// <summary>
         /// 鎵�鏈夋埧闂翠腑鏀寔琚粦瀹氱殑璁惧鍒楄〃
         /// </summary>
@@ -130,7 +130,10 @@
         /// Ac缁戝畾鐩爣鍥炶皟
         /// </summary>
         public Action<string> actionAcTarget = null;
-
+        /// <summary>
+        /// 鏄惁鑳藉埛鏂�
+        /// </summary>
+        private bool canFresh = false;
         #endregion
 
         #region UI璁捐
@@ -143,6 +146,7 @@
             //鏍囬鏍忎笅鐨刄I
             MidFrameLayoutContent();
             //鍒濆鍖栬澶囨暟鎹�
+            CommonPage.Loading.Start("");
             InitData();
         }
 
@@ -184,7 +188,7 @@
         /// <summary>
         /// 涓儴UI銆愭爣棰樻爮涓嬬殑UI銆�
         /// </summary>
-        async void MidFrameLayoutContent()
+        void MidFrameLayoutContent()
         {
             var btnMidTopLayout = new FrameLayout
             {
@@ -208,6 +212,7 @@
             this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
             midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
             {
+                canFresh = true;
                 midVerticalScrolViewLayout.BeginHeaderRefreshing();
                 InitData();
             };
@@ -221,20 +226,24 @@
             };
             this.midFrameLayout.AddChidren(bottomFrameLayout);
 
+            var bottomTipPicFrameLayout = new FrameLayout()
+            {
+                Height = Application.GetMinReal(40 + 44 - 10),
+            };
+            bottomFrameLayout.AddChidren(bottomTipPicFrameLayout);
+
             var btnTipPicFrameLayout = new FrameLayout()
             {
-                Width = Application.GetMinReal(40 + 23 + 37),
+                Width = Application.GetMinReal(23 + 37),
                 Height = Application.GetMinReal(40 + 44 - 10),
-                X = Application.GetMinReal(383 - 37),
             };
-            bottomFrameLayout.AddChidren(btnTipPicFrameLayout);
+            bottomTipPicFrameLayout.AddChidren(btnTipPicFrameLayout);
 
             btnTipPic = new Button()
             {
                 Width = Application.GetMinReal(40),
                 Height = Application.GetMinReal(40),
-                X = Application.GetMinReal(40),
-                Y = Application.GetRealHeight(22),
+                Y = Application.GetRealHeight(19),
                 UnSelectedImagePath = "BindPic/EmptyTargets.png",
                 SelectedImagePath = "BindPic/EmptyTargetsSelected.png",
             };
@@ -243,14 +252,16 @@
             btnTipText = new Button()
             {
                 Height = Application.GetRealHeight(84 - 10),
-                X = Application.GetMinReal(444),
+                X = Application.GetMinReal(58),
                 Width = Application.GetMinReal(1080 - 446),
                 TextID = R.MyInternationalizationString.BindEmptyTargets,
-                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,//XMTopTitleText
+                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                 TextSize = 12,
                 TextAlignment = TextAlignment.CenterLeft,
             };
-            bottomFrameLayout.AddChidren(btnTipText);
+            bottomTipPicFrameLayout.AddChidren(btnTipText);
+            bottomTipPicFrameLayout.Width = btnTipPicFrameLayout.Width + Application.GetMinReal(2) + btnTipText.GetTextWidth();
+            bottomTipPicFrameLayout.Gravity = Gravity.CenterHorizontal;
 
             EventHandler<MouseEventArgs> eHandlerEmptyTargets = (sender, e) =>
             {
@@ -306,20 +317,19 @@
         void RefreshRoomList()
         {
             Room curRoom = null;
-            if (supportRoomList.Count == 0)
-            {
-                return;
-            }
             btnHorizontalScrolViewLayout.RemoveAll();
             Button curentOldRoom = null;
             FrameLayout curentOldRoomFrameLayout = null;
             int index = 0;
-            var roomTempList = BindInfo.GetSupportRoomList(curControlDev, supportRoomList, curDeviceBindType);
             Room slectedRoom = null;
-
             var roomUn = new Room();
             roomUn.Name = Language.StringByID(R.MyInternationalizationString.Undistributed);
             roomUn.Id = "UndistributedId";
+            List<Room> roomTempList = new List<Room> { };
+            if (supportRoomList.Count != 0)
+            {
+                roomTempList = BindInfo.GetSupportRoomList(curControlDev, supportRoomList, curDeviceBindType);
+            }
             if (undistruibuteDevList.Count != 0)
             {
                 roomTempList.Add(roomUn);
@@ -445,6 +455,8 @@
                     var btn = (Button)frame.GetChildren(0);
                     frame.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
                     btn.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+                    curentOldRoom = btn;
+                    curentOldRoomFrameLayout = frame;
                 }
                 else
                 {
@@ -464,7 +476,6 @@
             midVerticalScrolViewLayout.RemoveAll();
             Button oldDevice = null;
             int curIndex = 0;
-
             if (curRoom.Id == "UndistributedId")
             {
                 currentRoomSupportBindDeviceList = BindInfo.GetUndistributeDeviceList(undistruibuteDevList, curDeviceBindType);
@@ -640,6 +651,26 @@
                 btnChoose.MouseUpEventHandler += hander;
                 curIndex++;
             }
+
+            //棣栨鏄惁鑳界偣鍑讳繚瀛�
+            if (targetList.Count == 0)
+            {
+                if (targetListTemp.Count == 0)
+                {
+                    btnFinifh.Enable = false;
+                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
+                }
+                else
+                {
+                    btnFinifh.Enable = true;
+                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                }
+            }
+            else
+            {
+                btnFinifh.Enable = true;
+                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+            }
         }
 
         #endregion
@@ -648,23 +679,19 @@
         /// <summary>
         /// 鍒濆鍖栬澶囨暟鎹�
         /// </summary>
-        void InitData()
+        void InitData(bool canUpdateBindName = false)
         {
             System.Threading.Tasks.Task.Run(async () =>
             {
                 try
                 {
-                    Application.RunOnMainThread(() =>
-                    {
-                        CommonPage.Loading.Start("");
-                    });
                     //鑾峰彇琚粦鐩爣绛変俊鎭�
                     BindDevInfo(curBindDevice);
 
-                    //鑾峰彇妤煎眰
+                    //鑾峰彇妤煎眰    
                     dicFloorList = HdlRoomLogic.Current.GetFloorSortList();
-                    //鑾峰彇妤煎眰涓埧闂村垪琛�
-                    supportRoomList = BindInfo.GetFloorRoomList();
+                    //鑾峰彇鎴块棿鍒楄〃
+                    supportRoomList = BindInfo.GetSupportRoomList();
 
                     //鑾峰彇鎵�鏈夋埧闂翠腑鍖归厤鐨勮兘缁戠殑鐩爣
                     currentPanelSupportBindDeviceList = BindInfo.GetAllRoomSupportDeviceList(currentPanelSupportBindDeviceList, supportRoomList, curDeviceBindType);
@@ -685,13 +712,27 @@
                     {
                         Application.RunOnMainThread(() =>
                         {
-                            CommonPage.Loading.Hide();
+                            canFresh = false;
                             midVerticalScrolViewLayout.EndHeaderRefreshing();
+                            CommonPage.Loading.Hide();
                             new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+
+                            this.midFrameLayout.RemoveAll();
+
+                            ShowReLoadView();
+                            ReLoadAction += () =>
+                            {
+                                this.midFrameLayout.RemoveAll();
+                                //鍒濆鍖栬澶囨暟鎹�
+                                CommonPage.Loading.Start("");
+                                MidFrameLayoutContent();
+                                InitData(true);
+                            };
+
                         });
                     }
 
-                    targetList.Clear();
+                    oldTargetList.Clear();
                     //閫変腑鐩爣鍒楄〃 targetList
                     if (curControlDev.bindList.Count != 0)
                     {
@@ -700,7 +741,7 @@
                             var mainKey = bindDev.BindMacAddr + bindDev.BindEpoint;
 
                             //鍒嗛厤鐨勭洰鏍囧垪琛�
-                            if (currentPanelSupportBindDeviceList.Count != 0)
+                            if (Shared.Common.LocalDevice.Current.listAllDevice.Count != 0)
                             {
                                 var dev = currentPanelSupportBindDeviceList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == mainKey));
                                 if (dev != null)
@@ -738,31 +779,44 @@
                 {
                     Application.RunOnMainThread(() =>
                     {
-                        BindDownFrameLayout(this.midFrameLayout, curControlDev, dicFloorList, ref btnFloorText);
+                        //妤煎眰渚ц竟鏍忕粦瀹�
+                        if (!canFresh)
+                        {
+                            BindDownFrameLayout(this.midFrameLayout, curControlDev, dicFloorList, ref btnFloorText);
+                        }
                         ChooseFloorAction += (floorId, btnMethodText) =>
                         {
+                            btnFloorText.Text = string.Empty;
                             btnFloorText.Text = dicFloorList[floorId];
-                            //鑾峰彇妤煎眰涓埧闂村垪琛�
-                            supportRoomList = BindInfo.GetFloorRoomList();
+                            //鑾峰彇鎴块棿鍒楄〃
+                            supportRoomList = BindInfo.GetSupportRoomList();
                             //鑾峰彇鏈湴鏈垎閰嶇殑鏀寔褰撳墠绫诲瀷鐨勭粦瀹氳澶囧垪琛�
                             undistruibuteDevList = BindInfo.GetUndistributeDeviceList(undistruibuteDevList, curDeviceBindType);
                             RefreshRoomList();
                         };
+
+                        //榛樿妤煎眰鏄剧ず
+                        if (BindInfo.GetCurrentSelectFloorIdName() != null)
+                        {
+                            Application.RunOnMainThread(() =>
+                            {
+                                btnFloorText.Text = BindInfo.GetCurrentSelectFloorIdName();
+                            });
+                        }
 
                         //棣栨鏄惁鑳界偣鍑讳繚瀛�
                         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;
+
+                            //鏇存柊澶栭潰鐩爣鍚嶅瓧锛氭棤
+                            if (canUpdateBindName)
+                            {
+                                TargesBindName();
+                            }
                         }
                         else
                         {
@@ -785,6 +839,28 @@
                                         curControlDev.currentSelectRoomId = "UndistributedId";
                                     }
                                 }
+
+                                if (canUpdateBindName)
+                                {
+                                    //鏇存柊澶栭潰鐩爣鍚嶅瓧锛氬叿浣撳悕瀛椼�愬埛鏂版湰鍦扮晫闈細瀵艰嚧澶栭儴鐩爣鍙樺寲銆�
+                                    string bindName = Common.LocalDevice.Current.GetDeviceEpointName(dev);
+                                    switch (curDeviceBindType)
+                                    {
+                                        case BindInfo.BindType.Temperature:
+                                            if (dev.Type == DeviceType.PMSensor)
+                                            {
+                                                bindName += "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                                            }
+                                            break;
+                                        case BindInfo.BindType.Humidity:
+                                            if (dev.Type == DeviceType.PMSensor)
+                                            {
+                                                bindName += "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
+                                            }
+                                            break;
+                                    }
+                                    TargesBindName(bindName);
+                                }
                             }
                             if (!string.IsNullOrEmpty(curControlDev.currentSelectFloorId))
                             {
@@ -798,15 +874,11 @@
                             btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                         }
 
-
                         //鑾峰彇妤煎眰涓埧闂村垪琛�
-                        if (supportRoomList.Count != 0)
-                        {
-                            RefreshRoomList();
-                        }
-
-                        CommonPage.Loading.Hide();
+                        RefreshRoomList();
+                        canFresh = false;
                         midVerticalScrolViewLayout.EndHeaderRefreshing();
+                        CommonPage.Loading.Hide();
                     });
                 }
             });
@@ -827,75 +899,94 @@
                     try
                     {
                         Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
-
-                        if (oldTargetList.Count != 0)
+                        if (btnTipPic.IsSelected)
                         {
-                            //鍒犻櫎鍙栨秷鐨勭洰鏍�
-                            foreach (var bd in oldTargetList)
+                            //鍒犻櫎鎯呭喌1:缁戝畾绌虹洰鏍囧繀椤诲彇娑堟寜閿腑宸茬粡瀛樺湪鐨勭洰鏍�
+                            if (oldTargetList.Count != 0)
                             {
-                                var delDevice = new DelDeviceBindData();
-                                delDevice.DeviceAddr = curControlDev.DeviceAddr;
-                                delDevice.Epoint = curControlDev.DeviceEpoint;
+                                //鍒犻櫎鎸夐敭涓凡缁忕粦瀹氱殑鐩爣涓暟銆愬垹闄ゆ垚鍔熶釜鏁般��
+                                int sOldTargetListCount = 0;
 
-                                var removeDevice = new RemoveBindListObj();
-                                removeDevice.BindType = 0;
-                                switch (curDeviceBindType)
+                                foreach (var bd in oldTargetList)
                                 {
-                                    case BindInfo.BindType.FreshAir:
-                                        removeDevice.BindCluster = 514;
-                                        break;
-                                    case BindInfo.BindType.Temperature:
-                                        removeDevice.BindCluster = 1026;
-                                        break;
-                                    case BindInfo.BindType.Humidity:
-                                        removeDevice.BindCluster = 1029;
-                                        break;
-                                    case BindInfo.BindType.PM:
-                                        removeDevice.BindCluster = 1066;
-                                        break;
-                                    case BindInfo.BindType.AC:
-                                        removeDevice.BindCluster = 513;//Ac闇�瑕佺粦瀹�2涓皣513鍜�514
-                                        break;
-                                }
-                                removeDevice.BindMacAddr = bd.DeviceAddr;
-                                removeDevice.BindEpoint = bd.DeviceEpoint;
-                                delDevice.RemoveBindList.Add(removeDevice);
+                                    var delDevice = DelBindDevice(bd);
 
-                                if (curDeviceBindType == BindInfo.BindType.AC)
-                                {
-                                    //瑕佺Щ闄ょ┖璋冿細闇�瑕佺Щ闄�513锛�514
-                                    var removeDevice3 = new RemoveBindListObj();
-                                    removeDevice3.BindCluster = 514;
-                                    removeDevice3.BindType = 0;
-                                    removeDevice3.BindMacAddr = bd.DeviceAddr;
-                                    removeDevice3.BindEpoint = bd.DeviceEpoint;
-                                    delDevice.RemoveBindList.Add(removeDevice3);
-                                }
+                                    //姝ゆ鎸夐敭涓渶瑕佺Щ闄ょ殑鐩爣涓暟銆愬悓涓�涓洰鏍囨惡甯︾殑澶氫釜鍔熻兘鍒犻櫎鎴愬姛鐨勪釜鏁般��
+                                    int sRemoveBindListCount = 0;
 
-                                var delResult = new DelDeviceBindResponseAllData();
-                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
-                                if (delResult == null)
-                                {
-                                    Application.RunOnMainThread(() =>
+                                    var delResult = new DelDeviceBindResponseAllData();
+                                    delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
+                                    if (delResult == null)
                                     {
-                                        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)
+                                        Application.RunOnMainThread(() =>
                                         {
-                                            foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
+                                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                            CommonPage.Loading.Hide();
+
+                                            ShowReLoadView();
+                                            ReLoadAction += () =>
                                             {
-                                                if (d.Result == 0 || d.Result == 1)
+                                                this.midFrameLayout.RemoveAll();
+                                                //鍒濆鍖栬澶囨暟鎹�
+                                                CommonPage.Loading.Start("");
+                                                MidFrameLayoutContent();
+                                                InitData(true);
+                                            };
+                                        });
+                                        return;
+                                    }
+                                    else
+                                    {
+                                        if (delResult.removeBindResultResponseData == null)
+                                        {
+                                            if (delResult.delDeviceBindResponseData != null)
+                                            {
+                                                foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
                                                 {
-                                                    EmptyTargesMess();
+                                                    if (d.Result == 0 || d.Result == 1)
+                                                    {
+                                                        sRemoveBindListCount++;
+                                                        if (sRemoveBindListCount == delDevice.RemoveBindList.Count)
+                                                        {
+                                                            sOldTargetListCount++;
+                                                        }
+
+                                                        //鎸夐敭鐩爣涓殑璇ョ被鍨嬩釜鏁伴兘鍒犻櫎鎴愬姛
+                                                        if (sOldTargetListCount == oldTargetList.Count)
+                                                        {
+                                                            TargesBindName();
+                                                            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)
+                                            {
+                                                sOldTargetListCount++;
+                                                //鎸夐敭鐩爣涓殑璇ョ被鍨嬩釜鏁伴兘鍒犻櫎鎴愬姛
+                                                if (sOldTargetListCount == oldTargetList.Count)
+                                                {
+                                                    TargesBindName();
                                                     Application.RunOnMainThread(() =>
                                                     {
                                                         CommonPage.Loading.Hide();
@@ -904,54 +995,26 @@
                                                         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)
-                                        {
-                                            EmptyTargesMess();
-                                            Application.RunOnMainThread(() =>
+                                            else
                                             {
-                                                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;
+                                                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 (btnTipPic.IsSelected)
+                            else
                             {
-                                EmptyTargesMess();
+                                //鎸夐敭涓病鏈夌洰鏍囩洿鎺ョ粦瀹氱┖鐩爣
+                                TargesBindName();
                                 Application.RunOnMainThread(() =>
                                 {
                                     CommonPage.Loading.Hide();
@@ -959,22 +1022,6 @@
                                     btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                                     this.RemoveFromParent();
                                 });
-                            }
-                            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;
                             }
                         }
                     }
@@ -986,6 +1033,8 @@
                             CommonPage.Loading.Hide();
                         });
                         btnFinifh.Enable = true;
+                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+
                     }
                 });
             }
@@ -1014,11 +1063,17 @@
                     {
                         Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
 
-                        //鍒犻櫎宸茬粡瀛樺湪鐨勭洰鏍�
+                        //鍒犻櫎鎯呭喌2:鎸夐敭涔嬪墠宸茬粡瀛樺湪鐨勭洰鏍�
                         if (oldTargetList.Count != 0)
                         {
+                            //鍒犻櫎鎸夐敭涓凡缁忕粦瀹氱殑鐩爣涓暟銆愬垹闄ゆ垚鍔熶釜鏁般��
+                            int sOldTargetListCount = 0;
+
                             foreach (var bd in oldTargetList)
                             {
+                                //姝ゆ鎸夐敭涓渶瑕佺Щ闄ょ殑鐩爣涓暟銆愬悓涓�涓洰鏍囨惡甯︾殑澶氫釜鍔熻兘鍒犻櫎鎴愬姛鐨勪釜鏁般��
+                                int sRemoveBindListCount = 0;
+
                                 var delDevice = DelBindDevice(bd);
                                 var delResult = new DelDeviceBindResponseAllData();
                                 delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
@@ -1028,9 +1083,17 @@
                                     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();
+
+                                        ShowReLoadView();
+                                        ReLoadAction += () =>
+                                        {
+                                            this.midFrameLayout.RemoveAll();
+                                            //鍒濆鍖栬澶囨暟鎹�
+                                            CommonPage.Loading.Start("");
+                                            MidFrameLayoutContent();
+                                            InitData(true);
+                                        };
                                     });
                                     return;
                                 }
@@ -1053,84 +1116,43 @@
                                                     });
                                                     return;
                                                 }
+
+                                                sRemoveBindListCount++;
+                                                if (sRemoveBindListCount == delDevice.RemoveBindList.Count)
+                                                {
+                                                    sOldTargetListCount++;
+                                                }
                                             }
                                         }
                                     }
-                                }
-                                if (delResult != null && delResult.removeBindResultResponseData != null)
-                                {
-                                    if (delResult.removeBindResultResponseData.Result != 0)
+                                    else
                                     {
-                                        Application.RunOnMainThread(() =>
+                                        if (delResult.removeBindResultResponseData.Result != 0)
                                         {
-                                            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;
+                                            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;
+                                        }
+                                        sOldTargetListCount++;
                                     }
                                 }
                             }
-                        }
-                        else
-                        {
-                            //妫�娴嬪凡缁忕粦瀹氱殑鐩爣鏄惁涓嶅湪鏈湴鎴栬�呮病鏈夊垎閰嶅埌浠讳綍鎴块棿涓�
-                            //姝ゆ椂闇�瑕佸垹闄ゅ凡缁忚缁戝畾鍒扮洰鏍囷紝鎵嶈兘缁х画缁戝畾鏂扮洰鏍�
-                            if (curBindDevice != null)
-                            {
-                                var delDevice = DelBindDevice(curBindDevice);
-                                var delResult = new DelDeviceBindResponseAllData();
-                                delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
 
-                                if (delResult == null)
+                            if (sOldTargetListCount != oldTargetList.Count)
+                            {
+                                Application.RunOnMainThread(() =>
                                 {
-                                    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 != 0 && 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;
-                                    }
-                                }
+                                    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;
                             }
                         }
 
@@ -1204,9 +1226,16 @@
                             {
                                 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;
+
+                                ShowReLoadView();
+                                ReLoadAction += () =>
+                                {
+                                    this.midFrameLayout.RemoveAll();
+                                    //鍒濆鍖栬澶囨暟鎹�
+                                    CommonPage.Loading.Start("");
+                                    MidFrameLayoutContent();
+                                    InitData(true);
+                                };
                             });
                         }
                         else
@@ -1215,39 +1244,8 @@
                             {
                                 targetList.Clear();
                                 targetListTemp.Clear();
-                                switch (curDeviceBindType)
-                                {
-                                    case BindInfo.BindType.FreshAir:
-                                        if (actionFreshAirTarget != null)
-                                        {
-                                            actionFreshAirTarget(addBindeDev.BindName);
-                                        }
-                                        break;
-                                    case BindInfo.BindType.Temperature:
-                                        if (actionTemperatureTarget != null)
-                                        {
-                                            actionTemperatureTarget(addBindeDev.BindName);
-                                        }
-                                        break;
-                                    case BindInfo.BindType.Humidity:
-                                        if (actionHumidityTarget != null)
-                                        {
-                                            actionHumidityTarget(addBindeDev.BindName);
-                                        }
-                                        break;
-                                    case BindInfo.BindType.PM:
-                                        if (actionPMTarget != null)
-                                        {
-                                            actionPMTarget(addBindeDev.BindName);
-                                        }
-                                        break;
-                                    case BindInfo.BindType.AC:
-                                        if (actionAcTarget != null)
-                                        {
-                                            actionAcTarget(addBindeDev.BindName);
-                                        }
-                                        break;
-                                }
+
+                                TargesBindName(addBindeDev.BindName);
 
                                 Application.RunOnMainThread(() =>
                                 {
@@ -1308,9 +1306,9 @@
         }
 
         /// <summary>
-        /// 鐩爣涓虹┖鏃剁殑鏂囨湰鏄剧ず
+        /// 鐩爣涓烘枃鏈樉绀�
         /// </summary>
-        void EmptyTargesMess()
+        void EmptyTargesMess1()
         {
             switch (curDeviceBindType)
             {
@@ -1346,6 +1344,45 @@
                     break;
             }
         }
+        /// <summary>
+        /// 鐩爣涓烘枃鏈樉绀�
+        /// </summary>
+        void TargesBindName(string name = "")
+        {
+            switch (curDeviceBindType)
+            {
+                case BindInfo.BindType.FreshAir:
+                    if (actionFreshAirTarget != null)
+                    {
+                        actionFreshAirTarget(name);
+                    }
+                    break;
+                case BindInfo.BindType.Temperature:
+                    if (actionTemperatureTarget != null)
+                    {
+                        actionTemperatureTarget(name);
+                    }
+                    break;
+                case BindInfo.BindType.Humidity:
+                    if (actionHumidityTarget != null)
+                    {
+                        actionHumidityTarget(name);
+                    }
+                    break;
+                case BindInfo.BindType.PM:
+                    if (actionPMTarget != null)
+                    {
+                        actionPMTarget(name);
+                    }
+                    break;
+                case BindInfo.BindType.AC:
+                    if (actionAcTarget != null)
+                    {
+                        actionAcTarget(name);
+                    }
+                    break;
+            }
+        }
 
         /// <summary>
         /// 缁戝畾鐩爣鍒楄〃
@@ -1364,7 +1401,6 @@
                     {
                         if (device.Type == DeviceType.FreshAir)
                         {
-                            targetList.Add(device);
                             oldTargetList.Add(device);
                         }
                     }
@@ -1375,7 +1411,6 @@
                         var bDev = device as TemperatureSensor;
                         if (bDev.SensorDiv == 1)
                         {
-                            targetList.Add(device);
                             oldTargetList.Add(device);
                         }
                     }
@@ -1383,7 +1418,6 @@
                     {
                         if (bindDev.BindCluster == 1026)
                         {
-                            targetList.Add(device);
                             oldTargetList.Add(device);
                         }
                     }
@@ -1394,20 +1428,17 @@
                         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);
                         }
                     }
@@ -1417,7 +1448,6 @@
                     {
                         if (bindDev.BindCluster == 1066)
                         {
-                            targetList.Add(device);
                             oldTargetList.Add(device);
                         }
                     }
@@ -1427,12 +1457,18 @@
                     {
                         if (bindDev.BindCluster == 513)
                         {
-                            targetList.Add(device);
                             oldTargetList.Add(device);
                         }
                     }
                     break;
             }
+
+            targetList.Clear();
+            if (oldTargetList.Count != 0)
+            {
+                targetList.Add(oldTargetList[0]);
+            }
+
             targetListTemp.Clear();
             foreach (var d in targetList)
             {
@@ -1492,14 +1528,26 @@
                     removeDevice.BindCluster = 1066;
                     break;
                 case BindInfo.BindType.AC:
-                    removeDevice.BindCluster = 513;
+                    removeDevice.BindCluster = 513;//Ac闇�瑕佺粦瀹�2涓皣513鍜�514
                     break;
             }
             removeDevice.BindMacAddr = bd.DeviceAddr;
             removeDevice.BindEpoint = bd.DeviceEpoint;
             delDevice.RemoveBindList.Add(removeDevice);
+
+            if (curDeviceBindType == BindInfo.BindType.AC)
+            {
+                //瑕佺Щ闄ょ┖璋冿細闇�瑕佺Щ闄�513锛�514
+                var removeDevice3 = new RemoveBindListObj();
+                removeDevice3.BindCluster = 514;
+                removeDevice3.BindType = 0;
+                removeDevice3.BindMacAddr = bd.DeviceAddr;
+                removeDevice3.BindEpoint = bd.DeviceEpoint;
+                delDevice.RemoveBindList.Add(removeDevice3);
+            }
             return delDevice;
         }
+
         #endregion
 
         #region 绉婚櫎鏂规硶

--
Gitblit v1.8.0