using Shared.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
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>
|
/// 关闭设备管理界面(如果解除绑定的网关是当前所选择的网关的话,则关闭设备管理界面)
|
/// </summary>
|
private bool closeDeviceManagForm = false;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
public void ShowForm()
|
{
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uGatewayManagement));
|
|
//展示模板不允许编辑
|
if (Config.Instance.Home.IsShowTemplate == false)
|
{
|
//添加图标
|
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++)
|
{
|
//添加行
|
this.AddRowLayout(listway[i].GwId, i != listway.Count - 1);
|
}
|
|
//调整列表控件的高度
|
this.listview.AdjustRealHeight(Application.GetRealHeight(23));
|
|
//如果是展示模板的话,不需要检测
|
if (Common.Config.Instance.Home.IsShowTemplate == false)
|
{
|
//开启网关在线监测的线程
|
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.BindEvent);
|
gatewayRow.AddTag("btnNew", btnNew);
|
//单击事件
|
gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
|
{
|
if (HdlUserCenterResourse.HideOption.GotoGatewayProductInfoForm == 1)
|
{
|
//强制跳转
|
var form2 = new GatewayProductInfoForm();
|
form2.AddForm(gateway);
|
return;
|
}
|
var form = new GatewayInfoEditorForm();
|
form.AddForm(gateway);
|
};
|
|
//如果是展示模板的话,不能编辑
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
return;
|
}
|
|
//非虚拟住宅,才有这个功能
|
if (Common.Config.Instance.Home.IsVirtually == false)
|
{
|
//切换
|
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 == HdlGatewayResourse.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 == HdlGatewayResourse.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);
|
});
|
});
|
};
|
|
this.dicRowContr[strWayId] = gatewayRow;
|
//设置一个选择网关的默认值
|
if (string.IsNullOrEmpty(HdlGatewayResourse.AppOldSelectGatewayId) == true)
|
{
|
HdlGatewayLogic.Current.SaveGatewayIdToLocation(strWayId);
|
}
|
|
//当前网关的角标
|
if (strWayId == HdlGatewayResourse.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);
|
}
|
}
|
|
#endregion
|
|
#region ■ 解绑网关___________________________
|
|
/// <summary>
|
/// 解绑网关
|
/// </summary>
|
/// <param name="strWayId"></param>
|
/// <param name="row"></param>
|
private void DeleteGateway(string strWayId)
|
{
|
//打开进度条
|
this.ShowProgressBar();
|
//删除云端网关
|
bool result = HdlGatewayLogic.Current.DeleteGateway(strWayId);
|
//关闭进度条
|
this.CloseProgressBar();
|
if (result == false)
|
{
|
return;
|
}
|
|
if (strWayId == HdlGatewayResourse.AppOldSelectGatewayId)
|
{
|
//如果解除绑定的网关是当前所选择的网关的话,则关闭设备管理界面
|
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 void DoSwitchGateway(string gatewayId)
|
{
|
var result = HdlGatewayLogic.Current.DoSwitchGateway(gatewayId);
|
if (result == false)
|
{
|
return;
|
}
|
//如果选择了刷新的网关,则不关闭管理界面
|
this.closeDeviceManagForm = false;
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
if (HdlFormLogic.Current.IsFormOpen("DeviceListMainForm") == false)
|
{
|
//刷新主画面
|
var form = new Device.DeviceListMainForm();
|
this.AddFormAndCloseNowForm(form);
|
}
|
else
|
{
|
//关闭界面
|
this.CloseForm();
|
//刷新主画面(不重新获取设备状态)
|
this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame");
|
}
|
});
|
}
|
|
#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.CheckGatewayOnlineByMemory(way);
|
this.GatewayOnlinePush(way, online, true);
|
}
|
//网关新版本检测
|
this.CheckGatewayNewVersion(listway);
|
});
|
}
|
|
/// <summary>
|
/// 网关在线状态变更
|
/// </summary>
|
/// <param name="gateWay">网关对象</param>
|
/// <param name="online">在线状态变更后的状态</param>
|
/// <param name="hadGwOnline">2020.05.25追加:此住宅是否拥有网关在线</param>
|
public override void GatewayOnlinePush(ZbGateway gateWay, bool online, bool hadGwOnline)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
if (this.Parent == null)
|
{
|
return;
|
}
|
string gwid = gateWay.GwId;
|
if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null)
|
{
|
this.dicRowContr[gwid].IsOnline = online;
|
}
|
}, ShowErrorMode.NO);
|
}
|
|
#endregion
|
|
#region ■ 网关新版本检测_____________________
|
|
/// <summary>
|
/// 网关新版本检测
|
/// </summary>
|
/// <param name="listWays"></param>
|
private void CheckGatewayNewVersion(List<ZbGateway> listWays)
|
{
|
foreach (var way in listWays)
|
{
|
if (this.Parent == null)
|
{
|
return;
|
}
|
if (HdlGatewayLogic.Current.CheckGatewayOnlineByMemory(way) == false)
|
{
|
//不在线的不用理它
|
continue;
|
}
|
//获取最新版本
|
var result = HdlGatewayLogic.Current.GetGatewayAllNewVersion(way, ShowErrorMode.NO);
|
if (result == null)
|
{
|
continue;
|
}
|
if (result[0] != null || result[1] != null || result[2] != null)
|
{
|
//有新版本
|
string gwid = way.GwId;
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
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 (HdlGatewayResourse.AppOldSelectGatewayId == string.Empty)
|
{
|
//关闭设备列表
|
this.closeDeviceManagForm = true;
|
}
|
//初始化中部控件
|
this.InitMiddleFrame();
|
return 1;
|
}
|
|
#endregion
|
}
|
}
|