From 3272ca5b51e19f7f8a827b0f68400570a547fe60 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 28 四月 2020 15:02:44 +0800
Subject: [PATCH] 2020-04-28-1

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs |  532 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 338 insertions(+), 194 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
index db02ddd..4bd8639 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
@@ -20,7 +20,11 @@
         /// <summary>
         /// 鍒楄〃鎺т欢
         /// </summary>
-        private VerticalListControl listView = null;
+        private VerticalListRefreshControl listView = null;
+        /// <summary>
+        /// 鍓嶄竴娆℃樉绀哄嚭宸︽粦鑿滃崟鐨凴owLayout
+        /// </summary>
+        private RowLayoutControl oldShowRightMuneRow = null;
         /// <summary>
         /// 琛屾帶浠剁殑淇℃伅(Keys锛歁ac鍦板潃)
         /// </summary>
@@ -43,6 +47,8 @@
         /// </summary>
         public void ShowForm()
         {
+            this.ScrollEnabled = false;
+
             //璁剧疆鏍囬淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DeviceManagement));
 
@@ -53,20 +59,6 @@
             btnAddDeviceIcon.InitControl();
             btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
             {
-                ZbGateway realWay = null;
-                if (GatewayResourse.NowSelectGateway == null || HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == false)
-                {
-                    //缃戝叧瀵硅薄寮傚父,璇烽噸鏂伴�夋嫨缃戝叧
-                    string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsErrorAndReSelect);
-                    this.ShowMassage(ShowMsgType.Error, msg, () =>
-                    {
-                        var form2 = new GatewayManage.GatewayListForm();
-                        form2.AddForm();
-                    });
-                    return;
-                }
-                GatewayResourse.NowSelectGateway = realWay;
-
                 var form = new DeviceDirection.AddDeviceTypeListForm();
                 form.AddForm();
             };
@@ -86,12 +78,11 @@
             this.ClearBodyFrame();
 
             //鍒濆鍖栫綉鍏宠鎺т欢
-            GatewayResourse.NowSelectGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
-            this.gatewayViewRow = new MyGatewayControl(GatewayResourse.NowSelectGateway);
+            GatewayResourse.NowSelectGatewayId = GatewayResourse.AppOldSelectGatewayId;
+            var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
+            this.gatewayViewRow = new MyGatewayControl(nowGateway);
             bodyFrameLayout.AddChidren(gatewayViewRow);
             gatewayViewRow.InitControl();
-            //璁剧疆缃戝叧鎺ュ彈鍦ㄧ嚎鐘舵�佹帹閫�
-            this.AddGatewayOnlinePush();
 
             //鍒濆鍖栨悳绱㈡帶浠�
             this.InitSearchControl();
@@ -128,10 +119,18 @@
             txtSearchControl.BindEvent(this.SetRowDataBySearchKeys);
 
             //鍒楄〃鎺т欢
-            listView = new VerticalListControl(29);
+            listView = new VerticalListRefreshControl(29);
             listView.Y = txtSearchControl.Bottom + Application.GetRealHeight(29);
             listView.Height = frame.Height - txtSearchControl.Bottom - Application.GetRealHeight(29);
             frame.AddChidren(listView);
+            listView.BeginHeaderRefreshingAction += () =>
+            {
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    //涓嬫媺鍒锋柊
+                    this.ListViewBeginHeaderRefreshing();
+                });
+            };
         }
 
         #endregion
