From 97e259d966cb5cb5d73c105d5dbaadcc1f920614 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期五, 18 十月 2019 13:48:43 +0800
Subject: [PATCH] 合并了全部的代码

---
 ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs |  252 +++++++++++++++++++++++++++-----------------------
 1 files changed, 135 insertions(+), 117 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
index d32bd4c..7662561 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
@@ -2,6 +2,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Threading.Tasks;
 using ZigBee.Device;
 
 namespace Shared.Phone.UserCenter.GatewayManage
@@ -45,7 +46,7 @@
             btnAdd.InitControl();
             btnAdd.ButtonClickEvent += (sender, e) =>
             {
-                var form = new GatewayAdd.NewGateWaySelectForm();
+                var form = new GatewayAdd.NewGateWayMenuSelectForm();
                 form.AddForm();
             };
 
@@ -67,8 +68,11 @@
             listview.BackgroundColor = UserCenterColor.Current.White;
             bodyFrameLayout.AddChidren(listview);
 
-            //璁惧畾涓儴淇℃伅
-            this.SetMiddleFrameInfo();
+            HdlThreadLogic.Current.RunMainInThread(() =>
+            {
+                //璁惧畾涓儴淇℃伅
+                this.SetMiddleFrameInfo();
+            });
         }
 
         /// <summary>
@@ -83,24 +87,32 @@
             List<ZbGateway> listway = HdlGatewayLogic.Current.GetAllLocalGateway();
             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);
                 return;
             }
 
-            int count = listway.Count - 1;
             for (int i = 0; i < listway.Count; i++)
             {
                 //娣诲姞琛�
                 var gwId = HdlGatewayLogic.Current.GetGatewayId(listway[i]);
-                this.AddRowLayout(gwId, i != count);
+                this.AddRowLayout(gwId, i != listway.Count - 1);
             }
+
             //璋冩暣鍒楄〃鎺т欢鐨勯珮搴�
-            var realHeight = listview.ChildrenCount * listview.GetChildren(listview.ChildrenCount - 1).Height;
-            realHeight += Application.GetRealHeight(23);
-            if (realHeight < listview.Height)
-            {
-                //缂╁皬鎺т欢楂樺害
-                listview.Height = realHeight;
-            }
+            this.listview.AdjustRealHeight(Application.GetRealHeight(23));
 
             //璁剧疆鎺ュ彈鍦ㄧ嚎鐘舵�佹帹閫�
             this.AddGatewayOnlinePush();
@@ -120,64 +132,78 @@
         private void AddRowLayout(string strWayId, bool addLine)
         {
             //缃戝叧鎺т欢
-            var Gateway = HdlGatewayLogic.Current.GetLocalGateway(strWayId);
-            var gatewayRow = new GatewayRowControl(Gateway, listview.rowSpace / 2);
+            var gateway = HdlGatewayLogic.Current.GetLocalGateway(strWayId);
+            var gatewayRow = new GatewayRowControl(gateway, listview.rowSpace / 2);
             listview.AddChidren(gatewayRow);
             gatewayRow.InitControl(81);
             //鍚戝彸鍥炬爣
             gatewayRow.frameTable.AddRightArrow();
-            //娣诲姞鍦ㄧ嚎鐘舵��
-            gatewayRow.AddOnLineControl();
             if (addLine == true)
             {
                 gatewayRow.frameTable.AddBottomLine();
             }
-
             //鎻愮ず鏈夋柊鐗堟湰
-            var btnNew = new InformationTipView(gatewayRow.btnIcon);
+            var btnNew = new RowNewVersionTipView();
             btnNew.Visible = false;
             gatewayRow.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
             gatewayRow.AddTag("btnNew", btnNew);
-
-            this.dicRowContr[strWayId] = gatewayRow;
-
-            //璁剧疆涓�涓�夋嫨缃戝叧鐨勯粯璁ゅ��
-            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && gatewayRow.IsOnline == true)
+            //鍗曞嚮浜嬩欢
+            gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
             {
-                this.SaveGatewayIdToLocation(strWayId);
-            }
 
