陈嘉乐
2020-12-01 307e554fb2ef6491d08afc58a6c0a852f44b4f46
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
using System;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class MainView
    {
        /// <summary>
        /// 记录逻辑自动化父控件
        /// </summary>
        public static FrameLayout automationPage;
        /// <summary>
        /// 加载逻辑列表显示界面
        /// </summary>
        public static void MainShow()
        {
            automationPage.RemoveAll();
            VerticalScrolViewLayout vv = new VerticalScrolViewLayout();
            automationPage.AddChidren(vv);
 
            for (int i = 0; i < Logic.LogicList.Count; i++)
            {
                var currLogic = Logic.LogicList[i];
                ///上下间隔12像素
                vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(12) });
                LogicView.SingleLogicView logicView = new LogicView.SingleLogicView();
                vv.AddChidren(logicView.FLayoutView());
                logicView.btnLogicName.Text = currLogic.name;
                logicView.btnWeekText.Text = GetWeekText(currLogic);
                logicView.btnclick.MouseUpEventHandler += (sen, e) =>
                {
                    Logic.currlogic = currLogic;
                    var addLogic = new AddLogic();
                    MainPage.BasePageView.AddChidren(addLogic);
                    addLogic.Show();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                logicView.btnSwitchIcon.MouseUpEventHandler += (sender1, e1) =>
                {
                    logicView.btnSwitchIcon.IsSelected = !logicView.btnSwitchIcon.IsSelected;
                    if (logicView.btnSwitchIcon.IsSelected)
                    {
                        logicView.btnSwitchIcon.IsSelected = true;
                    }
                    else
                    {
                        logicView.btnSwitchIcon.IsSelected = false;
                    }
                };
                if (currLogic.enable == "true")
                {
                    logicView.btnSwitchIcon.IsSelected = true;
                }
                else
                {
                    logicView.btnSwitchIcon.IsSelected = false;
                }
            }
 
            if (Logic.LogicList.Count == 0)
            {
                Button btnTipNot = new Button()
                {
                    Gravity = Gravity.CenterHorizontal,
                    Y = Application.GetRealHeight(120),
                    Width = Application.GetRealWidth(180),
                    Height = Application.GetRealWidth(180),
                    UnSelectedImagePath = "TipNot.png",
                };
                automationPage.AddChidren(btnTipNot);
                Button btnTipNotText = new Button()
                {
                    Y = btnTipNot.Bottom,
                    Height = Application.GetRealWidth(100),
                    TextID = StringId.TipNotOpen,
                    TextAlignment = TextAlignment.Center,
                    TextColor = CSS.CSS_Color.TextualColor,
                    TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel,
                };
                automationPage.AddChidren(btnTipNotText);
            }
        }
        /// <summary>
        ///  按+跳转到逻辑界面的方法
        /// </summary>
        public static void SkipAddLogicPage()
        {
            Logic.currlogic = new Logic();
            var addLogic = new AddLogic();
            MainPage.BasePageView.AddChidren(addLogic);
            addLogic.Show();
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
        }
        /// <summary>
        ///返回循环描述文本
        /// </summary>
        /// <param name="logic"></param>
        public static string GetWeekText(Logic logic)
        {
 
            string weekName = "";
            /// (执行一次:once,每天:day,每月:mon,星期:week,日期段:date_to_date)
            switch (logic.cycle.type)
            {
                case "once":
                    {
                        weekName = Language.StringByID(StringId.performA);
                    }
                    break;
                case "day":
                    {
                        weekName = Language.StringByID(StringId.days);
                    }
                    break;
                case "week":
                    {
 
                        weekName = GetWeekString(logic.cycle.value);
 
                    }
                    break;
                case "mon":
                    {
                        weekName = GetMonString(logic.cycle.value);
                    }
                    break;
            }
            return weekName;
        }
        /// <summary>
        /// 获取星期的字符串
        /// </summary>
        /// <param name="weekList"></param>
        /// <returns></returns>
        public static string GetWeekString(List<string> weekList)
        {
            string weekTextName = "";
 
            if (weekList.Contains("0"))
            {
                weekTextName += Language.StringByID(StringId.monday) + ",";
            }
            if (weekList.Contains("1"))
            {
                weekTextName += Language.StringByID(StringId.tuesday) + ",";
            }
            if (weekList.Contains("2"))
            {
                weekTextName += Language.StringByID(StringId.wednesday) + ",";
            }
            if (weekList.Contains("3"))
            {
                weekTextName += Language.StringByID(StringId.thursday) + ",";
            }
            if (weekList.Contains("4"))
            {
                weekTextName += Language.StringByID(StringId.friday) + ",";
            }
            if (weekList.Contains("5"))
            {
                weekTextName += Language.StringByID(StringId.saturday) + ",";
            }
            if (weekList.Contains("6"))
            {
                weekTextName += Language.StringByID(StringId.sunday) + ",";
            }
            if (weekTextName == "")
            {
                return "";
            }
            return weekTextName.TrimEnd(',');
        }
        /// <summary>
        /// 获取每月的字符串
        /// </summary>
        /// <param name="monList"></param>
        /// <returns></returns>
        public static string GetMonString(List<string> monList)
        {
            string monTextName = Language.StringByID(StringId.monthly);
 
            for (int i = 1; i < 32; i++)
            {
                if (monList.Contains(i.ToString()))
                {
                    monTextName += i.ToString() + ",";
                }
            }
            return monTextName.TrimEnd(',');
        }
    }
}