@@ -144,8 +143,9 @@
         private void InitDeviceListControl()
         {
             //鑾峰彇璁惧鍒楄〃
-            string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
-            var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(gwID);
+            var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(GatewayResourse.NowSelectGatewayId);
+            var listSpecialOta = Common.LocalDevice.Current.GetSpecialOtaDevice(GatewayResourse.NowSelectGatewayId);
+            listDevice.AddRange(listSpecialOta);
 
             this.dicRowInfo.Clear();
 
@@ -158,12 +158,12 @@
             //鏍规嵁MAC鍚堝苟璁惧鍒楄〃
             this.MargeAllDeviceByMac(listDevice);
 
-            Application.RunOnMainThread(() =>
+            if (this.Parent == null)
             {
-                if (this.Parent == null)
-                {
-                    return;
-                }
+                return;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
                 var listOta = new List<OTADevice>();
                 foreach (var macAddress in this.dicRowInfo.Keys)
                 {
@@ -176,17 +176,14 @@
                     //娣诲姞璁惧鐨勮彍鍗曡
                     this.AddDeviceMenuRow(macAddress);
                 }
-                //娣诲姞搴曢儴闂撮殭
-                var frameTemp = new FrameLayout();
-                frameTemp.Height = Application.GetRealHeight(23);
-                listView.AddChidren(frameTemp);
-
-                //寮�鍚澶囧睘鎬у彉鏇寸洃鍚�
-                this.AddDeviceAttributePush();
-                //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼
-                this.StartGatewayOnlieCheckThread();
-                //妫�娴嬭澶囨柊鐗堟湰
-                this.CheckDeviceNewVersion(listOta);
+                //濡傛灉褰撳墠涓嶆槸铏氭嫙浣忓畢
+                if (Common.Config.Instance.Home.IsVirtually == false)
+                {
+                    //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼
+                    this.StartGatewayOnlieCheckThread();
+                    //妫�娴嬭澶囨柊鐗堟湰
+                    this.CheckDeviceNewVersion(listOta);
+                }
             });
         }
 
@@ -210,12 +207,13 @@
 
             //鎺т欢
             var rowMenu = new DeviceObjectControl(deviceMac, listView.rowSpace / 2);
+            rowMenu.MainKeys = deviceMac;
             frameTable.AddChidren(rowMenu);
             rowMenu.InitControl();
             rowInfo.MenuRow = rowMenu;
             //鍚戝彸鍥炬爣
             var btnRight = rowMenu.frameTable.AddMostRightEmptyIcon(58, 58);
-            btnRight.UnSelectedImagePath = "Item/Next.png";
+            btnRight.UnSelectedImagePath = "Item/RightNext.png";
             btnRight.SelectedImagePath = "Item/Down.png";
             rowMenu.frameTable.ChangedChidrenBindMode(btnRight, ChidrenBindMode.NotBind);
 
@@ -227,16 +225,11 @@
 
             //妫�娴嬭澶囨槸鍚︽嫢鏈夊畾浣嶇殑鍔熻兘
             var listdevice = Common.LocalDevice.Current.GetDevicesByMac(deviceMac);
