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
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
using System;
using System.Collections.Generic;
using Shared;
using Shared.SimpleControl;
using Shared.SimpleControl.R;
using SmartHome;
namespace SuperGateWay
{
    public class Cycle : FrameLayout
    {
        Action action;
        public Cycle (Action action)
        {
            this.action = action;
        }
        public Cycle ()
        {
            Tag = "Logic";
        }
        /// <summary>
        /// 选中
        /// </summary>
        Button beforeClickButton = new Button ();
        public void Show (GateWay superGateWay)
        {
            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 ();
            };
            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 - 80);
            middle.BackgroundColor = 0xff2F2F2F;
            this.AddChidren (middle);
            string timename = "";
            if (Logic.CurrentLogic.date.ContainsKey ("type")) {
                var type = Logic.CurrentLogic.date ["type"]?.ToString ();
                switch (type) {
                case "week": {
                        var weekvalue = Newtonsoft.Json.JsonConvert.DeserializeObject<int []> (Newtonsoft.Json.JsonConvert.SerializeObject (Logic.CurrentLogic.date ["week"]));
                        if (weekvalue != null) {
                            int a0 = Array.IndexOf (weekvalue, 0);
                            int a1 = Array.IndexOf (weekvalue, 1);
                            int a2 = Array.IndexOf (weekvalue, 2);
                            int a3 = Array.IndexOf (weekvalue, 3);
                            int a4 = Array.IndexOf (weekvalue, 4);
                            int a5 = Array.IndexOf (weekvalue, 5);
                            int a6 = Array.IndexOf (weekvalue, 6);
                            if (weekvalue.Length == 2 && a0 != -1 && a6 != -1) {
                                ///周未
                                timename = Language.StringByID (MyInternationalizationString.weekend);
                            } else if (weekvalue.Length == 5 && a1 != -1 && a2 != -1 && a3 != -1 && a4 != -1 && a5 != -1) {
                                ///工作日
                                timename = Language.StringByID (MyInternationalizationString.workingday);
                            } else {
                                var datecycle = new Datecycle ();
                                MainPage.MainFrameLayout.AddChidren (datecycle);
                                datecycle.Show (superGateWay);
                            }
                        }
                    }
                    break;
                case "day": {
                        var datecycle = new Datecycle ();
                        MainPage.MainFrameLayout.AddChidren (datecycle);
                        datecycle.Show (superGateWay);
                    }
                    break;
                case "every_day": {
                        timename = Language.StringByID (MyInternationalizationString.everyday);
                    }
                    break;
                case "every_month": {
                        var everymonthPage = new EverymonthPage ();
                        MainPage.MainFrameLayout.AddChidren (everymonthPage);
                        everymonthPage.Show (superGateWay);
                    }
                    break;
                case "every_year": {
                        var everyyearPage = new EveryyearPage ();
                        MainPage.MainFrameLayout.AddChidren (everyyearPage);
                        everyyearPage.Show (superGateWay);
 
                    }
                    break;
                }
            }else{
                //timename = Language.StringByID (MyInternationalizationString.executeonce);
            }
 
 
 
            var cyclelist = new List<string> ();
            cyclelist.AddRange (new string [] {
                //Language.StringByID(MyInternationalizationString.executeonce),
                Language.StringByID(MyInternationalizationString.everyday),
                Language.StringByID(MyInternationalizationString.workingday),
                Language.StringByID(MyInternationalizationString.weekend),
                Language.StringByID(MyInternationalizationString.monthly),
                Language.StringByID(MyInternationalizationString.everyyear),
                Language.StringByID(MyInternationalizationString.custom1),
            });
 
