using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Safety
|
{
|
/// <summary>
|
/// 添加报警目标(场景)的列表界面
|
/// </summary>
|
public class AlarmTargetAddSceneForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
/// <summary>
|
/// 防区ID(这个东西似乎是唯一的)
|
/// </summary>
|
private int zoonID = 0;
|
/// <summary>
|
/// 选择的场景
|
/// </summary>
|
private Dictionary<int, Common.SceneUI> dicSelectScene = new Dictionary<int, Common.SceneUI>();
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_zoonID">防区ID</param>
|
/// <param name="i_listScene">现存的场景</param>
|
public void ShowForm(int i_zoonID, List<Common.SceneUI> i_listScene)
|
{
|
this.zoonID = i_zoonID;
|
|
//设置头部信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uScence));
|
|
//初始化中部信息
|
this.InitMiddleFrame(i_listScene);
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
/// <param name="listScene">现存的场景</param>
|
private void InitMiddleFrame(List<Common.SceneUI> listScene)
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
this.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.RunThread(() =>
|
{
|
//获取本地安防的场景
|
Dictionary<int, string> dicScene = HdlSafeguardLogic.Current.GetLocalSceneByZoneID(this.zoonID);
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
int count = listScene.Count - 1;
|
for (int i = 0; i < listScene.Count; i++)
|
{
|
//如果安防里面已经添加有,则不再显示
|
if (dicScene.ContainsKey(listScene[i].Id) == true)
|
{
|
continue;
|
}
|
//添加行
|
this.AddRowControl(listScene[i], i != count);
|
}
|
//调整真实高度
|
listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
|
});
|
});
|
|
//完成
|
var btnfinish = new BottomClickButton();
|
btnfinish.TextID = R.MyInternationalizationString.uFinish;
|
bodyFrameLayout.AddChidren(btnfinish);
|
btnfinish.ButtonClickEvent += (sender, e) =>
|
{
|
if (this.dicSelectScene.Count == 0)
|
{
|
//关闭界面
|
this.CloseForm();
|
return;
|
}
|
//保存场景到安防
|
this.SaveSceneToSafety();
|
};
|
}
|
|
#endregion
|
|
#region ■ 添加行_____________________________
|
|
/// <summary>
|
/// 添加行
|
/// </summary>
|
/// <param name="scene"></param>
|
/// <param name="addLine"></param>
|
private void AddRowControl(Common.SceneUI scene, bool addLine)
|
{
|
var rowContr = new FrameRowControl(listView.rowSpace / 2);
|
listView.AddChidren(rowContr);
|
|
//图标
|
var btnIcon = rowContr.AddLeftIcon(81);
|
btnIcon.UnSelectedImagePath = "Scene/SceneIcon.png";
|
//场景名
|
var btnName = rowContr.AddLeftCaption(scene.Name, 700);
|
btnName.TextSize = 15;
|
//选择
|
var btnSelect = rowContr.AddMostRightEmptyIcon(58, 58);
|
btnSelect.Visible = false;
|
btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
|
if (addLine == true)
|
{
|
//底线
|
rowContr.AddBottomLine();
|
}
|
|
rowContr.ButtonClickEvent += (sender, e) =>
|
{
|
btnSelect.Visible = !btnSelect.Visible;
|
if (btnSelect.Visible == true)
|
{
|
dicSelectScene[scene.Id] = scene;
|
}
|
else
|
{
|
dicSelectScene.Remove(scene.Id);
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 保存场景___________________________
|
|
/// <summary>
|
/// 保存场景到安防
|
/// </summary>
|
private async void SaveSceneToSafety()
|
{
|
var listAction = new List<Safeguard.AlarmActionObj>();
|
foreach (var scene in this.dicSelectScene.Values)
|
{
|
var actionObj = new Safeguard.AlarmActionObj();
|
actionObj.Type = 1;
|
actionObj.ScenesId = scene.Id;
|
listAction.Add(actionObj);
|
}
|
//添加报警目标到安防
|
bool success = await HdlSafeguardLogic.Current.AddAlarmTagetToSafety(this.zoonID, listAction);
|
if (success == true)
|
{
|
//关闭自身
|
this.CloseForm();
|
}
|
}
|
#endregion
|
}
|
}
|