-            if (Common.LocalDevice.Current.DeviceIsCanFixedPosition(listdevice[0]) == true)
+            if (listdevice.Count > 0 && Common.LocalDevice.Current.DeviceIsCanFixedPosition(listdevice[0]) == true)
             {
                 //瀹氫綅
-                var btnPosition = new NormalViewControl(Application.GetRealWidth(184), rowMenu.Height, false);
+                var btnPosition = rowMenu.AddEditorControl(false);
                 btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
-                btnPosition.TextAlignment = TextAlignment.Center;
-                btnPosition.TextSize = 12;
-                btnPosition.TextColor = UserCenterColor.Current.White;
-                btnPosition.BackgroundColor = 0xff4a4a4a;
-                rowMenu.AddRightView(btnPosition);
                 btnPosition.ButtonClickEvent += (sender, e) =>
                 {
                     //瀹氫綅
@@ -266,11 +259,30 @@
 
             rowMenu.frameTable.ButtonClickEvent += (sender, e) =>
             {
+                //闅愯棌鑿滃崟
+                rowMenu.HideMenu();
+                //寮哄埗璺宠浆鐪熷疄璁惧鐣岄潰
+                if (UserCenterResourse.HideOption.GotoRealDeviceForm == 1)
+                {
+                    var form2 = new DeviceAddSuccessForm();
+                    form2.AddForm(deviceMac);
+                    return;
+                }
                 btnNew.Visible = false;
                 var form = new DeviceMacInfoEditorForm();
                 form.AddForm(deviceMac);
                 //鐣岄潰璺宠浆,璁板綍褰撳墠鐨勬鍦ㄦ搷浣滅殑璁惧鐨凪ac鍦板潃
                 this.nowActionDeviceMac = deviceMac;
+            };
+            //宸︽粦鑿滃崟浜嬩欢
+            rowMenu.OpenMenuAction += () =>
+            {
+                if (this.oldShowRightMuneRow != null && this.oldShowRightMuneRow.MainKeys != rowMenu.MainKeys)
+                {
+                    //宸︽粦鑿滃崟鍙兘婊戜竴涓�
+                    this.oldShowRightMuneRow.HideMenu();
+                }
+                this.oldShowRightMuneRow = rowMenu;
             };
         }
 
@@ -327,6 +339,7 @@
 
             //琛屾帶浠�
             var rowDevice = new DeviceRoomControl(device, frame.rowSpace / 2);
+            rowDevice.MainKeys = LocalDevice.Current.GetDeviceMainKeys(device);
             frame.AddChidren(rowDevice);
             rowDevice.frameTable.LeftOffset = Application.GetRealWidth(173) - ControlCommonResourse.XXLeft;
             rowDevice.InitControl();
@@ -345,13 +358,8 @@
             if (Common.LocalDevice.Current.DeviceIsCanFixedPosition(device) == true)
             {
                 //瀹氫綅
-                var btnPosition = new NormalViewControl(Application.GetRealWidth(184), rowDevice.Height, false);
+                var btnPosition = rowDevice.AddEditorControl(false);
                 btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
-                btnPosition.TextAlignment = TextAlignment.Center;
-                btnPosition.TextSize = 12;
-                btnPosition.TextColor = UserCenterColor.Current.White;
-                btnPosition.BackgroundColor = 0xff4a4a4a;
-                rowDevice.AddRightView(btnPosition);
                 btnPosition.ButtonClickEvent += (sender, e) =>
                 {
                     //瀹氫綅
@@ -361,10 +369,26 @@
 
             rowDevice.frameTable.ButtonClickEvent += (sender, e) =>
             {
+                //闅愯棌鑿滃崟
+                rowDevice.HideMenu();
                 //鐣岄潰璺宠浆,璁板綍褰撳墠鐨勬鍦ㄦ搷浣滅殑璁惧鐨凪ac鍦板潃
                 this.nowActionDeviceMac = device.DeviceAddr;
-                //鏄剧ず璁惧鍔熻兘閰嶇疆鐣岄潰
-                this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo);
+                //濡傛灉褰撳墠浣忓畢涓嶆槸铏氭嫙浣忓畢
+                if (Common.Config.Instance.Home.IsVirtually == false)
+                {
+                    //鏄剧ず璁惧鍔熻兘閰嶇疆鐣岄潰
+                    this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo);
+                }
+            };
+            //宸︽粦鑿滃崟浜嬩欢
+            rowDevice.OpenMenuAction += () =>
+            {
+                if (this.oldShowRightMuneRow != null && this.oldShowRightMuneRow.MainKeys != rowDevice.MainKeys)
+                {
+                    //宸︽粦鑿滃崟鍙兘婊戜竴涓�
+                    this.oldShowRightMuneRow.HideMenu();
+                }
+                this.oldShowRightMuneRow = rowDevice;
             };
         }
 
@@ -389,14 +413,70 @@
             //pir浼犳劅鍣�
             else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.Sensor_Pir)
             {
-                var form = new DevicePirSensor.PirSensorBindTargetSettionForm();
-                form.AddForm((IASZone)device);
+                if (device is IASZone)
+                {
+                    var form = new DevicePirSensor.PirSensorBindTargetSettionForm();
+                    form.AddForm((IASZone)device);
+                }
+                else
+                {
+                    //pir浼犳劅鍣�,浠栦滑鍙堟悶浜嗕釜缁х數鍣ㄥ湪閲岄潰
+                    var form = new DeviceFunctionSettionForm();
+                    form.AddForm(device, true);
+                }
             }
             //涓ぎ绌鸿皟
             else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.AirConditioner_ZbGateway)
             {
                 var form = new DeviceAirConditioner.IndoorUnitSettionForm();
                 form.AddForm((AC)device);
+            }
+            //鐜闈㈡澘
+            else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueEnvironment)
+            {
+                var form = new DeviceFunctionSettionForm();
+                form.AddForm(device, true);
+            }
+            //鏂伴闈㈡澘
+            else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+            {
+                //鏂规偊鏂伴闈㈡澘鐨勬寜閿厤缃�
+                //骞叉帴鐐�
+                if (device.Type == DeviceType.FreshAir)
+                {
+                    var form = new DevicePanel.PanelFangyueFreshAirButtonSettionForm();
+                    form.AddForm(device);
+                }
+                else
+                {
+                    var form = new DeviceFunctionSettionForm();
+                    form.AddForm(device, true);
+                }
+            }
+            //鏂规偊闈㈡澘
+            else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueTwo
+                || deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFour
+                || deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueEight)
+            {
+                //骞叉帴鐐�
+                if (device.Type == DeviceType.OnOffSwitch)
+                {
+                    //鏂规偊闈㈡澘鐨勬寜閿厤缃�
+                    var form = new DevicePanel.PanelFangyueButtonSettionForm();
+                    form.AddForm(device);
+                }
+                //缁х數鍣�
+                else if (device.Type == DeviceType.OnOffOutput)
+                {
+                    //鏂规偊闈㈡澘鐨勫姛鑳介厤缃�
+                    var form = new DevicePanel.PanelFangyueFunctionSettionForm();
+                    form.AddForm(device);
+                }
+                else
+                {
+                    var form = new DeviceFunctionSettionForm();
+                    form.AddForm(device, true);
+                }
             }
             //闈㈡澘璁惧
             else if (deviceEnumInfo.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘)