-            //缂栬緫鎸夐挳
-            var btnEditor = new NormalViewControl(Application.GetRealWidth(177), gatewayRow.Height, false);
-            btnEditor.BackgroundColor = UserCenterColor.Current.RowEditorButtonColor;
-            btnEditor.TextAlignment = TextAlignment.Center;
-            btnEditor.TextColor = UserCenterColor.Current.White;
-            btnEditor.TextID = R.MyInternationalizationString.uEditor;
-            gatewayRow.AddRightView(btnEditor);
-            btnEditor.ButtonClickEvent += (sender, e) =>
-            {
-                //濡傛灉鐐瑰嚮鐨勬槸涓嶅湪绾跨殑缃戝叧锛屽垯褰撲粈涔堜簨閮芥病鏈夊彂鐢�
-                if (gatewayRow.IsOnline == false)
-                {
-                    //鎸囧畾鐨勭綉鍏充笉鍦ㄧ嚎
-                    this.ShowMassage(ShowMsgType.Normal, Language.StringByID(R.MyInternationalizationString.uTheGatewayIsNotOnline));
-                    return;
-                }
-                //鐐瑰嚮缂栬緫鐨勮瘽锛岀洿鎺ラ殣钘�
-                btnNew.Visible = false;
-
-                var form = new GatewayInfoEditorForm();
-                form.AddForm(Gateway);
             };
 
-            //瑙i櫎缁戝畾
-            var btnUnBind = new NormalViewControl(Application.GetRealWidth(177), gatewayRow.Height, false);
-            btnUnBind.BackgroundColor = UserCenterColor.Current.RowDeleteButtonColor;
-            btnUnBind.TextAlignment = TextAlignment.Center;
-            btnUnBind.TextColor = UserCenterColor.Current.White;
-            btnUnBind.TextID = R.MyInternationalizationString.uUnBinded;
-            gatewayRow.AddRightView(btnUnBind);
-            btnUnBind.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)
+                {
+                    //鏄惁閲嶆柊鍒锋柊{0}缃戝叧?
+                    msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + gatewayRow.btnName.Text + "]");
+                }
+                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                {
+                    //鎵ц鍒囨崲缃戝叧鎿嶄綔
+                    this.DoSwitchGateway(strWayId, gatewayRow.IsOnline);
+                });
+            };
+
+            //瀹氫綅
+            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;
+            btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
+            gatewayRow.AddRightView(btnPosition);
+            btnPosition.ButtonClickEvent += (sender, e) =>
+            {
+                //鍙戦�佸畾浣嶅懡浠�
+                HdlGatewayLogic.Current.SetFixedPositionCommand(gateway);
+            };
+
+            //鍒犻櫎
+            var btnDelete = new NormalViewControl(Application.GetRealWidth(184), gatewayRow.Height, false);
+            btnDelete.BackgroundColor = 0xfff75858;
+            btnDelete.TextAlignment = TextAlignment.Center;
+            btnDelete.TextColor = UserCenterColor.Current.White;
+            btnDelete.TextSize = 12;
+            btnDelete.TextID = R.MyInternationalizationString.uDelete;
+            gatewayRow.AddLeftView(btnDelete);
+            btnDelete.ButtonClickEvent += (sender, e) =>
             {
                 //濡傜Щ闄ょ綉鍏筹紝璇ョ綉鍏崇粦瀹氱殑璁惧鍒楄〃{0}灏嗘竻绌猴紝纭缁х画鎵ц璇ユ搷浣滐紵
                 string msg = Language.StringByID(R.MyInternationalizationString.uUnBindedMsg);
@@ -191,42 +217,12 @@
                 });
             };
 
-            //鍗曞嚮浜嬩欢
-            gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
+            this.dicRowContr[strWayId] = gatewayRow;
+            //璁剧疆涓�涓�夋嫨缃戝叧鐨勯粯璁ゅ��
+            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && gatewayRow.IsOnline == true)
             {
-                //濡傛灉鐐瑰嚮鐨勬槸涓嶅湪绾跨殑缃戝叧锛屽垯褰撲粈涔堜簨閮芥病鏈夊彂鐢�
-                if (gatewayRow.IsOnline == false)
-                {
-                    //鎸囧畾鐨勭綉鍏充笉鍦ㄧ嚎
-                    this.ShowMassage(ShowMsgType.Normal, Language.StringByID(R.MyInternationalizationString.uTheGatewayIsNotOnline));
-                    return;
-                }
-                //濡傛灉瀛樺湪鏂扮増鏈�,骞朵笖鍗曞嚮浠栫殑璇�
-                if (btnNew.Visible == true)
-                {
-                    if (sender is InformationTipView || sender is IconViewControl)
-                    {
-                        //鎵撳紑缂栬緫鐣岄潰
-                        btnNew.Visible = false;
-                        var form = new GatewayInfoEditorForm();
-                        form.AddForm(Gateway);
-                        return;
-                    }
-                }
-
-                //鏄惁鍒囨崲鍒皗0}缃戝叧?
-                string msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToSwitchTheGateway), "[" + gatewayRow.btnName.Text + "]");
-                if (strWayId == GatewayResourse.AppOldSelectGatewayId)
-                {
-                    //鏄惁閲嶆柊鍒锋柊{0}缃戝叧?
-                    msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + gatewayRow.btnName.Text + "]");
-                }
-                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
-                {
-                    //鎵ц鍒囨崲缃戝叧鎿嶄綔
-                    this.DoSwitchGateway(strWayId);
-                });
-            };
+                this.SaveGatewayIdToLocation(strWayId);
+            }
         }
 
         #endregion
