黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.MainPage.ControlForm
{
    /// <summary>
    /// 继电器类型的深度卡片界面(含空气开关)
    /// </summary>
    public class DeviceRelayDetailCardForm : DeviceDetailCardCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 界面上可以操作的控件
        /// </summary>
        private List<ButtonBase> listControl = new List<ButtonBase>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 底层初始化中部控件完成之后
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack)
        {
            //先清空
            this.listControl = new List<ButtonBase>();
 
            if (this.device.DfunctionType == DeviceFunctionType.A开关)
            {
                //初始化开关类型控件
                this.InitSwitchControl(frameWhiteBack);
            }
            else if (this.device.DfunctionType == DeviceFunctionType.A插座)
            {
                //初始化插座类型控件
                this.InitPlugControl(frameWhiteBack);
            }
            else
            {
                //初始化灯光类型控件
                this.InitLightControl(frameWhiteBack);
            }
            //设置状态文字
            this.SetStatuText(HdlDeviceCommonLogic.Current.GetMainPageDeviceStatuText(this.device));
        }
 
        #endregion
 
        #region ■ 初始化灯光类型_____________________
 
        /// <summary>
        /// 初始化灯光类型控件
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        private void InitLightControl(FrameLayout frameWhiteBack)
        {
            //灯光图片
            var picLight = new PicViewControl(377, 435);
            picLight.Y = Application.GetRealHeight(389);
            picLight.UnSelectedImagePath = "Light/DeskLamp.png";
            picLight.SelectedImagePath = "Light/DeskLampSelected.png";
            picLight.Gravity = Gravity.CenterHorizontal;
            frameWhiteBack.AddChidren(picLight);
            listControl.Add(picLight);
 
            //开关
            var btnSwitch = new IconViewControl(81);
            btnSwitch.UnSelectedImagePath = "Item/Switch.png";
            btnSwitch.SelectedImagePath = "Item/SwitchSelected.png";
            btnSwitch.Y = picLight.Bottom + Application.GetRealHeight(173);
            btnSwitch.Gravity = Gravity.CenterHorizontal;
            frameWhiteBack.AddChidren(btnSwitch);
            listControl.Add(btnSwitch);
 
            //设置初始状态
            if (((LightBase)this.device).OnOffStatus == 1)
            {
                picLight.IsSelected = true;
                btnSwitch.IsSelected = true;
            }
 
            picLight.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SetSwitchCommand(!picLight.IsSelected);
            };
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SetSwitchCommand(!btnSwitch.IsSelected);
            };
        }
 
        #endregion
 
        #region ■ 初始化开关类型_____________________
 
        /// <summary>
        /// 初始化开关类型控件
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        private void InitSwitchControl(FrameLayout frameWhiteBack)
        {
            //开关的背景图片
            var picSwitchBack = new FrameLayout();
            picSwitchBack.Height = this.GetPictrueRealSize(579);
            picSwitchBack.Width = this.GetPictrueRealSize(579);
            picSwitchBack.Y = Application.GetRealHeight(340);
            picSwitchBack.BackgroundImagePath = "Light/OnOff.png";
            picSwitchBack.Gravity = Gravity.CenterHorizontal;
            frameWhiteBack.AddChidren(picSwitchBack);
 
            //关闭
            var btnClose = new IconViewControl(81);
            btnClose.UnSelectedImagePath = "Light/OFF.png";
            btnClose.SelectedImagePath = "Light/OFFSelected.png";
            btnClose.X = this.GetPictrueRealSize(101);
            btnClose.Y = this.GetPictrueRealSize(248);
            picSwitchBack.AddChidren(btnClose);
            listControl.Add(btnClose);
 
            //打开
            var btnOpen = new IconViewControl(81);
            btnOpen.UnSelectedImagePath = "Light/ON.png";
            btnOpen.SelectedImagePath = "Light/ONSelected.png";
            btnOpen.X = this.GetPictrueRealSize(397);
            btnOpen.Y = btnClose.Y;
            picSwitchBack.AddChidren(btnOpen);
            listControl.Add(btnOpen);
 
            //设置初始状态
            if (((LightBase)this.device).OnOffStatus == 1)
            {
                btnOpen.IsSelected = true;
            }
            else
            {
                btnClose.IsSelected = true;
            }
 
            btnClose.ButtonClickEvent += (sender, e) =>
            {
                if (btnClose.IsSelected == true) { return; }
                //发送开关命令
                this.SetSwitchCommand(false);
            };
            btnOpen.ButtonClickEvent += (sender, e) =>
            {
                if (btnOpen.IsSelected == true) { return; }
                //发送开关命令
                this.SetSwitchCommand(true);
            };
        }
 
        #endregion
 
        #region ■ 初始化插座类型_____________________
 
        /// <summary>
        /// 初始化插座类型控件
        /// </summary>
        /// <param name="frameWhiteBack"></param>
        private void InitPlugControl(FrameLayout frameWhiteBack)
        {
            //插座图片
            var picPlug = new PicViewControl(567, 567);
            picPlug.Y = Application.GetRealHeight(334);
            picPlug.UnSelectedImagePath = "Light/Plug.png";
            picPlug.SelectedImagePath = "Light/PlugSelected.png";
            picPlug.Gravity = Gravity.CenterHorizontal;
            frameWhiteBack.AddChidren(picPlug);
            listControl.Add(picPlug);
 
            //开关
            var btnSwitch = new IconViewControl(81);
            btnSwitch.UnSelectedImagePath = "Item/Switch.png";
            btnSwitch.SelectedImagePath = "Item/SwitchSelected.png";
            btnSwitch.Y = picPlug.Bottom + Application.GetRealHeight(89);
            btnSwitch.Gravity = Gravity.CenterHorizontal;
            frameWhiteBack.AddChidren(btnSwitch);
            listControl.Add(btnSwitch);
 
            //设置初始状态
            if (((LightBase)this.device).OnOffStatus == 1)
            {
                picPlug.IsSelected = true;
                btnSwitch.IsSelected = true;
            }
 
            picPlug.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SetSwitchCommand(!picPlug.IsSelected);
            };
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SetSwitchCommand(!btnSwitch.IsSelected);
            };
        }
 
        #endregion
 
        #region ■ 刷新开关状态_______________________
 
        /// <summary>
        /// 刷新开关状态
        /// </summary>
        /// <param name="isOpen">打开状态</param>
        private void RefreshSwitchStatu(bool isOpen)
        {
            //变更状态
            if (this.device.DfunctionType == DeviceFunctionType.A开关)
            {
                //开状态
                listControl[1].IsSelected = isOpen;
                //关状态 取反开状态
                listControl[0].IsSelected = !isOpen;
            }
            else
            {
                //开关以外
                listControl[0].IsSelected = isOpen;
                listControl[1].IsSelected = isOpen;
            }
            //设置状态文字
            this.SetStatuText(HdlDeviceCommonLogic.Current.GetMainPageDeviceStatuText(this.device));
        }
 
        #endregion
 
        #region ■ 是否获取网关反馈的结果_____________
 
        /// <summary>
        /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport)
        /// </summary>
        /// <param name="comandDiv">命令区分</param>
        /// <param name="report">上报数据</param>
        /// <returns></returns>
        public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report)
        {
            if (comandDiv == ReceiveComandDiv.A设备属性上报)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //变更卡片状态
                    this.RefreshSwitchStatu(((LightBase)this.device).OnOffStatus == 1);
                });
                return true;
            }
            return false;
        }
 
        #endregion
 
        #region ■ 发送开关命令_______________________
 
        /// <summary>
        /// 发送开关命令
        /// </summary>
        /// <param name="isOpen"></param>
        private void SetSwitchCommand(bool isOpen)
        {
            //如果住宅为虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
                //变更卡片状态
                this.RefreshSwitchStatu(((LightBase)this.device).OnOffStatus == 1);
                return;
            }
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(this.listControl, (result) =>
            {
                //接收到网关回复
                if (result == true)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //变更卡片状态
                        bool statu = ((LightBase)this.device).OnOffStatus == 1;
                        this.RefreshSwitchStatu(statu);
                    });
                }
            });
            if (isOpen == true)
            {
                //打开
                this.device.SwitchControl(1);
            }
            else
            {
                //关闭
                this.device.SwitchControl(0);
            }
        }
 
        #endregion
    }
}