using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.Safety { /// /// 报警目标设置画面 /// public class AlarmTargetSettionForm : UserCenterCommonForm { /// /// 防区ID(这个东西似乎是唯一的) /// private int zoonID = 0; /// /// 列表控件 /// private VerticalScrolViewLayout listView = null; /// /// 标题控件 /// private TitleViewControl btnTitle = null; /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 防区ID 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(); } /// /// 初始化中部信息 /// 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(); } /// /// 设置中间部分信息 /// 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(); } /// /// 添加报警目标的明细行 /// private void AddAlarmTargetList(List 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); }); } } } /// /// 添加场景行 /// /// /// 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); }; } /// /// 添加设备行 /// /// 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); }; } /// /// 删除指定报警目标 /// /// /// public async void DeleteAlarmTarget(StatuRowLayout 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 Common.LocalSafeguard.Current.DeleteAlarmTaget(this.zoonID, Pra); //关闭进度条 this.CloseProgressBar(); if (result == false) { return; } Application.RunOnMainThread(() => { //行移除 row.RemoveFromParent(); if (listView.ChildrenCount == 0) { btnTitle.Visible = false; } }); } } }