wxr
2021-03-08 8e5ba5665861b29a4b8da0335c81d620aa891862
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
using System;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
    public class AddControl : FrameLayout
    {
        public AddControl()
        {
            Tag = "Pir";
        }
        public void Show(Control control)
        {
 
            #region 界面布局
 
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            PirDevice.View.TopView topView = new View.TopView();
            topView.topNameBtn.TextID = StringId.zhinengyaokongqi;
            topView.topIconBtn.Visible = true;
            topView.topIconBtn.UnSelectedImagePath = "PirIcon/del.png";
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                
                this.RemoveFromParent();
 
            };
 
            #region 添加按钮
            FrameLayout addLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(84),
                Width = Application.GetRealWidth(TextSize.view375),
            };
            this.AddChidren(addLayout);
 
            Button addBtn = new Button
            {
                Width = Application.GetRealWidth(344),
                Height = Application.GetRealHeight(44),
                Y = Application.GetRealHeight(24),
                X = Application.GetRealWidth(16),
                TextID = StringId.tianjiaanniu,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.btnSaveBackgroundColor,
                BorderColor = CSS.CSS_Color.btnSaveBackgroundColor,
                BorderWidth = 1,
                Radius = (uint)Application.GetRealHeight(22),
            };
            addLayout.AddChidren(addBtn);
            #endregion
            FrameLayout frameLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64 + 84),
                Height = Application.GetRealHeight(667 - 64 - 84),
                Width = Application.GetRealWidth(TextSize.view375),
            };
            this.AddChidren(frameLayout);
 
            #region 保存
            FrameLayout saveLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(667 - 104),
                Height = Application.GetRealHeight(104),
                Width = Application.GetRealWidth(TextSize.view375),
                BackgroundColor = CSS.CSS_Color.viewLine,
            };
            this.AddChidren(saveLayout);
            saveLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
 
            Button paixuBtn = new Button
            {
                Width = Application.GetRealWidth(375 - 16 * 2),
                Height = Application.GetRealHeight(20),
                Y = Application.GetRealHeight(12),
                X = Application.GetRealWidth(16),
                TextID = StringId.paixu,
                TextSize = TextSize.text14,
                TextColor = CSS.CSS_Color.textTipColor,
            };
            saveLayout.AddChidren(paixuBtn);
 
            Button saveBtn = new Button
            {
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Y = paixuBtn.Bottom + Application.GetRealHeight(12),
                X = Application.GetRealWidth(78),
                TextID = StringId.save,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.textWhiteColor,
                TextAlignment = TextAlignment.Center,
                BackgroundColor = CSS.CSS_Color.btnSaveBackgroundColor,
                Radius = (uint)Application.GetRealHeight(22),
 
            };
            saveLayout.AddChidren(saveBtn);
            #endregion
 
            VerticalScrolViewLayout vv = new VerticalScrolViewLayout();
            frameLayout.AddChidren(vv);
            RefreshView(vv, false);
            #endregion
 
            #region  界面点击事件
            //删除点击事件
            topView.clickSetBtn.MouseUpEventHandler += (sender, e) =>
            {
                topView.clickSetBtn.IsSelected = !topView.clickSetBtn.IsSelected;
                if (topView.clickSetBtn.IsSelected)
                {
                    topView.topIconBtn.UnSelectedImagePath = "";
                    topView.topIconBtn.Text = Language.StringByID(StringId.wancheng);
                    topView.topIconBtn.TextSize = TextSize.text14;
                    topView.topIconBtn.TextColor = CSS.CSS_Color.textColor;
                    RefreshView(vv, true);
                }
                else
                {
                    topView.topIconBtn.UnSelectedImagePath = "PirIcon/del.png";
                    topView.topIconBtn.Text = "";
                    RefreshView(vv, false);
                }
 
 
 
            };
            //添加按钮点击事件
            addBtn.MouseUpEventHandler += (sender, e) =>
            {
                AddButton addButton = new AddButton();
                MainPage.BasePageView.AddChidren(addButton);
                addButton.Show(control);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            //保存点击事件
            saveBtn.MouseUpEventHandler += (sender, e) =>
            {
               //移除当前界面
                this.RemoveFromParent();
                //可能之前已经存在该界面
                for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
                {
                    var view = MainPage.BasePageView.GetChildren(i);
                    if (view.GetType() == typeof(AddControlComplete))
                    {
                        view.RemoveFromParent();
                    }
                }
                //MainPage.BasePageView.RemoveViewByTag("Pir");
                AddControlComplete addControlComplete = new AddControlComplete();
                MainPage.BasePageView.AddChidren(addControlComplete);
                addControlComplete.Show(control,false);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            #endregion
        }
        /// <summary>
        /// 加载按钮控件View的方法
        /// </summary>
        /// <param name="vv">上下滑动控件</param>
        /// <param name="if_bool">表示是否显示删除图标</param>
        void RefreshView(VerticalScrolViewLayout vv, bool if_bool)
        {
            vv.RemoveAll();
            //定义一个变量记录行数
            int sum = 0;
            if (Pir.BuottonList.Count % 3 == 0)
            {
                sum = Pir.BuottonList.Count / 3;
            }
            else
            {
                sum = Pir.BuottonList.Count / 3 + 1;
            }
            //计算加载出来的数据需要的高度
            int h = 16 + sum * (16 + 44) + 104 + 76;
            int line = 0;
            //按钮的父控件
            var FLayout = new FrameLayout
            {
                Height = Application.GetRealWidth(h),
            };
            vv.AddChidren(FLayout);
            for (int i = 1, j = 0; i <= Pir.BuottonList.Count; i++, j++)
            {
                var nameObj = Pir.BuottonList[i - 1];
                //按钮
                var buttonNameBtn = new Button
                {
 
                    Y = Application.GetRealHeight(16 + line * (16 + 44)),
                    X = Application.GetRealWidth(16 + (16 + 104) * j),
                    Width = Application.GetRealWidth(104),
                    Height = Application.GetRealHeight(44),
                    Text = nameObj.value,
                    TextSize = TextSize.text16,
                    TextColor = CSS.CSS_Color.textColor,
                    TextAlignment = TextAlignment.Center,
                    Radius = (uint)Application.GetRealHeight(18),
                    BorderWidth = 1,
                    BorderColor = CSS.CSS_Color.textCancelColor,
                };
                FLayout.AddChidren(buttonNameBtn);
                //删除图标
                var delIconBtn = new Button
                {
                    UnSelectedImagePath = "PirIcon/delbuton.png",
                    Y = Application.GetRealHeight(12 + line * (16 + 44)),
                    X = Application.GetRealWidth((16 + 92) + (104 + 16) * j),
                    Width = Application.GetRealWidth(16),
                    Height = Application.GetRealWidth(16),
                    Tag = nameObj,
                };
                if (if_bool)
                {
                    FLayout.AddChidren(delIconBtn);
                }
                //删除图标的点击事件
                delIconBtn.MouseUpEventHandler += (sender, e) =>
                {
                    var obj = delIconBtn.Tag as ButtonObj;
                    //加载log
                    Loading loading = new Loading();
                    this.AddChidren(loading);
                    HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
                    loading.Start();
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            //发送按键删除;
                            responsePackNew = PirSend.CodeRemove(obj);
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                loading.Hide();
                                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                                {
                                    ///这里:监听MTTP推送下来主题,才知道是否添加成功
                                    var buttonObj = Pir.BuottonList.Find((c) => c.value == obj.value);
                                    if (buttonObj != null)
                                    {
                                        Pir.BuottonList.Remove(buttonObj);
                                    }
                                    RefreshView(vv, true);
                                }
                                else {
                                    Method method = new Method();
                                    method.ErrorShow(responsePackNew);
                                }
 
                            });
                        }
 
                    })
                    { IsBackground = true }.Start();
 
 
                };
                if (i % 3 == 0)
                {
                    //满一行重置j=0值;
                    j = -1;
                    line += 1;
                }
 
            }
 
        }
    }
}