From 224ea4055d5359d0bae0e7087ccc11724a2e49e5 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期二, 14 七月 2020 16:09:19 +0800
Subject: [PATCH] 备份新改的代码
---
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs | 441 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 441 insertions(+), 0 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
new file mode 100755
index 0000000..448ff57
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
@@ -0,0 +1,441 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.GatewayAdd
+{
+ /// <summary>
+ /// 缃戝叧鎼滅储涓�
+ /// </summary>
+ public class WiredGatewaySearchForm : EditorCommonForm
+ {
+ #region 鈻� 鍙橀噺澹版槑___________________________
+
+ /// <summary>
+ /// 缃戝叧鐨勪富閿�(value:鍓╀綑妫�娴嬫鏁�,鐢ㄤ簬瀵瑰簲寮傚父鐨勭綉鍏�)
+ /// </summary>
+ private Dictionary<string, int> dicIdCheckCount = new Dictionary<string, int>();
+ /// <summary>
+ /// 鎼滅储鍒扮殑缃戝叧鍒楄〃
+ /// </summary>
+ private List<ZbGateway> listZbGateway = new List<ZbGateway>();
+ /// <summary>
+ /// 鎼滅储鍒扮殑缃戝叧绫诲埆 0:绗竴娆$粦瀹� 1:宸茬粡缁戝畾 2:闇�瑕佹崲缁�
+ /// </summary>
+ private Dictionary<string, int> dicZbGatewayDiv = new Dictionary<string, int>();
+ /// <summary>
+ /// 鑾峰彇寰楀埌浜嗘柊缃戝叧
+ /// </summary>
+ private bool newGatewayGetting = false;
+ /// <summary>
+ /// 缃戝叧鎼滅储涓�
+ /// </summary>
+ private bool isGatewaySearching = true;
+
+ #endregion
+
+ #region 鈻� 鍒濆鍖朹____________________________
+
+ /// <summary>
+ /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+ /// </summary>
+ public void ShowForm()
+ {
+ //璁剧疆鏍囬淇℃伅
+ base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddWiredGateway));
+
+ //鍒濆鍖栧垵濮嬩腑閮ㄦ帶浠�
+ this.InitDefultMiddleFrame();
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栧垵濮嬩腑閮ㄦ帶浠�
+ /// </summary>
+ private void InitDefultMiddleFrame()
+ {
+ //娓呯┖bodyFrame
+ this.ClearBodyFrame();
+
+ //鍥炬爣
+ var picGwImage = new FrameLayout();
+ picGwImage.Width = this.GetPictrueRealSize(861);
+ picGwImage.Height = this.GetPictrueRealSize(478);
+ picGwImage.Y = Application.GetRealHeight(251);
+ picGwImage.Gravity = Gravity.CenterHorizontal;
+ picGwImage.BackgroundImagePath = "Gateway/WiredGatewaySearching.png";
+ bodyFrameLayout.AddChidren(picGwImage);
+
+ //姝e湪鎼滅储缃戝叧鈥�
+ var btnMsg = new NormalViewControl(bodyFrameLayout.Width, false);
+ btnMsg.TextID = R.MyInternationalizationString.uGatewaySearching;
+ btnMsg.Y = Application.GetRealHeight(1008);
+ btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
+ btnMsg.TextAlignment = TextAlignment.Center;
+ bodyFrameLayout.AddChidren(btnMsg);
+
+ //鍒濆鍖栬繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉
+ this.InitConcetionAnimete(picGwImage, btnMsg);
+ //寮�鍚綉鍏虫娴嬬殑绾跨▼
+ this.StartCheckGatewayThread();
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栧け璐ユā寮忕殑涓儴鎺т欢
+ /// </summary>
+ private void InitFailMiddleFrame()
+ {
+ //娓呯┖bodyFrame
+ this.ClearBodyFrame();
+
+ //鍥炬爣
+ var picGwImage = new FrameLayout();
+ picGwImage.Width = this.GetPictrueRealSize(861);
+ picGwImage.Height = this.GetPictrueRealSize(478);
+ picGwImage.Y = Application.GetRealWidth(158);
+ picGwImage.Gravity = Gravity.CenterHorizontal;
+ picGwImage.BackgroundImagePath = "Gateway/WiredGatewaySearching.png";
+ bodyFrameLayout.AddChidren(picGwImage);
+ var btnFailIcon = new PicViewControl(66, 66);
+ btnFailIcon.UnSelectedImagePath = "Item/FailIcon.png";
+ btnFailIcon.Gravity = Gravity.CenterHorizontal;
+ btnFailIcon.Y = this.GetPictrueRealSize(181);
+ picGwImage.AddChidren(btnFailIcon);
+ //鎼滅储澶辫触
+ var btnFailView = new NormalViewControl(300, 60, true);
+ btnFailView.TextAlignment = TextAlignment.Center;
+ btnFailView.Y = this.GetPictrueRealSize(305);
+ btnFailView.Gravity = Gravity.CenterHorizontal;
+ btnFailView.TextColor = UserCenterColor.Current.TextGrayColor3;
+ btnFailView.TextID = R.MyInternationalizationString.uSearchFail;
+ picGwImage.AddChidren(btnFailView);
+
+ //瑙e喅鏂规硶锛屽彲閫夋嫨鎵ц浠ヤ笅浠绘剰涓�绉嶆柟寮忥細
+ var btnMsg1 = new NormalViewControl(930, 60, true);
+ btnMsg1.X = Application.GetRealWidth(75);
+ btnMsg1.Y = picGwImage.Bottom + Application.GetRealHeight(112);
+ btnMsg1.TextID = R.MyInternationalizationString.uSearchGatewayFailMsg1;
+ bodyFrameLayout.AddChidren(btnMsg1);
+ //1.鐭寜HID/WCFG鎸夐敭锛岀郴缁熸寚绀虹伅蹇棯3绉掞紝缃戝叧杩涘叆鎹㈢粦妯″紡锛屽己鍒剁綉鍏崇粦瀹氬埌褰撳墠APP
+ var btnMsg2 = new NormalViewControl(930, 100, true);
+ btnMsg2.X = Application.GetRealWidth(75);
+ btnMsg2.Y = btnMsg1.Bottom + Application.GetRealHeight(35);
+ btnMsg2.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg2).Replace("{0}", "\r\n");
+ btnMsg2.TextSize = 12;
+ btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
+ btnMsg2.IsMoreLines = true;
+ bodyFrameLayout.AddChidren(btnMsg2);
+ //2.闀挎寜缃戝叧ZB/RST鎸夐敭20绉掍互涓婏紝鐩村埌鎵�鏈夋寚绀虹伅鍚屾椂鐏紝鍗虫仮澶嶅嚭鍘傝缃苟閲嶅惎
+ var btnMsg3 = new NormalViewControl(930, 100, true);
+ btnMsg3.X = Application.GetRealWidth(75);
+ btnMsg3.Y = btnMsg2.Bottom + Application.GetRealHeight(12);
+ btnMsg3.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg3).Replace("{0}", "\r\n");
+ btnMsg3.TextSize = 12;
+ btnMsg3.TextColor = UserCenterColor.Current.TextGrayColor1;
+ btnMsg3.IsMoreLines = true;
+ bodyFrameLayout.AddChidren(btnMsg3);
+ //3.璇烽噸璇曪紝閲嶆柊娣诲姞缃戝叧銆�
+ var btnMsg4 = new NormalViewControl(930, 50, true);
+ btnMsg4.X = Application.GetRealWidth(75);
+ btnMsg4.Y = btnMsg3.Bottom + Application.GetRealHeight(12);
+ btnMsg4.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg4);
+ btnMsg4.TextSize = 12;
+ btnMsg4.TextColor = UserCenterColor.Current.TextGrayColor1;
+ bodyFrameLayout.AddChidren(btnMsg4);
+ //4.杩斿洖缃戝叧绠$悊銆�
+ var btnMsg5 = new NormalViewControl(930, 50, true);
+ btnMsg5.X = Application.GetRealWidth(75);
+ btnMsg5.Y = btnMsg4.Bottom + Application.GetRealHeight(12);
+ btnMsg5.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg5);
+ btnMsg5.TextSize = 12;
+ btnMsg5.TextColor = UserCenterColor.Current.TextGrayColor1;
+ bodyFrameLayout.AddChidren(btnMsg5);
+
+ //閲嶈瘯
+ var frameback = new FrameLayoutStatuControl();
+ frameback.UseClickStatu = false;
+ frameback.Y = Application.GetRealHeight(1259);
+ frameback.Gravity = Gravity.CenterHorizontal;
+ frameback.Width = Application.GetRealWidth(746);
+ frameback.Height = Application.GetRealHeight(184);
+ frameback.BackgroundImagePath = "Item/BottomButtonGround.png";
+ bodyFrameLayout.AddChidren(frameback);
+ var btnReDo = new NormalViewControl(300, 65, true);
+ btnReDo.IsBold = true;
+ btnReDo.TextColor = UserCenterColor.Current.White;
+ btnReDo.TextSize = 16;
+ btnReDo.Y = Application.GetRealHeight(49);
+ btnReDo.Gravity = Gravity.CenterHorizontal;
+ btnReDo.TextAlignment = TextAlignment.Center;
+ btnReDo.TextID = R.MyInternationalizationString.uReDoAgain;
+ frameback.AddChidren(btnReDo, ChidrenBindMode.BindEvent);
+ frameback.ButtonClickEvent += (sender, e) =>
+ {
+ //鍒濆鍖栧垵濮嬩腑閮ㄦ帶浠�
+ this.InitDefultMiddleFrame();
+ };
+
+ //杩斿洖缃戝叧绠$悊
+ var btnGoBack = new BottomClickButton(688);
+ btnGoBack.Y = Application.GetRealHeight(1495);
+ btnGoBack.TextID = R.MyInternationalizationString.uGobackGatewayManage;
+ if (UserCenterResourse.DicActionForm.ContainsKey("GatewayListForm") == false)
+ {
+ //杩斿洖涓婚〉
+ btnGoBack.TextID = R.MyInternationalizationString.uGobackToHomePage;
+ }
+ bodyFrameLayout.AddChidren(btnGoBack);
+ btnGoBack.ButtonClickEvent += (sender, e) =>
+ {
+ this.CloseForm();
+ //鍏抽棴鎸囧畾鐣岄潰
+ this.CloseFormByFormName("NewGateWayMenuSelectForm");
+ };
+ }
+
+ #endregion
+
+ #region 鈻� 鍋囨兂鍔ㄧ敾(缃戝叧妫�娴�)_________________
+
+ /// <summary>
+ /// 鍒濆鍖栬繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉
+ /// </summary>
+ private void InitConcetionAnimete(FrameLayout picGwImage, NormalViewControl btnMsg)
+ {
+ //棣栨牸鐨刋杞�
+ int firstPoint = this.GetPictrueRealSize(288);
+ //涓�鏍肩殑瀹藉害
+ int width = this.GetPictrueRealSize(22);
+ //闂磋窛澶у皬
+ int space = this.GetPictrueRealSize(12);
+
+ //鐢熸垚鏍煎瓙鍧愭爣
+ var listPoint = new List<int>();
+ for (int i = 0; i < 9; i++)
+ {
+ listPoint.Add(firstPoint + (width + space) * i);
+ }
+
+ //寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼
+ var btnRound = new PicViewControl(width, width, false);
+ btnRound.Radius = (uint)width / 2;
+ btnRound.BackgroundColor = UserCenterColor.Current.ConcetionRoundColor;
+ btnRound.Y = this.GetPictrueRealSize(202);
+ btnRound.X = listPoint[0];
+ picGwImage.AddChidren(btnRound);
+
+ string strMsg = btnMsg.Text;
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ int index = 1;
+ int maxCount = 120 * 2;
+ int timeCount = 120;
+ while (picGwImage.Parent != null)
+ {
+ System.Threading.Thread.Sleep(500);
+ maxCount--;
+ if (maxCount % 2 == 0)
+ {
+ timeCount--;
+ }
+ if (maxCount <= 0 || this.newGatewayGetting == true)
+ {
+ //鑾峰彇寰楀埌鏂扮綉鍏�,鍒欎腑鏂嚎绋�
+ break;
+ }
+ Application.RunOnMainThread(() =>
+ {
+ btnRound.X = listPoint[index];
+ index++;
+ if (index == listPoint.Count)
+ {
+ index = 0;
+ }
+ //姝e湪鎼滅储缃戝叧鈥Xs
+ btnMsg.Text = strMsg + timeCount + "s";
+ });
+ }
+ //鎼滅储缁撴潫
+ this.isGatewaySearching = false;
+
+ if (maxCount <= 0)
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //鍒濆鍖栧け璐ユā寮忕殑涓儴鎺т欢
+ this.InitFailMiddleFrame();
+ });
+ }
+ else if (newGatewayGetting == true)
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ if (this.Parent != null)
+ {
+ var form = new GatewayManage.GatewaySearchListForm();
+ this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
+ }
+ });
+ }
+ });
+ }
+
+ #endregion
+
+ #region 鈻� 缃戝叧妫�娴媉__________________________
+
+ /// <summary>
+ /// 寮�鍚綉鍏虫娴嬬殑绾跨▼
+ /// </summary>
+ private void StartCheckGatewayThread()
+ {
+ this.isGatewaySearching = true;
+ HdlThreadLogic.Current.RunThread(async () =>
+ {
+ //娓呯┖鍏ㄩ儴鍒楄〃
+ HdlGatewayLogic.Current.ClearAllRealGateway();
+ ZigBee.Common.Application.IsSearchingGateway = true;
+
+ int count = 0;
+ while (this.Parent != null && this.isGatewaySearching == true)
+ {
+ //姣�2绉掓娴嬫悳绱㈠埌鐨勭綉鍏�
+ System.Threading.Thread.Sleep(500);
+ count++;
+ if (count < 4)
+ {
+ //涓昏涓轰簡蹇竴鐐硅兘澶熶腑鏂繖涓嚎绋�
+ continue;
+ }
+ count = 0;
+
+ await this.CheckZbGatewayAndSetRow();
+
+ if (this.newGatewayGetting == true)
+ {
+ //鑾峰彇寰楀埌鏂扮綉鍏�,鍒欎腑鏂嚎绋�
+ break;
+ }
+ }
+ });
+ }
+
+ /// <summary>
+ /// 妫�娴嬫悳绱㈠埌鐨勭綉鍏筹紝鐒跺悗娣诲姞鍒扮敾闈㈢殑琛岄噷闈�
+ /// </summary>
+ private async Task<bool> CheckZbGatewayAndSetRow()
+ {
+ List<string> listId = new List<string>();
+ for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
+ {
+ if (ZbGateway.GateWayList[i].GwIP == string.Empty)
+ {
+ //IP娌℃湁鐨勭綉鍏筹紝鎴戜篃涓嶇煡閬撳畠鏄共鍢涚殑
+ continue;
+ }
+ string gwId = ZbGateway.GateWayList[i].GwId;
+ //閲嶅娣诲姞妫�娴�
+ if (this.dicIdCheckCount.ContainsKey(gwId) == false)
+ {
+ //鍏佽浜旀妫�娴�
+ this.dicIdCheckCount[gwId] = 5;
+ listId.Add(gwId);
+ }
+ else if (this.dicIdCheckCount[gwId] > 0)
+ {
+ //濡傛灉鍓嶄竴娆℃娴嬪け璐ヤ簡鐨勮瘽锛屽畠鐨勬鏁�-1
+ this.dicIdCheckCount[gwId] = this.dicIdCheckCount[gwId] - 1;
+ listId.Add(gwId);
+ }
+ }
+ if (listId.Count == 0)
+ {
+ //娌℃湁鏂扮殑缃戝叧锛屾垨鑰呮鏁板凡缁忕敤瀹�
+ return true;
+ }
+ for (int i = 0; i < listId.Count; i++)
+ {
+ ZbGateway way = ZbGateway.GateWayList.Find((obj) => obj.GwId == listId[i]);
+ if (way == null)
+ {
+ continue;
+ }
+
+ //缃戝叧缁戝畾妯″紡
+ GatewayBindMode mode = GatewayBindMode.BindAgain;
+ //濡傛灉鏄涓�娆$粦瀹�,鎴栬�呮槸浠ュ墠宸茬粡缁戝畾杩囦簡鐨�
+ if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true
+ || way.HomeId == Common.Config.Instance.HomeId)
+ {
+ if (way.HomeId != Common.Config.Instance.HomeId)
+ {
+ //绗竴娆$粦瀹�,涔熷氨鏄綉鍏充綇瀹匢D涓虹┖
+ mode = GatewayBindMode.First;
+ }
+ else
+ {
+ //宸茬粡缁戝畾杩囦簡
+ mode = GatewayBindMode.Binded;
+ }
+
+ //娣诲姞鎼滅储鍒扮殑缃戝叧鍒扮紦瀛�(鎵ц缃戝叧淇濆瓨鎿嶄綔)
+ ShowErrorMode showMode = this.dicIdCheckCount[listId[i]] == 0 ? ShowErrorMode.YES : ShowErrorMode.NO;
+ var result = await HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
+ if (result == false)
+ {
+ continue;
+ }
+ }
+ //鏀堕泦缃戝叧瀵硅薄
+ this.listZbGateway.Add(way);
+
+ //濡傛灉瀹冨凡缁忓畬鍏ㄦ垚鍔熶簡鐨勮瘽锛屽垯灏嗗畠鐨勫墿浣欐鏁扮疆闆�
+ this.dicIdCheckCount[listId[i]] = 0;
+ //鍏ㄩ儴澶勭悊OK鍚庯紝鎵嶈兘璁剧疆flage
+ if (mode == GatewayBindMode.First)
+ {
+ //绗竴娆$粦瀹�
+ this.dicZbGatewayDiv[listId[i]] = 0;
+ //鑾峰彇鍒颁簡鏂扮綉鍏�
+ this.newGatewayGetting = true;
+ }
+ else if (mode == GatewayBindMode.Binded)
+ {
+ //宸茬粡缁戝畾杩�
+ this.dicZbGatewayDiv[listId[i]] = 1;
+ }
+ else
+ {
+ //闇�瑕侀噸鏂扮粦瀹�
+ this.dicZbGatewayDiv[listId[i]] = 2;
+ //鑾峰彇鍒颁簡鏂扮綉鍏�
+ this.newGatewayGetting = true;
+ }
+
+ if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
+ {
+ //鎴戣寰楄繖閲岄渶瑕佽幏鍙栦竴涓嬫柊缃戝叧鐨勮澶囧垪琛�
+ Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
+ }
+ }
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 鐣岄潰鍏抽棴___________________________
+
+ /// <summary>
+ /// 鐢婚潰鍏抽棴
+ /// </summary>
+ public override void CloseFormBefore()
+ {
+ ZigBee.Common.Application.IsSearchingGateway = false;
+
+ base.CloseFormBefore();
+ }
+
+ #endregion
+ }
+}
--
Gitblit v1.8.0