using System;
using ZigBee.Device;
using System.Collections.Generic;
namespace Shared.Phone.UserCenter.GatewayManage
{
///
/// 编辑网关信息的画面UI★
///
public class GatewayInfoEditorForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 网关名称控件
///
private FrameCaptionInputControl rowGateway = null;
///
/// 设备明细列表控件的桌布
///
private DeviceInformationListControl listDeviceControl = null;
///
/// 当前选择的网关
///
private ZbGateway zbGateway = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 当前选择的网关
public void ShowForm(ZbGateway i_zbGateway)
{
this.zbGateway = i_zbGateway;
//设置标题信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorGatewayInformation));
//网关定位
var btnIcon = new MostRightIconControl(69, 69);
btnIcon.UnSelectedImagePath = "Item/Test.png";
topFrameLayout.AddChidren(btnIcon);
btnIcon.InitControl();
btnIcon.ButtonClickEvent += (sender, e) =>
{
//测试
HdlGatewayLogic.Current.SetTestCommand(i_zbGateway);
};
//初始化中部控件
this.InitMiddleFrame();
}
///
/// 初始化中部控件
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
//图片上下的间距(上下间距一致)
int picSpcae = Application.GetRealHeight(100);
//图片
var btnImage = new PicViewControl(838, 530, true);
btnImage.Y = picSpcae;
btnImage.Gravity = Gravity.CenterHorizontal;
HdlGatewayLogic.Current.SetRealGatewayPictrue(btnImage, zbGateway);
bodyFrameLayout.AddChidren(btnImage);
//完成按钮
var btnFinish = new BottomClickButton();
btnFinish.TextID = R.MyInternationalizationString.uFinish;
bodyFrameLayout.AddChidren(btnFinish);
btnFinish.MouseUpEventHandler += (sender, e) =>
{
//完成按钮按下
this.FinishButtonClick();
};
//白色底部背景
var frameBottomWhite = new FrameLayout();
frameBottomWhite.Y = btnFinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace;
frameBottomWhite.Height = bodyFrameLayout.Height - btnFinish.Y + ControlCommonResourse.BottomButtonAndListViewSpace;
frameBottomWhite.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBottomWhite);
//将完成按钮置顶
btnFinish.BringToFront();
//自定义的设备列表容器
this.listDeviceControl = new DeviceInformationListControl();
//列表控件最大的高度(完成按钮的Y轴 - 设置的间隔 - 图片Y轴 - 图片的三分之一)
int listViewMaxHeight = btnFinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace - btnImage.Y - btnImage.Height / 3;
//明细Frame的最小高度(底部frame的Y轴 - 图片底部 - 图片与弧度圆的间距 - 弧度圆高度)
int minDetailHeight = frameBottomWhite.Y - btnImage.Bottom - picSpcae - listDeviceControl.halfRoundHeigth;
//初始化控件
listDeviceControl.InitControl(bodyFrameLayout, frameBottomWhite.Height, listViewMaxHeight, minDetailHeight, 4);
//设备编辑
var btnTitle = new DetailTitleControl(Application.GetRealWidth(800), listDeviceControl.titleHeight, false);
btnTitle.TextID = R.MyInternationalizationString.uDeviceEditor;
listDeviceControl.AddChidren(btnTitle);
//添加全部菜单行
this.AddAllMenuRow();
}
#endregion
#region ■ 添加全部菜单行_____________________
///
/// 添加全部菜单行
///
private void AddAllMenuRow()
{
//网关名称
string caption = Language.StringByID(R.MyInternationalizationString.uGatewayName);
string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
this.rowGateway = new FrameCaptionInputControl(caption, nameValue);
listDeviceControl.AddChidren(rowGateway);
rowGateway.InitControl();
rowGateway.AddBottomLine();
//网关IP
caption = Language.StringByID(R.MyInternationalizationString.uGatewayIP);
nameValue = HdlGatewayLogic.Current.GetGatewayBaseInfoAttribute(zbGateway, "IpAddress").ToString();
var btnIp = new FrameCaptionViewControl(caption, nameValue);
listDeviceControl.AddChidren(btnIp);
btnIp.InitControl();
btnIp.txtView.TextColor = UserCenterColor.Current.TextGrayColor;
btnIp.AddBottomLine();
//主网关或者子网关标识
var btnFlage = new RowMostRightTextView();
btnFlage.TextColor = UserCenterColor.Current.TextGrayColor;
btnIp.AddChidren(btnFlage, ChidrenBindMode.NotBind);
int result = HdlGatewayLogic.Current.IsMainGateway(this.zbGateway);
//主网关
if (result == 1) { btnFlage.TextID = R.MyInternationalizationString.uMainGateway; }
//子网关
else if (result == 0) { btnFlage.TextID = R.MyInternationalizationString.uChidrenGateway; }
//网关类型
caption = Language.StringByID(R.MyInternationalizationString.uGatewayType);
nameValue = HdlGatewayLogic.Current.GetGatewayImageText(this.zbGateway);
var btnObject = new FrameCaptionViewControl(caption, nameValue);
listDeviceControl.AddChidren(btnObject);
btnObject.InitControl();
btnObject.txtView.TextColor = UserCenterColor.Current.TextGrayColor;
btnObject.AddBottomLine();
//固件信息
this.AddHardWareInfoRow();
}
#endregion
#region ■ 添加固件信息行_____________________
///
/// 添加固件信息行
///
private void AddHardWareInfoRow()
{
var rowInfo = new RowLayoutControl();
listDeviceControl.AddChidren(rowInfo);
//固件信息
//var btnInfo = new RowCenterViewControl(false, 14);
//btnInfo.TextID = R.MyInternationalizationString.uFirmwareInformation;
//rowInfo.AddChidren(btnInfo);
//向右图标
//rowInfo.AddRightArrow();
//新版本提示控件
var btnNewVersion = new RowNewVersionTipView();
btnNewVersion.Visible = false;
rowInfo.AddChidren(btnNewVersion);
//rowInfo.MouseUpEvent += (sender, e) =>
//{
// btnNewVersion.Visible = false;
// var form = new GatewayFirmwareInfoForm();
// form.AddForm(zbGateway);
//};
//检测新版本
this.CheckNewVersion(btnNewVersion);
}
///
/// 检测新版本
///
/// 提示有新版本的控件
private async void CheckNewVersion(RowNewVersionTipView btnNewVersion)
{
//打开进度条
this.ShowProgressBar();
//获取网关版本信息
var result = await HdlGatewayLogic.Current.GetGatewayAllNewVersion(this.zbGateway);
if (result == null)
{
//关闭进度条
this.CloseProgressBar(ShowReLoadMode.YES);
return;
}
//关闭进度条
this.CloseProgressBar();
Application.RunOnMainThread(() =>
{
if (this.rowGateway != null)
{
//设置网关名称
this.rowGateway.Text = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
if (result[0] != null || result[1] != null || result[2] != null)
{
//提示有新版本
btnNewVersion.Visible = true;
}
}
});
}
#endregion
#region ■ 完成按钮按下_______________________
///
/// 完成按钮按下
///
private void FinishButtonClick()
{
if (string.IsNullOrEmpty(this.rowGateway.Text) == true)
{
//请输入网关名称
this.rowGateway.Text = string.Empty;
string msg = Language.StringByID(R.MyInternationalizationString.uGatewayNameMastInput);
this.ShowMassage(ShowMsgType.Error, msg);
return;
}
string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
if (nameValue == this.rowGateway.Text)
{
//同名不需要处理
this.CloseForm();
return;
}
//修改名字
this.SetGatewayName(this.rowGateway.Text);
}
#endregion
#region ■ 修改名字___________________________
///
/// 设置网关名字
///
/// 网关名称
private async void SetGatewayName(string gatewayName)
{
//打开进度条
this.ShowProgressBar();
//修改网关名
var result = await HdlGatewayLogic.Current.ReName(zbGateway, gatewayName);
//关闭进度条
this.CloseProgressBar();
//网关修改失败
if (result == false)
{
return;
}
Application.RunOnMainThread(() =>
{
//关闭界面
this.CloseForm();
});
}
#endregion
}
}