From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs |  324 +++++++++++++++++++++++------------------------------
 1 files changed, 139 insertions(+), 185 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
index 7662561..b78fa72 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
@@ -2,7 +2,6 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
-using System.Threading.Tasks;
 using ZigBee.Device;
 
 namespace Shared.Phone.UserCenter.GatewayManage
@@ -39,16 +38,20 @@
             //璁剧疆鏍囬淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uGatewayManagement));
 
-            //娣诲姞鍥炬爣
-            var btnAdd = new MostRightIconControl(69, 69);
-            btnAdd.UnSelectedImagePath = "Item/Add.png";
-            topFrameLayout.AddChidren(btnAdd);
-            btnAdd.InitControl();
-            btnAdd.ButtonClickEvent += (sender, e) =>
+            //灞曠ず妯℃澘涓嶅厑璁哥紪杈�
+            if (Config.Instance.Home.IsShowTemplate == false)
             {
-                var form = new GatewayAdd.NewGateWayMenuSelectForm();
-                form.AddForm();
-            };
+                //娣诲姞鍥炬爣
+                var btnAdd = new MostRightIconControl(69, 69);
+                btnAdd.UnSelectedImagePath = "Item/Add.png";
+                topFrameLayout.AddChidren(btnAdd);
+                btnAdd.InitControl();
+                btnAdd.ButtonClickEvent += (sender, e) =>
+                {
+                    var form = new GatewayAdd.NewGateWayMenuSelectForm();
+                    form.AddForm();
+                };
+            }
 
             //鍒濆鍖栦腑閮ㄦ帶浠�
             this.InitMiddleFrame();
@@ -88,36 +91,25 @@
             if (listway.Count == 0)
             {
                 //杩樻病鏈夌粦瀹氱綉鍏冲摝
-                var btnPic = new PicViewControl(683, 392);
-                btnPic.UnSelectedImagePath = "Item/NoFunction.png";
-                btnPic.Y = (int)(bodyFrameLayout.Height * 0.382) - Application.GetRealHeight(392 / 2);
-                btnPic.Gravity = Gravity.CenterHorizontal;
-                bodyFrameLayout.AddChidren(btnPic);
-
-                var btnView = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
-                btnView.Y = btnPic.Bottom + Application.GetRealHeight(32);
-                btnView.TextID = R.MyInternationalizationString.uHadNotBindGatewayMsg;
-                btnView.TextAlignment = TextAlignment.Center;
-                btnView.TextSize = 12;
-                btnView.TextColor = UserCenterColor.Current.TextGrayColor1;
-                bodyFrameLayout.AddChidren(btnView);
+                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uHadNotBindGatewayMsg));
                 return;
             }
 
             for (int i = 0; i < listway.Count; i++)
             {
                 //娣诲姞琛�
-                var gwId = HdlGatewayLogic.Current.GetGatewayId(listway[i]);
-                this.AddRowLayout(gwId, i != listway.Count - 1);
+                this.AddRowLayout(listway[i].GwId, i != listway.Count - 1);
             }
 
             //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
             this.listview.AdjustRealHeight(Application.GetRealHeight(23));
 
-            //璁剧疆鎺ュ彈鍦ㄧ嚎鐘舵�佹帹閫�
-            this.AddGatewayOnlinePush();
-            //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼
-            this.StartGatewayOnlieCheckThread(listway);
+            //濡傛灉鏄睍绀烘ā鏉跨殑璇�,涓嶉渶瑕佹娴�
+            if (Common.Config.Instance.Home.IsShowTemplate == false)
+            {
+                //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼
+                this.StartGatewayOnlieCheckThread(listway);
+            }
         }
 
         #endregion
@@ -142,53 +134,69 @@
             {
                 gatewayRow.frameTable.AddBottomLine();
             }
-            //鎻愮ず鏈夋柊鐗堟湰
-            var btnNew = new RowNewVersionTipView();
+            //鎻愮ず鏂扮増鏈�
+            var btnNew = new InformationTipView(gatewayRow.btnIcon);
             btnNew.Visible = false;
