1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
using System;
namespace Shared.SimpleControl.Phone
{
    public class UserSensorSettingTempPushDialog
    {
        string TriggerTemp = "";
        public UserSensorSettingTempPushDialog()
        {
            TriggerTemp = Language.StringByID (R.MyInternationalizationString.TriggerTemp);
        }
        public void ShowAutomationChoose (SensorAutomationDevice device,byte targetPushLoopId)
        {
            MainPage.Loading.Start ("Please wait...");
            System.Threading.Tasks.Task.Run (() => {
                try {
                    var pushRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushMessage, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, device.LoopID, 255 });
                    System.Collections.Generic.List<byte []> pushTempList = new System.Collections.Generic.List<byte []> ();
                    Application.RunOnMainThread (() => {
                        if (pushRevertBytes == null) {
                            new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            pushRevertBytes = new byte [27];
                            return;
                        }
                        Dialog dialog = new Dialog ();
 
                        FrameLayout dialogView = new FrameLayout () {
                            BackgroundColor = SkinStyle.Current.White20Transparent,
                        };
                        dialog.AddChidren (dialogView);
                        dialogView.MouseUpEventHandler += (ds, fdd) => {
                            dialog.Close ();
                        };
 
                        var verticalScrolView = new VerticalScrolViewLayout () {
                            Y = Application.GetRealHeight (1138 - 400 ),
                            Height = Application.GetRealHeight (100 * 4),
                            BackgroundColor = SkinStyle.Current.DialogColor
                        };
                        dialogView.AddChidren (verticalScrolView);
 
                        for (int i = targetPushLoopId; i < targetPushLoopId + 4; i++) {
                            int pushTemp = 0;
                            var pushValuesRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushValues, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, (byte)i });
                            if(pushValuesRevertBytes == null)
                            {
                                pushValuesRevertBytes = new byte [] { device.DevicePushType, (byte)i, 0, 0, 0, 255 };
                            }
                            pushTemp = pushValuesRevertBytes [4] * 256 + pushValuesRevertBytes [5];
                            pushTempList.Add (pushValuesRevertBytes);
 
                            #region ---设置---
                            RowLayout setTargetTemp1View = new RowLayout () {
                                Height = Application.GetRealHeight (100),
                            };
                            verticalScrolView.AddChidren (setTargetTemp1View);
                            string setTemp = (pushTemp > 40448 ? ((40448 - pushTemp) / 10).ToString () : ((pushTemp / 10).ToString ())) + "°C";
                            Button btnTip = new Button () {
                                TextColor = SkinStyle.Current.TextColor,
                                TextAlignment = TextAlignment.Center,
                                Tag = i
                            };
                            setTargetTemp1View.AddChidren (btnTip);
                            if (targetPushLoopId == 0) {
                                btnTip.Text = TriggerTemp + ":> " + setTemp;
                            } else {
                                btnTip.Text = TriggerTemp + ":< " + setTemp;
                            }
                            btnTip.MouseUpEventHandler += (dfdd, fffd) => {
                                //var uslp = new UserSensorAutomationTargetListPage ();
                                //UserMiddle.DevicePageView.AddChidren (uslp);
                                //uslp.ShowPage (device, Convert.ToInt32(btnTip.Tag));
                                //UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
                                dialog.Close ();
                            };
                            #endregion
                        }
                        dialog.Show ();
                    });
                } catch { } finally {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                    });
                }
            });
        }
 
 
        public void ShowSettingTempPushDialog (Sensor device, byte targetPushLoopId,byte[] pushEnableRevertBytes)
        {
            MainPage.Loading.Start ("Please wait...");
            System.Threading.Tasks.Task.Run (() => {
                try {
                    var pushRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushMessage, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, device.LoopID, 255 });
                    System.Collections.Generic.List<byte []> pushTempList = new System.Collections.Generic.List<byte []> ();
                    Application.RunOnMainThread (() => {
                        if (pushRevertBytes == null) {
                            new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            pushRevertBytes = new byte [27];
                            return;
                        }
                        Dialog dialog = new Dialog ();
 
                        FrameLayout bodyView = new FrameLayout () {
                            BackgroundColor = SkinStyle.Current.DialogColor,
                        };
                        dialog.AddChidren (bodyView);
 
                        Button btnDialogTitle = new Button () {
                            Height = Application.GetRealHeight (126),
                            TextID = R.MyInternationalizationString.Overheat,
                            TextColor = SkinStyle.Current.TextColor1,
                            BackgroundColor = SkinStyle.Current.DialogTitle,
                            TextAlignment = TextAlignment.Center,
                            TextSize = 21,
                            Padding = new Padding (20, 0, 0, 0)
                        };
                        bodyView.AddChidren (btnDialogTitle);
                        if (targetPushLoopId == 4) {
                            btnDialogTitle.TextID = R.MyInternationalizationString.Overcooling;
                        }
 
                        VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout () {
                            Y = Application.GetRealHeight (126),
                            Height = Application.GetRealHeight (1136 - 126 - 110),
                            BackgroundColor = SkinStyle.Current.DialogColor,
                        };
                        bodyView.AddChidren (verticalScrolView);
 
 
                        for (int i = targetPushLoopId; i < targetPushLoopId + 4; i++) {
                            int pushTemp = 0;
                            var pushValuesRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushValues, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, (byte)i });
                            if (pushValuesRevertBytes == null) {
                                pushValuesRevertBytes = new byte [] { device.DevicePushType, (byte)i, 0, 0, 0, 255 };
                            }
                            if (targetPushLoopId == 3) {
                                pushTemp = pushValuesRevertBytes [4] * 256 + pushValuesRevertBytes [5];
                            } else {
                                pushTemp = pushValuesRevertBytes [2] * 256 + pushValuesRevertBytes [3];
                            }
                            pushTempList.Add (pushValuesRevertBytes);
 
                            #region ---温度推送设置---
                            RowLayout setTargetTemp1View = new RowLayout () {
                                Height = Application.GetRealHeight (200),
                            };
                            verticalScrolView.AddChidren (setTargetTemp1View);
                            string setTemp = (pushTemp > 40448 ? ((40448 - pushTemp) / 10).ToString () : ((pushTemp / 10).ToString ())) + "°C";
                            Button btnTip = new Button () {
                                X = Application.GetRealWidth (30),
                                Width = Application.GetRealWidth (300),
                                Height = Application.GetRealHeight(80),
                                TextColor = SkinStyle.Current.TextColor,
                                TextAlignment = TextAlignment.CenterLeft,
                            };
                            setTargetTemp1View.AddChidren (btnTip);
                            if (targetPushLoopId == 0) {
                                btnTip.Text = TriggerTemp + ":> " + setTemp;
                            } else {
                                btnTip.Text = TriggerTemp + ":< " + setTemp;
                            }
 
                            Button btnMin = new Button () {
                                X = Application.GetRealWidth (30),
                                Gravity = Gravity.CenterVertical,
                                Width = Application.GetRealWidth (80),
                                Text = "-20°C",
                                TextColor = SkinStyle.Current.TextColor,
                                TextAlignment = TextAlignment.CenterLeft
                            };
                            setTargetTemp1View.AddChidren (btnMin);
 
                            var tempSeekBarFrame = new FrameLayout () {
                                Width = Application.GetRealWidth (550 - 120),
                                Height = Application.GetRealHeight (80),
                                X = Application.GetRealWidth (10) + btnMin.Right,
                                Gravity = Gravity.CenterVertical
                            };
                            setTargetTemp1View.AddChidren (tempSeekBarFrame);
                            var horizontalSeekBar = new HorizontalSeekBar () {
                                ThumbColor = SkinStyle.Current.SelectedColor,
                                Max = 60,
                                Progress = (pushTemp > 40448 ? ( (pushTemp - 40448) / 10) : ( (pushTemp / 10))) +20 ,
                            };
                            tempSeekBarFrame.AddChidren (horizontalSeekBar);
                            Button btnMax = new Button () {
                                Width = Application.GetRealWidth (90),
                                Height = Application.GetRealHeight (80),
                                X = tempSeekBarFrame.Right + Application.GetRealWidth (10),
                                Gravity = Gravity.CenterVertical,
                                Text = 40 + "°C",
                                TextAlignment = TextAlignment.CenterLeft,
                                TextColor = SkinStyle.Current.TextColor
                            };
                            setTargetTemp1View.AddChidren (btnMax);
                            if (targetPushLoopId == 0) {
                                horizontalSeekBar.ProgressColor = 0xFFCADBE1;
                                horizontalSeekBar.BackgroundColor = 0xFFFF0000;
                            } else {
                                horizontalSeekBar.BackgroundColor = 0xFFCADBE1;
                                horizontalSeekBar.ProgressColor = 0xFF6BDFFE;
                            }
                            horizontalSeekBar.ProgressChanged += (sender22, e4) => {
                                if (targetPushLoopId == 0) {
                                    btnTip.Text = TriggerTemp + ":> " + (horizontalSeekBar.Progress - 20) + "°C";
                                } else {
                                    btnTip.Text = TriggerTemp + ":< " + (horizontalSeekBar.Progress - 20) + "°C";
                                }
                                if (20 > e4) {
                                    pushTemp = (20 - e4) * 10 + 40448;
                                } else {
                                    pushTemp = (e4 - 20) * 10;
                                }
                            };
                            horizontalSeekBar.MouseUpEventHandler += (asss, ddd) => {
                                if (targetPushLoopId == 3) {
                                    pushValuesRevertBytes [2] = 40848 / 256;
                                    pushValuesRevertBytes [3] = 40848 % 256;
                                    pushValuesRevertBytes [4] = (byte)(pushTemp / 256);
                                    pushValuesRevertBytes [5] = (byte)(pushTemp % 256);
                                } else {
                                    pushValuesRevertBytes [2] = (byte)(pushTemp / 256);
                                    pushValuesRevertBytes [3] = (byte)(pushTemp % 256);
                                    pushValuesRevertBytes [4] = 1250 / 256;
                                    pushValuesRevertBytes [5] = 1250 % 256;
                                }
                            };
 
                            Button btnPushEnable = new Button () {
                                X = Application.GetRealWidth (300),
                                Y = horizontalSeekBar.Bottom+ Application.GetRealHeight(40),
                                Width = Application.GetRealWidth (300),
                                Height = Application.GetRealHeight (80),
                                //Text = "推送使能:关",
                                TextID = R.MyInternationalizationString.PushEnableClose,
                                TextColor = SkinStyle.Current.TextColor,
                                SelectedTextColor = SkinStyle.Current.TextColor,
                                TextAlignment = TextAlignment.CenterRight,
                                Tag = i,
                            };
                            setTargetTemp1View.AddChidren (btnPushEnable);
                            if (pushEnableRevertBytes [3 + 3 * i] == 0) {
                                btnPushEnable.TextID = R.MyInternationalizationString.PushEnableClose;
                                btnPushEnable.IsSelected = false;
                            } else {
                                btnPushEnable.TextID = R.MyInternationalizationString.PushEnableOpen;
                                //btnPushEnable.Text = "推送使能:开";
                                btnPushEnable.IsSelected = true;
                            }
                            btnPushEnable.MouseUpEventHandler += (ddd, sss) => {
                                MainPage.Loading.Start ("Saving...");
                                byte setPushValua = btnPushEnable.IsSelected == true ? (byte)0 : (byte)1;
                                System.Threading.Tasks.Task.Run (() => {
                                    try {
                                        var setPushRevertBytes = Control.ControlBytesSendHasReturn (Command.SetSensorPushMessage, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, device.LoopID, Convert.ToByte(((Button)ddd).Tag), setPushValua, 255, 255 });
                                        Application.RunOnMainThread (() => {
                                            if (setPushRevertBytes == null) {
                                                new Alert ("", Language.StringByID (R.MyInternationalizationString.TargetsSetFail), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                            } else {
                                                if (btnPushEnable.IsSelected) {
                                                    btnPushEnable.TextID = R.MyInternationalizationString.PushEnableClose;
                                                    //btnPushEnable.Text = "推送使能:关";
                                                    btnPushEnable.IsSelected = false;
                                                } else {
                                                    btnPushEnable.TextID = R.MyInternationalizationString.PushEnableOpen;
                                                    //btnPushEnable.Text = "推送使能:开";
                                                    btnPushEnable.IsSelected = true;
                                                }
                                                pushEnableRevertBytes [3 + 3 * Convert.ToByte (((Button)ddd).Tag)] = setPushValua;
                                            }
                                        });
                                    } catch (Exception ex) {
                                        Console.WriteLine (ex.Message);
                                    } finally {
                                        Application.RunOnMainThread (() => {
                                            MainPage.Loading.Hide ();
                                        });
                                    }
                                });
                            };
                            #endregion
                        }
 
                        Button btnClose = new Button () {
                            Y = bodyView.Height - Application.GetRealHeight (110),
                            Width = Application.GetRealWidth (319),
                            Height = Application.GetRealHeight (110),
                            TextID = R.MyInternationalizationString.Close,
                            TextColor = SkinStyle.Current.TextColor1,
                            BackgroundColor = SkinStyle.Current.DialogTitle,
                        };
                        bodyView.AddChidren (btnClose);
                        btnClose.MouseUpEventHandler += (kkk, ddd) => {
                            dialog.Close ();
                        };
 
                        Button btnSave = new Button () {
                            Y = btnClose.Y,
                            X = btnClose.Right + 1,
                            Width = Application.GetRealWidth (319),
                            Height = btnClose.Height,
                            TextID = R.MyInternationalizationString.SAVE,
                            TextColor = SkinStyle.Current.TextColor1,
                            BackgroundColor = SkinStyle.Current.DialogTitle,
                        };
                        bodyView.AddChidren (btnSave);
                        btnSave.MouseUpEventHandler += (kkk, ddd) => {
                            MainPage.Loading.Start ("Saving...");
                            System.Threading.Tasks.Task.Run (() => {
                                try {
                                    foreach (var sendPushBytes in pushTempList) {
                                        var setPushValuesACK = Control.ControlBytesSendHasReturn (Command.SetSensorPushValues, device.SubnetID, device.DeviceID, sendPushBytes);
                                        if (setPushValuesACK == null) {
                                            Application.RunOnMainThread (() => {
                                                new Alert ("", Language.StringByID (R.MyInternationalizationString.TargetsSetFail), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                            });
                                        } else {
                                            Application.RunOnMainThread (() => {
                                                dialog.Close ();
                                            });
                                        }
                                    }
                                } catch { } finally {
                                    Application.RunOnMainThread (() => {
                                        MainPage.Loading.Hide ();
                                    });
                                }
                            });
                        };
 
                        dialog.Show ();
                    });
                } catch { } finally {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                    });
                }
            });
        }
    }
}