using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Safety
|
{
|
/// <summary>
|
/// 报警目标设置画面
|
/// </summary>
|
public class AlarmTargetSettionForm : UserCenterCommonForm
|
{
|
/// <summary>
|
/// 防区ID(这个东西似乎是唯一的)
|
/// </summary>
|
private int zoonID = 0;
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalScrolViewLayout listView = null;
|
/// <summary>
|
/// 标题控件
|
/// </summary>
|
private TitleViewControl btnTitle = null;
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_zoonID">防区ID</param>
|
public void ShowForm(int i_zoonID)
|
{
|
this.zoonID = i_zoonID;
|
|
//设置头部信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAlarmTargetSettion));
|
|
//右上添加按钮
|
var btnAddDeviceIcon = new TopLayoutMostRightView();
|
btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
|
btnAddDeviceIcon.SelectedImagePath = "Item/AddSelected.png";
|
topFrameLayout.AddChidren(btnAddDeviceIcon);
|
btnAddDeviceIcon.MouseUpEventHandler += (sender, e) =>
|
{
|
var form = new AddAlarmTargetTypeListForm();
|
this.AddForm(form, this.zoonID);
|
};
|
|
//初始化中部信息
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
//当该防区报警时,以下目标将会响应
|
btnTitle = new TitleViewControl();
|
btnTitle.TextColor = UserCenterColor.Current.TextGrayColor;
|
btnTitle.Visible = false;
|
btnTitle.Y = Application.GetRealHeight(40);
|
btnTitle.TextID = R.MyInternationalizationString.uTargetViewAlarmAfterZoonAlarm;
|
bodyFrameLayout.AddChidren(btnTitle);
|
|
this.listView = new VerticalScrolViewLayout();
|
this.listView.Y = btnTitle.Bottom + Application.GetRealHeight(20);
|
this.listView.Height = bodyFrameLayout.Height - btnTitle.Bottom - Application.GetRealHeight(20);
|
bodyFrameLayout.AddChidren(this.listView);
|
|
//设置中间部分信息
|
this.SetMiddleInfo();
|
}
|
|
/// <summary>
|
/// 设置中间部分信息
|
/// </summary>
|
public void SetMiddleInfo()
|
{
|
this.listView.RemoveAll();
|
|
//根据防区ID获取本地的报警目标列表
|
var listData = Common.LocalSafeguard.Current.GetLocalAlarmTargetInfoByZoneId(this.zoonID);
|
if (listData.Count > 0)
|
{
|
btnTitle.Visible = true;
|
}
|
|
new System.Threading.Thread(() =>
|
{
|
//添加报警目标的明细行
|
this.AddAlarmTargetList(listData);
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 添加报警目标的明细行
|
/// </summary>
|
private void AddAlarmTargetList(List<Safeguard.CatActionResponseObj> listData)
|
{
|
foreach (var data in listData)
|
{
|
//场景
|
if (data.Type == 1)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
this.AddDeviceRow(data);
|
});
|
}
|
//设备
|
if (data.Type == 0)
|
{
|
CommonDevice device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
|
if (device == null)
|
{
|
//本地没有这个设备的话
|
continue;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
this.AddSceneRow(data, device);
|
});
|
}
|
}
|
}
|
|
/// <summary>
|
/// 添加场景行
|
/// </summary>
|
/// <param name="data"></param>
|
/// <param name="device"></param>
|
private void AddSceneRow(Safeguard.CatActionResponseObj data, CommonDevice device)
|
{
|
//行控件
|
var row = new DeviceRoomViewRow(this.listView, device);
|
//状态显示
|
var btnStatu = new RowSecondRightTextView();
|
row.AddChidren(btnStatu);
|
if (data.TaskList.Count > 0)
|
{
|
btnStatu.Text = SafeguardLogic.GetLightAlarmStatuText(data.TaskList);
|
btnStatu.TextColor = UserCenterColor.Current.Green;
|
}
|
else
|
{
|
//无动作
|
btnStatu.TextID = R.MyInternationalizationString.uNotAction;
|
}
|
|
var btnDelete = new RowDeleteButton();
|
row.AddRightView(btnDelete);
|
btnDelete.MouseUpEventHandler += (sender, e) =>
|
{
|
//删除
|
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
|
this.ShowConfirmMsg(msg, "DeleteAlarmTarget", row, data);
|
};
|
}
|
|
/// <summary>
|
/// 添加设备行
|
/// </summary>
|
/// <param name="data"></param>
|
private void AddDeviceRow(Safeguard.CatActionResponseObj data)
|
{
|
//行控件
|
var row = new SceneRoomViewRow(this.listView, data.ScenesId, data.ESName);
|
|
var btnDelete = new RowDeleteButton();
|
row.AddRightView(btnDelete);
|
btnDelete.MouseUpEventHandler += (sender, e) =>
|
{
|
//删除
|
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
|
this.ShowConfirmMsg(msg, "DeleteAlarmTarget", row, data);
|
};
|
}
|
|
/// <summary>
|
/// 删除指定报警目标
|
/// </summary>
|
/// <param name="row"></param>
|
/// <param name="delObj"></param>
|
public async void DeleteAlarmTarget(StatuRowLayout row, Safeguard.CatActionResponseObj delObj)
|
{
|
//参数
|
var Pra = new List<Safeguard.DelAlarmActionObj>();
|
var actionObj = new Safeguard.DelAlarmActionObj();
|
actionObj.DeviceAddr = delObj.DeviceAddr;
|
actionObj.Epoint = delObj.Epoint;
|
actionObj.ScenesId = delObj.ScenesId;
|
actionObj.Type = delObj.Type;
|
Pra.Add(actionObj);
|
|
//打开进度条
|
this.ShowProgressBar();
|
|
//执行删除
|
bool result = await Common.LocalSafeguard.Current.DeleteAlarmTaget(this.zoonID, Pra);
|
|
//关闭进度条
|
this.CloseProgressBar();
|
|
if (result == false)
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
//行移除
|
row.RemoveFromParent();
|
if (listView.ChildrenCount == 0)
|
{
|
btnTitle.Visible = false;
|
}
|
});
|
}
|
}
|
}
|