using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Safety
{
///
/// 报警目标设置画面
///
public class AlarmTargetSettionForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 防区ID(这个东西似乎是唯一的)
///
private int zoonID = 0;
///
/// 列表控件
///
private VerticalListControl listView = null;
///
/// 底部的【添加目标】的行
///
private FrameRowControl frameBottomAddRow = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 防区ID
public void ShowForm(int i_zoonID)
{
this.zoonID = i_zoonID;
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAlarmTargetSettion));
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
//根据防区ID获取本地的报警目标列表
var listData = HdlSafeguardLogic.Current.GetLocalAlarmTargetInfoByZoneId(this.zoonID);
if (listData.Count == 0)
{
//特殊特效,如果没有报警目标的话,则显示的界面效果非常的大
this.ShowNotAlarmTargetAppeal();
frameBottomAddRow = null;
return;
}
//当该防区报警时,以下目标将会响应
var frameBack = new FrameLayout();
frameBack.Height = Application.GetRealHeight(92);
frameBack.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBack);
var btnTitle = new NormalViewControl(860, 49, true);
btnTitle.X = ControlCommonResourse.XXLeft;
btnTitle.Y = Application.GetRealHeight(35);
btnTitle.TextSize = 12;
btnTitle.TextColor = UserCenterColor.Current.TextGrayColor2;
btnTitle.TextID = R.MyInternationalizationString.uTargetViewAlarmAfterZoonAlarm;
frameBack.AddChidren(btnTitle);
int maxRowCount = listData.Count;
if (maxRowCount > 8)
{
//特效问题,它只能显示8个,超过8个只能用滑动
maxRowCount = 8;
}
this.listView = new VerticalListControl(29);
this.listView.Y = frameBack.Bottom;
this.listView.BackgroundColor = UserCenterColor.Current.White;
this.listView.Height = (ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29)) * maxRowCount;
bodyFrameLayout.AddChidren(this.listView);
//添加底部 添加报警目标的菜单行
this.AddBottomAlarmTargetMenu();
HdlThreadLogic.Current.RunThread(() =>
{
//设置中间部分信息
this.SetMiddleInfo(listData);
});
}
///
/// 设置中间部分信息
///
public void SetMiddleInfo(List listData)
{
if (this.Parent == null)
{
return;
}
//添加报警目标的明细行S
Application.RunOnMainThread(() =>
{
foreach (var data in listData)
{
//场景
if (data.Type == 1)
{
this.AddSceneRow(data);
}
//设备
if (data.Type == 0)
{
CommonDevice device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
if (device != null)
{
this.AddDeviceRow(data, device);
}
}
}
});
}
#endregion
#region ■ 报警目标菜单行_____________________
///
/// 显示无报警目标特效
///
private void ShowNotAlarmTargetAppeal()
{
var frameTemp = new FrameRowControl();
frameTemp.Height = Application.GetRealHeight(173);
frameTemp.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameTemp);
//添加目标
var btnText = frameTemp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAddTarget), 400);
btnText.TextSize = 15;
//加号
var btnAdd = frameTemp.AddMostRightEmptyIcon(58, 58);
btnAdd.UnSelectedImagePath = "Item/Add.png";
frameTemp.ButtonClickEvent += (sender, e) =>
{
var form = new AddAlarmTargetTypeListForm();
form.AddForm(this.zoonID);
};
}
///
/// 添加底部 添加报警目标的菜单行
///
private void AddBottomAlarmTargetMenu()
{
//添加目标
frameBottomAddRow = new FrameRowControl();
frameBottomAddRow.Y = this.listView.Bottom;
frameBottomAddRow.Height = ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29 + 29);
frameBottomAddRow.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBottomAddRow);
var frameTemp = new FrameRowControl();
frameTemp.Gravity = Gravity.CenterVertical;
frameBottomAddRow.AddChidren(frameTemp);
var btnText = frameTemp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAddTarget), 400);
btnText.TextSize = 15;
//加号
var btnAdd = frameTemp.AddMostRightEmptyIcon(58, 58);
btnAdd.UnSelectedImagePath = "Item/Add.png";
//底线
frameTemp.AddBottomLine();
frameTemp.ButtonClickEvent += (sender, e) =>
{
var form = new AddAlarmTargetTypeListForm();
form.AddForm(this.zoonID);
};
}
#endregion
#region ■ 报警目标明细行_____________________
///
/// 添加报警目标的明细行
///
private void AddAlarmTargetList(List listData)
{
foreach (var data in listData)
{
//场景
if (data.Type == 1)
{
Application.RunOnMainThread(() =>
{
if (this.Parent != null)
{
this.AddSceneRow(data);
}
});
}
//设备
if (data.Type == 0)
{
CommonDevice device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
if (device == null)
{
//本地没有这个设备的话
continue;
}
Application.RunOnMainThread(() =>
{
if (this.Parent != null)
{
this.AddDeviceRow(data, device);
}
});
}
}
}
///
/// 添加设备行
///
///
///
private void AddDeviceRow(Safeguard.CatActionResponseObj data, CommonDevice device)
{
//行控件
var row = new DeviceRoomControl(device, listView.rowSpace / 2);
listView.AddChidren(row);
row.InitControl();
row.frameTable.UseClickStatu = false;
//底线
row.frameTable.AddBottomLine();
//删除图标
var btnDelete = row.frameTable.AddMostRightEmptyIcon(58, 58);
btnDelete.UnSelectedImagePath = "Item/DeleteIcon1.png";
row.frameTable.ChangedChidrenBindMode(btnDelete, ChidrenBindMode.NotBind);
btnDelete.ButtonClickEvent += (sender, e) =>
{
//删除
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
{
//删除报警目标
this.DeleteAlarmTarget(row, data);
});
};
//状态显示
var btnStatu = row.frameTable.AddMostRightView("", 400);
if (data.TaskList.Count > 0)
{
btnStatu.Text = HdlSafeguardLogic.Current.GetLightAlarmStatuText(data.TaskList);
}
else
{
//无动作
btnStatu.TextID = R.MyInternationalizationString.uNotAction;
}
}
///
/// 添加场景行
///
///
private void AddSceneRow(Safeguard.CatActionResponseObj data)
{
//行控件
var row = new SceneRoomControl(data.ScenesId, data.ESName, listView.rowSpace / 2);
listView.AddChidren(row);
row.InitControl();
row.frameTable.UseClickStatu = false;
//底线
row.frameTable.AddBottomLine();
//删除图标
var btnDelete = row.frameTable.AddMostRightEmptyIcon(58, 58);
btnDelete.UnSelectedImagePath = "Item/DeleteIcon1.png";
row.frameTable.ChangedChidrenBindMode(btnDelete, ChidrenBindMode.NotBind);
btnDelete.ButtonClickEvent += (sender, e) =>
{
//删除
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
{
//删除报警目标
this.DeleteAlarmTarget(row, data);
});
};
}
#endregion
#region ■ 删除指定报警目标___________________
///
/// 删除指定报警目标
///
///
///
private async void DeleteAlarmTarget(RowLayoutControl row, Safeguard.CatActionResponseObj delObj)
{
//参数
var Pra = new List();
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 HdlSafeguardLogic.Current.DeleteAlarmTaget(this.zoonID, Pra);
//关闭进度条
this.CloseProgressBar();
if (result == false)
{
return;
}
Application.RunOnMainThread(() =>
{
//行移除
row?.RemoveFromParent();
if (listView != null && listView.ChildrenCount == 0)
{
//重新初始化中部信息
this.InitMiddleFrame();
return;
}
var realHeight = listView.ChildrenCount * listView.GetChildren(listView.ChildrenCount - 1).Height;
if (realHeight < listView.Height)
{
//缩小控件高度
listView.Height = realHeight;
//移动行控件
frameBottomAddRow.Y = this.listView.Bottom;
}
});
}
#endregion
#region ■ 界面重新激活事件___________________
///
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
///
public override int FormActionAgainEvent()
{
//重新刷新界面
this.InitMiddleFrame();
return 1;
}
#endregion
}
}