xm
2019-07-16 b910cb79c9b5bcc204022a3cf9e6950f0a64dfbd
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 报警目标设置画面
    /// </summary>
    public class AlarmTargetSettionForm : UserCenterCommonForm
    {
        /// <summary>
        /// 防区ID(这个东西似乎是唯一的)
        /// </summary>
        private int zoonID = 0;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listView = null;
        /// <summary>
        /// 标题控件
        /// </summary>
        private TitleViewControl btnTitle = null;
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_zoonID">防区ID</param>
        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();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        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();
        }
 
        /// <summary>
        /// 设置中间部分信息
        /// </summary>
        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();
        }
 
        /// <summary>
        /// 添加报警目标的明细行
        /// </summary>
        private void AddAlarmTargetList(List<Safeguard.CatActionResponseObj> 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);
                    });
                }
            }
        }
 
        /// <summary>
        /// 添加场景行
        /// </summary>
        /// <param name="data"></param>
        /// <param name="device"></param>
        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);
            };
        }
 
        /// <summary>
        /// 添加设备行
        /// </summary>
        /// <param name="data"></param>
        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);
            };
        }
 
        /// <summary>
        /// 删除指定报警目标
        /// </summary>
        /// <param name="row"></param>
        /// <param name="delObj"></param>
        public async void DeleteAlarmTarget(StatuRowLayout row, Safeguard.CatActionResponseObj delObj)
        {
            //参数
            var Pra = new List<Safeguard.DelAlarmActionObj>();
            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;
                }
            });
        }
    }
}