using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Safety
{
///
/// 已经设置了的传感器的一览画面
///
public class GarrisonAreaExistSensorForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 列表控件
///
private VerticalListControl listView = null;
///
/// 防区ID
///
private int zoonID = 0;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 防区名字
/// 防区ID
public void ShowForm(string SectorsName, int i_zoonID)
{
this.zoonID = i_zoonID;
//设置头部信息
base.SetTitleText(SectorsName + Language.StringByID(R.MyInternationalizationString.uSettion));
//右上角的“+”图标
var btnTopIcon = new MostRightIconControl(69, 69);
btnTopIcon.UnSelectedImagePath = "Item/Add.png";
topFrameLayout.AddChidren(btnTopIcon);
btnTopIcon.InitControl();
btnTopIcon.ButtonClickEvent += (sender, e) =>
{
//添加新的传感器
this.AddNewSensorDevice();
};
//初始化传感器列表信息
this.InitSensorDevicesListInfo();
}
///
/// 初始化传感器列表信息
///
private void InitSensorDevicesListInfo()
{
//清空bodyFrameLayout
this.ClearBodyFrame();
//获取指定防区全部的传感器设备的信息
var listInfo = HdlSafeguardLogic.Current.GetSensorDevicesInfoByZoonID(this.zoonID);
if (listInfo.Count == 0)
{
//还没有设置传感器哦
this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uDoNotHadSettionSensorMsg));
this.listView = null;
return;
}
listView = new VerticalListControl(29);
listView.Y = Application.GetRealHeight(-6);
listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
listView.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(listView);
HdlThreadLogic.Current.RunMainInThread(() =>
{
int count = listInfo.Count - 1;
for (int i = 0; i < listInfo.Count; i++)
{
this.AddRowLayout(listInfo[i], i != count);
}
//调整列表控件的高度
this.listView.AdjustRealHeight(Application.GetRealHeight(23));
});
}
#endregion
#region ■ 添加传感器行_______________________
///
/// 添加行
///
/// 传感器信息
/// 是否添加底线
private void AddRowLayout(Safeguard.ZoneDeviceListData sensorInfo, bool addLine)
{
CommonDevice device = Common.LocalDevice.Current.GetDevice(sensorInfo.MacAddr, sensorInfo.Epoint);
if (device == null)
{
return;
}
//自定义控件
var rowLayout = new DeviceRoomControl(device, listView.rowSpace / 2);
listView.AddChidren(rowLayout);
rowLayout.InitControl();
rowLayout.frameTable.UseClickStatu = false;
if (addLine == true)
{
//底线
rowLayout.frameTable.AddBottomLine();
}
//旁路状态
var txtStatu = rowLayout.frameTable.AddMostRightView("", 350);
txtStatu.TextColor = UserCenterColor.Current.TextGrayColor1;
//旁路设置
var btnBypass = new NormalViewControl(Application.GetRealWidth(184), rowLayout.Height, false);
btnBypass.TextID = R.MyInternationalizationString.uBypass;
btnBypass.BackgroundColor = 0xff4a4a4a;
btnBypass.TextColor = UserCenterColor.Current.TextColor3;
btnBypass.TextAlignment = TextAlignment.Center;
btnBypass.TextSize = 12;
if (sensorInfo.IsBypass == 1)
{
//已设置旁路
txtStatu.TextID = R.MyInternationalizationString.uHadSetBypass;
//取消旁路
btnBypass.TextID = R.MyInternationalizationString.uCancelBypass;
}
rowLayout.AddLeftView(btnBypass);
btnBypass.ButtonClickEvent += (sender, e) =>
{
//设置旁路状态
this.SetBypassStatu(sensorInfo, device);
};
//删除
var btnDelete = new NormalViewControl(Application.GetRealWidth(184), rowLayout.Height, false);
btnDelete.TextID = R.MyInternationalizationString.uDelete;
btnDelete.BackgroundColor = 0xfff75858;
btnDelete.TextColor = UserCenterColor.Current.TextColor3;
btnDelete.TextAlignment = TextAlignment.Center;
btnDelete.TextSize = 12;
rowLayout.AddRightView(btnDelete);
btnDelete.ButtonClickEvent += (sender, e) =>
{
//确认是否要删除?
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
{
//删除传感器行
this.DeleteRow(rowLayout, device);
});
};
}
#endregion
#region ■ 删除传感器行_______________________
///
/// 删除行
///
///
///
private async void DeleteRow(DeviceRoomControl rowLayout, CommonDevice device)
{
bool result = await HdlSafeguardLogic.Current.DeleteSensorDevice(this.zoonID, new List() { device });
if (result == false)
{
return;
}
//从画面中移除
rowLayout?.RemoveFromParent();
//调整列表控件的高度
this.listView.AdjustRealHeight(Application.GetRealHeight(23));
if (this.listView.ChildrenCount == 0)
{
//初始化传感器列表信息
this.InitSensorDevicesListInfo();
}
}
#endregion
#region ■ 旁路设置___________________________
///
/// 设置旁路状态
///
/// 传感器信息
/// 传感器设备
private async void SetBypassStatu(Safeguard.ZoneDeviceListData sensorInfo, CommonDevice device)
{
//变更状态
int statu = sensorInfo.IsBypass == 1 ? 0 : 1;
bool result = await HdlSafeguardLogic.Current.SetByPassStatuToSafety(this.zoonID, device, statu);
if (result == false)
{
return;
}
//变更状态
sensorInfo.IsBypass = statu;
this.InitSensorDevicesListInfo();
}
#endregion
#region ■ 添加新的传感器_____________________
///
/// 添加新的传感器
///
private void AddNewSensorDevice()
{
//获取能够添加的传感器
var list = this.GetCanAddSensorDevice();
//显示选择界面
var form = new SelectDeviceForm();
form.AddForm(list, new List(), true, false);
form.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddSensor));
//设备选择确定
form.ActionSelectDeviceEx += (async (listDevice) =>
{
if (listDevice.Count == 0)
{
//关闭界面
form.CloseForm();
return;
}
//添加设备到安防
bool success = await HdlSafeguardLogic.Current.AddSensorDevice(this.zoonID, listDevice);
if (success == true)
{
//关闭界面
form.CloseForm();
//刷新列表
this.InitSensorDevicesListInfo();
}
});
}
///
/// 获取能够添加的传感器
///
///
private List GetCanAddSensorDevice()
{
List listNew = new List();
List listDevices = Common.LocalDevice.Current.listAllDevice;
foreach (CommonDevice device in listDevices)
{
//只要传感器
if (device.Type != DeviceType.IASZone)
{
continue;
}
//如果那个设备已经添加了,则不再显示
if (HdlSafeguardLogic.Current.IsSensorDeviceExist(device) == true)
{
continue;
}
listNew.Add(device);
}
return listNew;
}
#endregion
}
}