            foreach (var name in cyclelist) {
                var cyclerwLayout = new RowLayout {
                    Height = Application.GetRealHeight (100),
                };
                middle.AddChidren (cyclerwLayout);
 
                var btn = new Button {
                    Height = Application.GetRealHeight (100),
                    Width = LayoutParams.MatchParent,
                    SelectedBackgroundColor = 0xfffe5e00,
                };
                cyclerwLayout.AddChidren (btn);
 
                var btnName = new Button {
                    Gravity = Gravity.CenterVertical,
                    Text = name,
                    Width = Application.GetRealWidth (200),
                    Height = Application.GetRealHeight (100),
                    X=Application.GetRealWidth(30),
                    TextSize = 16,
                    TextAlignment=TextAlignment.CenterLeft,
                };
                cyclerwLayout.AddChidren (btnName);
 
                var btntimeback = new Button {
                    Width = Application.GetRealWidth (87),
                    Height = Application.GetRealHeight (100),
                    UnSelectedImagePath = "MusicIcon/Next.png",
                    SelectedImagePath = "MusicIcon/NextSelecte.png",
                    X = Application.GetRealWidth (550),
                };
                if (name ==Language.StringByID (MyInternationalizationString.monthly) || name ==Language.StringByID (MyInternationalizationString.everyyear) || name == Language.StringByID (MyInternationalizationString.custom1)) {
                    cyclerwLayout.AddChidren (btntimeback);
                }
 
                if (timename == name) {
                    beforeClickButton.IsSelected = false;
                    beforeClickButton = btn;
                    btn.IsSelected = true;
                }
 
                EventHandler<MouseEventArgs>timeclick= (sender,e) => { 
                    if (btnName.Text == Language.StringByID (MyInternationalizationString.custom1)) {
                        var datecycle = new Datecycle ();
                        MainPage.MainFrameLayout.AddChidren (datecycle);
                        datecycle.Show (superGateWay);
                    } else if (btnName.Text ==Language.StringByID (MyInternationalizationString.monthly)) {
                        var everymonthPage = new EverymonthPage ();
                        MainPage.MainFrameLayout.AddChidren (everymonthPage);
                        everymonthPage.Show (superGateWay);
                    } else if (btnName.Text ==Language.StringByID (MyInternationalizationString.everyyear)) {
                        var everyyearPage = new EveryyearPage ();
                        MainPage.MainFrameLayout.AddChidren (everyyearPage);
                        everyyearPage.Show (superGateWay);
                    } else {
                        beforeClickButton.IsSelected = false;
                        beforeClickButton = btn;
                        btn.IsSelected = true;
                        selectedMode (btnName.Text);
                    }
                };
                cyclerwLayout.MouseUpEventHandler += timeclick;
                btn.MouseUpEventHandler += timeclick;
                btnName.MouseUpEventHandler += timeclick;
                btntimeback.MouseUpEventHandler += timeclick;
 
            };
                      
            var btncomplete = new Button {
                Y = middle.Bottom,
                Height = Application.GetRealHeight (80),
                TextID = MyInternationalizationString.complete,
                BackgroundColor = 0xff1f1f1f,
                TextSize = 16,
            };
            AddChidren (btncomplete);
 
            btncomplete.MouseUpEventHandler += (sedder, e) => {
                RemoveFromParent ();
                action ();
            };
 
        }
 
        void selectedMode (string text)
        {
            if (Logic.CurrentLogic.date.ContainsKey ("type")) {
                Logic.CurrentLogic.date.Remove ("type");
            }
            if (Logic.CurrentLogic.date.ContainsKey ("date")) {
                Logic.CurrentLogic.date.Remove ("date");
            }
            if (Logic.CurrentLogic.date.ContainsKey ("week")) {
                Logic.CurrentLogic.date.Remove ("week");
            }
            if (text == Language.StringByID (MyInternationalizationString.everyday)) {
                Logic.CurrentLogic.date.Add ("type", "every_day");
            } else if (text == Language.StringByID (MyInternationalizationString.workingday)) {
                Logic.CurrentLogic.date.Add ("type", "week");
                Logic.CurrentLogic.date.Add ("week", new object [] { 1, 2, 3, 4, 5, });
            } else if (text == Language.StringByID (MyInternationalizationString.weekend)) {
                Logic.CurrentLogic.date.Add ("type", "week");
                Logic.CurrentLogic.date.Add ("week", new object [] { 0, 6 });
            }
        }
    }
}