@@ -430,12 +510,6 @@
                         var form = new DeviceFunctionSettionForm();
                         form.AddForm(device, true);
                     }
-                }
-                //娓╂箍搴�
-                else if (device.Type == DeviceType.TemperatureSensor)
-                {
-                    var form = new DeviceFunctionSettionForm();
-                    form.AddForm(device, true);
                 }
                 else
                 {
@@ -512,6 +586,73 @@
 
         #endregion
 
+        #region 鈻� 涓嬫媺鍒锋柊___________________________
+
+        /// <summary>
+        /// 婊戝姩鎺т欢涓嬫媺鍒锋柊
+        /// </summary>
+        private async void ListViewBeginHeaderRefreshing()
+        {
+            //濡傛灉褰撳墠浣忓畢鏄櫄鎷熺殑
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                //灏辨樉绀轰竴涓壒鏁堣�屽凡
+                System.Threading.Thread.Sleep(2000);
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //闅愯棌涓嬫媺鍒锋柊鐗规晥
+                    listView.EndHeaderRefreshing();
+                });
+                return;
+            }
+            //濡傛灉鏄湪绾跨殑
+            var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.NowSelectGatewayId);
+            if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(nowGateway) == true)
+            {
+                //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D
+                ZbGateway realWay = null;
+                if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, nowGateway) == true)
+                {
+                    //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆)
+                    if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
+                    {
+                        //鏄剧ず杩涘害鏉�
+                        ProgressBar.Show();
+                        int result2 = await HdlGatewayLogic.Current.ReBindNewGateway(realWay);
+                        //鍏抽棴杩涘害鏉�
+                        ProgressBar.Close();
+                        if (result2 == -1)
+                        {
+                            return;
+                        }
+                    }
+                }
+            }
+            if (this.Parent == null)
+            {
+                return;
+            }
+
+            //鑾峰彇鍏ㄩ儴璁惧
+            int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(nowGateway);
+            if (this.Parent == null)
+            {
+                return;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //闅愯棌涓嬫媺鍒锋柊鐗规晥
+                listView.EndHeaderRefreshing();
+                if (result != -1)
+                {
+                    //閲嶆柊鍒锋柊鐣岄潰
+                    this.InitMiddleFrame(false);
+                }
+            });
+        }
+
+        #endregion
+
         #region 鈻� 缃戝叧鍦ㄧ嚎妫�娴媉______________________
 
         /// <summary>
