From f6e34a69f1d1e0b0b3a6252fe20acddca7fe56e5 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期二, 17 三月 2020 15:43:44 +0800
Subject: [PATCH] 2020-03-17-1

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs |  228 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 164 insertions(+), 64 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
index 1d82707..fe01496 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
@@ -43,6 +43,8 @@
         /// </summary>
         public void ShowForm()
         {
+            this.ScrollEnabled = false;
+
             //璁剧疆鏍囬淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DeviceManagement));
 
@@ -132,21 +134,10 @@
             frame.AddChidren(listView);
             listView.BeginHeaderRefreshingAction += () =>
             {
-                //涓嬫媺鍒锋柊
                 HdlThreadLogic.Current.RunThread(() =>
                 {
-                    //鑾峰彇鍏ㄩ儴璁惧
-                    bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(GatewayResourse.NowSelectGateway);
-                    HdlThreadLogic.Current.RunMain(() =>
-                    {
-                        //闅愯棌涓嬫媺鍒锋柊鐗规晥
-                        listView.EndHeaderRefreshing();
-                        if (result == true)
-                        {
-                            //閲嶆柊鍒锋柊鐣岄潰
-                            this.InitMiddleFrame(false);
-                        }
-                    });
+                    //涓嬫媺鍒锋柊
+                    this.ListViewBeginHeaderRefreshing();
                 });
             };
         }
@@ -163,6 +154,8 @@
             //鑾峰彇璁惧鍒楄〃
             string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
             var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(gwID);
+            var listSpecialOta = Common.LocalDevice.Current.GetSpecialOtaDevice(gwID);
+            listDevice.AddRange(listSpecialOta);
 
             this.dicRowInfo.Clear();
 
@@ -175,6 +168,10 @@
             //鏍规嵁MAC鍚堝苟璁惧鍒楄〃
             this.MargeAllDeviceByMac(listDevice);
 
+            if (this.Parent == null)
+            {
+                return;
+            }
             HdlThreadLogic.Current.RunMain(() =>
             {
                 var listOta = new List<OTADevice>();
@@ -222,7 +219,7 @@
             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);
 
@@ -234,7 +231,7 @@
 
             //妫�娴嬭澶囨槸鍚︽嫢鏈夊畾浣嶇殑鍔熻兘
             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);
@@ -396,14 +393,60 @@
             //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_FangyueNewWind)
+            {
+                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鎸夐敭闈㈡澘)
@@ -437,12 +480,6 @@
                         var form = new DeviceFunctionSettionForm();
                         form.AddForm(device, true);
                     }
-                }
-                //娓╂箍搴�
-                else if (device.Type == DeviceType.TemperatureSensor)
-                {
-                    var form = new DeviceFunctionSettionForm();
-                    form.AddForm(device, true);
                 }
                 else
                 {
@@ -515,6 +552,60 @@
                     }
                 });
             }
+        }
+
+        #endregion
+
+        #region 鈻� 涓嬫媺鍒锋柊___________________________
+
+        /// <summary>
+        /// 婊戝姩鎺т欢涓嬫媺鍒锋柊
+        /// </summary>
+        private async void ListViewBeginHeaderRefreshing()
+        {
+            //濡傛灉鏄湪绾跨殑
+            if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(GatewayResourse.NowSelectGateway) == true)
+            {
+                //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D
+                ZbGateway realWay = null;
+                if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == 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(GatewayResourse.NowSelectGateway);
+            if (this.Parent == null)
+            {
+                return;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //闅愯棌涓嬫媺鍒锋柊鐗规晥
+                listView.EndHeaderRefreshing();
+                if (result != -1)
+                {
+                    //閲嶆柊鍒锋柊鐣岄潰
+                    this.InitMiddleFrame(false);
+                }
+            });
         }
 
         #endregion
@@ -616,7 +707,16 @@
             {
                 //杩欓噷涓昏鍙槸鑾峰彇鍦ㄧ嚎鐘舵��
                 var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
-                var result = Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, false, this.ReceiveDeviceStatu, 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]);
+                    }
+                }
             });
         }
 
@@ -626,51 +726,44 @@
         /// <param name="device"></param>
         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>
@@ -704,7 +797,7 @@
         {
             HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormSensor", ReceiveComandDiv.A浼犳劅鍣ㄤ笂鎶�, (device) =>
              {
-                 Application.RunOnMainThread(() =>
+                 HdlThreadLogic.Current.RunMain(() =>
                  {
                      if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == false)
                      {
@@ -785,8 +878,14 @@
                 var localDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr);
                 if (localDevice.Count == 0)
                 {
-                    //鍏ョ綉涔嬪悗锛屽張鎶婂畠鍒犱簡
-                    return;
+                    //閽堝鍗曠函鍙湁涓�涓�200绔偣鐨勮澶�
+                    var ota = Common.LocalDevice.Current.GetOTADevice(deviceAddr);
+                    if (ota == null)
+                    {
+                        //鍏ョ綉涔嬪悗锛屽張鎶婂畠鍒犱簡
+                        return;
+                    }
+                    localDevice.Add(ota);
                 }
                 var rowNewInfo = new DeviceObjRowInfo();
                 rowNewInfo.DeviceMac = deviceAddr;
@@ -846,8 +945,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;

--
Gitblit v1.8.0