陈嘉乐
2021-01-06 2313f465c76d58d93d7cea5e1c3dfe5361853006
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
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class Time3:FrameLayout
    {
      
        public Time3()
        {
            Tag = "Logic";
        }
 
        public void Show(string titelText,bool edit,int index)
        {
            #region  界面布局
            LogicView.TopView topView = new LogicView.TopView();
            topView.frameLayout.Height = Application.GetRealHeight(64+20);
            this.AddChidren(topView.FLayoutView());
            Button locationBtn = new Button
            {
                Width = Application.GetRealWidth(18),
                Height = Application.GetRealWidth(18),
                X = Application.GetRealWidth(208),
                Y = Application.GetRealHeight(34),
                UnSelectedImagePath = "LogicIcon/location.png",
 
            };
            topView.frameLayout.AddChidren(locationBtn);
 
            Button textBtn = new Button
            {
                Height = Application.GetRealHeight(14),
                Y = Application.GetRealHeight(57),
                TextSize =LogicView.TextSize.text10,
                TextColor = CSS.CSS_Color.textCancelColor,
                Text = "广东广州市番禺区石楼镇",
            };
            topView.frameLayout.AddChidren(textBtn);
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
            };
            topView.topNameBtn.Text=titelText;
 
            FrameLayout viewLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64+20),
                Width = Application.GetRealWidth(LogicView.TextSize.view375),
                Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64-20),
                BackgroundColor = CSS.CSS_Color.viewMiddle,
            };
            this.AddChidren(viewLayout);
 
            var list = new List<string> {
                Language.StringByID(StringId.punctually),
                Language.StringByID(StringId.advanced),
                Language.StringByID(StringId.delayLogic),
            };
 
            for (int i = 0; i < list.Count; i++)
            {
                LogicView.SelectTypeView timeView = new LogicView.SelectTypeView();
                timeView.frameLayout.Y = Application.GetRealHeight(i * 50);
                timeView.btnIcon.Visible = false;
                timeView.btnText.X = Application.GetRealWidth(16);
                timeView.btnLine.X = Application.GetRealWidth(16);
                timeView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
                timeView.btnText.Text = list[i];
                timeView.btnClick.Tag= list[i];
                if (i==0) {
                    timeView.btnNextIcon.Visible = false;
                }
                viewLayout.AddChidren(timeView.FLayoutView());
 
                timeView.btnClick.MouseUpEventHandler += (sen, e) =>
                {
                    string clickText = timeView.btnClick.Tag.ToString();
                    string keyValue = GetKeyValue(clickText, titelText);
                    if (clickText == Language.StringByID(StringId.punctually))
                    {
                        //正点
                        AddDic(keyValue, "0", edit, index);
                    }
                    else
                    {
                        //提前/延时
                        PublicInterface timePublicInterface = new PublicInterface();
                        var timelist = timePublicInterface.GetViewList("time");
                        timePublicInterface.SingleSelectionShow(this, timelist, clickText, ""
                           , (value) =>
                           {
                               string timeValue = value.Split(" ")[0];
                               AddDic(keyValue, timeValue, edit, index);
 
                           });
                    }
 
                };
            }
            #endregion
 
        }
        /// <summary>
        /// 获取键值
        /// </summary>
        /// <param name="clickText">当前选中文本</param>
        /// <param name="titelText">标题文本</param>
        /// <returns></returns>
        private string GetKeyValue(string clickText, string titelText)
        {
 
            string keyValue = "";
            if (clickText == Language.StringByID(StringId.advanced))
            {
                if (titelText == Language.StringByID(StringId.sunrise) + Language.StringByID(StringId.h))
                {
                    keyValue = "before_sunrise";
                }
                else if (titelText == Language.StringByID(StringId.sunset) + Language.StringByID(StringId.h))
                {
                    keyValue = "before_sunset";
                }
                else
                {
                    keyValue = "at_sunrise";
 
                }
            }
            else
            {
 
                if (titelText == Language.StringByID(StringId.sunrise) + Language.StringByID(StringId.h))
                {
                    keyValue = "after_sunrise";
                }
                else if (titelText == Language.StringByID(StringId.sunset) + Language.StringByID(StringId.h))
                {
                    keyValue = "“after_sunset";
                }
                else
                {
                    keyValue = "at_sunset";
 
                }
            }
            return keyValue;
        }
        /// <summary>
        /// 封装数据
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="value"></param>
        /// <param name="edit"></param>
        /// <param name="index"></param>
        private void AddDic(string keyValue, string value, bool edit, int index)
        {
            Input inputTime = new Input();
            inputTime.sid = LogicMethod.NewSid();
            inputTime.condition_type = "1";
            Dictionary<string, string> dic = new Dictionary<string, string>();
            LogicMethod.dictionary(dic, "key", keyValue);
            LogicMethod.dictionary(dic, "comparator", "=");
            LogicMethod.dictionary(dic, "data_type", "string");
            LogicMethod.dictionary(dic, "value", value);
            inputTime.condition.Add(dic);
            AddCondition(inputTime, edit, index);
        }
        /// <summary>
        /// 添加条件
        /// </summary>
        /// <param name="input"></param>
        private void AddCondition(Input input, bool edit, int index)
        {
            if (edit)
            {
                //移除旧数据
                Logic.currlogic.input.RemoveAt(index);
                //新数据插入旧数据的位置
                Logic.currlogic.input.Insert(index, input);
            }
            else
            {
                //添加一个新的时间条件
                Logic.currlogic.input.Add(input);
            }
            LogicMethod.RemoveAllView();
            AddLogic addLogic = new AddLogic();
            MainPage.BasePageView.AddChidren(addLogic);
            addLogic.Show();
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
        }
    }
}