-            gatewayRow.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
+            gatewayRow.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEvent);
             gatewayRow.AddTag("btnNew", btnNew);
             //鍗曞嚮浜嬩欢
             gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
             {
-
-            };
-
-            //鍒囨崲
-            var btnSwitch = new NormalViewControl(Application.GetRealWidth(184), gatewayRow.Height, false);
-            btnSwitch.BackgroundColor = 0xfffb744a;
-            btnSwitch.TextAlignment = TextAlignment.Center;
-            btnSwitch.TextColor = UserCenterColor.Current.White;
-            btnSwitch.TextSize = 12;
-            btnSwitch.TextID = R.MyInternationalizationString.uSwitch1;
-            if (strWayId == GatewayResourse.AppOldSelectGatewayId)
-            {
-                btnSwitch.TextID = R.MyInternationalizationString.uRefresh;
-            }
-            gatewayRow.AddRightView(btnSwitch);
-            btnSwitch.ButtonClickEvent += (sender, e) =>
-            {
-                //鏄惁鍒囨崲鍒皗0}缃戝叧?
-                string msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToSwitchTheGateway), "[" + gatewayRow.btnName.Text + "]");
-                if (strWayId == GatewayResourse.AppOldSelectGatewayId)
+                if (HdlUserCenterResourse.HideOption.GotoGatewayProductInfoForm == 1)
                 {
-                    //鏄惁閲嶆柊鍒锋柊{0}缃戝叧?
-                    msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + gatewayRow.btnName.Text + "]");
+                    //寮哄埗璺宠浆
+                    var form2 = new GatewayProductInfoForm();
+                    form2.AddForm(gateway);
+                    return;
                 }
-                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
-                {
-                    //鎵ц鍒囨崲缃戝叧鎿嶄綔
-                    this.DoSwitchGateway(strWayId, gatewayRow.IsOnline);
-                });
+                var form = new GatewayInfoEditorForm();
+                form.AddForm(gateway);
             };
+
+            //濡傛灉鏄睍绀烘ā鏉跨殑璇�,涓嶈兘缂栬緫
+            if (Common.Config.Instance.Home.IsShowTemplate == true)
+            {
+                return;
+            }
+
+            //闈炶櫄鎷熶綇瀹�,鎵嶆湁杩欎釜鍔熻兘
+            if (Common.Config.Instance.Home.IsVirtually == false)
+            {
+                //鍒囨崲
+                var btnSwitch = new NormalViewControl(Application.GetRealWidth(184), gatewayRow.Height, false);
+                btnSwitch.BackgroundColor = 0xfffb744a;
+                btnSwitch.TextAlignment = TextAlignment.Center;
+                btnSwitch.TextColor = UserCenterColor.Current.White;
+                btnSwitch.TextSize = 12;
+                btnSwitch.TextID = R.MyInternationalizationString.uSwitch1;
+                if (strWayId == HdlGatewayResourse.AppOldSelectGatewayId)
+                {
+                    btnSwitch.TextID = R.MyInternationalizationString.uRefresh;
+                }
+                gatewayRow.AddRightView(btnSwitch);
+                btnSwitch.ButtonClickEvent += (sender, e) =>
+                {
+                    //鏄惁鍒囨崲鍒皗0}缃戝叧?
+                    string msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToSwitchTheGateway), "[" + gatewayRow.btnName.Text + "]");
+                    if (strWayId == HdlGatewayResourse.AppOldSelectGatewayId)
+                    {
+                        //鏄惁閲嶆柊鍒锋柊{0}缃戝叧?
+                        msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + gatewayRow.btnName.Text + "]");
+                    }
+                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                    {
+                        HdlThreadLogic.Current.RunThread(() =>
+                        {
+                            //鎵ц鍒囨崲缃戝叧鎿嶄綔
+                            this.DoSwitchGateway(strWayId);
+                        });
+                    });
+                };
+            }
 
             //瀹氫綅
