From 2be70a32d2a8c517bd9868fb60913fcc843e66fe Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期三, 13 五月 2020 11:21:32 +0800 Subject: [PATCH] 上传代码 --- ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs | 315 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 202 insertions(+), 113 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs index 0dc5e74..8f904cd 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs @@ -30,10 +30,6 @@ /// </summary> private Dictionary<string, DeviceObjRowInfo> dicRowInfo = new Dictionary<string, DeviceObjRowInfo>(); /// <summary> - /// 閲嶆柊鑾峰彇璁惧鐨勫湪绾跨姸鎬� - /// </summary> - private bool reGetDeviceOnlineStatu = false; - /// <summary> /// 褰撳墠姝e湪鎿嶄綔鐨勮澶囧璞ac鍦板潃(璁惧淇℃伅缂栬緫鐣岄潰鐢�) /// </summary> private string nowActionDeviceMac = null; @@ -59,41 +55,41 @@ btnAddDeviceIcon.InitControl(); btnAddDeviceIcon.ButtonClickEvent += (sender, e) => { - ZbGateway realWay = null; - if (GatewayResourse.NowSelectGateway == null || HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == false) - { - //缃戝叧瀵硅薄寮傚父,璇烽噸鏂伴�夋嫨缃戝叧 - string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsErrorAndReSelect); - this.ShowMassage(ShowMsgType.Error, msg, () => - { - var form2 = new GatewayManage.GatewayListForm(); - form2.AddForm(); - }); - return; - } - GatewayResourse.NowSelectGateway = realWay; - var form = new DeviceDirection.AddDeviceTypeListForm(); form.AddForm(); }; //鍒濆鍖栦腑閮ㄦ帶浠� this.InitMiddleFrame(); + + //寮�鍚紶鎰熷櫒鎶ヨ鐩戣 + this.StartCheckDeviceAlarm(); + //娣诲姞鎺ユ敹璁惧鍦ㄧ嚎涓婃姤鐨勭洃鍚� + HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormReceivePushOnline", ReceiveComandDiv.A璁惧鍦ㄧ嚎涓婃姤, (report) => + { + HdlThreadLogic.Current.RunMain(() => + { + //鎺ュ彈璁惧鐘舵�� + this.ReceiveDeviceStatu(report); + + }, ShowErrorMode.NO); + }); + //寮�鍚娴嬬綉鍏冲湪绾跨姸鎬佺殑绾跨▼ + HdlGatewayLogic.Current.StartCheckGatewayOnlineThread(this); } /// <summary> /// 鍒濆鍖栦腑閮ㄦ帶浠�(澶栭儴鍙互璋冪敤) /// </summary> - /// <param name="i_reGetDeviceOnlineStatu">閲嶆柊鑾峰彇璁惧鐨勫湪绾跨姸鎬�</param> - public void InitMiddleFrame(bool i_reGetDeviceOnlineStatu = true) + public void InitMiddleFrame() { - this.reGetDeviceOnlineStatu = i_reGetDeviceOnlineStatu; //娓呯┖bodyFrame this.ClearBodyFrame(); //鍒濆鍖栫綉鍏宠鎺т欢 - GatewayResourse.NowSelectGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId); - this.gatewayViewRow = new MyGatewayControl(GatewayResourse.NowSelectGateway); + GatewayResourse.NowSelectGatewayId = GatewayResourse.AppOldSelectGatewayId; + var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId); + this.gatewayViewRow = new MyGatewayControl(nowGateway); bodyFrameLayout.AddChidren(gatewayViewRow); gatewayViewRow.InitControl(); @@ -138,6 +134,9 @@ frame.AddChidren(listView); listView.BeginHeaderRefreshingAction += () => { + //鍒锋柊璁惧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂� + UserView.UserPage.Instance.RefreshForm = true; + HdlThreadLogic.Current.RunThread(() => { //涓嬫媺鍒锋柊 @@ -156,9 +155,8 @@ private void InitDeviceListControl() { //鑾峰彇璁惧鍒楄〃 - string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway); - var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(gwID); - var listSpecialOta = Common.LocalDevice.Current.GetSpecialOtaDevice(gwID); + var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(GatewayResourse.NowSelectGatewayId); + var listSpecialOta = Common.LocalDevice.Current.GetSpecialOtaDevice(GatewayResourse.NowSelectGatewayId); listDevice.AddRange(listSpecialOta); this.dicRowInfo.Clear(); @@ -190,11 +188,14 @@ //娣诲姞璁惧鐨勮彍鍗曡 this.AddDeviceMenuRow(macAddress); } - - //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼ - this.StartGatewayOnlieCheckThread(); - //妫�娴嬭澶囨柊鐗堟湰 - this.CheckDeviceNewVersion(listOta); + //濡傛灉褰撳墠涓嶆槸铏氭嫙浣忓畢 + if (Common.Config.Instance.Home.IsVirtually == false) + { + //寮�鍚綉鍏冲湪绾跨洃娴嬬殑绾跨▼ + this.StartGatewayOnlieCheckThread(); + //妫�娴嬭澶囨柊鐗堟湰 + this.CheckDeviceNewVersion(listOta); + } }); } @@ -359,8 +360,7 @@ //鍙崇澶� rowDevice.frameTable.AddRightArrow(); //鍦ㄧ嚎鐘舵�� - rowDevice.isOnline = device.IsOnline == 1; - + rowDevice.IsOnline = rowInfo.MenuRow.IsOnline; //淇濆瓨鎺т欢 string maikey = Common.LocalDevice.Current.GetDeviceMainKeys(device); rowInfo.dicDetailRow[maikey] = rowDevice; @@ -384,8 +384,12 @@ rowDevice.HideMenu(); //鐣岄潰璺宠浆,璁板綍褰撳墠鐨勬鍦ㄦ搷浣滅殑璁惧鐨凪ac鍦板潃 this.nowActionDeviceMac = device.DeviceAddr; - //鏄剧ず璁惧鍔熻兘閰嶇疆鐣岄潰 - this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo); + //濡傛灉褰撳墠浣忓畢涓嶆槸铏氭嫙浣忓畢 + if (Common.Config.Instance.Home.IsVirtually == false) + { + //鏄剧ず璁惧鍔熻兘閰嶇疆鐣岄潰 + this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo); + } }; //宸︽粦鑿滃崟浜嬩欢 rowDevice.OpenMenuAction += () => @@ -448,8 +452,17 @@ else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir) { //鏂规偊鏂伴闈㈡澘鐨勬寜閿厤缃� - var form = new DevicePanel.PanelFangyueFreshAirButtonSettionForm(); - form.AddForm(device); + //骞叉帴鐐� + if (device.Type == DeviceType.FreshAir) + { + var form = new DevicePanel.PanelFangyueFreshAirButtonSettionForm(); + form.AddForm(device); + } + else + { + var form = new DeviceFunctionSettionForm(); + form.AddForm(device, true); + } } //鏂规偊闈㈡澘 else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueTwo @@ -591,12 +604,25 @@ /// </summary> private async void ListViewBeginHeaderRefreshing() { + //濡傛灉褰撳墠浣忓畢鏄櫄鎷熺殑 + if (Common.Config.Instance.Home.IsVirtually == true) + { + //灏辨樉绀轰竴涓壒鏁堣�屽凡 + System.Threading.Thread.Sleep(2000); + HdlThreadLogic.Current.RunMain(() => + { + //闅愯棌涓嬫媺鍒锋柊鐗规晥 + listView.EndHeaderRefreshing(); + }); + return; + } //濡傛灉鏄湪绾跨殑 - if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(GatewayResourse.NowSelectGateway) == true) + var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.NowSelectGatewayId); + if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(nowGateway) == true) { //妫�娴嬪箍鎾埌鐨勮繖涓綉鍏虫槸鍚︽嫢鏈変綇瀹匢D ZbGateway realWay = null; - if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == true) + if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, nowGateway) == true) { //閲嶆柊璁剧疆浣忓畢ID(杩欎釜搴旇鏄笉缁忚繃APP,鐩存帴鎶婄綉鍏虫仮澶嶄簡鍑哄巶璁剧疆) if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true) @@ -619,7 +645,7 @@ } //鑾峰彇鍏ㄩ儴璁惧 - int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(GatewayResourse.NowSelectGateway); + int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(nowGateway); if (this.Parent == null) { return; @@ -631,7 +657,7 @@ if (result != -1) { //閲嶆柊鍒锋柊鐣岄潰 - this.InitMiddleFrame(false); + this.InitMiddleFrame(); } }); } @@ -645,12 +671,7 @@ /// </summary> private void StartGatewayOnlieCheckThread() { - if (GatewayResourse.NowSelectGateway == null) - { - return; - } - - string selectGwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway); + string selectGwId = GatewayResourse.NowSelectGatewayId; HdlThreadLogic.Current.RunThread(() => { ZbGateway zbGateway = HdlGatewayLogic.Current.GetLocalGateway(selectGwId); @@ -666,9 +687,10 @@ if (this.gatewayViewRow != null && this.gatewayViewRow.zbGatewayId == selectGwId) { bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbGateway); - this.gatewayViewRow.RefreshControl(); - //寮�鍚澶囧湪绾跨嚎绋� - this.StartDeviceListControlThread(online); + //鍒锋柊鎺т欢鍦ㄧ嚎鐘舵�� + this.gatewayViewRow?.RefreshOnlineStatu(); + //鏍规嵁缃戝叧鍦ㄧ嚎鐘舵�佸埛鏂拌澶囧湪绾跨姸鎬� + this.RefreshDeviceOnlineStatuByGatewayOnline(online); } }); }); @@ -689,7 +711,14 @@ { Application.RunOnMainThread(() => { - this.gatewayViewRow?.RefreshControl(); + //鐩稿悓鐨勭姸鎬�,涓嶉渶瑕佸啀娆″埛鏂� + if (this.gatewayViewRow.isOnline != online) + { + //鏍规嵁缃戝叧鍦ㄧ嚎鐘舵�佸埛鏂拌澶囧湪绾跨姸鎬� + this.RefreshDeviceOnlineStatuByGatewayOnline(online); + } + //鍒锋柊鎺т欢鍦ㄧ嚎鐘舵�� + this.gatewayViewRow?.RefreshOnlineStatu(); }); } } @@ -699,52 +728,43 @@ #region 鈻� 璁惧鍦ㄧ嚎妫�娴媉______________________ /// <summary> - /// 寮�鍚澶囧湪绾跨嚎绋� + /// 鏍规嵁缃戝叧鍦ㄧ嚎鐘舵�佸埛鏂拌澶囧湪绾跨姸鎬� /// </summary> /// <param name="gatewayOnline">缃戝叧鐨勫湪绾跨姸鎬�</param> - private void StartDeviceListControlThread(bool gatewayOnline) + private void RefreshDeviceOnlineStatuByGatewayOnline(bool gatewayOnline) { if (gatewayOnline == false) { //璁剧疆鍏ㄩ儴璁惧绂荤嚎 this.SetAllDeviceOffLine(); - return; } - //寮�鍚紶鎰熷櫒鎶ヨ鐩戣 - this.StartCheckDeviceAlarm(); - //寮�鍚澶囧湪绾跨洃娴� - this.StartCheckDeviceOnline(); + else + { + //鍒锋柊璁惧鍦ㄧ嚎鐘舵�� + this.RefreshDeviceOnlineStatu(); + } } /// <summary> - /// 寮�鍚澶囧湪绾跨洃娴� + /// 鍒锋柊璁惧鍦ㄧ嚎鐘舵�� /// </summary> - private void StartCheckDeviceOnline() + private void RefreshDeviceOnlineStatu() { - //澶栭儴璋冪敤鐨勮瘽,涓嶅啀閲嶆柊鑾峰彇璁惧鐘舵�� - if (GatewayResourse.NowSelectGateway == null || this.reGetDeviceOnlineStatu == false) - { - return; - } - - //娣诲姞鎺ユ敹璁惧鍦ㄧ嚎涓婃姤鐨勭洃鍚� - HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormReceivePushOnline", ReceiveComandDiv.A璁惧鍦ㄧ嚎涓婃姤, this.ReceiveDeviceStatu); - - string gwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway); + string gwId = GatewayResourse.NowSelectGatewayId; HdlThreadLogic.Current.RunThread(() => { + System.Threading.Thread.Sleep(2000); //杩欓噷涓昏鍙槸鑾峰彇鍦ㄧ嚎鐘舵�� - var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId); - int statu = 0; - var list = LocalDevice.Current.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO); - if (statu != -1) + var list = LocalDevice.Current.GetDeviceOnlineList(gwId); + HdlThreadLogic.Current.RunMain(() => { for (int i = 0; i < list.Count; i++) { //璁剧疆璁惧鍦ㄧ嚎鐘舵�� this.ReceiveDeviceStatu(list[i]); } - } + + }, ShowErrorMode.NO); }); } @@ -778,20 +798,14 @@ localDevice.ReSave(); } - HdlThreadLogic.Current.RunMain(() => + rowInfo.MenuRow.IsOnline = Common.LocalDevice.Current.CheckDeviceIsOnline(device); + if (rowInfo.dicDetailRow != null) { - if (rowInfo != null) + foreach (var detailRow in rowInfo.dicDetailRow.Values) { - rowInfo.MenuRow.isOnline = device.IsOnline == 1; - if (rowInfo.dicDetailRow != null) - { - foreach (var detailRow in rowInfo.dicDetailRow.Values) - { - detailRow.isOnline = rowInfo.MenuRow.isOnline; - } - } + detailRow.IsOnline = rowInfo.MenuRow.IsOnline; } - }); + } } /// <summary> @@ -799,17 +813,20 @@ /// </summary> private void SetAllDeviceOffLine() { - lock (dicRowInfo) + foreach (var rowInfo in this.dicRowInfo.Values) { - foreach (var rowInfo in this.dicRowInfo.Values) + //鑿滃崟 + if (rowInfo.MenuRow != null) { - Application.RunOnMainThread(() => + rowInfo.MenuRow.IsOnline = false; + } + //鏄庣粏 + if (rowInfo.dicDetailRow != null) + { + foreach (var detailRow in rowInfo.dicDetailRow.Values) { - if (rowInfo.MenuRow != null) - { - rowInfo.MenuRow.isOnline = false; - } - }); + detailRow.IsOnline = false; + } } } } @@ -895,7 +912,7 @@ #region 鈻� 瀹炵幇澶栭儴璋冪敤_______________________ /// <summary> - /// 娣诲姞鏂扮殑璁惧鍒扮晫闈㈡甯冧腑 + /// 娣诲姞鏂扮殑璁惧鍒扮晫闈㈡甯冧腑(澶栭儴璋冪敤) /// </summary> /// <param name="deviceAddr">璁惧Mac鍦板潃</param> public void AddDeviceToFormTable(string deviceAddr) @@ -923,6 +940,30 @@ //鍒涘缓鏂扮殑琛� this.AddDeviceMenuRow(deviceAddr); + + //璁板綍褰撳墠鐨勬鍦ㄦ搷浣滅殑璁惧鐨凪ac鍦板潃 + this.nowActionDeviceMac = deviceAddr; + } + } + + /// <summary> + /// 鍒锋柊鎸囧畾璁惧琛岀殑淇℃伅(澶栭儴璋冪敤) + /// </summary> + /// <param name="deviceAddr">璁惧Mac鍦板潃</param> + public void RefreshDeviceRow(string deviceAddr) + { + if (this.dicRowInfo.ContainsKey(deviceAddr) == true) + { + var row = this.dicRowInfo[deviceAddr]; + row.MenuRow?.RefreshControlInfo(true); + //鏄庣粏 + if (row.dicDetailRow != null) + { + foreach (var detailRow in row.dicDetailRow.Values) + { + detailRow.RefreshControlInfo(); + } + } } } @@ -1017,8 +1058,6 @@ HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceListFormSensor"); HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline"); - GatewayResourse.NowSelectGateway = null; - base.CloseFormBefore(); } @@ -1074,6 +1113,10 @@ /// 缃戝叧鍚嶅瓧鎺т欢 /// </summary> private NormalViewControl btnName = null; + /// <summary> + /// 鍦ㄧ嚎鐘舵�� + /// </summary> + public bool isOnline = false; /// <summary> /// 鑷畾涔夌綉鍏虫帶浠� @@ -1082,7 +1125,10 @@ public MyGatewayControl(ZbGateway i_zbGateway) { this.UseClickStatu = false; - this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway); + if (i_zbGateway != null) + { + this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway); + } this.BackgroundColor = UserCenterColor.Current.White; this.Height = Application.GetRealHeight(173); } @@ -1096,16 +1142,34 @@ ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId); //鍥炬爣 var btnIcon = this.AddLeftIcon(81); - HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway); + if (zbway != null) + { + HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway); + } + else + { + btnIcon.UnSelectedImagePath = "Gateway/GatewayIcon1.png"; + } //鏄剧ず鏂囨湰 - btnName = this.AddLeftCaption(HdlGatewayLogic.Current.GetGatewayName(zbway), 700); + btnName = this.AddLeftCaption(string.Empty, 700); btnName.Height = Application.GetRealHeight(60); btnName.TextSize = 15; btnName.Y = Application.GetRealHeight(35); - if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false) + if (zbway != null) { - btnName.TextColor = UserCenterColor.Current.TextGrayColor1; + btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway); + //鍦ㄧ嚎鐘舵�� + this.isOnline = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway); + if (this.isOnline == false) + { + btnName.TextColor = UserCenterColor.Current.TextGrayColor1; + } + } + else + { + //铏氭嫙缃戝叧 + btnName.Text = Language.StringByID(R.MyInternationalizationString.uVirtualGateway); } //褰撳墠缃戝叧 @@ -1122,15 +1186,19 @@ var btnMament = this.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGatewayManagement), 300); btnMament.Name = "btnMament"; - this.ButtonClickEvent += (sernder, e) => + //褰撳墠涓嶆槸铏氭嫙浣忓畢鐨勮瘽 + if (Common.Config.Instance.Home.IsVirtually == false) { - if (string.IsNullOrEmpty(((View)sernder).Name) == false) + this.ButtonClickEvent += (sernder, e) => { - //鎵撳紑缃戝叧鍒楄〃鐣岄潰 - var form = new GatewayManage.GatewayListForm(); - form.AddForm(); - } - }; + if (string.IsNullOrEmpty(((View)sernder).Name) == false) + { + //鎵撳紑缃戝叧鍒楄〃鐣岄潰 + var form = new GatewayManage.GatewayListForm(); + form.AddForm(); + } + }; + } } /// <summary> @@ -1145,13 +1213,34 @@ return; } btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway); - if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false) + //鍒锋柊鎺т欢鍦ㄧ嚎鐘舵�� + this.RefreshOnlineStatu(); + } + + /// <summary> + /// 鍒锋柊鎺т欢鍦ㄧ嚎鐘舵�� + /// </summary> + public void RefreshOnlineStatu() + { + //鑾峰彇鏈湴缃戝叧瀵硅薄 + ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId); + if (zbway == null) { - btnName.TextColor = UserCenterColor.Current.TextGrayColor1; + return; } - else + //鍦ㄧ嚎鐘舵�� + bool statu = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway); + if (this.isOnline != statu) { - btnName.TextColor = UserCenterColor.Current.TextColor1; + this.isOnline = statu; + if (this.isOnline == false) + { + btnName.TextColor = UserCenterColor.Current.TextGrayColor1; + } + else + { + btnName.TextColor = UserCenterColor.Current.TextColor1; + } } } } -- Gitblit v1.8.0