using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared.Common;
|
using Shared.Phone.UserCenter;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.MainPage
|
{
|
/// <summary>
|
/// 主页的设备信息界面
|
/// </summary>
|
public class DeviceDetailInfoForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 界面关闭事件(该事件目前给分类界面的自定义行控件使用)
|
/// </summary>
|
public Action<CommonDevice, Room> FormCloseEvent = null;
|
/// <summary>
|
/// 设备对象
|
/// </summary>
|
private CommonDevice device;
|
/// <summary>
|
/// 房间对象(这个房间有可能是喜爱)
|
/// </summary>
|
private Room room = null;
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private FrameListControl listview = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_device">设备对象</param>
|
/// <param name="i_room">房间对象(这个房间有可能是喜爱)</param>
|
public void ShowForm(CommonDevice i_device, Room i_room)
|
{
|
this.device = i_device;
|
this.room = i_room;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.FunctionSetting));
|
|
//主人和管理员才能更改
|
if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
|
{
|
//初始化中部控件(主人,管理员)
|
this.InitMiddleFrameByAdmin();
|
}
|
//成员不允许变更
|
else
|
{
|
//初始化中部控件(成员)
|
this.InitMiddleFrameByMember();
|
}
|
}
|
|
/// <summary>
|
/// 初始化中部控件(主人,管理员)
|
/// </summary>
|
private void InitMiddleFrameByAdmin()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
var listBackControl = new VerticalFrameControl();
|
listBackControl.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listBackControl);
|
|
//初始化桌布
|
var tableContr = new InformationEditorControl();
|
this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1319);
|
|
//图片
|
var btnPic = new DeviceInfoIconControl();
|
btnPic.Y = Application.GetRealHeight(46);
|
btnPic.Gravity = Gravity.CenterHorizontal;
|
listBackControl.frameTable.AddChidren(btnPic);
|
btnPic.InitControl(device.DeviceAddr, device.DeviceEpoint);
|
btnPic.ButtonClickEvent += (sender, e) =>
|
{
|
var localPic = new Device.CommonForm.DeviceIconSelectedIMGByLocal();
|
UserView.HomePage.Instance.AddChidren(localPic);
|
UserView.HomePage.Instance.PageIndex += 1;
|
localPic.Show();
|
localPic.action = (unSelectedImagePath, selectedImagePath) =>
|
{
|
//变更图片
|
device.IconPath = unSelectedImagePath;
|
device.IsCustomizeImage = true;
|
device.ReSave();
|
//刷新控件
|
btnPic.RefreshControl();
|
};
|
};
|
|
//设备所属类型
|
var infoType = LocalDevice.Current.GetDeviceBelongEnumInfo(device);
|
var btnBelongType = new NormalViewControl(700, 62, true);
|
btnBelongType.Y = btnPic.Bottom + Application.GetRealHeight(35);
|
btnBelongType.Gravity = Gravity.CenterHorizontal;
|
btnBelongType.TextID = infoType.BeloneTextId;
|
btnBelongType.TextSize = 15;
|
btnBelongType.TextAlignment = TextAlignment.Center;
|
listBackControl.frameTable.AddChidren(btnBelongType);
|
|
//功能名称
|
string caption = Language.StringByID(R.MyInternationalizationString.FunctionName);
|
string deviceName = LocalDevice.Current.GetDeviceEpointName(device);
|
var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
|
listview.AddChidren(btnNote);
|
btnNote.InitControl();
|
//划线
|
btnNote.AddBottomLine();
|
btnNote.txtInput.FinishInputEvent += () =>
|
{
|
string oldName = LocalDevice.Current.GetDeviceEpointName(device);
|
if (btnNote.Text == string.Empty)
|
{
|
btnNote.Text = oldName;
|
}
|
if (oldName != btnNote.Text)
|
{
|
//修改名字
|
this.DeviceReName(btnNote.Text, false);
|
}
|
};
|
|
//喜爱房间不允许变更区域
|
if (this.room.IsLove == false)
|
{
|
//所属区域
|
var rowBeloneArea = new BelongAreaControl(listview.rowSpace / 2);
|
listview.AddChidren(rowBeloneArea);
|
rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), this.device);
|
//底线
|
rowBeloneArea.AddBottomLine();
|
rowBeloneArea.SelectRoomEvent += (roomKeys) =>
|
{
|
//房间重新获取
|
this.room = HdlRoomLogic.Current.GetRoomById(roomKeys);
|
HdlRoomLogic.Current.ChangedRoom(device, roomKeys);
|
};
|
}
|
|
//所属模块
|
caption = Language.StringByID(R.MyInternationalizationString.BelongModel);
|
deviceName = Common.LocalDevice.Current.GetDeviceMacName(device);
|
var rowBelongModul = new FrameCaptionViewControl(caption, deviceName, listview.rowSpace / 2);
|
listview.AddChidren(rowBelongModul);
|
rowBelongModul.InitControl();
|
//划线
|
rowBelongModul.AddBottomLine();
|
|
//添加【功能类型】行(主人,管理员)
|
this.AddFunctionTypeRowByAdmin(btnBelongType);
|
|
//初始化桌布完成
|
tableContr.FinishInitControl();
|
tableContr = null;
|
|
//保存
|
var btnFinish = new BottomClickButton();
|
btnFinish.TextID = R.MyInternationalizationString.uSave;
|
bodyFrameLayout.AddChidren(btnFinish);
|
btnFinish.ButtonClickEvent += (sender, e) =>
|
{
|
string oldName = LocalDevice.Current.GetDeviceEpointName(device);
|
if (btnNote.Text.Trim() == string.Empty)
|
{
|
btnNote.Text = oldName;
|
}
|
if (oldName != btnNote.Text.Trim())
|
{
|
//修改名字
|
this.DeviceReName(btnNote.Text.Trim(), true);
|
}
|
else
|
{
|
//关闭自身
|
this.CloseForm();
|
}
|
};
|
}
|
|
/// <summary>
|
/// 初始化中部控件(成员)
|
/// </summary>
|
private void InitMiddleFrameByMember()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
var listBackControl = new VerticalFrameControl();
|
listBackControl.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listBackControl);
|
|
//初始化桌布
|
var tableContr = new InformationEditorControl();
|
this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1319);
|
|
//图片
|
var btnPic = new DeviceInfoIconControl();
|
btnPic.Y = Application.GetRealHeight(92);
|
btnPic.Gravity = Gravity.CenterHorizontal;
|
listBackControl.frameTable.AddChidren(btnPic);
|
btnPic.InitControl(device.DeviceAddr, device.DeviceEpoint);
|
|
//设备所属类型
|
var infoType = LocalDevice.Current.GetDeviceBelongEnumInfo(device);
|
var btnBelongType = new NormalViewControl(700, 62, true);
|
btnBelongType.Y = btnPic.Bottom + Application.GetRealHeight(35);
|
btnBelongType.Gravity = Gravity.CenterHorizontal;
|
btnBelongType.TextID = infoType.BeloneTextId;
|
btnBelongType.TextSize = 15;
|
btnBelongType.TextAlignment = TextAlignment.Center;
|
listBackControl.frameTable.AddChidren(btnBelongType);
|
|
//功能名称
|
string caption = Language.StringByID(R.MyInternationalizationString.FunctionName);
|
string nameValue = LocalDevice.Current.GetDeviceEpointName(device);
|
var btnNote = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
|
btnNote.UseClickStatu = false;
|
listview.AddChidren(btnNote);
|
btnNote.InitControl();
|
//划线
|
btnNote.AddBottomLine();
|
|
//喜爱房间不允许出现区域
|
if (this.room.IsLove == false)
|
{
|
//所属区域
|
caption = Language.StringByID(R.MyInternationalizationString.uBelongArea);
|
nameValue = HdlRoomLogic.Current.GetRoomNameByDevice(device);
|
var rowBeloneArea = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
|
rowBeloneArea.UseClickStatu = false;
|
listview.AddChidren(rowBeloneArea);
|
rowBeloneArea.InitControl();
|
//划线
|
rowBeloneArea.AddBottomLine();
|
}
|
|
//所属模块
|
caption = Language.StringByID(R.MyInternationalizationString.BelongModel);
|
nameValue = Common.LocalDevice.Current.GetDeviceMacName(device);
|
var rowBelongModul = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
|
rowBelongModul.UseClickStatu = false;
|
listview.AddChidren(rowBelongModul);
|
rowBelongModul.InitControl();
|
//划线
|
rowBelongModul.AddBottomLine();
|
|
//添加【功能类型】行(成员)
|
this.AddFunctionTypeRowByMember();
|
|
//初始化桌布完成
|
tableContr.FinishInitControl();
|
tableContr = null;
|
}
|
|
#endregion
|
|
#region ■ 功能类型___________________________
|
|
/// <summary>
|
/// 添加【功能类型】行(主人,管理员)
|
/// </summary>
|
private void AddFunctionTypeRowByAdmin(NormalViewControl btnBelongType)
|
{
|
//如果是继电器,空气开关,调光器的话
|
if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.DimmableLight
|
|| device.Type == DeviceType.ColorDimmableLight || device.Type == DeviceType.AirSwitch)
|
{
|
//功能类型的翻译名字
|
int nowSelectNo = 1;
|
string strType = string.Empty;
|
if (this.device.DfunctionType == DeviceFunctionType.A灯光)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uLight);
|
nowSelectNo = 1;
|
}
|
else if (this.device.DfunctionType == DeviceFunctionType.A开关)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
|
nowSelectNo = 0;
|
}
|
else if (this.device.DfunctionType == DeviceFunctionType.A插座)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
|
nowSelectNo = 2;
|
}
|
//功能类型
|
var btnFunction = new FrameCaptionViewControl(Language.StringByID(R.MyInternationalizationString.uFunctionType), strType, listview.rowSpace / 2);
|
btnFunction.UseClickStatu = false;
|
listview.AddChidren(btnFunction);
|
btnFunction.InitControl();
|
//底线
|
btnFunction.AddBottomLine();
|
//如果是空气开关和继电器,才能修改
|
if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.AirSwitch)
|
{
|
//右箭头
|
btnFunction.AddRightArrow();
|
btnFunction.ButtonClickEvent += (sender, e) =>
|
{
|
//显示列表
|
var listText = new List<string>();
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uSwitch));//开关
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uLight));//灯光
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uSocket1));//插座
|
//标题:选择功能类型
|
var title = Language.StringByID(R.MyInternationalizationString.uSelectFunctionType);
|
|
var form = new BottomItemSelectForm();
|
form.AddForm(title, listText, nowSelectNo);
|
form.FinishSelectEvent += (selectNo) =>
|
{
|
btnFunction.Text = listText[selectNo];
|
//当类型变更时,头上的类型也一起变更
|
btnBelongType.Text = listText[selectNo];
|
nowSelectNo = selectNo;
|
//记录起当前选择的功能类型
|
if (selectNo == 0)
|
{
|
this.device.DfunctionType = DeviceFunctionType.A开关;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
this.device.IconPath = "Device/Switch.png";
|
}
|
}
|
else if (selectNo == 1)
|
{
|
this.device.DfunctionType = DeviceFunctionType.A灯光;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
this.device.IconPath = "Device/Light.png";
|
}
|
}
|
else
|
{
|
this.device.DfunctionType = DeviceFunctionType.A插座;
|
if (this.device.IsCustomizeImage == false)
|
{
|
//重新设置图片
|
this.device.IconPath = "Device/Socket1.png";
|
}
|
}
|
this.device.ReSave();
|
};
|
};
|
}
|
}
|
}
|
|
/// <summary>
|
/// 添加【功能类型】行(成员)
|
/// </summary>
|
private void AddFunctionTypeRowByMember()
|
{
|
//如果是继电器,空气开关,调光器的话
|
if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.DimmableLight
|
|| device.Type == DeviceType.ColorDimmableLight || device.Type == DeviceType.AirSwitch)
|
{
|
//功能类型的翻译名字
|
string strType = string.Empty;
|
if (this.device.DfunctionType == DeviceFunctionType.A灯光)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uLight);
|
}
|
else if (this.device.DfunctionType == DeviceFunctionType.A开关)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
|
}
|
else if (this.device.DfunctionType == DeviceFunctionType.A插座)
|
{
|
strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
|
}
|
|
//功能类型
|
var btnFunction = new FrameCaptionViewControl(Language.StringByID(R.MyInternationalizationString.uFunctionType), strType, listview.rowSpace / 2);
|
btnFunction.UseClickStatu = false;
|
listview.AddChidren(btnFunction);
|
btnFunction.InitControl();
|
//底线
|
btnFunction.AddBottomLine();
|
}
|
}
|
|
#endregion
|
|
#region ■ 修改名字___________________________
|
|
/// <summary>
|
/// 设备重命名
|
/// </summary>
|
/// <param name="i_deviceName">deviceName.</param>
|
private async void DeviceReName(string i_deviceName, bool closeForm)
|
{
|
//修改MAC名
|
string deviceName = i_deviceName.Trim();
|
var result = await LocalDevice.Current.ReName(this.device, deviceName);
|
if (result == false)
|
{
|
return;
|
}
|
if (closeForm == true)
|
{
|
//关闭界面
|
this.CloseForm();
|
}
|
else
|
{
|
//设备备注修改成功!
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNoteSuccess);
|
this.ShowMassage(ShowMsgType.Tip, msg);
|
}
|
}
|
|
#endregion
|
|
#region ■ 界面关闭___________________________
|
|
/// <summary>
|
/// 界面关闭
|
/// </summary>
|
public override void CloseFormBefore()
|
{
|
this.FormCloseEvent?.Invoke(this.device, this.room);
|
this.FormCloseEvent = null;
|
|
base.CloseFormBefore();
|
}
|
|
#endregion
|
}
|
}
|