黄学彪
2019-10-10 2ed75b8b337048e5d75e6d9ec8307633134f02fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 添加场景的列表界面
    /// </summary>
    public class AddSceneAlarmTargetListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 防区ID(这个东西似乎是唯一的)
        /// </summary>
        private int zoonID = 0;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_zoonID">防区ID</param>
        /// <param name="i_listScene">现存的场景</param>
        public void ShowForm(int i_zoonID, List<Common.SceneRoomUI> 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.SceneRoomUI> listScene)
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //完成
            var btnfinish = new BottomClickButton();
            btnfinish.TextID = R.MyInternationalizationString.uFinish;
            bodyFrameLayout.AddChidren(btnfinish);
            btnfinish.ButtonClickEvent += (sender, e) =>
            {
                //保存场景到安防
                this.SaveSceneToSafety();
            };
 
            this.listView = new VerticalListControl(29);
            listView.Y = Application.GetRealHeight(-6);
            listView.Height = btnfinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace + Application.GetRealHeight(6);
            listView.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(listView);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //获取本地安防的场景
                Dictionary<int, string> dicScene = HdlSafeguardLogic.Current.GetLocalSceneByZoneID(this.zoonID);
                if (this.Parent == null)
                {
                    return;
                }
                Application.RunOnMainThread(() =>
                {
                    int count = listScene.Count - 1;
                    for (int i = 0; i < listScene.Count; i++)
                    {
                        //如果安防里面已经添加有,则不再显示
                        if (dicScene.ContainsKey(listScene[i].sceneUI.Id) == true)
                        {
                            continue;
                        }
                        var row = new SceneSimpleSelectControl(listScene[i].sceneUI, listView.rowSpace / 2);
                        listView.AddChidren(row);
                        row.InitControl();
                        if (i != count)
                        {
                            //底线
                            row.AddBottomLine();
                        }
                    }
                    if (listView.ChildrenCount > 0)
                    {
                        int realHeight = (listView.GetChildren(listView.ChildrenCount - 1).Height) * listView.ChildrenCount + Application.GetRealHeight(23);
                        if (realHeight < listView.Height)
                        {
                            //调整真实高度
                            listView.Height = realHeight;
                        }
                    }
                });
            });
        }
 
        #endregion
 
        #region ■ 保存场景___________________________
 
        /// <summary>
        /// 保存场景到安防
        /// </summary>
        private async void SaveSceneToSafety()
        {
            var listAction = new List<Safeguard.AlarmActionObj>();
 
            for (int i = 0; ; i++)
            {
                var myView = this.listView.GetChildren(i);
                if (myView == null)
                {
                    break;
                }
                var row = (SceneSimpleSelectControl)myView;
                if (row.IsSelected == false)
                {
                    continue;
                }
                var actionObj = new Safeguard.AlarmActionObj();
                actionObj.Type = 1;
                actionObj.ScenesId = row.Scene.Id;
                listAction.Add(actionObj);
            }
            if (listAction.Count == 0)
            {
                Application.RunOnMainThread(() =>
                {
                    //关闭自身
                    this.CloseForm();
                });
                return;
            }
 
            //打开进度条
            this.ShowProgressBar();
 
            //添加报警目标到安防
            bool success = await HdlSafeguardLogic.Current.AddAlarmTagetToSafety(this.zoonID, listAction);
            //关闭进度条
            this.CloseProgressBar();
 
            if (success == true)
            {
                Application.RunOnMainThread(() =>
                {
                    //关闭自身
                    this.CloseForm();
                });
            }
        }
        #endregion
    }
}