黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceAirConditioner
{
    /// <summary>
    /// 空调模式的界面
    /// </summary>
    public class AirConditionerModeForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 当前选择的网关
        /// </summary>
        private AC deviceAc = null;
        /// <summary>
        /// 上报的数据(用二进制来玩自定义模式 0:制冷 1:制热 2:送风 3:除湿 4:自动 5~7:备用)
        /// </summary>
        private string reportValue = null;
        /// <summary>
        /// 旧的数据
        /// </summary>
        private string oldReportValue = null;
        /// <summary>
        /// 固定预留的数据
        /// </summary>
        private string fixValue = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_deviceAc">选择的空调回路</param>
        public void ShowForm(AC i_deviceAc)
        {
            this.deviceAc = i_deviceAc;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAirConditionerMode));
 
            //读取空调自定义模式
            this.ReadAirConditionerModeSupport();
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息 ☆☆☆☆☆
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var listView = new VerticalListControl(29);
            listView.Y = Application.GetRealHeight(-6);
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
            bodyFrameLayout.AddChidren(listView);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //开启进度条
                this.ShowProgressBar();
                int timeOut = 0;
                while (this.reportValue == null && timeOut <= 30)
                {
                    System.Threading.Thread.Sleep(100);
                    timeOut++;
                }
                if (this.reportValue == null)
                {
                    //获取空调模式失败
                    string msg = Language.StringByID(R.MyInternationalizationString.uGetAcModeFail);
                    msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时");
                    this.ShowMassage(ShowMsgType.Tip, msg);
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar();
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //制冷
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Cool2.png", Language.StringByID(R.MyInternationalizationString.uMode_Cool), 0);
                    //制热
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Heat2.png", Language.StringByID(R.MyInternationalizationString.uMode_Heat), 1);
                    //自动
                    this.AddAirConditionerModeRow(listView, "AC/Mode_AutoSelected.png", Language.StringByID(R.MyInternationalizationString.uMode_Auto), 4);
                    //送风
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Fan2.png", Language.StringByID(R.MyInternationalizationString.uMode_FanOnly), 2);
                    //除湿
                    this.AddAirConditionerModeRow(listView, "AC/Mode_Dry2.png", Language.StringByID(R.MyInternationalizationString.uMode_Dry), 3);
 
                    listView.AdjustRealHeight(Application.GetRealHeight(23));
 
                    //保存
                    var btnOk = new BottomClickButton();
                    btnOk.TextID = R.MyInternationalizationString.uSave;
                    bodyFrameLayout.AddChidren(btnOk);
                    btnOk.ButtonClickEvent += (sender, e) =>
                    {
                        if (this.oldReportValue == this.reportValue)
                        {
                            //数据相同,不需要修改
                            this.CloseForm();
                            return;
                        }
                        //将二进制转换为十进制
                        var data = Convert.ToInt32(this.fixValue + this.reportValue, 2);
                        var result = HdlDeviceAirConditionerLogic.Current.SetAcModeSupport(deviceAc, data);
                        if (result == true)
                        {
                            //更改缓存
                            for (int i = 0; i < this.reportValue.Length; i++)
                            {
                                deviceAc.listSupportMode[i] = Convert.ToInt32(reportValue[i].ToString());
                            }
                            deviceAc.ReSave();
                            this.CloseForm();
                        }
                    };
                    //如果是展示模板
                    if (Common.Config.Instance.Home.IsShowTemplate == true)
                    {
                        btnOk.CanClick = false;
                    }
                });
            });
        }
 
        /// <summary>
        /// 添加空调模式行
        /// </summary>
        /// <param name="listView">列表控件</param>
        /// <param name="imagePath">图片地址</param>
        /// <param name="textValue">显示文本</param>
        /// <param name="div">区分</param>
        private void AddAirConditionerModeRow(VerticalListControl listView, string imagePath, string textValue, int div)
        {
            var rowFrame = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(rowFrame);
            //图标
            var btnIcon = rowFrame.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = imagePath;
            //显示文本
            var btnText = rowFrame.AddLeftCaption(textValue, 400);
            btnText.TextSize = 15;
            if (div != 3)
            {
                //底线
                rowFrame.AddBottomLine();
            }
            //选择
            var btnSelect = rowFrame.AddMostRightEmptyIcon(58, 58);
            if (this.reportValue[div] == '0')
            {
                btnSelect.Visible = false;
            }
            btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
            rowFrame.ButtonClickEvent += (sender, e) =>
            {
                btnSelect.Visible = !btnSelect.Visible;
                //变更值
                if (btnSelect.Visible == true)
                {
                    this.reportValue = reportValue.Substring(0, div) + "1" + reportValue.Substring(div + 1);
                }
                else
                {
                    this.reportValue = reportValue.Substring(0, div) + "0" + reportValue.Substring(div + 1);
                }
            };
            //如果是展示模板
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                rowFrame.CanClick = false;
            }
        }
 
        #endregion
 
        #region ■ 读取空调自定义模式_________________
 
        /// <summary>
        /// 读取空调自定义模式 ☆☆☆☆☆
        /// </summary>
        private void ReadAirConditionerModeSupport()
        {
            //如果是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
            {
                var data = HdlTemplateDeviceDataLogic.Current.GetAcModeSupport(deviceAc);
                //转换为二进制
                var value = Convert.ToString(data, 2).PadLeft(16, '0');
                //这五个设置是放在后面的
                this.fixValue = value.Substring(0, value.Length - 5);
                this.reportValue = value.Substring(this.fixValue.Length);
                oldReportValue = reportValue;
                return;
            }
 
            string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(deviceAc);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReadAirConditionerModeSupport", ReceiveComandDiv.A设备属性上报, (report) =>
            {
                string checkKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(report);
                if (checkKeys != mainkeys || report.DeviceStatusReport.CluterID != 513)
                {
                    return;
                }
                for (int i = 0; i < report.DeviceStatusReport.AttriBute.Count; i++)
                {
                    var data = report.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 4099)
                    {
                        HdlGatewayReceiveLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
                        //转换为二进制
                        var value = Convert.ToString(data.AttriButeData, 2).PadLeft(16, '0');
                        //这五个设置是放在后面的
                        this.fixValue = value.Substring(0, value.Length - 5);
                        this.reportValue = value.Substring(this.fixValue.Length);
                        oldReportValue = reportValue;
                    }
                }
            });
            //发送读取空调自定义模式
            deviceAc.ReadModeSupport();
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            HdlGatewayReceiveLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
 
            base.CloseFormBefore();
        }
 
        #endregion
    }
}