using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.Safety { /// /// 添加场景的列表界面 /// public class AddSceneAlarmTargetListForm : UserCenterCommonForm { /// /// 列表控件 /// private VerticalScrolViewLayout listView = null; /// /// 防区ID(这个东西似乎是唯一的) /// private int zoonID = 0; /// /// 本地存在的场景 /// private List listScene = null; /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 防区ID /// 现存的场景 public void ShowForm(int i_zoonID, List i_listScene) { this.zoonID = i_zoonID; this.listScene = i_listScene; //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uScence)); //完成 var btnfinish = new TopLayoutFinshView(); topFrameLayout.AddChidren(btnfinish); btnfinish.MouseUpEventHandler += (sender, e) => { //保存场景到安防 this.SaveSceneToSafety(); }; //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //场景列表 var btnTitle = new TitleViewControl(); btnTitle.TextColor = UserCenterColor.Current.TextGrayColor; btnTitle.Y = Application.GetRealHeight(60); btnTitle.Text = Language.StringByID(R.MyInternationalizationString.uScence) + 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); new System.Threading.Thread(() => { //获取本地安防的场景 Dictionary dicScene = Common.LocalSafeguard.Current.GetLocalSceneByZoneID(this.zoonID); foreach (var scene in this.listScene) { //如果安防里面已经添加有,则不再显示 if (dicScene.ContainsKey(scene.sceneUI.Id) == true) { continue; } Application.RunOnMainThread(() => { //添加场景行 this.AddSceneRowLayout(scene); }); } }) { IsBackground = true }.Start(); } /// /// 添加场景行 /// /// private void AddSceneRowLayout(Common.SceneRoomUI i_Scene) { var row = new SceneSelectRow(this.listView, i_Scene); } /// /// 保存场景到安防 /// private async void SaveSceneToSafety() { var listAction = new List(); for (int i = 0; ; i++) { var myView = this.listView.GetChildren(i); if (myView == null) { break; } var row = (SceneSelectRow)myView; if (row.IsSelected == false) { continue; } var actionObj = new Safeguard.AlarmActionObj(); actionObj.Type = 1; actionObj.ScenesId = row.sceneRoomUI.sceneUI.Id; listAction.Add(actionObj); } if (listAction.Count == 0) { Application.RunOnMainThread(() => { //关闭自身 this.CloseForm(); }); return; } //打开进度条 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(); }); } } } }