黄学彪
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
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 System;
using System.Collections.Generic;
using Shared;
using Shared.Common;
using Shared.Phone;
using Shared.Phone.Device.Logic.LogicView;
using Shared.R;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Logic
{
    public class TimePage : FrameLayout
    {
        public TimePage()
        {
            Tag = "Logic";
        }
        public bool IsEditor;
        public string str1;
 
        Dictionary<string, string> timeBucketConditionsInfo = new Dictionary<string, string>();
        public void Show()
        {
 
            #region  上面的布局代码
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.TextID = MyInternationalizationString.selection;
            view.clickBtn.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); };
            #endregion
 
            #region  最下面的布局代码
            var middle = new FrameLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184 - 260),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
            //保存
            SaveView saveView = new SaveView();
            saveView.frameLayout.Y = middle.Bottom;
            this.AddChidren(saveView.Show());
            #endregion
 
            #region   -----时间范围  开始时间  结束时间
            #region   -----时间范围
 
            TypeView typeView = new TypeView();
            middle.AddChidren(typeView.Show());
            typeView.textBtn.TextID = MyInternationalizationString.type;
            typeView.titleBtn.Width = Application.GetRealWidth(630 + 70);
            typeView.titleBtn.TextID = MyInternationalizationString.timeframe;
            typeView.backBtn.Visible = false;
 
            #endregion
 
            #region  -----开始时间
 
            TypeView startView = new TypeView();
            startView.frameLayout.Y = typeView.frameLayout.Bottom;
            middle.AddChidren(startView.Show());
            startView.textBtn.TextID = MyInternationalizationString.starttime;
            startView.titleBtn.Tag = "0";
            #endregion
 
            #region  -----结束时间
 
            TypeView endView = new TypeView();
            endView.frameLayout.Y = startView.frameLayout.Bottom;
            endView.frameLayout.Height = Application.GetRealHeight(160 + 20);//最后一行增加20高度;
            middle.AddChidren(endView.Show());
            endView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;//改变最后一行线颜色;
            endView.textBtn.TextID = MyInternationalizationString.endtime;
            endView.titleBtn.Tag = "0";
 
            #endregion
            #endregion
 
            if (IsEditor)
            {
                if (str1 != null)
                {
 
                    string[] timestr = str1.Split('-');
                    string[] starttime = timestr[0].Split(':');
                    string[] endtime = timestr[1].Split(':');
                    string s1 = "", s2 = "";
                    if (starttime[1].Length < 2)
                    {
                        s1 = "0" + starttime[1];
                    }
                    else
                    {
                        s1 = starttime[1];
                    }
                    if (endtime[1].Length < 2)
                    {
                        s2 = "0" + endtime[1];
                    }
                    else
                    {
                        s2 = endtime[1];
                    }
                    startView.titleBtn.Text = starttime[0] + ":" + s1;
                    endView.titleBtn.Text = endtime[0] + ":" + s2;
 
                    //btnstarttime.Text = timestr[0];
                    //btnendtime.Text = timestr[1];
                    if (timeBucketConditionsInfo.ContainsKey("StartHour"))
                    {
                        timeBucketConditionsInfo.Remove("StartHour");
                    }
                    if (timeBucketConditionsInfo.ContainsKey("StartMin"))
                    {
                        timeBucketConditionsInfo.Remove("StartMin");
                    }
                    if (timeBucketConditionsInfo.ContainsKey("StopHour"))
                    {
                        timeBucketConditionsInfo.Remove("StopHour");
                    }
                    if (timeBucketConditionsInfo.ContainsKey("StopMin"))
                    {
                        timeBucketConditionsInfo.Remove("StopMin");
                    }
                    timeBucketConditionsInfo.Add("StartHour", starttime[0]);
                    timeBucketConditionsInfo.Add("StartMin", starttime[1]);
                    timeBucketConditionsInfo.Add("StopHour", endtime[0]);
                    timeBucketConditionsInfo.Add("StopMin", endtime[1]);
                    startView.titleBtn.Tag = int.Parse(starttime[0]) * 60 + int.Parse(starttime[1]);
                    endView.titleBtn.Tag = int.Parse(endtime[0]) * 60 + int.Parse(endtime[1]);
                }
 
            }
 
            startView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
 
                var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicTranslucentColor };
                AddChidren(flMain);
                flMain.MouseUpEventHandler += (sender11, e11) =>
                {
                    flMain.RemoveFromParent();
                };
 
                var timeview = new TimeView
                {
                    Y = Application.GetRealHeight(1920 - 600),
                    Height = Application.GetRealHeight(600),
                    BackgroundColor = ZigbeeColor.Current.LogicTimeViewColor,
                    Width = Application.GetRealWidth(1080),
                };
                flMain.AddChidren(timeview);
 
 
                var btnSave = new Button
                {
                    Y = Application.GetRealHeight(1920 - 600),
                    Width = Application.GetRealWidth(200),
                    Height = Application.GetRealHeight(150),
                    Text = Language.StringByID(MyInternationalizationString.complete),
                    // TextColor = 0xFF121212,
                    TextColor = ZigbeeColor.Current.LogicTimeViewSaveButton,
                    //TextAlignment = TextAlignment.CenterRight
                    X = Application.GetRealWidth(1080 - 200),
                };
                flMain.AddChidren(btnSave);
 
                btnSave.MouseUpEventHandler += (sender2, e2) =>
                {
                    flMain.RemoveFromParent();
 
                    var startval = timeview.Hour * 60 + timeview.Minute;
 
                    if (endView.titleBtn.Tag.ToString() != "0" && startval.ToString() == endView.titleBtn.Tag.ToString())
                    {
 
                        var alert = new ShowMsgControl(ShowMsgType.Normal,
                                        Language.StringByID(MyInternationalizationString.nottime),
                                       Language.StringByID(MyInternationalizationString.confrim));
                        alert.Show();
                        return;
                    }
                    if (endView.titleBtn.Tag.ToString() != "0" && startval > int.Parse(endView.titleBtn.Tag.ToString()))
                    {
 
                        var alert = new ShowMsgControl(ShowMsgType.Normal,
                                        Language.StringByID(MyInternationalizationString.timesetting),
                                       Language.StringByID(MyInternationalizationString.confrim));
                        alert.Show();
                        return;
                    }
                    if (timeBucketConditionsInfo.ContainsKey("StartHour"))
                    {
                        timeBucketConditionsInfo.Remove("StartHour");
                    }
                    if (timeBucketConditionsInfo.ContainsKey("StartMin"))
                    {
                        timeBucketConditionsInfo.Remove("StartMin");
                    }
                    startView.titleBtn.Tag = timeview.Hour * 60 + timeview.Minute;
                    timeBucketConditionsInfo.Add("StartHour", timeview.Hour.ToString());
                    timeBucketConditionsInfo.Add("StartMin", timeview.Minute.ToString());
                    startView.titleBtn.Text = timeview.Hour.ToString() + ":" + (timeview.Minute.ToString().Length < 2 ? "0" + timeview.Minute.ToString() : timeview.Minute.ToString());
                };
            };
 
            endView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
             {
 
                 var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicTranslucentColor };
                 AddChidren(flMain);
                 flMain.MouseUpEventHandler += (sender11, e11) =>
                 {
                     flMain.RemoveFromParent();
                 };
 
                 var timeview = new TimeView
                 {
                     Y = Application.GetRealHeight(1920 - 600),
                     Height = Application.GetRealHeight(600),
                     BackgroundColor = ZigbeeColor.Current.LogicTimeViewColor,
                     Width = Application.GetRealWidth(1080),
                 };
                 flMain.AddChidren(timeview);
 
 
                 var btnSave = new Button
                 {
                     Y = Application.GetRealHeight(1920 - 600),
                     Width = Application.GetRealWidth(200),
                     Height = Application.GetRealHeight(150),
                     Text = Language.StringByID(MyInternationalizationString.complete),
                    //TextColor = 0xFF121212,
                    TextColor = ZigbeeColor.Current.LogicTimeViewSaveButton,
                    //TextAlignment = TextAlignment.CenterRight
                    X = Application.GetRealWidth(1080 - 200),
                 };
                 flMain.AddChidren(btnSave);
 
                 btnSave.MouseUpEventHandler += (sender2, e2) =>
                 {
                     flMain.RemoveFromParent();
 
                     var endval = timeview.Hour * 60 + timeview.Minute;
 
                     if (startView.titleBtn.Tag.ToString() != "0" && endval.ToString() == startView.titleBtn.Tag.ToString())
                     {
 
                         var alert = new ShowMsgControl(ShowMsgType.Normal,
                                         Language.StringByID(MyInternationalizationString.nottime),
                                        Language.StringByID(MyInternationalizationString.confrim));
                         alert.Show();
                         return;
                     }
                     if (startView.titleBtn.Tag.ToString() != "0" && endval < int.Parse(startView.titleBtn.Tag.ToString()))
                     {
 
                         var alert = new ShowMsgControl(ShowMsgType.Normal,
                                         Language.StringByID(MyInternationalizationString.timesetting),
                                        Language.StringByID(MyInternationalizationString.confrim));
                         alert.Show();
                         return;
                     }
 
                     if (timeBucketConditionsInfo.ContainsKey("StopHour"))
                     {
                         timeBucketConditionsInfo.Remove("StopHour");
                     }
                     if (timeBucketConditionsInfo.ContainsKey("StopMin"))
                     {
                         timeBucketConditionsInfo.Remove("StopMin");
                     }
                     endView.titleBtn.Tag = timeview.Hour * 60 + timeview.Minute;
                     timeBucketConditionsInfo.Add("StopHour", timeview.Hour.ToString());
                     timeBucketConditionsInfo.Add("StopMin", timeview.Minute.ToString());
                     endView.titleBtn.Text = timeview.Hour.ToString() + ":" + (timeview.Minute.ToString().Length < 2 ? "0" + timeview.Minute.ToString() : timeview.Minute.ToString());
                 };
             };
 
 
            ///完成点击事件
            saveView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
             {
                 if (timeBucketConditionsInfo.ContainsKey("Type"))
                 {
                     timeBucketConditionsInfo.Remove("Type");
                 }
                 if (timeBucketConditionsInfo.ContainsKey("IsValid"))
                 {
                     timeBucketConditionsInfo.Remove("IsValid");
                 }
                 timeBucketConditionsInfo.Add("Type", "5");
                 timeBucketConditionsInfo.Add("IsValid", "1");
 
                 if (string.IsNullOrEmpty(startView.titleBtn.Text) || string.IsNullOrEmpty(endView.titleBtn.Text))
                 {
                     var alert = new ShowMsgControl(ShowMsgType.Normal,
                                            Language.StringByID(MyInternationalizationString.completeNext),
                                           Language.StringByID(MyInternationalizationString.confrim));
                     alert.Show();
                     return;
                 }
                 if (startView.titleBtn.Text == endView.titleBtn.Text)
                 {
                     var alert = new ShowMsgControl(ShowMsgType.Normal,
                                            Language.StringByID(MyInternationalizationString.sametime),
                                           Language.StringByID(MyInternationalizationString.confrim));
                     alert.Show();
                     return;
                 }
 
                 if (IsEditor)
                 {
                     for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
                     {
                         if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == "5")
                         {
 
                             var timeBucketInfo = Common.Logic.CurrentLogic.Conditions[i];
                             var s = timeBucketInfo["StartHour"] + ":" + timeBucketInfo["StartMin"] + "-" + timeBucketInfo["StopHour"] + ":" + timeBucketInfo["StopMin"];
                             if (str1 == s)
                             {
                                 Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                                 Common.Logic.CurrentLogic.Conditions.Insert(i, timeBucketConditionsInfo);
                             }
 
                         }
                     }
                 }
                 else
                 {
                     Common.Logic.CurrentLogic.Conditions.Add(timeBucketConditionsInfo);
                 }
 
                //LogicIfon.logicIfon.Addconditions(timeBucketConditionsInfo,timeBucketConditionsInfo.Type);
 
                var logicCommunalPage = new LogicCommunalPage { };
                 UserView.HomePage.Instance.AddChidren(logicCommunalPage);
                 UserView.HomePage.Instance.PageIndex += 1;
                 logicCommunalPage.Show(() => { });
 
             };
        }
 
    }
}