@@ -519,12 +660,7 @@
         /// </summary>
         private void StartGatewayOnlieCheckThread()
         {
-            if (GatewayResourse.NowSelectGateway == null)
-            {
-                return;
-            }
-
-            string selectGwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
+            string selectGwId = GatewayResourse.NowSelectGatewayId;
             HdlThreadLogic.Current.RunThread(() =>
             {
                 ZbGateway zbGateway = HdlGatewayLogic.Current.GetLocalGateway(selectGwId);
@@ -570,29 +706,7 @@
 
         #endregion
 
-        #region 鈻� 璁惧灞炴�у彉鏇存帹閫乢__________________
-
-        /// <summary>
-        /// 璁惧灞炴�у彉鏇存帹閫�
-        /// </summary>
-        /// <param name="device"></param>
-        public override void DeviceAttributePush(CommonDevice device)
-        {
-            if (dicRowInfo.ContainsKey(device.DeviceAddr) == false)
-            {
-                return;
-            }
-            var rowInfo = dicRowInfo[device.DeviceAddr];
-            Application.RunOnMainThread(() =>
-            {
-                //鍒锋柊鑿滃崟
-                rowInfo.MenuRow?.RefreshControlInfo(false);
-            });
-        }
-
-        #endregion
-
-        #region 鈻� 寮�鍚澶囧湪绾跨嚎绋媉__________________
+        #region 鈻� 璁惧鍦ㄧ嚎妫�娴媉______________________
 
         /// <summary>
         /// 寮�鍚澶囧湪绾跨嚎绋�
@@ -612,80 +726,82 @@
             this.StartCheckDeviceOnline();
         }
 
-        #endregion
-
-        #region 鈻� 璁惧鍦ㄧ嚎___________________________
-
         /// <summary>
         /// 寮�鍚澶囧湪绾跨洃娴�
         /// </summary>
         private void StartCheckDeviceOnline()
         {
             //澶栭儴璋冪敤鐨勮瘽,涓嶅啀閲嶆柊鑾峰彇璁惧鐘舵��
-            if (GatewayResourse.NowSelectGateway == null || this.reGetDeviceOnlineStatu == false)
+            if (this.reGetDeviceOnlineStatu == false)
             {
                 return;
             }
-            string gwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
+
+            //娣诲姞鎺ユ敹璁惧鍦ㄧ嚎涓婃姤鐨勭洃鍚�
+            HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormReceivePushOnline", ReceiveComandDiv.A璁惧鍦ㄧ嚎涓婃姤, this.ReceiveDeviceStatu);
+
+            string gwId = GatewayResourse.NowSelectGatewayId;
             HdlThreadLogic.Current.RunThread(() =>
             {
                 //杩欓噷涓昏鍙槸鑾峰彇鍦ㄧ嚎鐘舵��
                 var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
-                var result = Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, false, this.ReceiveDeviceStatuPush, ShowErrorMode.NO);
+                int statu = 0;
+                var list = LocalDevice.Current.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO);
+                if (statu != -1)
+                {
+                    for (int i = 0; i < list.Count; i++)
+                    {
+                        //璁剧疆璁惧鍦ㄧ嚎鐘舵��
+                        this.ReceiveDeviceStatu(list[i]);
+                    }
+                }
             });
         }
 
         /// <summary>
-        /// 鎺ュ彈璁惧鍦ㄧ嚎鎺ㄩ��
+        /// 鎺ュ彈璁惧鐘舵��
         /// </summary>
         /// <param name="device"></param>
-        private void ReceiveDeviceStatuPush(CommonDevice device)
+        private void ReceiveDeviceStatu(CommonDevice device)
         {
-            lock (dicRowInfo)
+            DeviceObjRowInfo rowInfo = null;
+            if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == true)
             {
-                if (this.Parent == null)
+                rowInfo = this.dicRowInfo[device.DeviceAddr];
+            }
+            if (rowInfo == null || rowInfo.MenuRow == null)
+            {
+                return;
+            }
+            //鍒锋柊璁惧鐨勫湪绾跨姸鎬�
+            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+            var localDevice = Common.LocalDevice.Current.GetDevice(mainkeys);
+            if (localDevice != null)
+            {
+                //鍦ㄧ嚎鐘舵�佷竴鏍风殑璇濓紝涓嶉渶瑕佸埛鏂�
+                if (localDevice.IsOnline == device.IsOnline)
                 {
                     return;
                 }
-                DeviceObjRowInfo rowInfo = null;
-                if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == true)
-                {
-                    rowInfo = this.dicRowInfo[device.DeviceAddr];
-                }
-                if (rowInfo == null || rowInfo.MenuRow == null)
-                {
-                    return;
-                }
-                //鍒锋柊璁惧鐨勫湪绾跨姸鎬�
-                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
-                var localDevice = Common.LocalDevice.Current.GetDevice(mainkeys);
-                if (localDevice != null)
-                {
-                    //鍦ㄧ嚎鐘舵�佷竴鏍风殑璇濓紝涓嶉渶瑕佸埛鏂�
-                    if (localDevice.IsOnline == device.IsOnline)
-                    {
-                        return;
-                    }
-                    //淇濆瓨鐘舵��
-                    localDevice.IsOnline = device.IsOnline;
-                    localDevice.ReSave();
-                }
+                //淇濆瓨鐘舵��
+                localDevice.IsOnline = device.IsOnline;
+                localDevice.ReSave();
+            }
 
