using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Gateway
{
///
/// 编辑新添加的网关信息的画面UI
///
public class GatewayInfoAddForm : UserCenterCommonForm
{
#region ■ 变量声明___________________________
///
/// 网关名字修改后的回调函数
///
public Action ActionGatewayReName = null;
///
/// 列表控件
///
private VerticalScrolViewLayout listView = 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 TopLayoutMostRightView();
btnIcon.UnSelectedImagePath = "Item/Test.png";
btnIcon.SelectedImagePath = "Item/TestSelected.png";
topFrameLayout.AddChidren(btnIcon);
btnIcon.MouseUpEventHandler += (sender, e) =>
{
//测试
Common.LocalGateway.Current.SetTestCommand(i_zbGateway);
};
//初始化中部控件
this.InitMiddleFrame();
}
///
/// 初始化中部控件
///
private void InitMiddleFrame()
{
bodyFrameLayout.RemoveAll();
//进度条一样的东西,没什么逻辑
var btnLine = new ProgressLine();
bodyFrameLayout.AddChidren(btnLine);
btnLine.SetValue(80);
//图片
var btnImage = new PicViewControl(915, 492, true);
btnImage.Y = btnLine.Bottom + Application.GetRealHeight(10);
btnImage.Gravity = Gravity.CenterHorizontal;
Common.LocalGateway.Current.SetRealGatewayPictrue(btnImage, zbGateway);
bodyFrameLayout.AddChidren(btnImage);
listView = new VerticalScrolViewLayout();
listView.Y = btnImage.Bottom + Application.GetRealHeight(20);
listView.Height = bodyFrameLayout.Height - btnImage.Bottom - Application.GetRealHeight(20);
bodyFrameLayout.AddChidren(listView);
//网关名称
string caption = Language.StringByID(R.MyInternationalizationString.uGatewayName);
string nameValue = Common.LocalGateway.Current.GetGatewayName(zbGateway);
var btnGateway = new EditorNameValueRow(caption, nameValue);
listView.AddChidren(btnGateway);
btnGateway.InitControl();
//请输入网关名称
btnGateway.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uGatewayNameMastInput));
//编辑网关名称
btnGateway.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorGatewayName));
btnGateway.ActionNameChangedEvent += (gatewayName) =>
{
//设置网关名称
this.SetGatewayName(gatewayName);
};
//添加网关IP行
this.AddGatewayIpRow();
//添加网关类型行
this.AddGatewayObjectRow();
}
#endregion
#region ■ 添加网关IP行_______________________
///
/// 添加网关IP行
///
private void AddGatewayIpRow()
{
//网关ip行
var rowIp = new RowLayout();
rowIp.Height = ControlCommonResourse.ListViewRowHeight;
listView.AddChidren(rowIp);
//网关ip
var btnIpView = new RowTopGrayView(false);
btnIpView.TextID = R.MyInternationalizationString.uGatewayIP;
rowIp.AddChidren(btnIpView);
var btnIp = new RowBottomBlackView(false);
var ipValue = Common.LocalGateway.Current.GetGatewayBaseInfoAttribute(zbGateway, "IpAddress");
btnIp.Text = ipValue.ToString();
rowIp.AddChidren(btnIp);
}
#endregion
#region ■ 添加网关类型行_____________________
///
/// 添加网关类型行
///
private void AddGatewayObjectRow()
{
//网关类型行
var rowIp = new RowLayout();
rowIp.Height = ControlCommonResourse.ListViewRowHeight;
listView.AddChidren(rowIp);
//网关类型
var btnView = new RowTopGrayView(false);
btnView.TextID = R.MyInternationalizationString.uGatewayType;
rowIp.AddChidren(btnView);
var btnObj = new RowBottomBlackView(false);
btnObj.Text = Common.LocalGateway.Current.GetGatewayImageText(this.zbGateway);
rowIp.AddChidren(btnObj);
}
#endregion
#region ■ 修改名字___________________________
///
/// 设置网关名字
///
/// 网关名称
private async void SetGatewayName(string gatewayName)
{
//打开进度条
this.ShowProgressBar();
//修改本地网关名
var result = await Common.LocalGateway.Current.ReName(zbGateway, gatewayName);
//关闭进度条
this.CloseProgressBar();
//网关修改失败
if (result == false)
{
return;
}
Application.RunOnMainThread(() =>
{
//网关列表刷新
this.LoadFormMethodByName("GatewayManagementForm", "AddRowLayout", Common.LocalGateway.Current.GetGatewayId(zbGateway));
//变更设备管理界面的网关名字
this.LoadFormMethodByName("DeviceManagementMainForm", "ChangedGatewayName", zbGateway);
if (this.ActionGatewayReName != null)
{
this.ActionGatewayReName(zbGateway);
}
});
}
#endregion
}
}