@@ -270,7 +266,44 @@
         /// 鎵ц鍒囨崲缃戝叧鎿嶄綔
         /// </summary>
         /// <param name="gatewayId"></param>
-        private async void DoSwitchGateway(string gatewayId)
+        /// <param name="online"></param>
+        private async void DoSwitchGateway(string gatewayId,bool online)
+        {
+            if (online == true)
+            {
+                //閲嶆柊鑾峰彇鍦ㄧ嚎缃戝叧鐨勪俊鎭�
+                var result = await this.GetOnlineGatewayInfo(gatewayId);
+                if (result == false)
+                {
+                    return;
+                }
+            }
+            //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
+            this.SaveGatewayIdToLocation(gatewayId);
+            //濡傛灉閫夋嫨浜嗗埛鏂扮殑缃戝叧锛屽垯涓嶅叧闂鐞嗙晫闈�
+            this.closeDeviceManagForm = false;
+
+            if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false)
+            {
+                //鍒锋柊涓荤敾闈�
+                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();
@@ -297,7 +330,7 @@
                     {
                         //鍏抽棴杩涘害鏉�
                         this.CloseProgressBar();
-                        return;
+                        return false;
                     }
                     //閲嶆柊缁戝畾缃戝叧閲岄潰宸茬粡閲嶆柊鑾峰彇浜嗙綉鍏充俊鎭�
                     getGatewayInfo = false;
@@ -312,7 +345,7 @@
                 {
                     //鍏抽棴杩涘害鏉�
                     this.CloseProgressBar();
-                    return;
+                    return false;
                 }
             }
 
@@ -322,27 +355,9 @@
             this.CloseProgressBar();
             if (result == false)
             {
-                return;
+                return false;
             }
-
-            //鍒囨崲缃戝叧,淇濆瓨缂撳瓨
-            this.SaveGatewayIdToLocation(gatewayId);
-            //濡傛灉閫夋嫨浜嗗埛鏂扮殑缃戝叧锛屽垯涓嶅叧闂鐞嗙晫闈�
-            this.closeDeviceManagForm = false;
-
-            if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false)
-            {
-                //鍒锋柊涓荤敾闈�
-                var form = new Device.DeviceListMainForm();
-                this.AddFromAndRemoveNowForm(form);
-            }
-            else
-            {
-                //鍏抽棴鐣岄潰
-                this.CloseForm();
-                //鍒锋柊涓荤敾闈�(涓嶉噸鏂拌幏鍙栬澶囩姸鎬�)
-                this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame", false);
-            }
+            return true;
         }
 
         /// <summary>
@@ -371,11 +386,14 @@
         /// <param name="listway"></param>
         private void StartGatewayOnlieCheckThread(List<ZbGateway> listway)
         {
-            var timeValue = (DateTime.Now - oldGetOnlineTime).Milliseconds;
-            if (timeValue <= 10000)
+            if (oldGetOnlineTime.Year != 1900)
             {
-                //鏈�灏戣闂撮殧鍗佺,鎵嶅幓閲嶆柊鑾峰彇
-                return;
+                var timeValue = (DateTime.Now - oldGetOnlineTime).TotalSeconds;
+                if (timeValue < 10)
+                {
+                    //鏈�灏戣闂撮殧鍗佺,鎵嶅幓閲嶆柊鑾峰彇
+                    return;
+                }
             }
             oldGetOnlineTime = DateTime.Now;
 
@@ -454,7 +472,7 @@
                     {
                         if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null)
                         {
-                            var btnNew = (InformationTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
+                            var btnNew = (RowNewVersionTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
                             if (btnNew != null)
                             {
                                 btnNew.Visible = true;

--
Gitblit v1.8.0