-                HdlThreadLogic.Current.RunMain(() =>
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                if (rowInfo != null)
                 {
-                    if (rowInfo != null)
+                    rowInfo.MenuRow.isOnline = device.IsOnline == 1;
+                    if (rowInfo.dicDetailRow != null)
                     {
-                        rowInfo.MenuRow.isOnline = device.IsOnline == 1;
-                        if (rowInfo.dicDetailRow != null)
+                        foreach (var detailRow in rowInfo.dicDetailRow.Values)
                         {
-                            foreach (var detailRow in rowInfo.dicDetailRow.Values)
-                            {
-                                detailRow.isOnline = rowInfo.MenuRow.isOnline;
-                            }
+                            detailRow.isOnline = rowInfo.MenuRow.isOnline;
                         }
                     }
-                });
-            }
+                }
+            });
         }
 
         /// <summary>
@@ -706,6 +822,29 @@
                     });
                 }
             }
+        }
+
+        #endregion
+
+        #region 鈻� 浼犳劅鍣ㄦ姤璀________________________
+
+        /// <summary>
+        /// 寮�鍚紶鎰熷櫒鎶ヨ鐩戣
+        /// </summary>
+        private void StartCheckDeviceAlarm()
+        {
+            HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormSensor", ReceiveComandDiv.A浼犳劅鍣ㄤ笂鎶�, (device) =>
+             {
+                 HdlThreadLogic.Current.RunMain(() =>
+                 {
+                     if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == false)
+                     {
+                         return;
+                     }
+                     //鏄剧ず浼犳劅鍣ㄤ笂鎶ョ殑鐗规晥
+                     this.dicRowInfo[device.DeviceAddr].MenuRow?.StartSensorPushAppeal();
+                 });
+             });
         }
 
         #endregion
@@ -763,32 +902,6 @@
 
         #endregion
 
-        #region 鈻� 浼犳劅鍣ㄦ姤璀________________________
-
-        /// <summary>
-        /// 寮�鍚紶鎰熷櫒鎶ヨ鐩戣
-        /// </summary>
-        private void StartCheckDeviceAlarm()
-        {
-            HdlDeviceAttributeLogic.Current.AddAttributeEvent("DeviceListFormSensor", "IASInfoReport", (device) =>
-             {
-                 Application.RunOnMainThread(() =>
-                 {
-                     if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == false)
-                     {
-                         return;
-                     }
-                     var row = this.dicRowInfo[device.DeviceAddr].MenuRow;
-                     if (row != null)
-                     {
-                         row.frameTable.StartSelectStatuAppeal(3000);
-                     }
-                 });
-             });
-        }
-
-        #endregion
-
         #region 鈻� 瀹炵幇澶栭儴璋冪敤_______________________
 
         /// <summary>
@@ -801,6 +914,17 @@
             if (this.dicRowInfo.ContainsKey(deviceAddr) == false)
             {
                 var localDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr);
+                if (localDevice.Count == 0)
+                {
+                    //閽堝鍗曠函鍙湁涓�涓�200绔偣鐨勮澶�
+                    var ota = Common.LocalDevice.Current.GetOTADevice(deviceAddr);
+                    if (ota == null)
+                    {
+                        //鍏ョ綉涔嬪悗锛屽張鎶婂畠鍒犱簡
+                        return;
+                    }
+                    localDevice.Add(ota);
+                }
                 var rowNewInfo = new DeviceObjRowInfo();
                 rowNewInfo.DeviceMac = deviceAddr;
                 rowNewInfo.MacName = Common.LocalDevice.Current.GetDeviceMacName(localDevice[0]);
@@ -809,8 +933,6 @@
 
                 //鍒涘缓鏂扮殑琛�
                 this.AddDeviceMenuRow(deviceAddr);
-
-                return;
             }
         }
 
@@ -851,23 +973,6 @@
 
         #endregion
 
