HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-08-11 26d1cdf2f5246c1ad7890e6740444c4a6a80e6fb
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
using Shared.Common;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.DevicePanel
{
    public class DataCorrectionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________ 
        /// <summary>
        /// 面板的回路
        /// </summary>
        private CommonDevice device;
        /// <summary>
        /// 保存完成按钮
        /// </summary>
        Button btnFinifh;
        /// <summary>
        /// 校正温度值
        /// </summary>
        double correctTValue = 0;
        /// <summary>
        /// 校正湿度值
        /// </summary>
        double correctHValue = 0;
        #endregion
 
        #region ■ 初始化____________________________ 
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_device">设备的某一回路</param>
        public void ShowForm(CommonDevice device)
        {
            this.device = device;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DataCorrection));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private async void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            TemperatureDataUI();
            TipUI();
        }
 
        #endregion
 
        #region ■ 温度设置_______________________ 
        /// <summary>
        ///  温度设置
        /// </summary>
        private void TemperatureDataUI()
        {
            var listview = new VerticalScrolViewLayout();
            listview.Height = Application.GetRealHeight(320);
            bodyFrameLayout.AddChidren(listview);
            listview.ScrollEnabled = false;
 
            for (int i = 0; i < 2; i++)
            {
                var rowLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(23 + 127),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                };
                listview.AddChidren(rowLayout);
 
                var devicePic = new Button()
                {
                    X = Application.GetRealWidth(58),
                    Y = Application.GetRealHeight(46),
                    Width = Application.GetMinRealAverage(81),
                    Height = Application.GetMinRealAverage(81),
                };
                rowLayout.AddChidren(devicePic);
 
                var btnName = new Button()
                {
                    Width = Application.GetRealWidth(790),
                    X = devicePic.Right + Application.GetRealWidth(20),
                    TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 15,
                };
                rowLayout.AddChidren(btnName);
 
                var tframeLayout = new FrameLayout()
                {
                    X = Application.GetRealWidth(714 - 29),
                    Y = Application.GetRealHeight(35),
                    Width = Application.GetMinRealAverage(118 + 98 * 2),
                    Height = Application.GetMinRealAverage(81),
                    BackgroundImagePath = "BindPic/CorrectTemperatureBackGround.png",
                };
                rowLayout.AddChidren(tframeLayout);
 
                var btnReduction = new Button()
                {
                    Width = Application.GetMinRealAverage(98),
                    Height = Application.GetMinRealAverage(81),
                };
                tframeLayout.AddChidren(btnReduction);
 
                var btnNum = new EditText()
                {
                    Width = Application.GetMinReal(115),
                    Height = Application.GetRealHeight(80),
                    X = Application.GetRealWidth(98),
                    Text = "0",
                    PlaceholderTextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                    TextSize = 20,
                    TextAlignment = TextAlignment.Center,
                };
                tframeLayout.AddChidren(btnNum);
 
                var btnAdd = new Button()
                {
                    X = Application.GetRealWidth(98 + 118),
                    Width = Application.GetMinRealAverage(98),
                    Height = Application.GetMinRealAverage(81),
                };
                tframeLayout.AddChidren(btnAdd);
 
                var line2 = new Button()
                {
                    Y = rowLayout.Height - 1,
                    X = devicePic.Right + Application.GetRealWidth(20),
                    Width = Application.GetRealWidth(965 - 116),
                    Height = 1,
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                };
                rowLayout.AddChidren(line2);
 
                int curIndex = i;
                if (curIndex == 0)
                {
                    devicePic.UnSelectedImagePath = "Device/SensorTemperature.png";
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.Temperature) + "  (℃)";
                }
                else
                {
                    line2.Visible = false;
                    devicePic.UnSelectedImagePath = "Device/SensorHumidity.png";
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.Humidity) + "  (%)";
                }
 
                btnNum.TextChangeEventHandler += (sender, e) =>
                {
                    if (!string.IsNullOrEmpty((sender as EditText).Text))
                    {
                        var curText = (sender as EditText).Text;
                        var textFir = curText.Substring(0, 1);
                        double curV;
                        var res = double.TryParse(curText, out curV);
                        if (!res)
                        {
                            if (textFir != "-")
                            {
                                curV = 0D;
                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NumTip), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                return;
                            }
                        }
                        if (curIndex == 0)
                        {
                            correctTValue = curV;
                        }
                        else
                        {
                            correctHValue = curV;
                        }
                    }
                };
 
                btnReduction.MouseDownEventHandler += async (sender, e) =>
                {
                    double vTemp = double.Parse(btnNum.Text);
                    vTemp -= 0.1;
                    btnNum.Text = vTemp.ToString();
                    if (curIndex == 0)
                    {
                        correctTValue = double.Parse(btnNum.Text);
                    }
                    else
                    {
                        correctHValue = double.Parse(btnNum.Text);
                    }
                };
 
                btnAdd.MouseDownEventHandler += async (sender, e) =>
                {
                    double vTemp = double.Parse(btnNum.Text);
                    vTemp += 0.1;
                    btnNum.Text = vTemp.ToString();
                    if (curIndex == 0)
                    {
                        correctTValue = double.Parse(btnNum.Text);
                    }
                    else
                    {
                        correctHValue = double.Parse(btnNum.Text);
                    }
                };
            }
        }
        #endregion
 
        #region ■ 底部提示_______________________ 
        /// <summary>
        ///  底部提示
        /// </summary>
        private void TipUI()
        {
            var bottomFrameLayout = new FrameLayout()
            {
                Y = Application.GetRealHeight(1426),
                Height = Application.GetMinRealAverage(58),
            };
            bodyFrameLayout.AddChidren(bottomFrameLayout);
 
            var temperatureAttentionPic = new Button()
            {
                Width = Application.GetMinRealAverage(58),
                Height = Application.GetMinRealAverage(58),
                UnSelectedImagePath = "BindPic/TemperaTureAttention.png"
            };
            bottomFrameLayout.AddChidren(temperatureAttentionPic);
 
            var btnText = new Button()
            {
                Width = Application.GetRealWidth(790),
                X = Application.GetRealWidth(56),
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 12,
                Text = Language.StringByID(R.MyInternationalizationString.DataCorrectionTip),
            };
            bottomFrameLayout.AddChidren(btnText);
 
            btnFinifh = new Button()
            {
                Width = Application.GetRealWidth(907),
                Height = Application.GetRealHeight(127),
                Y = Application.GetRealHeight(1426 + 58 + 12),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealHeight(127) / 2,
                TextID = R.MyInternationalizationString.Save,
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                IsBold = true,
                TextSize = 16,
            };
            bodyFrameLayout.AddChidren(btnFinifh);
            btnFinifh.MouseUpEventHandler += (sender, e) =>
            {
                SaveTarget();
            };
 
            bottomFrameLayout.Width = temperatureAttentionPic.Width + Application.GetRealWidth(10) + btnText.GetTextWidth();
            bottomFrameLayout.Gravity = Gravity.CenterHorizontal;
        }
        #endregion
 
        #region ■ 保存_______________________ 
        /// <summary>
        /// 保存 
        /// </summary>
        /// <param name="curControlDev"></param>
        void SaveTarget()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Start();
                    });
                    this.ShowProgressBar();
                    bool result = false;
                    int direction = 0;
                    double sendValue = 0;
                    //温度
                    sendValue = correctTValue;
                    if (correctTValue > 0)
                    {
                        direction = 1;
                    }
                    else if (correctTValue < 0)
                    {
                        direction = 2;
                        sendValue = System.Math.Abs(correctTValue);
                    }
 
                    result = await HdlDevicePanelLogic.Current.CorrectTemperature(device, sendValue, direction, 0);
                    if (result == false)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                        });
                        return;
                    }
                    //湿度
                    direction = 0;
                    sendValue = correctHValue;
                    if (correctHValue > 0)
                    {
                        direction = 1;
                    }
                    else if (correctHValue < 0)
                    {
                        direction = 2;
                        sendValue = (-1) * correctHValue;
                    }
                    result = await HdlDevicePanelLogic.Current.CorrectTemperature(device, sendValue, direction, 1);
                    if (result == false)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                        });
                        return;
                    }
                    Application.RunOnMainThread(() =>
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.SetSuccessXm), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        CommonPage.Loading.Hide();
                    });
                }
                catch { }
            });
        }
        #endregion
 
 
    }
}