From f14dcfd967404e197e7ec995ca8d6f2b090d3b7d Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期五, 11 九月 2020 09:16:59 +0800
Subject: [PATCH] 优化多功能面板:绑定温湿度传感器目标,和设备列表回路显示。优化数据矫正功能温湿度度不设置的情况。优化门锁时间设置最后一天和最后最后一个月的时间显示等 细节

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs | 1579 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1,579 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs
new file mode 100755
index 0000000..37af8dc
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/PaneTargetsBaseForm.cs
@@ -0,0 +1,1579 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Shared.Common;
+using Shared.Phone.UserCenter.DeviceBind;
+using ZigBee.Device;
+using static ZigBee.Device.BindObj;
+using static ZigBee.Device.Panel;
+namespace Shared.Phone.UserCenter.Device.Bind
+{
+    /// <summary>
+    /// 鐗规畩闈㈡澘鐨勭粦瀹氱晫闈€�愬彧鑳界粦瀹氱壒瀹氱被鍨嬶紝姣忕绫诲瀷鍙湁涓�涓洰鏍囥��
+    /// </summary>
+    public class PaneTargetsBaseForm : BindCommonLayout
+    {
+        #region  鏋勯�犲嚱鏁�
+        /// <summary>
+        /// 鏋勯�犲嚱鏁�
+        /// </summary>
+        /// <param name="device"></param>
+        /// <param name="deviceBindType">1:鏂伴;2:娓╁害浼犳劅鍣�;3:婀垮害浼犳劅鍣�;4:PM2.5浼犳劅鍣�;5:绌鸿皟鐩爣,6:鍦版殩鐩爣銆愭殏鏃舵病鍋氾紝鍥犱负娌℃湁璇ヨ澶囷紝鍚庢湡澧炲姞銆�</param>
+        /// <param name="bindDev">缁戝畾鐩爣 </param>
+        public PaneTargetsBaseForm(CommonDevice device, CommonDevice bindDev, DeviceBind.BindInfo.BindType deviceBindType)
+        {
+            curControlDev = new Panel();
+            curControlDev.DeviceAddr = device.DeviceAddr;
+            curControlDev.DeviceEpoint = device.DeviceEpoint;
+            curControlDev.CurrentGateWayId = device.CurrentGateWayId;
+            curControlDev.Type = device.Type;
+            this.curBindDevice = bindDev;
+            this.curDeviceBindType = deviceBindType;
+        }
+        #endregion
+
+        #region  鍙橀噺鐢虫槑
+        /// <summary>
+        /// 鎺у埗璁惧
+        /// </summary>
+        Panel curControlDev;
+        /// <summary>
+        /// 褰撳墠琚粦璁惧
+        /// </summary>
+        CommonDevice curBindDevice;
+        /// <summary>
+        /// 鏄剧ず琚粦瀹氳澶囨垨鍦烘櫙鐨剉iew
+        /// </summary>
+        VerticalRefreshLayout midVerticalScrolViewLayout;
+        /// <summary>
+        /// 鏄剧ず鎴块棿鐨剉iew
+        /// </summary>
+        HorizontalScrolViewLayout btnHorizontalScrolViewLayout;
+        /// <summary>
+        /// 鎸夐敭閰嶇疆鐨勭洰鏍囧垪琛�
+        /// </summary>
+        List<CommonDevice> targetList = new List<CommonDevice>();
+        /// <summary>
+        /// 鎸夐敭閰嶇疆鐨勭洰鏍囦复鏃跺垪琛�
+        /// </summary>
+        List<CommonDevice> targetListTemp = new List<CommonDevice>();
+        /// <summary>
+        /// 涓存椂鎴块棿
+        /// </summary>
+        Room tempRoom;
+        /// <summary>
+        /// 闈㈡澘涓凡缁忓瓨鍦ㄧ殑鐩爣鍒楄〃
+        /// </summary>
+        List<CommonDevice> oldTargetList = new List<CommonDevice>();
+        /// <summary>
+        /// 褰撳墠璁惧缁戝畾绫诲瀷
+        /// 1:鏂伴
+        /// 2:娓╁害浼犳劅鍣�
+        /// 3:婀垮害浼犳劅鍣�
+        /// 4:PM2.5浼犳劅鍣�
+        /// 5:绌鸿皟鐩爣
+        /// 6:鍦版殩鐩爣銆愭殏鏃舵病鍋氾紝鍥犱负娌℃湁璇ヨ澶囷紝鍚庢湡澧炲姞銆�
+        /// </summary>
+        DeviceBind.BindInfo.BindType curDeviceBindType = 0;
+        /// <summary>
+        /// 鏈湴鎴块棿鍒楄〃
+        /// </summary>
+        List<Room> supportRoomList = new List<Room>();
+        /// <summary>
+        /// 淇濆瓨瀹屾垚鎸夐挳
+        /// </summary>
+        Button btnFinifh;
+        /// <summary>
+        /// 妤煎眰鏂囨湰
+        /// </summary>
+        Button btnFloorText;
+        /// <summary>
+        /// 绌虹洰鏍囨寜閽�
+        /// </summary>
+        Button btnTipPic;
+        /// <summary>
+        /// 绌虹洰鏍囨枃鏈�
+        /// </summary>
+        Button btnTipText;
+        /// <summary>
+        /// 妤煎眰鍒楄〃
+        /// </summary>
+        Dictionary<string, string> dicFloorList = new Dictionary<string, string> { };
+        /// <summary>
+        /// 鎵�鏈夋埧闂翠腑鏀寔琚粦瀹氱殑璁惧鍒楄〃
+        /// </summary>
+        List<CommonDevice> currentPanelSupportBindDeviceList = new List<CommonDevice>();
+        /// <summary>
+        /// 鏈垎閰嶇殑璁惧鍒楄〃
+        /// </summary>
+        List<CommonDevice> undistruibuteDevList = new List<CommonDevice>();
+        /// <summary>
+        /// 褰撳墠鎴块棿涓敮鎸佽缁戝畾鐨勮澶囧垪琛�
+        /// </summary>
+        List<CommonDevice> currentRoomSupportBindDeviceList = new List<CommonDevice>();
+        /// <summary>
+        /// 闈㈡澘涓瓨鍦ㄧ殑閿��
+        /// </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;
+        /// <summary>
+        /// Ac缁戝畾鐩爣鍥炶皟
+        /// </summary>
+        public Action<string> actionAcTarget = null;
+        /// <summary>
+        /// Fh缁戝畾鐩爣鍥炶皟
+        /// </summary>
+        public Action<string> actionFhTarget = null;
+        /// <summary>
+        /// 鏄惁鑳藉埛鏂�
+        /// </summary>
+        private bool canFresh = false;
+        #endregion
+
+        #region UI璁捐
+        /// <summary>
+        /// 鐩爣椤垫樉绀�
+        /// </summary>
+        public void Show()
+        {
+            TitleUI();
+            //鏍囬鏍忎笅鐨刄I
+            MidFrameLayoutContent();
+            //鍒濆鍖栬澶囨暟鎹�
+            CommonPage.Loading.Start("");
+            InitData();
+        }
+
+        /// <summary>
+        /// 鏍囬鏍�
+        /// </summary>
+        void TitleUI()
+        {
+            string titleText = "";
+            switch (curDeviceBindType)
+            {
+                case DeviceBind.BindInfo.BindType.FreshAir:
+                    titleText = Language.StringByID(R.MyInternationalizationString.uNewWindTarget);
+                    break;
+                case DeviceBind.BindInfo.BindType.Temperature:
+                    titleText = Language.StringByID(R.MyInternationalizationString.TemperatureSource);
+                    break;
+                case DeviceBind.BindInfo.BindType.Humidity:
+                    titleText = Language.StringByID(R.MyInternationalizationString.HumiditySource);
+                    break;
+                case DeviceBind.BindInfo.BindType.PM:
+                    titleText = Language.StringByID(R.MyInternationalizationString.PM25Source);
+                    break;
+                case DeviceBind.BindInfo.BindType.AC:
+                    titleText = Language.StringByID(R.MyInternationalizationString.AcTargets);
+                    break;
+                case DeviceBind.BindInfo.BindType.Fh:
+                    titleText = Language.StringByID(R.MyInternationalizationString.uFloorHeatingTarget);
+                    break;
+            }
+            this.TopFrameLayout(this, titleText);
+            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
+            {
+                RemoveFromParent();
+            };
+            this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300);
+            this.btnBack.MouseUpEventHandler += eHandlerBack;
+            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
+            this.MidFrameLayout(this);
+        }
+
+        /// <summary>
+        /// 涓儴UI銆愭爣棰樻爮涓嬬殑UI銆�
+        /// </summary>
+        void MidFrameLayoutContent()
+        {
+            var btnMidTopLayout = new FrameLayout
+            {
+                Height = Application.GetRealHeight(389 - 184),
+            };
+            this.midFrameLayout.AddChidren(btnMidTopLayout);
+
+            //鎴块棿鏍�
+            btnHorizontalScrolViewLayout = new HorizontalScrolViewLayout
+            {
+                X = Application.GetRealWidth(58),
+            };
+            btnMidTopLayout.AddChidren(btnHorizontalScrolViewLayout);
+
+            //璁惧鏍�
+            midVerticalScrolViewLayout = new VerticalRefreshLayout()
+            {
+                Y = btnMidTopLayout.Bottom,
+                Height = Application.GetRealHeight(1145),
+            };
+            this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
+            midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
+            {
+                canFresh = true;
+                midVerticalScrolViewLayout.BeginHeaderRefreshing();
+                InitData();
+            };
+
+            //搴曢儴淇濆瓨鏍�
+            var bottomFrameLayout = new FrameLayout()
+            {
+                Width = LayoutParams.MatchParent,
+                Height = Application.GetRealHeight(84 * 2 + 127),
+                Y = Application.GetRealHeight(1388),
+            };
+            this.midFrameLayout.AddChidren(bottomFrameLayout);
+
+            var bottomTipPicFrameLayout = new FrameLayout()
+            {
+                Height = Application.GetMinReal(40 + 44 - 10),
+            };
+            bottomFrameLayout.AddChidren(bottomTipPicFrameLayout);
+
+            var btnTipPicFrameLayout = new FrameLayout()
+            {
+                Width = Application.GetMinReal(23 + 37),
+                Height = Application.GetMinReal(40 + 44 - 10),
+            };
+            bottomTipPicFrameLayout.AddChidren(btnTipPicFrameLayout);
+
+            btnTipPic = new Button()
+            {
+                Width = Application.GetMinReal(40),
+                Height = Application.GetMinReal(40),
+                Y = Application.GetRealHeight(19),
+                UnSelectedImagePath = "BindPic/EmptyTargets.png",
+                SelectedImagePath = "BindPic/EmptyTargetsSelected.png",
+            };
+            btnTipPicFrameLayout.AddChidren(btnTipPic);
+
+            btnTipText = new Button()
+            {
+                Height = Application.GetRealHeight(84 - 10),
+                X = Application.GetMinReal(58),
+                Width = Application.GetMinReal(1080 - 446),
+                TextID = R.MyInternationalizationString.BindEmptyTargets,
+                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
+                TextSize = 12,
+                TextAlignment = TextAlignment.CenterLeft,
+            };
+            bottomTipPicFrameLayout.AddChidren(btnTipText);
+            bottomTipPicFrameLayout.Width = btnTipPicFrameLayout.Width + Application.GetMinReal(12) + btnTipText.GetTextWidth();
+            bottomTipPicFrameLayout.Gravity = Gravity.CenterHorizontal;
+
+            EventHandler<MouseEventArgs> eHandlerEmptyTargets = (sender, e) =>
+            {
+                if (!btnFinifh.Enable)
+                {
+                    return;
+                }
+                if (btnTipPic.IsSelected)
+                {
+                    btnTipPic.IsSelected = false;
+                    foreach (var d in targetListTemp)
+                    {
+                        targetList.Add(d);
+                    }
+                    btnTipText.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
+                }
+                else
+                {
+                    btnTipPic.IsSelected = true;
+                    targetList.Clear();
+                    btnTipText.TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText;
+                }
+                RefreshDeviceList(tempRoom);
+            };
+            btnTipPicFrameLayout.MouseDownEventHandler += eHandlerEmptyTargets;
+            btnTipPic.MouseDownEventHandler += eHandlerEmptyTargets;
+
+            btnFinifh = new Button()
+            {
+                Width = Application.GetRealWidth(907),
+                Height = Application.GetRealHeight(127),
+                Y = Application.GetRealHeight(49 + 35),
+                Gravity = Gravity.CenterHorizontal,
+                Radius = (uint)Application.GetRealHeight(127) / 2,
+                TextID = R.MyInternationalizationString.Save,
+                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
+                TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
+                IsBold = true,
+                TextSize = 16,
+            };
+            bottomFrameLayout.AddChidren(btnFinifh);
+            btnFinifh.MouseUpEventHandler += (sender, e) =>
+            {
+                SaveTarget();
+            };
+        }
+
+        /// <summary>
+        /// 闈㈡澘缁戝畾鐩爣琛ㄦ樉绀�
+        /// </summary>
+        /// <param name="gateway">Gateway.</param>
+        /// <param name="key">Key.</param>
+        void RefreshRoomList()
+        {
+            Room curRoom = null;
+            btnHorizontalScrolViewLayout.RemoveAll();
+            Button curentOldRoom = null;
+            FrameLayout curentOldRoomFrameLayout = null;
+            int index = 0;
+            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);
+            }
+            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
+                {
+                    Height = Application.GetMinReal(159),
+                    Width = Application.GetMinReal(255 + 20),
+                    Y = Application.GetRealHeight(23),
+                    X = Application.GetRealWidth(5),
+                    BackgroundImagePath = "Item/RoomIconBackground.png",
+                    BorderWidth = 1,
+                };
+                btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayout);
+
+                var btnRoom = new Button
+                {
+                    Height = Application.GetRealHeight(66),
+                    Width = Application.GetRealWidth(187),
+                    Y = Application.GetRealHeight(58),
+                    X = Application.GetRealWidth(14),
+                    Text = room.Name,
+                    TextSize = 12,
+                    TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
+                    Gravity = Gravity.Center,
+                };
+                btnRoomFrameLayout.AddChidren(btnRoom);
+
+                btnRoom.IsSelected = false;
+                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 == roomTempList.Count - 1)
+                    {
+                        btnRoomFrameLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+                        btnRoom.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+                        curentOldRoom = btnRoom;
+                        curentOldRoomFrameLayout = btnRoomFrameLayout;
+                    }
+                }
+
+                if (index == roomTempList.Count - 1 && index > 2)
+                {
+                    var btnRoomFrameLayoutEmpty = new FrameLayout
+                    {
+                        Height = Application.GetMinReal(159),
+                        Width = Application.GetMinReal(50),
+                        Y = Application.GetRealHeight(23),
+                        X = Application.GetRealWidth(5),
+                        BorderWidth = 1,
+                    };
+                    btnHorizontalScrolViewLayout.AddChidren(btnRoomFrameLayoutEmpty);
+                }
+
+                EventHandler<MouseEventArgs> eHandlerRoom = (sender, e) =>
+                {
+                    if (!btnRoom.IsSelected)
+                    {
+                        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;
+
+                    //鏂伴闈㈡澘淇濆瓨浣胯兘
+                    btnFinifh.Enable = true;
+                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                    tempRoom = curRoom;
+                    RefreshDeviceList(curRoom);
+                };
+                btnRoom.MouseUpEventHandler += eHandlerRoom;
+                btnRoomFrameLayout.MouseUpEventHandler += eHandlerRoom;
+                index++;
+            }
+            BindInfo.FinishDisplay(roomTempList, btnFinifh);
+
+            if (roomTempList.Count == 0)
+            {
+                curRoom = new Shared.Common.Room();
+            }
+            else
+            {
+                if (slectedRoom == null)
+                {
+                    //鏈�変腑榛樿鏈�鍚庝竴涓�滄湭鍒嗛厤閫変腑鈥�
+                    curRoom = roomTempList[index - 1];
+                    var view = btnHorizontalScrolViewLayout.GetChildren(index - 1);
+                    var frame = (FrameLayout)view;
+                    var btn = (Button)frame.GetChildren(0);
+                    frame.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
+                    btn.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
+                    curentOldRoom = btn;
+                    curentOldRoomFrameLayout = frame;
+                }
+                else
+                {
+                    curRoom = slectedRoom;
+                }
+            }
+            tempRoom = curRoom;
+            RefreshDeviceList(curRoom);
+        }
+
+        /// <summary>
+        /// 鎸夐敭缁戠洰鏍囪〃鏄剧ず
+        /// </summary>
+        /// <param name="curRoom"></param>
+        void RefreshDeviceList(Room curRoom)
+        {
+            midVerticalScrolViewLayout.RemoveAll();
+            Button oldDevice = null;
+            int curIndex = 0;
+            if (curRoom.Id == "UndistributedId")
+            {
+                currentRoomSupportBindDeviceList = BindInfo.GetUndistributeDeviceList(undistruibuteDevList, curDeviceBindType);
+            }
+            else
+            {
+                currentRoomSupportBindDeviceList = BindInfo.GetCurRoomSupportDeviceList(currentRoomSupportBindDeviceList, curRoom, curDeviceBindType);
+            }
+            if (currentRoomSupportBindDeviceList.Count == 0)
+            {
+                btnFinifh.Enable = false;
+                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
+                return;
+            }
+            foreach (var device in currentRoomSupportBindDeviceList)
+            {
+                #region 缁戝畾琛║I鏄撅紙鏃犳暟鎹鐞嗭級
+                var rowLayout = new FrameLayout()
+                {
+                    Height = Application.GetRealHeight(23 + 127),
+                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
+                };
+                midVerticalScrolViewLayout.AddChidren(rowLayout);
+
+                var devicePic = new Button()
+                {
+                    X = Application.GetMinRealAverage(58),
+                    Y = Application.GetMinRealAverage(46),
+                    Width = Application.GetMinRealAverage(81),
+                    Height = Application.GetMinRealAverage(81),
+                    UnSelectedImagePath = device.IconPath,
+                };
+                rowLayout.AddChidren(devicePic);
+
+                var btnBindName = new Button()
+                {
+                    Width = Application.GetRealWidth(790),
+                    X = devicePic.Right + Application.GetRealWidth(20),
+                    TextAlignment = TextAlignment.CenterLeft,
+                    TextSize = 15,
+                    Text = Common.LocalDevice.Current.GetDeviceEpointName(device),
+                };
+                rowLayout.AddChidren(btnBindName);
+
+                var btnChoose = new Button()
+                {
+                    Width = Application.GetMinReal(60),
+                    Height = Application.GetMinReal(60),
+                    X = Application.GetRealWidth(861 + 81),
+                    Y = Application.GetRealHeight(35),
+                    SelectedImagePath = "DoorLock/SelectedIcon.png",
+                    Visible = false,
+                };
+                rowLayout.AddChidren(btnChoose);
+
+                var line2 = new Button()
+                {
+                    Y = rowLayout.Height - 1,
+                    X = devicePic.Right + Application.GetRealWidth(20),
+                    Width = Application.GetRealWidth(965 - 116),
+                    Height = 1,
+                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
+                };
+                rowLayout.AddChidren(line2);
+
+                if (curIndex == currentRoomSupportBindDeviceList.Count - 1)
+                {
+                    line2.Visible = false;
+                }
+                if (Common.LocalDevice.Current.CheckDeviceIsOnline(device) == true)
+                {
+                    btnBindName.TextColor = Shared.Common.ZigbeeColor.Current.TextBlack;
+                }
+                else
+                {
+                    btnBindName.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
+                }
+                switch (curDeviceBindType)
+                {
+                    case DeviceBind.BindInfo.BindType.FreshAir:
+                        devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
+                        break;
+                    case DeviceBind.BindInfo.BindType.Temperature:
+                        devicePic.UnSelectedImagePath = "Device/SensorTemperature.png";
+                        if (device.Type == DeviceType.PMSensor)
+                        {
+                            btnBindName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device) + "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                        }
+                        break;
+                    case DeviceBind.BindInfo.BindType.Humidity:
+                        devicePic.UnSelectedImagePath = "Device/SensorHumidity.png";
+                        if (device.Type == DeviceType.PMSensor)
+                        {
+                            btnBindName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device) + "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
+                        }
+                        break;
+                    case DeviceBind.BindInfo.BindType.PM:
+                        devicePic.UnSelectedImagePath = "Device/AirQualitySensorEpoint.png";
+                        break;
+                    case DeviceBind.BindInfo.BindType.AC:
+                        devicePic.UnSelectedImagePath = "Device/AirConditionerEpoint.png";
+                        break;
+                }
+                #endregion
+
+                string mianKey = device.DeviceAddr + device.DeviceEpoint;
+                if (targetList.Count != 0)
+                {
+                    foreach (var bindedDev in targetList)
+                    {
+                        if (bindedDev.DeviceAddr + bindedDev.DeviceEpoint == mianKey)
+                        {
+                            btnChoose.IsSelected = true;
+                            btnChoose.Visible = true;
+                            oldDevice = btnChoose;
+                        }
+                    }
+                }
+
+                EventHandler<MouseEventArgs> hander = (sender, e) =>
+                {
+                    if (btnChoose.IsSelected)
+                    {
+                        return;
+                    }
+                    if (btnTipPic.IsSelected)
+                    {
+                        btnTipPic.IsSelected = false;
+                        foreach (var d in targetListTemp)
+                        {
+                            targetList.Add(d);
+                        }
+                        btnTipText.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
+                    }
+                    btnChoose.IsSelected = true;
+
+                    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);
+                    }
+                    targetListTemp.Clear();
+                    foreach (var d in targetList)
+                    {
+                        targetListTemp.Add(d);
+                    }
+                    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)
+            {
+                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
+
+        #region 鏁版嵁澶勭悊
+        /// <summary>
+        /// 鍒濆鍖栬澶囨暟鎹�
+        /// </summary>
+        void InitData(bool canUpdateBindName = false)
+        {
+            System.Threading.Tasks.Task.Run(async () =>
+            {
+                try
+                {
+                    //鑾峰彇琚粦鐩爣绛変俊鎭�
+                    BindDevInfo(curBindDevice);
+
+                    //鑾峰彇妤煎眰    
+                    dicFloorList = HdlRoomLogic.Current.GetFloorSortList();
+                    //鑾峰彇鎴块棿鍒楄〃
+                    supportRoomList = BindInfo.GetSupportRoomList();
+
+                    //鑾峰彇鎵�鏈夋埧闂翠腑鍖归厤鐨勮兘缁戠殑鐩爣
+                    currentPanelSupportBindDeviceList = BindInfo.GetAllRoomSupportDeviceList(currentPanelSupportBindDeviceList, supportRoomList, curDeviceBindType);
+                    //鑾峰彇鏈湴鏈垎閰嶇殑鏀寔褰撳墠绫诲瀷鐨勭粦瀹氳澶囧垪琛�
+                    undistruibuteDevList = BindInfo.GetUndistributeDeviceList(undistruibuteDevList, curDeviceBindType);
+
+                    //鑾峰彇闈㈡澘涓瓨鍦ㄧ殑缁戝畾鐩爣
+                    var panelBindListRes = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
+                    if (panelBindListRes != null && panelBindListRes.getAllBindResponseData != null)
+                    {
+                        curControlDev.bindList.Clear();
+                        foreach (var bDev in panelBindListRes.getAllBindResponseData.BindList)
+                        {
+                            curControlDev.bindList.Add(bDev);
+                        }
+                    }
+                    else
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            canFresh = false;
+                            midVerticalScrolViewLayout.EndHeaderRefreshing();
+                            CommonPage.Loading.Hide();
+                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5007" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+
+                            this.midFrameLayout.RemoveAll();
+
+                            ShowReLoadView();
+                            ReLoadAction += () =>
+                            {
+                                this.midFrameLayout.RemoveAll();
+                                //鍒濆鍖栬澶囨暟鎹�
+                                CommonPage.Loading.Start("");
+                                MidFrameLayoutContent();
+                                InitData(true);
+                            };
+
+                        });
+                    }
+
+                    oldTargetList.Clear();
+                    //閫変腑鐩爣鍒楄〃 targetList
+                    if (curControlDev.bindList.Count != 0)
+                    {
+                        foreach (var bindDev in curControlDev.bindList)
+                        {
+                            var mainKey = bindDev.BindMacAddr + bindDev.BindEpoint;
+
+                            //鍒嗛厤鐨勭洰鏍囧垪琛�
+                            if (Shared.Common.LocalDevice.Current.listAllDevice.Count != 0)
+                            {
+                                var dev = currentPanelSupportBindDeviceList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == mainKey));
+                                if (dev != null)
+                                {
+                                    var device = LocalDevice.Current.GetDevice(dev.DeviceAddr, dev.DeviceEpoint);
+                                    if (device != null)
+                                    {
+                                        BindTypeTargetsList(device, bindDev);
+                                    }
+                                }
+                            }
+
+                            //鏈垎閰嶇殑鐩爣鍒楄〃
+                            if (undistruibuteDevList.Count != 0)
+                            {
+                                var dev = undistruibuteDevList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == mainKey));
+                                if (dev != null)
+                                {
+                                    var device = LocalDevice.Current.GetDevice(dev.DeviceAddr, dev.DeviceEpoint);
+                                    if (device != null)
+                                    {
+                                        BindTypeTargetsList(device, bindDev);
+                                    }
+
+                                }
+                            }
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    var mess = ex.Message;
+                }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        //妤煎眰渚ц竟鏍忕粦瀹�
+                        if (!canFresh)
+                        {
+                            BindDownFrameLayout(this.midFrameLayout, curControlDev, dicFloorList, ref btnFloorText);
+                        }
+                        ChooseFloorAction += (floorId, btnMethodText) =>
+                        {
+                            btnFloorText.Text = string.Empty;
+                            btnFloorText.Text = dicFloorList[floorId];
+                            //鑾峰彇鎴块棿鍒楄〃
+                            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;
+                            btnFinifh.Enable = false;
+                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
+
+                            //鏇存柊澶栭潰鐩爣鍚嶅瓧锛氭棤
+                            if (canUpdateBindName)
+                            {
+                                TargesBindName();
+                            }
+                        }
+                        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;
+                                    }
+                                    else
+                                    {
+                                        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))
+                            {
+                                if (BindInfo.GetBindTargetsFloorIdName(curControlDev.currentSelectFloorId) != null)
+                                {
+                                    btnFloorText.Text = BindInfo.GetBindTargetsFloorIdName(curControlDev.currentSelectFloorId);
+                                }
+                            }
+
+                            btnFinifh.Enable = true;
+                            btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                        }
+
+                        //鑾峰彇妤煎眰涓埧闂村垪琛�
+                        RefreshRoomList();
+                        canFresh = false;
+                        midVerticalScrolViewLayout.EndHeaderRefreshing();
+                        CommonPage.Loading.Hide();
+                    });
+                }
+            });
+        }
+
+        /// <summary>
+        /// 淇濆瓨鐩爣
+        /// </summary>
+        /// <param name="curControlDev"></param>
+        void SaveTarget()
+        {
+            btnFinifh.Enable = false;
+            if (targetList.Count == 0)
+            {
+                //绌虹洰鏍�
+                System.Threading.Tasks.Task.Run(async () =>
+                {
+                    try
+                    {
+                        Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
+                        if (btnTipPic.IsSelected)
+                        {
+                            //褰撶粦瀹氱┖鐩爣锛岃鍒犻櫎宸茬粡瀛樺湪鎸夐敭鐨勭洰鏍�
+                            if (oldTargetList.Count != 0)
+                            {
+                                //鍒犻櫎鎸夐敭涓凡缁忕粦瀹氱殑鐩爣涓暟銆愬垹闄ゆ垚鍔熶釜鏁般��
+                                int sOldTargetListCount = 0;
+
+                                foreach (var bd in oldTargetList)
+                                {
+                                    var delDevice = DelBindDevice(bd);
+
+                                    //姝ゆ鎸夐敭涓渶瑕佺Щ闄ょ殑鐩爣涓暟銆愬悓涓�涓洰鏍囨惡甯︾殑澶氫釜鍔熻兘鍒犻櫎鎴愬姛鐨勪釜鏁般��
+                                    int sRemoveBindListCount = 0;
+
+                                    var delResult = new DelDeviceBindResponseAllData();
+                                    delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
+                                    if (delResult == null)
+                                    {
+                                        Application.RunOnMainThread(() =>
+                                        {
+                                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5003_1" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                            CommonPage.Loading.Hide();
+
+                                            ShowReLoadView();
+                                            ReLoadAction += () =>
+                                            {
+                                                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)
+                                                {
+                                                    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) + "(" + "5003_3" + ")", 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();
+                                                        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) + "(" + "5003_2" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                                    btnFinifh.Enable = true;
+                                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                                    CommonPage.Loading.Hide();
+                                                });
+                                                return;
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                //鎸夐敭涓病鏈夌洰鏍囩洿鎺ョ粦瀹氱┖鐩爣
+                                TargesBindName();
+                                Application.RunOnMainThread(() =>
+                                {
+                                    CommonPage.Loading.Hide();
+                                    btnFinifh.Enable = true;
+                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                    this.RemoveFromParent();
+                                });
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        var mess = ex.Message;
+                        Application.RunOnMainThread(() =>
+                        {
+                            CommonPage.Loading.Hide();
+                        });
+                        btnFinifh.Enable = true;
+                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+
+                    }
+                });
+            }
+            else
+            {
+                //閫変腑鐩爣
+                //1銆佸凡缁忕粦瀹氳繃鐨勭洰鏍�
+                if (BindInfo.checkExistDevice(targetList, oldTargetList))
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        var myTip = new Tip();
+                        myTip.Direction = AMPopTipDirection.None;
+                        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;
+                }
+
+                System.Threading.Tasks.Task.Run(async () =>
+                {
+                    try
+                    {
+                        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);
+
+                                if (delResult == null)
+                                {
+                                    Application.RunOnMainThread(() =>
+                                    {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5003_4" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                        CommonPage.Loading.Hide();
+
+                                        ShowReLoadView();
+                                        ReLoadAction += () =>
+                                        {
+                                            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)
+                                            {
+                                                if (d.Result != 0 && d.Result != 1)
+                                                {
+                                                    Application.RunOnMainThread(() =>
+                                                    {
+                                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5003_6" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                                        btnFinifh.Enable = true;
+                                                        btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                                        CommonPage.Loading.Hide();
+                                                    });
+                                                    return;
+                                                }
+
+                                                sRemoveBindListCount++;
+                                                if (sRemoveBindListCount == delDevice.RemoveBindList.Count)
+                                                {
+                                                    sOldTargetListCount++;
+                                                }
+                                            }
+                                        }
+                                    }
+                                    else
+                                    {
+                                        if (delResult.removeBindResultResponseData.Result != 0)
+                                        {
+                                            Application.RunOnMainThread(() =>
+                                            {
+                                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5003_5" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+                                                btnFinifh.Enable = true;
+                                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                                CommonPage.Loading.Hide();
+                                            });
+                                            return;
+                                        }
+                                        sOldTargetListCount++;
+                                    }
+                                }
+                            }
+
+                            if (sOldTargetListCount != oldTargetList.Count)
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5003_7" + ")", 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;
+                        foreach (var de in targetList)
+                        {
+                            var addBindInfo = new AddBindListObj();
+                            switch (curDeviceBindType)
+                            {
+                                case BindInfo.BindType.FreshAir:
+                                    addBindInfo.BindCluster = 514;
+                                    break;
+                                case BindInfo.BindType.Temperature:
+                                    addBindInfo.BindCluster = 1026;
+                                    break;
+                                case BindInfo.BindType.Humidity:
+                                    addBindInfo.BindCluster = 1029;
+                                    break;
+                                case BindInfo.BindType.PM:
+                                    addBindInfo.BindCluster = 1066;
+                                    break;
+                                case BindInfo.BindType.AC:
+                                    addBindInfo.BindCluster = 513;
+                                    break;
+                            }
+                            addBindInfo.BindType = 0;
+                            addBindInfo.BindMacAddr = de.DeviceAddr;
+                            addBindInfo.BindEpoint = de.DeviceEpoint;
+                            addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de);
+                            switch (curDeviceBindType)
+                            {
+                                case BindInfo.BindType.Temperature:
+                                    if (de.Type == DeviceType.PMSensor)
+                                    {
+                                        addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de) + "-" + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                                    }
+                                    break;
+                                case BindInfo.BindType.Humidity:
+                                    if (de.Type == DeviceType.PMSensor)
+                                    {
+                                        addBindeDev.BindName = Common.LocalDevice.Current.GetDeviceEpointName(de) + "-" + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
+                                    }
+                                    break;
+                            }
+
+                            //閮ㄥ垎鐩爣闇�瑕佷簩娆$粦瀹氱浜岀鍔熻兘
+                            var addBindInfo2 = new AddBindListObj();
+                            addBindInfo2.BindType = 0;
+                            addBindInfo2.BindMacAddr = de.DeviceAddr;
+                            addBindInfo2.BindEpoint = de.DeviceEpoint;
+                            switch (curDeviceBindType)
+                            {
+                                case BindInfo.BindType.AC:
+                                    //瑕佺粦瀹氱┖璋冿細闇�瑕佺粦瀹�513锛�514
+                                    addBindInfo2.BindCluster = 514;
+                                    addBindeDev.BindList.Add(addBindInfo2);
+                                    break;
+                            }
+                            addBindeDev.BindList.Add(addBindInfo);
+                        }
+
+                        var dev = new AddedDeviceBindResponseAllData();
+                        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) + "(" + "5001" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
+
+                                ShowReLoadView();
+                                ReLoadAction += () =>
+                                {
+                                    this.midFrameLayout.RemoveAll();
+                                    //鍒濆鍖栬澶囨暟鎹�
+                                    CommonPage.Loading.Start("");
+                                    MidFrameLayoutContent();
+                                    InitData(true);
+                                };
+                            });
+                        }
+                        else
+                        {
+                            if (dev.addedDeviceBindResponseData.Result == 0)
+                            {
+                                targetList.Clear();
+                                targetListTemp.Clear();
+
+                                TargesBindName(addBindeDev.BindName);
+
+                                Application.RunOnMainThread(() =>
+                                {
+                                    CommonPage.Loading.Hide();
+                                    btnFinifh.Enable = true;
+                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                    this.RemoveFromParent();
+                                });
+                            }
+                            else if (dev.addedDeviceBindResponseData.Result == 1)
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    btnFinifh.Enable = true;
+                                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                    CommonPage.Loading.Hide();
+                                    new Tip()
+                                    {
+                                        MaxWidth = 150,
+                                        Text = Language.StringByID(R.MyInternationalizationString.BindFailed) + "(" + "5001_1" + ")",
+                                        Direction = AMPopTipDirection.None,
+                                        CloseTime = 1
+                                    }.Show(CommonPage.Instance);
+                                });
+
+                                return;
+                            }
+                            else
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    CommonPage.Loading.Hide();
+                                    new Tip()
+                                    {
+                                        MaxWidth = 150,
+                                        Text = Language.StringByID(R.MyInternationalizationString.BindUnknownError) + "(" + "5001_2" + ")",
+                                        Direction = AMPopTipDirection.None,
+                                        CloseTime = 1
+                                    }.Show(CommonPage.Instance);
+                                });
+                                btnFinifh.Enable = true;
+                                btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
+                                return;
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            CommonPage.Loading.Hide();
+                        });
+                        btnFinifh.Enable = true;
+                        var mess = ex.Message;
+                    }
+                });
+            }
+        }
+
+        /// <summary>
+        /// 鐩爣涓烘枃鏈樉绀�
+        /// </summary>
+        void EmptyTargesMess1()
+        {
+            switch (curDeviceBindType)
+            {
+                case BindInfo.BindType.FreshAir:
+                    if (actionFreshAirTarget != null)
+                    {
+                        actionFreshAirTarget("");
+                    }
+                    break;
+                case BindInfo.BindType.Temperature:
+                    if (actionTemperatureTarget != null)
+                    {
+                        actionTemperatureTarget("");
+                    }
+                    break;
+                case BindInfo.BindType.Humidity:
+                    if (actionHumidityTarget != null)
+                    {
+                        actionHumidityTarget("");
+                    }
+                    break;
+                case BindInfo.BindType.PM:
+                    if (actionPMTarget != null)
+                    {
+                        actionPMTarget("");
+                    }
+                    break;
+                case BindInfo.BindType.AC:
+                    if (actionAcTarget != null)
+                    {
+                        actionAcTarget("");
+                    }
+                    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>
+        /// 缁戝畾鐩爣鍒楄〃
+        /// </summary>
+        /// <param name="device"></param>
+        /// <param name="bindDev"></param>
+        void BindTypeTargetsList(CommonDevice device, BindListResponseObj bindDev)
+        {
+            switch (curDeviceBindType)
+            {
+                case BindInfo.BindType.FreshAir:
+                    //鑾峰彇璁惧绫诲瀷鐨�
+                    var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
+                    //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず
+                    if (deviceEnumInfo.ConcreteType != Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                    {
+                        if (device.Type == DeviceType.FreshAir)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    break;
+                case BindInfo.BindType.Temperature:
+                    if (device.Type == DeviceType.TemperatureSensor)
+                    {
+                        var bDev = device as TemperatureSensor;
+                        if (bDev.SensorDiv == 1)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    if (device.Type == DeviceType.PMSensor)
+                    {
+                        if (bindDev.BindCluster == 1026)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    break;
+                case BindInfo.BindType.Humidity:
+                    if (device.Type == DeviceType.TemperatureSensor)
+                    {
+                        var bDev = device as TemperatureSensor;
+                        if (bDev.SensorDiv == 2)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    if (device.Type == DeviceType.FreshAirHumiditySensor)
+                    {
+                        oldTargetList.Add(device);
+                    }
+                    if (device.Type == DeviceType.PMSensor)
+                    {
+                        if (bindDev.BindCluster == 1029)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    break;
+                case BindInfo.BindType.PM:
+                    if (device.Type == DeviceType.PMSensor)
+                    {
+                        if (bindDev.BindCluster == 1066)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    break;
+                case BindInfo.BindType.AC:
+                    if (device.Type == DeviceType.Thermostat)
+                    {
+                        if (bindDev.BindCluster == 513)
+                        {
+                            oldTargetList.Add(device);
+                        }
+                    }
+                    break;
+            }
+
+            targetList.Clear();
+            if (oldTargetList.Count != 0)
+            {
+                targetList.Add(oldTargetList[0]);
+            }
+
+            targetListTemp.Clear();
+            foreach (var d in targetList)
+            {
+                targetListTemp.Add(d);
+            }
+        }
+
+        /// <summary>
+        /// 褰撳墠琚粦瀹氳澶囨墍灞炴ゼ灞傚拰鎴块棿
+        /// </summary>
+        /// <param name="bindDev"></param>
+        void BindDevInfo(CommonDevice bindDev)
+        {
+            if (bindDev == null)
+            {
+                return;
+            }
+            //鑾峰彇鏈湴璁惧鍒楄〃
+            var localDeviceList = Shared.Common.LocalDevice.Current.listAllDevice;
+            var tempDev = localDeviceList.Find(obj => obj.DeviceAddr == bindDev.DeviceAddr && obj.DeviceEpoint == bindDev.DeviceEpoint);
+            if (tempDev != null)
+            {
+                //鑾峰彇璁惧鎵�灞炴埧闂�
+                var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
+                if (tempDevRoom != null)
+                {
+                    curControlDev.currentSelectRoomId = tempDevRoom.Id;
+                    curControlDev.currentSelectFloorId = tempDevRoom.FloorId;
+                }
+            }
+        }
+
+        /// <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 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);
+
+            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 绉婚櫎鏂规硶
+        /// <summary>
+        /// 閲嶅啓绉婚櫎鏂规硶
+        /// </summary>
+        public override void RemoveFromParent()
+        {
+            actionFreshAirTarget = null;
+            actionTemperatureTarget = null;
+            actionHumidityTarget = null;
+            actionPMTarget = null;
+            FloorAction = null;
+            base.RemoveFromParent();
+        }
+        #endregion
+    }
+}

--
Gitblit v1.8.0