| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.GatewayManage
|
| | |
| | | //设置标题信息
|
| | | 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();
|
| | |
| | | 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
|
| | |
| | | {
|
| | | 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) =>
|
| | | {
|
| | |
|
| | | 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)
|
| | | //如果是展示模板的话,不能编辑
|
| | | if (Common.Config.Instance.Home.IsShowTemplate == true)
|
| | | {
|
| | | btnSwitch.TextID = R.MyInternationalizationString.uRefresh;
|
| | | return;
|
| | | }
|
| | | gatewayRow.AddRightView(btnSwitch);
|
| | | btnSwitch.ButtonClickEvent += (sender, e) =>
|
| | |
|
| | | //非虚拟住宅,才有这个功能
|
| | | if (Common.Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | //是否切换到{0}网关?
|
| | | string msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToSwitchTheGateway), "[" + gatewayRow.btnName.Text + "]");
|
| | | //切换
|
| | | 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)
|
| | | {
|
| | | //是否重新刷新{0}网关?
|
| | | msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + gatewayRow.btnName.Text + "]");
|
| | | btnSwitch.TextID = R.MyInternationalizationString.uRefresh;
|
| | | }
|
| | | this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
| | | gatewayRow.AddRightView(btnSwitch);
|
| | | btnSwitch.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //执行切换网关操作
|
| | | this.DoSwitchGateway(strWayId, gatewayRow.IsOnline);
|
| | | });
|
| | | };
|
| | | //是否切换到{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 = 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) =>
|
| | | {
|
| | | //发送定位命令
|
| | |
| | | }
|
| | | 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(GatewayResourse.AppOldSelectGatewayId) == true)
|
| | | {
|
| | | this.SaveGatewayIdToLocation(strWayId);
|
| | | 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.BindEvent);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// </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;
|
| | |
| | | {
|
| | | //如果解除绑定的网关是当前所选择的网关的话,则关闭设备管理界面
|
| | | 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
|
| | |
| | | /// </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);
|
| | |
|
| | | //检测广播到的这个网关是否拥有住宅ID
|
| | | 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 (UserCenterResourse.DicActionForm.ContainsKey("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.AddFromAndRemoveNowForm(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>
|
| | | /// 保存选择的网关ID到本地
|
| | | /// </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
|
| | |
| | | {
|
| | | 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);
|
| | |
| | | /// </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
|
| | |
| | | /// 网关新版本检测
|
| | | /// </summary>
|
| | | /// <param name="listWays"></param>
|
| | | private async void CheckGatewayNewVersion(List<ZbGateway> listWays)
|
| | | private void CheckGatewayNewVersion(List<ZbGateway> listWays)
|
| | | {
|
| | | foreach (var way in listWays)
|
| | | {
|
| | |
| | | {
|
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | /// <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();
|
| | |
| | | /// </summary>
|
| | | public override int FormActionAgainEvent()
|
| | | {
|
| | | //进到这个界面,理论上前回的网关id是有的,如果为空了,应该是当前的网关被解绑了
|
| | | if (GatewayResourse.AppOldSelectGatewayId == string.Empty)
|
| | | {
|
| | | //关闭设备列表
|
| | | this.closeDeviceManagForm = true;
|
| | | }
|
| | | //初始化中部控件
|
| | | this.InitMiddleFrame();
|
| | | return 1;
|