-            var btnPosition = new NormalViewControl(Application.GetRealWidth(184), gatewayRow.Height, false);
-            btnPosition.BackgroundColor = 0xff4a4a4a;
-            btnPosition.TextAlignment = TextAlignment.Center;
-            btnPosition.TextColor = UserCenterColor.Current.White;
-            btnPosition.TextSize = 12;
+            var btnPosition = gatewayRow.AddEditorControl(false);
             btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
-            gatewayRow.AddRightView(btnPosition);
             btnPosition.ButtonClickEvent += (sender, e) =>
             {
                 //鍙戦�佸畾浣嶅懡浠�
@@ -213,15 +221,28 @@
                 }
                 this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                 {
-                    this.DeleteGateway(strWayId, gatewayRow);
+                    HdlThreadLogic.Current.RunThread(() =>
+                    {
+                        this.DeleteGateway(strWayId);
+                    });
                 });
             };
 
             this.dicRowContr[strWayId] = gatewayRow;
             //璁剧疆涓�涓�夋嫨缃戝叧鐨勯粯璁ゅ��
-            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && gatewayRow.IsOnline == true)
+            if (string.IsNullOrEmpty(HdlGatewayResourse.AppOldSelectGatewayId) == true)
             {
-                this.SaveGatewayIdToLocation(strWayId);
+                HdlGatewayLogic.Current.SaveGatewayIdToLocation(strWayId);
+            }
+
+            //褰撳墠缃戝叧鐨勮鏍�
+            if (strWayId == HdlGatewayResourse.AppOldSelectGatewayId)
+            {
+                var btnNow = new IconViewControl(52);
+                btnNow.Y = Application.GetMinReal(23) + gatewayRow.frameTable.chidrenYaxis;
+                btnNow.UnSelectedImagePath = "Item/NowAcctionTip.png";
+                btnNow.X = gatewayRow.btnName.X + gatewayRow.btnName.GetRealWidthByText();
+                gatewayRow.frameTable.AddChidren(btnNow, ChidrenBindMode.BindEvent);
             }
         }
 
@@ -234,28 +255,30 @@
         /// </summary>
         /// <param name="strWayId"></param>
         /// <param name="row"></param>
-        private async void DeleteGateway(string strWayId, GatewayRowControl row)
+        private void DeleteGateway(string strWayId)
         {
+            //鎵撳紑杩涘害鏉�
+            this.ShowProgressBar();
             //鍒犻櫎浜戠缃戝叧
-            bool result = await HdlGatewayLogic.Current.DeleteGateway(strWayId);
+            bool result = HdlGatewayLogic.Current.DeleteGateway(strWayId);
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
             if (result == false)
             {
                 return;
             }
 
-            if (strWayId == GatewayResourse.AppOldSelectGatewayId)
+            if (strWayId == HdlGatewayResourse.AppOldSelectGatewayId)
             {
                 //濡傛灉瑙i櫎缁戝畾鐨勭綉鍏虫槸褰撳墠鎵�閫夋嫨鐨勭綉鍏崇殑璇濓紝鍒欏叧闂澶囩鐞嗙晫闈�
                 this.closeDeviceManagForm = true;
-                this.SaveGatewayIdToLocation(string.Empty);
+                HdlGatewayLogic.Current.SaveGatewayIdToLocation(string.Empty);
             }
-
-            //绉婚櫎
-            if (this.dicRowContr.ContainsKey(strWayId) == true)
+            HdlThreadLogic.Current.RunMain(() =>
             {
-                this.dicRowContr.Remove(strWayId);
-            }
-            row?.RemoveFromParent();
+                //鍒濆鍖栦腑閮ㄦ帶浠�
+                this.InitMiddleFrame();
+            });
         }
 
         #endregion
@@ -267,108 +290,32 @@
         /// </summary>
         /// <param name="gatewayId"></param>
         /// <param name="online"></param>
