From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 16 四月 2020 17:10:57 +0800 Subject: [PATCH] 请合并代码 --- ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs | 458 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 458 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs new file mode 100755 index 0000000..805e646 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs @@ -0,0 +1,458 @@ +锘縰sing Shared.Common; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.GatewayManage +{ + /// <summary> + /// 缃戝叧绠$悊鐨勭晫闈� + /// </summary> + public class GatewayListForm : EditorCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鍒楄〃鎺т欢 + /// </summary> + private VerticalListControl listview = null; + /// <summary> + /// 鐢熸垚鐨勭綉鍏崇姸鎬佹帶浠舵殏鏃跺瓨鍏ュ唴瀛樹腑 + /// </summary> + private Dictionary<string, GatewayRowControl> dicRowContr = new Dictionary<string, GatewayRowControl>(); + /// <summary> + /// 鍏抽棴璁惧绠$悊鐣岄潰(濡傛灉瑙i櫎缁戝畾鐨勭綉鍏虫槸褰撳墠鎵�閫夋嫨鐨勭綉鍏崇殑璇濓紝鍒欏叧闂澶囩鐞嗙晫闈�) + /// </summary> + private bool closeDeviceManagForm = false; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + public void ShowForm() + { + //璁剧疆鏍囬淇℃伅 + 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) => + { + var form = new GatewayAdd.NewGateWayMenuSelectForm(); + form.AddForm(); + }; + + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄦ帶浠� + /// </summary> + private void InitMiddleFrame() + { + //娓呯┖bodyFrame + this.ClearBodyFrame(); + + listview = new VerticalListControl(29); + listview.Height = bodyFrameLayout.Height + Application.GetRealHeight(6); + listview.Y = Application.GetRealHeight(-6); + listview.BackgroundColor = UserCenterColor.Current.White; + bodyFrameLayout.AddChidren(listview); + + HdlThreadLogic.Current.RunMainInThread(() => + { + //璁惧畾涓儴淇℃伅 + this.SetMiddleFrameInfo(); + }); + } + + /// <summary> + /// 璁惧畾涓儴淇℃伅 + /// </summary> + private void SetMiddleFrameInfo() + { + this.dicRowContr.Clear(); + this.listview.RemoveAll(); + + //鑾峰彇鏈湴鍏ㄩ儴缃戝叧瀵硅薄 + List<ZbGateway> listway = HdlGatewayLogic.Current.GetAllLocalGateway(); + if (listway.Count == 0) + { + //杩樻病鏈夌粦瀹氱綉鍏冲摝 + 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.listview.AdjustRealHeight(Application.GetRealHeight(23)); + + //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼ + this.StartGatewayOnlieCheckThread(listway); + } + + #endregion + + #region 鈻� 娣诲姞缃戝叧琛宊________________________ + + /// <summary> + /// 娣诲姞琛� + /// </summary> + /// <param name="strWayId">String way.</param> + /// <param name="addLine">鏄惁娣诲姞搴曠嚎</param> + private void AddRowLayout(string strWayId, bool addLine) + { + //缃戝叧鎺т欢 + var gateway = HdlGatewayLogic.Current.GetLocalGateway(strWayId); + var gatewayRow = new GatewayRowControl(gateway, listview.rowSpace / 2); + listview.AddChidren(gatewayRow); + gatewayRow.InitControl(81); + //鍚戝彸鍥炬爣 + gatewayRow.frameTable.AddRightArrow(); + if (addLine == true) + { + gatewayRow.frameTable.AddBottomLine(); + } + //鎻愮ず鏂扮増鏈� + var btnNew = new InformationTipView(gatewayRow.btnIcon); + btnNew.Visible = false; + gatewayRow.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly); + gatewayRow.AddTag("btnNew", btnNew); + //鍗曞嚮浜嬩欢 + gatewayRow.frameTable.ButtonClickEvent += (sender, e) => + { + if (UserCenterResourse.HideOption.GotoGatewayProductInfoForm == 1) + { + //寮哄埗璺宠浆 + var form2 = new GatewayProductInfoForm(); + form2.AddForm(gateway); + return; + } + var form = new GatewayInfoEditorForm(); + form.AddForm(gateway); + }; + + //鍒囨崲 + 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, () => + { + HdlThreadLogic.Current.RunThread(() => + { + //鎵ц鍒囨崲缃戝叧鎿嶄綔 + this.DoSwitchGateway(strWayId); + }); + }); + }; + + //瀹氫綅 + var btnPosition = gatewayRow.AddEditorControl(false); + btnPosition.TextID = R.MyInternationalizationString.uFixedPosition; + 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); + if (msg.Contains("{0}") == true) + { + msg = string.Format(msg, "\r\n"); + } + this.ShowMassage(ShowMsgType.Confirm, msg, () => + { + HdlThreadLogic.Current.RunThread(() => + { + this.DeleteGateway(strWayId, gatewayRow); + }); + }); + }; + + this.dicRowContr[strWayId] = gatewayRow; + //璁剧疆涓�涓�夋嫨缃戝叧鐨勯粯璁ゅ�� + if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true) + { + HdlGatewayLogic.Current.SaveGatewayIdToLocation(strWayId); + } + + //褰撳墠缃戝叧鐨勮鏍� + if (strWayId == GatewayResourse.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.BindEventOnly); + } + } + + #endregion + + #region 鈻� 瑙g粦缃戝叧___________________________ + + /// <summary> + /// 瑙g粦缃戝叧 + /// </summary> + /// <param name="strWayId"></param> + /// <param name="row"></param> + private async void DeleteGateway(string strWayId, GatewayRowControl row) + { + //鎵撳紑杩涘害鏉� + this.ShowProgressBar(); + //鍒犻櫎浜戠缃戝叧 + bool result = await HdlGatewayLogic.Current.DeleteGateway(strWayId); + //鍏抽棴杩涘害鏉� + this.CloseProgressBar(); + if (result == false) + { + return; + } + + if (strWayId == GatewayResourse.AppOldSelectGatewayId) + { + //濡傛灉瑙i櫎缁戝畾鐨勭綉鍏虫槸褰撳墠鎵�閫夋嫨鐨勭綉鍏崇殑璇濓紝鍒欏叧闂澶囩鐞嗙晫闈� + this.closeDeviceManagForm = true; + HdlGatewayLogic.Current.SaveGatewayIdToLocation(string.Empty); + } + HdlThreadLogic.Current.RunMain(() => + { + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + }); + } + + #endregion + + #region 鈻� 缃戝叧鍒囨崲___________________________ + + /// <summary> + /// 鎵ц鍒囨崲缃戝叧鎿嶄綔 + /// </summary> + /// <param name="gatewayId"></param> + /// <param name="online"></param> + private async void DoSwitchGateway(string gatewayId) + { + var result = await HdlGatewayLogic.Current.DoSwitchGateway(gatewayId); + if (result == false) + { + return; + } + //濡傛灉閫夋嫨浜嗗埛鏂扮殑缃戝叧锛屽垯涓嶅叧闂鐞嗙晫闈� + this.closeDeviceManagForm = false; + + HdlThreadLogic.Current.RunMain(() => + { + if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false) + { + //鍒锋柊涓荤敾闈� + var form = new Device.DeviceListMainForm(); + this.AddFromAndRemoveNowForm(form); + } + else + { + //鍏抽棴鐣岄潰 + this.CloseForm(); + //鍒锋柊涓荤敾闈�(涓嶉噸鏂拌幏鍙栬澶囩姸鎬�) + this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame", false); + } + }); + } + + #endregion + + #region 鈻� 缃戝叧鍦ㄧ嚎妫�娴媉______________________ + + /// <summary> + /// 涓婁竴娆¤幏鍙栫綉鍏冲湪绾跨殑鏃堕棿(涓嶈兘璁╁畠姣忕偣涓�娆¢兘鍘昏幏鍙栫綉鍏崇姸鎬�) + /// </summary> + private DateTime oldGetOnlineTime = new DateTime(1900, 1, 1); + + /// <summary> + /// 寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼ + /// </summary> + /// <param name="listway"></param> + private void StartGatewayOnlieCheckThread(List<ZbGateway> listway) + { + if (oldGetOnlineTime.Year != 1900) + { + var timeValue = (DateTime.Now - oldGetOnlineTime).TotalSeconds; + if (timeValue < 10) + { + //鏈�灏戣闂撮殧鍗佺,鎵嶅幓閲嶆柊鑾峰彇 + return; + } + } + oldGetOnlineTime = DateTime.Now; + + HdlThreadLogic.Current.RunThread(() => + { + System.Threading.Thread.Sleep(300); + //鍒锋柊缃戝叧鍦ㄧ嚎鐘舵�� + HdlGatewayLogic.Current.RefreshGatewayOnlineStatu(listway); + foreach (var way in listway) + { + if (this.Parent == null) + { + return; + } + bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(way); + this.GatewayOnlinePush(way, online); + } + //缃戝叧鏂扮増鏈娴� + this.CheckGatewayNewVersion(listway); + }); + } + + /// <summary> + /// 缃戝叧鍦ㄧ嚎鐘舵�佸彉鏇� + /// </summary> + /// <param name="gateWay">缃戝叧瀵硅薄</param> + /// <param name="online">鍦ㄧ嚎鐘舵�佸彉鏇村悗鐨勭姸鎬�</param> + public override void GatewayOnlinePush(ZbGateway gateWay, bool online) + { + Application.RunOnMainThread(() => + { + if (this.Parent == null) + { + return; + } + string gwid = HdlGatewayLogic.Current.GetGatewayId(gateWay); + if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null) + { + this.dicRowContr[gwid].RefreshControl(gateWay); + } + }); + } + + #endregion + + #region 鈻� 缃戝叧鏂扮増鏈娴媉____________________ + + /// <summary> + /// 缃戝叧鏂扮増鏈娴� + /// </summary> + /// <param name="listWays"></param> + private async void CheckGatewayNewVersion(List<ZbGateway> listWays) + { + foreach (var way in listWays) + { + if (this.Parent == null) + { + return; + } + if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(way) == false) + { + //涓嶅湪绾跨殑涓嶇敤鐞嗗畠 + continue; + } + //鑾峰彇鏈�鏂扮増鏈� + var result = await HdlGatewayLogic.Current.GetGatewayAllNewVersion(way, ShowErrorMode.NO); + if (result == null) + { + continue; + } + if (result[0] != null || result[1] != null || result[2] != null) + { + //鏈夋柊鐗堟湰 + string gwid = HdlGatewayLogic.Current.GetGatewayId(way); + Application.RunOnMainThread(() => + { + if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null) + { + var btnNew = (InformationTipView)this.dicRowContr[gwid].GetTagByKey("btnNew"); + if (btnNew != null) + { + btnNew.Visible = true; + } + } + }); + } + } + } + + #endregion + + #region 鈻� 鐢婚潰鍏抽棴___________________________ + + /// <summary> + /// 鐢婚潰鍏抽棴 + /// </summary> + public override void CloseFormBefore() + { + base.CloseFormBefore(); + + if (this.closeDeviceManagForm == true) + { + //鍏抽棴鐣岄潰 + HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId(); + this.LoadFormMethodByName("DeviceListMainForm", "CloseForm"); + } + } + + #endregion + + #region 鈻� 鐣岄潰閲嶆柊婵�娲讳簨浠禵__________________ + + /// <summary> + /// 鑷韩鐨勪笂灞傜晫闈㈠叧闂悗,瀹冭嚜韬浜庢渶涓婂眰鏃�,瑙﹀彂鐨勪簨浠� + /// </summary> + public override int FormActionAgainEvent() + { + //杩涘埌杩欎釜鐣岄潰,鐞嗚涓婂墠鍥炵殑缃戝叧id鏄湁鐨�,濡傛灉涓虹┖浜�,搴旇鏄綋鍓嶇殑缃戝叧琚В缁戜簡 + if (GatewayResourse.AppOldSelectGatewayId == string.Empty) + { + //鍏抽棴璁惧鍒楄〃 + this.closeDeviceManagForm = true; + } + //鍒濆鍖栦腑閮ㄦ帶浠� + this.InitMiddleFrame(); + return 1; + } + + #endregion + } +} -- Gitblit v1.8.0