using System;
using System.Collections.Generic;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Safety
{
///
/// 添加报警目标菜单列表的画面
///
public class AddAlarmTargetTypeListForm : UserCenterCommonForm
{
#region ■ 变量声明___________________________
///
/// 防区ID(这个东西似乎是唯一的)
///
private int zoonID = 0;
///
/// 列表控件
///
private VerticalScrolViewLayout listView = null;
///
/// 全部设备信息
///
private List listAllDeviceInfo = new List();
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 防区ID
public void ShowForm(int i_zoonID)
{
this.zoonID = i_zoonID;
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddAlarmTarget));
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
bodyFrameLayout.RemoveAll();
this.listView = new VerticalScrolViewLayout();
this.listView.Height = bodyFrameLayout.Height;
bodyFrameLayout.AddChidren(this.listView);
//设置中间部分信息
this.SetMiddleInfo();
}
///
/// 设置中间部分信息
///
private void SetMiddleInfo()
{
new System.Threading.Thread(() =>
{
System.Threading.Thread.Sleep(100);
//获取设备的所有类型,并整理成每一行的数据
this.GetAllListData();
//添加设备的行
foreach (uRowInformation info in listAllDeviceInfo)
{
Application.RunOnMainThread(() =>
{
this.AddRowLaout(info);
});
}
})
{ IsBackground = true }.Start();
}
#endregion
#region ■ 添加行_____________________________
///
/// 添加行
///
///
private void AddRowLaout(uRowInformation uRow)
{
var rowlayout = new StatuRowLayout(this.listView);
//图标
var btnIcon = new RowLeftIconView();
btnIcon.UnSelectedImagePath = uRow.IconUnSelectPath;
btnIcon.SelectedImagePath = uRow.IconSelectPath;
rowlayout.AddChidren(btnIcon);
//设备名
var txtDevice = new RowCenterView();
txtDevice.Text = uRow.TextName;
rowlayout.AddChidren(txtDevice);
//向右图标
rowlayout.AddRightIconControl();
//单击事件
rowlayout.MouseUpEvent += (sender, e) =>
{
if (uRow.listScene == null)
{
//设备的一览
var form = new AddDeviceAlarmTargetListForm();
this.AddForm(form, this.zoonID, uRow.TextName, uRow.listDevice);
}
else
{
//场景的一览
var form = new AddSceneAlarmTargetListForm();
this.AddForm(form, this.zoonID, uRow.listScene);
}
};
}
#endregion
#region ■ 一般方法___________________________
///
/// 获取设备的所有类型,并整理成每一行的数据
///
private void GetAllListData()
{
Dictionary dic = new Dictionary();
this.listAllDeviceInfo.Clear();
var listDevice = Common.LocalDevice.Current.listAllDevice;
foreach (CommonDevice device in listDevice)
{
//如果那个设备已经添加了,则不再显示
if (Common.LocalSafeguard.Current.IsAlarmDeviceExist(this.zoonID, device) == true)
{
continue;
}
if (device.Type == DeviceType.IASZone//传感器
|| device.Type == DeviceType.OnOffSwitch//面板
)
{
continue;
}
//显示文本
string KeysName = Common.LocalDevice.Current.GetDeviceObjectText(new List() { device });
//图标地址:点亮
string IconSelect = string.Empty;
//图标地址:未点亮
string IconUnSelect = string.Empty;
Common.LocalDevice.Current.GetDeviceBeloneIcon(new List() { device }, ref IconUnSelect, ref IconSelect);
uRowInformation infoRow = null;
if (dic.ContainsKey(KeysName) == false)
{
//第一次时,设置它的显示文本及设置它的图标
infoRow = new uRowInformation();
dic[KeysName] = infoRow;
infoRow.TextName = KeysName;
infoRow.IconSelectPath = IconSelect;
infoRow.IconUnSelectPath = IconUnSelect;
this.listAllDeviceInfo.Add(infoRow);
}
infoRow = dic[KeysName];
//设备收集
var info = new uDeviceInfo
{
listRoomName = Shared.Common.Room.CurrentRoom.GetRoomListNameByDevice(device),
Device = device,
MainKeys = device.DeviceAddr + device.DeviceEpoint.ToString()
};
infoRow.listDevice.Add(info);
}
//获取场景
Common.SceneRoomUI.GetAllSceneRoomUIList();
List listScene = Common.SceneRoomUI.AllSceneRoomUIList;
if (listScene.Count == 0)
{
return;
}
//获取本地安防的场景
Dictionary dicScene = Common.LocalSafeguard.Current.GetLocalSceneByZoneID(this.zoonID);
var SceneInfo = new uRowInformation();
SceneInfo.listScene = new List();
foreach (var data in listScene)
{
//如果那个场景已经添加了,则不再显示
if (dicScene.ContainsKey(data.sceneUI.Id) == true)
{
continue;
}
SceneInfo.listScene.Add(data);
}
if (SceneInfo.listScene.Count > 0)
{
SceneInfo.TextName = Language.StringByID(R.MyInternationalizationString.uScence);
SceneInfo.IconSelectPath = "Item/SceneSelected.png";
SceneInfo.IconUnSelectPath = "Item/Scene.png";
this.listAllDeviceInfo.Add(SceneInfo);
}
}
#endregion
#region ■ 界面重新激活事件___________________
///
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
///
public override void FormActionAgainEvent()
{
//重新刷新界面
this.ShowForm(zoonID);
}
#endregion
#region ■ 自定义结构体_______________________
///
/// 每一行的行数据
///
private class uRowInformation
{
///
/// 图标地址:未点亮
///
public string IconUnSelectPath = string.Empty;
///
/// 图标地址:点亮
///
public string IconSelectPath = string.Empty;
///
/// 显示的内容
///
public string TextName = string.Empty;
///
/// 设备列表信息
///
public List listDevice = new List();
///
/// 场景
///
public List listScene = null;
}
#endregion
}
}