陈嘉乐
2020-06-24 adb12dcdbb2ddaeac687c3aa9e57bb7ed459ab7e
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
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.Category.Controls
{
    /// <summary>
    /// 分类界面的窗帘设备行控件
    /// </summary>
    public class DeviceCurtainRowControl : DeviceRowCommon
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 打开控件
        /// </summary>
        private MostRightIconControl btnOpen = null;
        /// <summary>
        /// 停止控件
        /// </summary>
        private MostRightIconControl btnStop = null;
        /// <summary>
        /// 关闭控件
        /// </summary>
        private MostRightIconControl btnClose = null;
        /// <summary>
        /// 窗帘类型 4:开合帘 0:卷帘
        /// </summary>
        private int WcdType = -2;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="i_device"></param>
        public override void InitControl(CommonDevice i_device, Common.Room i_nowSelectRoom)
        {
            base.InitControl(i_device, i_nowSelectRoom);
 
            //添加跳转深度卡片信息事件
            this.AddDetailInfoEvent(i_device);
 
            //打开控件
            this.btnOpen = new MostRightIconControl(69, 69);
            btnOpen.btnIcon.UseClickStatu = true;
            this.frameTable.AddChidren(btnOpen, ChidrenBindMode.NotBind);
            btnOpen.InitControl();
            btnOpen.X = Application.GetRealWidth(625) - btnOpen.XOffset;
            btnOpen.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,直接修改缓存
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)i_device).WcdCurrentPositionLiftPercentage = 100;
                    base.RefreshControlInfo(i_device);
                    return;
                }
                ((Rollershade)i_device).CurtainUpDownStopControl(0);
            };
 
            //停止控件
            this.btnStop = new MostRightIconControl(69, 69);
            btnStop.btnIcon.UseClickStatu = true;
            btnStop.UnSelectedImagePath = "RollerShade/Stop.png";
            btnStop.SelectedImagePath = "RollerShade/StopSelected.png";
            this.frameTable.AddChidren(btnStop, ChidrenBindMode.NotBind);
            btnStop.InitControl();
            btnStop.X = Application.GetRealWidth(769) - btnOpen.XOffset;
            btnStop.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,此功能无效
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    ((Rollershade)i_device).CurtainUpDownStopControl(2);
                }
            };
 
            //关闭
            this.btnClose = new MostRightIconControl(69, 69);
            btnClose.btnIcon.UseClickStatu = true;
            this.frameTable.AddChidren(btnClose, ChidrenBindMode.NotBind);
            btnClose.InitControl();
            btnClose.X = Application.GetRealWidth(896) - btnOpen.XOffset;
            btnClose.ButtonClickEvent += (sender, e) =>
            {
                //如果住宅为虚拟住宅,直接修改缓存
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    ((Rollershade)i_device).WcdCurrentPositionLiftPercentage = 0;
                    base.RefreshControlInfo(i_device);
                    return;
                }
                ((Rollershade)i_device).CurtainUpDownStopControl(1);
            };
 
            //刷新图标控件的图标
            this.RefreshIconControlImage(i_device);
        }
 
        #endregion
 
        #region ■ 深度卡片信息_______________________
 
        /// <summary>
        /// 添加跳转深度卡片信息事件
        /// </summary>
        private void AddDetailInfoEvent(CommonDevice i_device)
        {
            //深度卡片信息
            this.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //窗帘类型的深度卡片界面
                var form = new MainPage.ControlForm.DeviceCurtainDetailCardForm();
                form.RowOrCardControl = this;
                form.AddForm(i_device, this.nowSelectRoom, 965, 1316);
                form.FormCloseEvent += this.CardDetailInfoBackEvent;
            };
        }
 
        #endregion
 
        #region ■ 检测设备打开状态___________________
 
        /// <summary>
        /// 检测设备打开状态
        /// </summary>
        /// <param name="i_device"></param>
        /// <returns></returns>
        public override bool CheckIsOpenStatu(CommonDevice i_device)
        {
            return ((Rollershade)i_device).WcdCurrentPositionLiftPercentage > 0;
        }
 
        #endregion
 
        #region ■ 发送获取状态命令___________________
 
        /// <summary>
        /// 发送获取状态命令
        /// </summary>
        public override void SendStatuComand()
        {
            //如果住宅为虚拟住宅,此功能无效
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
            //检测能否发送获取状态命令
            if (this.CheckCanSendStatuComand() == true)
            {
                HdlDeviceAttributeLogic.Current.SendCurtainStatuComand(this.device);
            }
            if (((Rollershade)this.device).WcdType == -1)
            {
                //读取窗帘类型
                ((Rollershade)this.device).ReadWcdType();
            }
        }
 
        #endregion
 
        #region ■ 刷新控件状态_______________________
 
        /// <summary>
        /// 刷新控件状态
        /// </summary>
        /// <param name="i_device"></param>
        public override void RefreshControlInfo(CommonDevice i_device)
        {
            //刷新图标控件的图标
            this.RefreshIconControlImage(i_device);
 
            base.RefreshControlInfo(i_device);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新图标控件的图标
        /// </summary>
        /// <param name="i_device"></param>
        private void RefreshIconControlImage(CommonDevice i_device)
        {
            //还没有初始化完成
            if (btnOpen == null) { return; }
 
            int wcdType = ((Rollershade)i_device).WcdType;
            if (this.WcdType == wcdType)
            {
                //无需变更
                return;
            }
            this.WcdType = wcdType;
            if (this.WcdType == 0)
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Up.png";
                btnOpen.SelectedImagePath = "RollerShade/UpSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Down.png";
                btnClose.SelectedImagePath = "RollerShade/DownSelected.png";
            }
            else
            {
                btnOpen.UnSelectedImagePath = "RollerShade/Open.png";
                btnOpen.SelectedImagePath = "RollerShade/OpenSelected.png";
                btnClose.UnSelectedImagePath = "RollerShade/Close.png";
                btnClose.SelectedImagePath = "RollerShade/CloseSelected.png";
            }
        }
 
        #endregion
    }
}