-        private async void DoSwitchGateway(string gatewayId,bool online)
+        private void DoSwitchGateway(string gatewayId)
         {
-            if (online == true)
+            var result = HdlGatewayLogic.Current.DoSwitchGateway(gatewayId);
+            if (result == false)
             {
-                //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
-                var result = await this.GetOnlineGatewayInfo(gatewayId);
-                if (result == false)
-                {
-                    return;
-                }
+                return;
             }
-            //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
-            this.SaveGatewayIdToLocation(gatewayId);
             //濡傛灉閫夋嫨浜嗗埛鏂扮殑缃戝叧锛屽垯涓嶅叧闂鐞嗙晫闈�
             this.closeDeviceManagForm = false;
 
-            if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false)
+            HdlThreadLogic.Current.RunMain(() =>
             {
-                //鍒锋柊涓荤敾闈�
-                var form = new Device.DeviceListMainForm();
-                this.AddFromAndRemoveNowForm(form);
-            }
-            else
-            {
-                //鍏抽棴鐣岄潰
-                this.CloseForm();
-                //鍒锋柊涓荤敾闈�(涓嶉噸鏂拌幏鍙栬澶囩姸鎬�)
-                this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame", false);
-            }
-        }
-
-        /// <summary>
-        /// 鑾峰彇鍦ㄧ嚎缃戝叧淇℃伅
-        /// </summary>
-        /// <param name="gatewayId"></param>
-        /// <returns></returns>
-        private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
-        {
-            //鏄剧ず杩涘害鏉�
-            this.ShowProgressBar();
-            //鑾峰彇缃戝叧
-            var gateway = HdlGatewayLogic.Current.GetLocalGateway(gatewayId);
-
-            //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D
-            ZbGateway realWay = null;
-            bool getGatewayInfo = true;
-            if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, gatewayId) == true)
-            {
-                //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆)
-                if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
+                if (HdlFormLogic.Current.IsFormOpen("DeviceListMainForm") == false)
                 {
-                    int result2 = await HdlGatewayLogic.Current.ReBindNewGateway(realWay);
-                    if (result2 == 0)
-                    {
-                        //鍑虹幇鏈煡閿欒,璇风◢鍚庡啀璇�
-                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
-                        //鍏抽棴杩涘害鏉�
-                        this.CloseProgressBar();
-                    }
-                    else if (result2 == -1)
-                    {
-                        //鍏抽棴杩涘害鏉�
-                        this.CloseProgressBar();
-                        return false;
-                    }
-                    //閲嶆柊缁戝畾缃戝叧閲岄潰宸茬粡閲嶆柊鑾峰彇浜嗙綉鍏充俊鎭�
-                    getGatewayInfo = false;
+                    //鍒锋柊涓荤敾闈�
+                    var form = new Device.DeviceListMainForm();
+                    this.AddFormAndCloseNowForm(form);
                 }
-            }
-
-            if (getGatewayInfo == true)
-            {
-                //鑾峰彇缃戝叧淇℃伅
-                var info = await HdlGatewayLogic.Current.GetGatewayNewInfoAsync(gateway);
-                if (info == null)
+                else
                 {
-                    //鍏抽棴杩涘害鏉�
-                    this.CloseProgressBar();
-                    return false;
+                    //鍏抽棴鐣岄潰
+                    this.CloseForm();
+                    //鍒锋柊涓荤敾闈�(涓嶉噸鏂拌幏鍙栬澶囩姸鎬�)
+                    this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame");
                 }
-            }
-
-            //鑾峰彇鍏ㄩ儴璁惧
-            bool result = await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(gateway);
-            //鍏抽棴杩涘害鏉�
-            this.CloseProgressBar();
-            if (result == false)
-            {
-                return false;
-            }
-            return true;
-        }
-
-        /// <summary>
-        /// 淇濆瓨閫夋嫨鐨勭綉鍏矷D鍒版湰鍦�
-        /// </summary>
-        /// <param name="gatewayId"></param>
-        private void SaveGatewayIdToLocation(string gatewayId)
-        {
-            GatewayResourse.AppOldSelectGatewayId = gatewayId;
-            byte[] data = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId));
-            Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data);
+            });
         }
 
         #endregion
@@ -408,8 +355,8 @@
                     {
                         return;
                     }
-                    bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(way);
-                    this.GatewayOnlinePush(way, online);
+                    bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByMemory(way);
+                    this.GatewayOnlinePush(way, online, true);
                 }
                 //缃戝叧鏂扮増鏈娴�
                 this.CheckGatewayNewVersion(listway);
