| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.GatewayManage
|
| | |
| | | btnAdd.InitControl();
|
| | | btnAdd.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | var form = new GatewayAdd.NewGateWaySelectForm();
|
| | | var form = new GatewayAdd.NewGateWayMenuSelectForm();
|
| | | form.AddForm();
|
| | | };
|
| | |
|
| | |
| | | listview.BackgroundColor = UserCenterColor.Current.White;
|
| | | bodyFrameLayout.AddChidren(listview);
|
| | |
|
| | | //设定中部信息
|
| | | this.SetMiddleFrameInfo();
|
| | | HdlThreadLogic.Current.RunMainInThread(() =>
|
| | | {
|
| | | //设定中部信息
|
| | | this.SetMiddleFrameInfo();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | List<ZbGateway> listway = HdlGatewayLogic.Current.GetAllLocalGateway();
|
| | | if (listway.Count == 0)
|
| | | {
|
| | | //还没有绑定网关哦
|
| | | this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uHadNotBindGatewayMsg));
|
| | | 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();
|
| | |
| | | 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);
|
| | | 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);
|
| | | form.AddForm(gateway);
|
| | | };
|
| | |
|
| | | //解除绑定
|
| | | 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, () =>
|
| | | {
|
| | | 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;
|
| | | 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);
|
| | |
| | | });
|
| | | };
|
| | |
|
| | | //单击事件
|
| | | gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
|
| | | this.dicRowContr[strWayId] = gatewayRow;
|
| | | //设置一个选择网关的默认值
|
| | | if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == 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);
|
| | | });
|
| | | };
|
| | | HdlGatewayLogic.Current.SaveGatewayIdToLocation(strWayId);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | {
|
| | | //如果解除绑定的网关是当前所选择的网关的话,则关闭设备管理界面
|
| | | this.closeDeviceManagForm = true;
|
| | | this.SaveGatewayIdToLocation(string.Empty);
|
| | | HdlGatewayLogic.Current.SaveGatewayIdToLocation(string.Empty);
|
| | | }
|
| | |
|
| | | //移除
|
| | |
| | | /// 执行切换网关操作
|
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | /// <param name="online"></param>
|
| | | private async void DoSwitchGateway(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)
|
| | | {
|
| | | 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;
|
| | | }
|
| | | //重新绑定网关里面已经重新获取了网关信息
|
| | | getGatewayInfo = false;
|
| | | }
|
| | | }
|
| | |
|
| | | if (getGatewayInfo == true)
|
| | | {
|
| | | //获取网关信息
|
| | | var info = await HdlGatewayLogic.Current.GetGatewayNewInfoAsync(gateway);
|
| | | if (info == null)
|
| | | {
|
| | | //关闭进度条
|
| | | this.CloseProgressBar();
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | //获取全部设备
|
| | | bool result = await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(gateway);
|
| | | //关闭进度条
|
| | | this.CloseProgressBar();
|
| | | var result = await HdlGatewayLogic.Current.DoSwitchGateway(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | 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>
|
| | | /// 保存选择的网关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);
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false)
|
| | | {
|
| | | //刷新主画面
|
| | | var form = new Device.DeviceListMainForm();
|
| | | this.AddFromAndRemoveNowForm(form);
|
| | | }
|
| | | else
|
| | | {
|
| | | //关闭界面
|
| | | this.CloseForm();
|
| | | //刷新主画面(不重新获取设备状态)
|
| | | this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame", false);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <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;
|
| | |
|
| | |
| | | {
|
| | | base.CloseForm();
|
| | |
|
| | | 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;
|