JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using System.Collections.Generic;
using Shared;
using Shared.SimpleControl.R;
using SmartHome;
namespace SuperGateWay
{
    public class WeekPage : FrameLayout
    {
        public WeekPage ()
        {
            Tag = "Logic";
        }
        public void Show (GateWay superGateWay, Action<List<int>> action)
        {
            var weeklist = new List<string> ();
            var objects = new List<int> ();
            this.AddChidren (new Button {
                Height = Application.GetRealHeight (30),
                BackgroundColor = 0xFF1F1F1F,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (100),
                Y = Application.GetRealHeight (30),
                BackgroundColor = 0xFF1F1F1F,
            };
            AddChidren (topFrameLayout);
 
            var titleName = new Button {
                TextID = MyInternationalizationString.cycle,
                TextSize = 17,
            };
            topFrameLayout.AddChidren (titleName);
 
            var hdl = new Button {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Logo/Logo.png",
            };
            topFrameLayout.AddChidren (hdl);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
                if (action != null) {
                    action (objects);
                }
            };
 
            var titlerl = new RowLayout {
                Height = Application.GetRealHeight (100),
                BackgroundColor = 0xff0f0f0f,
                Y = Application.GetRealHeight (130),
            };
            AddChidren (titlerl);
 
            titlerl.AddChidren (
             new Button {
                 X = Application.GetRealWidth (40),
                 //Text = "请选择重复执行周期",
                 TextID = MyInternationalizationString.repeat,
                 TextSize = 17,
                 TextAlignment = TextAlignment.CenterLeft
             }
            );
 
            var middle = new VerticalScrolViewLayout ();
            middle.Y = titlerl.Bottom;
            middle.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 100);
            middle.BackgroundColor = 0xff2F2F2F;
            this.AddChidren (middle);
 
            var cyclelist = new List<string> ();
 
            if(Logic.CurrentLogic.date.ContainsKey ("type")) {
                var type = Logic.CurrentLogic.date ["type"]?.ToString ();
                if (type == "week") {
                    var weekvalue = Newtonsoft.Json.JsonConvert.DeserializeObject<int []> (Newtonsoft.Json.JsonConvert.SerializeObject (Logic.CurrentLogic.date ["week"]));
                    for (int i = 0; i < 7; i++) {
                        int a = Array.IndexOf (weekvalue, i);
                        if (a != -1) {
                            ///周 
                            if (i == 1) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.mon));
                            } else if (i == 2) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.tue));
                            } else if (i == 3) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.wed));
                            } else if (i == 4) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.thu));
                            } else if (i == 5) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.frl));
                            } else if (i == 6) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.sat));
                            } else if (i == 0) {
                                weeklist.Add (Language.StringByID (MyInternationalizationString.sun));
                            }
                        }
                    }
 
                }
            }
                    
            cyclelist.AddRange (new string [] {
                        Language.StringByID(MyInternationalizationString.mon),
                        Language.StringByID(MyInternationalizationString.tue),
                        Language.StringByID(MyInternationalizationString.wed),
                        Language.StringByID(MyInternationalizationString.thu),
                        Language.StringByID(MyInternationalizationString.frl),
                        Language.StringByID(MyInternationalizationString.sat),
                        Language.StringByID(MyInternationalizationString.sun),
            });
            foreach (var name in cyclelist) {
                var cyclerwLayout = new RowLayout {
                    Height = Application.GetRealHeight (100),
                };
                middle.AddChidren (cyclerwLayout);
 
                var btnname = new Button {
                    X = Application.GetRealWidth (40),
                    Width = Application.GetRealWidth (350),
                    Gravity = Gravity.CenterVertical,
                    TextAlignment = TextAlignment.CenterLeft,
                    Text = name,
                };
                cyclerwLayout.AddChidren (btnname);
 
                var btnCheck = new Button {
                    Width = Application.GetRealWidth (60),
                    Height = Application.GetRealHeight (59),
                    Gravity = Gravity.CenterVertical,
                    X = Application.GetRealWidth (520),
                    SelectedImagePath = "Light/CheckOn.png",
                    UnSelectedImagePath = "Light/Check.png",
                };
                cyclerwLayout.AddChidren (btnCheck);
 
                var str = weeklist.Find ((o) => { return o == name; });
                if (str != null) {
                    btnCheck.IsSelected = true;
                }
                ///选中时间 
                btnCheck.MouseUpEventHandler += (sender1, e1) => {
                    //var objects = new List<object> ();
                    objects.Clear ();
                    btnCheck.IsSelected = !btnCheck.IsSelected;
                    if (btnCheck.IsSelected) {
                        var d = weeklist.Find ((o) => { return o == name; });
                        if (d == null) {
                            weeklist.Add (name);
                        }
                    } else {
                        weeklist.RemoveAll ((o) => {
                            return o == name;
                        });
                    }
                    foreach (var strname in weeklist) {
                        if (Language.StringByID (MyInternationalizationString.mon) == strname) {
                            objects.Add (1);
                        }else if (Language.StringByID (MyInternationalizationString.tue) == strname) {
                            objects.Add (2);
                        } else if (Language.StringByID (MyInternationalizationString.wed) == strname) {
                            objects.Add (3);
                        } else if (Language.StringByID (MyInternationalizationString.thu) == strname) {
                            objects.Add (4);
                        } else if (Language.StringByID (MyInternationalizationString.frl) == strname) {
                            objects.Add (5);
                        } else if (Language.StringByID (MyInternationalizationString.sat) == strname) {
                            objects.Add (6);
                        } else if (Language.StringByID (MyInternationalizationString.sun) == strname) {
                            objects.Add (0);
                        } 
                    }
 
                    if (Logic.CurrentLogic.date.ContainsKey ("type")) {
                        Logic.CurrentLogic.date.Remove ("type");
                    }
                    if (Logic.CurrentLogic.date.ContainsKey ("week")) {
                        Logic.CurrentLogic.date.Remove ("week");
                    }
                    if (Logic.CurrentLogic.date.ContainsKey ("date")) {
                        Logic.CurrentLogic.date.Remove ("date");
                    }
                    Logic.CurrentLogic.date.Add ("type", "week");
                    Logic.CurrentLogic.date.Add ("week", objects.ToArray ());
                };
            }
 
        }
 
     }
}