@@ -421,20 +368,21 @@
         /// </summary>
         /// <param name="gateWay">缃戝叧瀵硅薄</param>
         /// <param name="online">鍦ㄧ嚎鐘舵�佸彉鏇村悗鐨勭姸鎬�</param>
-        public override void GatewayOnlinePush(ZbGateway gateWay, bool online)
+        /// <param name="hadGwOnline">2020.05.25杩藉姞:姝や綇瀹呮槸鍚︽嫢鏈夌綉鍏冲湪绾�</param>
+        public override void GatewayOnlinePush(ZbGateway gateWay, bool online, bool hadGwOnline)
         {
-            Application.RunOnMainThread(() =>
+            HdlThreadLogic.Current.RunMain(() =>
             {
                 if (this.Parent == null)
                 {
                     return;
                 }
-                string gwid = HdlGatewayLogic.Current.GetGatewayId(gateWay);
+                string gwid = gateWay.GwId;
                 if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null)
                 {
-                    this.dicRowContr[gwid].RefreshControl(gateWay);
+                    this.dicRowContr[gwid].IsOnline = online;
                 }
-            });
+            }, ShowErrorMode.NO);
         }
 
         #endregion
@@ -445,7 +393,7 @@
         /// 缃戝叧鏂扮増鏈娴�
         /// </summary>
         /// <param name="listWays"></param>
-        private async void CheckGatewayNewVersion(List<ZbGateway> listWays)
+        private void CheckGatewayNewVersion(List<ZbGateway> listWays)
         {
             foreach (var way in listWays)
             {
@@ -453,13 +401,13 @@
                 {
                     return;
                 }
-                if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(way) == false)
+                if (HdlGatewayLogic.Current.CheckGatewayOnlineByMemory(way) == false)
                 {
                     //涓嶅湪绾跨殑涓嶇敤鐞嗗畠
                     continue;
                 }
                 //鑾峰彇鏈�鏂扮増鏈�
-                var result = await HdlGatewayLogic.Current.GetGatewayAllNewVersion(way, ShowErrorMode.NO);
+                var result = HdlGatewayLogic.Current.GetGatewayAllNewVersion(way, ShowErrorMode.NO);
                 if (result == null)
                 {
                     continue;
@@ -467,12 +415,12 @@
                 if (result[0] != null || result[1] != null || result[2] != null)
                 {
                     //鏈夋柊鐗堟湰
-                    string gwid = HdlGatewayLogic.Current.GetGatewayId(way);
-                    Application.RunOnMainThread(() =>
+                    string gwid = way.GwId;
+                    HdlThreadLogic.Current.RunMain(() =>
                     {
                         if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null)
                         {
-                            var btnNew = (RowNewVersionTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
+                            var btnNew = (InformationTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
                             if (btnNew != null)
                             {
                                 btnNew.Visible = true;
@@ -490,11 +438,11 @@
         /// <summary>
         /// 鐢婚潰鍏抽棴
         /// </summary>
-        public override void CloseForm()
+        public override void CloseFormBefore()
         {
-            base.CloseForm();
+            base.CloseFormBefore();
 
-            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && this.closeDeviceManagForm == true)
+            if (this.closeDeviceManagForm == true)
             {
                 //鍏抽棴鐣岄潰
                 HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
@@ -511,6 +459,12 @@
         /// </summary>
         public override int FormActionAgainEvent()
         {
+            //杩涘埌杩欎釜鐣岄潰,鐞嗚涓婂墠鍥炵殑缃戝叧id鏄湁鐨�,濡傛灉涓虹┖浜�,搴旇鏄綋鍓嶇殑缃戝叧琚В缁戜簡
+            if (HdlGatewayResourse.AppOldSelectGatewayId == string.Empty)
+            {
+                //鍏抽棴璁惧鍒楄〃
+                this.closeDeviceManagForm = true;
+            }
             //鍒濆鍖栦腑閮ㄦ帶浠�
             this.InitMiddleFrame();
             return 1;

--
Gitblit v1.8.0