-        #region 鈻� 鍏抽棴鐣岄潰___________________________
-
-        /// <summary>
-        /// 鐢婚潰鍏抽棴
-        /// </summary>
-        public override void CloseForm()
-        {
-            HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormSensor");
-            HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline");
-
-            GatewayResourse.NowSelectGateway = null;
-
-            base.CloseForm();
-        }
-
-        #endregion
-
         #region 鈻� 鐣岄潰閲嶆柊婵�娲讳簨浠禵__________________
 
         /// <summary>
@@ -878,8 +983,9 @@
             if (this.nowActionDeviceMac != null)
             {
                 var rowInfo = this.dicRowInfo[nowActionDeviceMac];
-                //妫�娴嬭繖涓澶囨槸鍚﹁鍒犻櫎
-                if (Common.LocalDevice.Current.GetDevicesByMac(nowActionDeviceMac).Count == 0)
+                //妫�娴嬭繖涓澶囨槸鍚﹁鍒犻櫎 2020.01.13鍙樻洿:杩藉姞Ota璁惧鐨勫垽鏂�
+                if (Common.LocalDevice.Current.GetDevicesByMac(nowActionDeviceMac).Count == 0
+                    && Common.LocalDevice.Current.GetOTADevice(nowActionDeviceMac) == null)
                 {
                     //绉婚櫎鎺т欢
                     rowInfo.dicDetailRow = null;
@@ -907,6 +1013,21 @@
             this.gatewayViewRow.RefreshControl();
 
             return 1;
+        }
+
+        #endregion
+
+        #region 鈻� 鍏抽棴鐣岄潰___________________________
+
+        /// <summary>
+        /// 鐢婚潰鍏抽棴
+        /// </summary>
+        public override void CloseFormBefore()
+        {
+            HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceListFormSensor");
+            HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline");
+
+            base.CloseFormBefore();
         }
 
         #endregion
@@ -969,7 +1090,10 @@
             public MyGatewayControl(ZbGateway i_zbGateway)
             {
                 this.UseClickStatu = false;
-                this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
+                if (i_zbGateway != null)
+                {
+                    this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
+                }
                 this.BackgroundColor = UserCenterColor.Current.White;
                 this.Height = Application.GetRealHeight(173);
             }
@@ -983,16 +1107,32 @@
                 ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
                 //鍥炬爣
                 var btnIcon = this.AddLeftIcon(81);
-                HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway);
+                if (zbway != null)
+                {
+                    HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway);
+                }
+                else
+                {
+                    btnIcon.UnSelectedImagePath = "Gateway/GatewayIcon1.png";
+                }
 
                 //鏄剧ず鏂囨湰
-                btnName = this.AddLeftCaption(HdlGatewayLogic.Current.GetGatewayName(zbway), 700);
+                btnName = this.AddLeftCaption(string.Empty, 700);
                 btnName.Height = Application.GetRealHeight(60);
                 btnName.TextSize = 15;
                 btnName.Y = Application.GetRealHeight(35);
-                if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
+                if (zbway != null)
                 {
-                    btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
+                    btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway);
+                    if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
+                    {
+                        btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
+                    }
+                }
+                else
+                {
+                    //铏氭嫙缃戝叧
+                    btnName.Text = Language.StringByID(R.MyInternationalizationString.uVirtualGateway);
                 }
 
                 //褰撳墠缃戝叧
@@ -1009,15 +1149,19 @@
                 var btnMament = this.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGatewayManagement), 300);
                 btnMament.Name = "btnMament";
 
-                this.ButtonClickEvent += (sernder, e) =>
+                //褰撳墠涓嶆槸铏氭嫙浣忓畢鐨勮瘽
+                if (Common.Config.Instance.Home.IsVirtually == false)
                 {
-                    if (string.IsNullOrEmpty(((View)sernder).Name) == false)
+                    this.ButtonClickEvent += (sernder, e) =>
                     {
-                        //鎵撳紑缃戝叧鍒楄〃鐣岄潰
-                        var form = new GatewayManage.GatewayListForm();
-                        form.AddForm();
-                    }
-                };
+                        if (string.IsNullOrEmpty(((View)sernder).Name) == false)
+                        {
+                            //鎵撳紑缃戝叧鍒楄〃鐣岄潰
+                            var form = new GatewayManage.GatewayListForm();
+                            form.AddForm();
+                        }
+                    };
+                }
             }
 
             /// <summary>

--
Gitblit v1.8.0