using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Safety
|
{
|
/// <summary>
|
/// 添加报警目标指定设备类型的设备列表
|
/// </summary>
|
public class AddDeviceAlarmTargetListForm : UserCenterCommonForm
|
{
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalScrolViewLayout listView = null;
|
/// <summary>
|
/// 防区ID(这个东西似乎是唯一的)
|
/// </summary>
|
private int zoonID = 0;
|
/// <summary>
|
/// 设备列表
|
/// </summary>
|
private List<uDeviceInfo> listAllDevice = null;
|
/// <summary>
|
/// 现存的报警目标
|
/// </summary>
|
private Dictionary<string, Safeguard.CatActionResponseObj> dicAlarmDevice = null;
|
/// <summary>
|
/// 需要添加的报警设备
|
/// </summary>
|
private Dictionary<string, TaskInfoData> dicSaveDevice = new Dictionary<string, TaskInfoData>();
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_zoonID">防区ID</param>
|
/// <param name="i_deviceText">设备类型的名称</param>
|
/// <param name="i_listDevice">设备信息</param>
|
public void ShowForm(int i_zoonID, string i_deviceText, List<uDeviceInfo> i_listDevice)
|
{
|
this.zoonID = i_zoonID;
|
this.listAllDevice = i_listDevice;
|
|
//设置头部信息
|
base.SetTitleText(i_deviceText);
|
|
//完成
|
var btnfinish = new TopLayoutFinshView();
|
topFrameLayout.AddChidren(btnfinish);
|
btnfinish.MouseUpEventHandler += (sender, e) =>
|
{
|
//保存选择的设备
|
this.DoSaveSelectDeviceAsync();
|
};
|
|
//初始化中部信息
|
this.InitMiddleFrame(i_deviceText);
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
/// <param name="titleText">列表头部名称</param>
|
private void InitMiddleFrame(string titleText)
|
{
|
//XXX列表
|
var btnTitle = new TitleViewControl();
|
btnTitle.TextColor = UserCenterColor.Current.TextGrayColor;
|
btnTitle.Y = Application.GetRealHeight(60);
|
btnTitle.Text = titleText + Language.StringByID(R.MyInternationalizationString.uList);
|
bodyFrameLayout.AddChidren(btnTitle);
|
|
this.listView = new VerticalScrolViewLayout();
|
this.listView.Y = btnTitle.Bottom;
|
this.listView.Height = bodyFrameLayout.Height - btnTitle.Bottom;
|
bodyFrameLayout.AddChidren(this.listView);
|
|
//设置中部信息
|
this.SetMiddleFrameInfo();
|
}
|
|
/// <summary>
|
/// 设置中部信息
|
/// </summary>
|
private void SetMiddleFrameInfo()
|
{
|
new System.Threading.Thread(() =>
|
{
|
//获取现存的报警设备
|
var listData = Common.LocalSafeguard.Current.GetLocalAlarmTargetInfoByZoneId(this.zoonID);
|
dicAlarmDevice = new Dictionary<string, Safeguard.CatActionResponseObj>();
|
foreach (var data in listData)
|
{
|
if (data.Type == 1)
|
{
|
//不需要场景
|
continue;
|
}
|
string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
|
dicAlarmDevice[mainkeys] = data;
|
}
|
|
foreach (var deviceInfo in listAllDevice)
|
{
|
//如果那个设备已经添加了,则不再显示
|
if (Common.LocalSafeguard.Current.IsAlarmDeviceExist(this.zoonID, deviceInfo.Device) == true)
|
{
|
continue;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
//添加行目标
|
this.AddRowLayout(deviceInfo);
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 添加行目标
|
/// </summary>
|
/// <param name="deviceInfo"></param>
|
private void AddRowLayout(uDeviceInfo deviceInfo)
|
{
|
var row = new DeviceRoomViewRow(this.listView, deviceInfo.Device, deviceInfo.listRoomName);
|
//添加向右的图标
|
row.AddRightIconControl();
|
|
//状态显示
|
var btnStatu = new RowSecondRightTextView();
|
row.AddChidren(btnStatu);
|
|
string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceInfo.Device);
|
List<Safeguard.TaskListInfo> listTaskinfo = null;
|
if (this.dicAlarmDevice.ContainsKey(mainKeys) == true)
|
{
|
//显示现存的状态文本
|
listTaskinfo = this.dicAlarmDevice[mainKeys].TaskList;
|
btnStatu.Text = SafeguardLogic.GetLightAlarmStatuText(listTaskinfo);
|
btnStatu.TextColor = UserCenterColor.Current.Green;
|
}
|
else
|
{
|
//无动作
|
btnStatu.TextID = R.MyInternationalizationString.uNotAction;
|
}
|
row.MouseUpEvent += (sender, e) =>
|
{
|
var form = new LightAlarmSettionForm();
|
this.AddForm(form, deviceInfo.Device, listTaskinfo);
|
form.formCloseEvent += (statuText, listInfo) =>
|
{
|
btnStatu.Text = statuText;
|
if (listInfo == null)
|
{
|
//指定为无动作模式
|
if (this.dicSaveDevice.ContainsKey(mainKeys) == true)
|
{
|
this.dicSaveDevice.Remove(mainKeys);
|
}
|
btnStatu.TextColor = UserCenterColor.Current.TextColor;
|
}
|
else
|
{
|
//确认添加动作
|
var data = new TaskInfoData();
|
this.dicSaveDevice[mainKeys] = data;
|
data.MacAddress = deviceInfo.Device.DeviceAddr;
|
data.Epoint = deviceInfo.Device.DeviceEpoint;
|
data.listInfos = listInfo;
|
|
btnStatu.TextColor = UserCenterColor.Current.Green;
|
}
|
};
|
};
|
}
|
|
/// <summary>
|
/// 保存选择的设备
|
/// </summary>
|
private async void DoSaveSelectDeviceAsync()
|
{
|
if (this.dicSaveDevice.Count == 0)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
this.CloseForm();
|
});
|
return;
|
}
|
|
var listAction = new List<Safeguard.AlarmActionObj>();
|
foreach (var data in this.dicSaveDevice.Values)
|
{
|
var actionObj = new Safeguard.AlarmActionObj();
|
actionObj.DeviceAddr = data.MacAddress;
|
actionObj.Epoint = data.Epoint;
|
actionObj.Type = 0;
|
actionObj.TaskList = data.listInfos;
|
listAction.Add(actionObj);
|
}
|
//打开进度条
|
this.ShowProgressBar();
|
|
//添加报警目标到安防
|
bool success = await Common.LocalSafeguard.Current.AddAlarmTagetToSafety(this.zoonID, listAction);
|
//关闭进度条
|
this.CloseProgressBar();
|
|
if (success == true)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
//刷新一览画面
|
this.LoadFormMethodByName("AlarmTargetSettionForm", "SetMiddleInfo");
|
//关闭自身
|
this.CloseForm();
|
});
|
}
|
}
|
|
/// <summary>
|
/// 报警目标数据
|
/// </summary>
|
private class TaskInfoData
|
{
|
/// <summary>
|
/// MAC地址
|
/// </summary>
|
public string MacAddress = string.Empty;
|
/// <summary>
|
/// 端口号
|
/// </summary>
|
public int Epoint = 0;
|
/// <summary>
|
/// 报警动作
|
/// </summary>
|
public List<Safeguard.TaskListInfo> listInfos = new List<Safeguard.TaskListInfo>();
|
}
|
}
|
}
|