陈嘉乐
2021-03-22 002bb6950a15e703e2ad6ef7b2b4c5d80c4ee64b
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
using System;
using System.Collections.Generic;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
    public class AddControlComplete : FrameLayout
    {
        public AddControlComplete()
        {
            Tag = "PirView";
        }
        public void Show(Control control, bool bool_library)
        {
            //数据转换
            Entity.Function function = new Entity.Function();
            {
                function.sid = control.sid;
                function.deviceId = control.deviceId;
                function.name = control.name;
                function.spk = control.spk;
                //function.attributes.AddRange(control.status);
                //遥控器添加到列表;
                if (null == Pir.currPir.FunctioList.Find((c) => c.sid == function.sid))
                {
                    Pir.currPir.FunctioList.Add(function);
                }
            }
            #region 界面布局
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            PirDevice.View.TopView topView = new View.TopView();
            topView.topNameBtn.TextID = StringId.tianjiayaokongqi;
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); };
 
            FrameLayout fLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64),
                BackgroundColor = CSS.CSS_Color.textWhiteColor,
                Height = Application.GetRealHeight(224),
                Width = Application.GetRealWidth(375),
            };
            this.AddChidren(fLayout);
            //
            Button iconBtn = new Button
            {
                Y = Application.GetRealHeight(28),
                X = Application.GetRealWidth(137),
                Width = Application.GetRealWidth(102),
                Height = Application.GetRealWidth(102),
                UnSelectedImagePath = "PirIcon/succeed.png",
            };
            fLayout.AddChidren(iconBtn);
 
            //添加成功
            Button text1Btn = new Button
            {
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(22),
                Y = Application.GetRealHeight(158),
                X = Application.GetRealWidth(16),
                TextID = StringId.tianjiachenggong,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.btnSaveBackgroundColor,
                TextAlignment = TextAlignment.Center,
            };
            fLayout.AddChidren(text1Btn);
            //可到分类-功能-操作使用
            Button text2Btn = new Button
            {
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(22),
                Y = Application.GetRealHeight(188),
                X = Application.GetRealWidth(16),
                TextID = StringId.kedaofenlei,
                TextSize = TextSize.text14,
                TextColor = CSS.CSS_Color.textTipColor,
                TextAlignment = TextAlignment.Center,
            };
            fLayout.AddChidren(text2Btn);
            //所属分类
            View.PatchView fenlei = new View.PatchView();
            fenlei.frameLayout.Y = fLayout.Bottom + Application.GetRealHeight(8);
            this.AddChidren(fenlei.FLayoutView(false));
            fenlei.btnText1.TextID = StringId.suoshufenlei;
            fenlei.btnText2.TextID = StringId.dianqi;
            //遥控器名称
            View.PatchView namePatchView = new View.PatchView();
            namePatchView.frameLayout.Y = fenlei.frameLayout.Bottom;
            this.AddChidren(namePatchView.FLayoutView());
            namePatchView.btnText1.TextID = StringId.yaokongqimingcheng;
            namePatchView.btnText2.Text = control.name;
 
            //所属区域
            View.PatchView quyuPatchView = new View.PatchView();
            quyuPatchView.frameLayout.Y = namePatchView.frameLayout.Bottom;
            this.AddChidren(quyuPatchView.FLayoutView());
            quyuPatchView.btnText1.TextID = StringId.suoshuquyu;
            quyuPatchView.btnText2.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(function);
 
            //继续添加
            Button addBtn = new Button
            {
                Y = quyuPatchView.frameLayout.Bottom + Application.GetRealHeight(125),
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(20),
                TextID = StringId.jixutianjia,
                TextSize = TextSize.text14,
                TextColor = CSS.CSS_Color.textConfirmColor,
                TextAlignment = TextAlignment.Center,
            };
            this.AddChidren(addBtn);
            //完成
            View.SaveView saveView = new View.SaveView();
            this.AddChidren(saveView.FLayoutView());
            saveView.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            #endregion
            #region  界面点击事件
            //遥控器名称点击事件
            namePatchView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
 
                List<string> list = new List<string>();
                for (int i = 0; i < Pir.currPir.FunctioList.Count; i++)
                {
                    list.Add(Pir.currPir.FunctioList[i].name);
                }
                Method method = new Method();
                method.EditControlName(StringId.editName, list, control.name, (name, dialog) =>
                {
                    Method.ThreadSend(new Control { deviceId = control.deviceId, name = name }, (responsePackNew) =>
                    {
                        dialog.Close();
                        namePatchView.btnText2.Text = name;
                        function.name = name;
 
                    }, "修改名称", "dialog", null, dialog);
                }, () => { });
            };
            //所属区域点击事件
            quyuPatchView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                Method method = new Method();
                method.ManagementPosition(function, () =>
                {
                    //更新区域
                    quyuPatchView.btnText2.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(function);
                });
            };
            //继续添加点击事件
            addBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (bool_library)
                {
                    this.RemoveFromParent();
                    RefreshView();
                }
                else
                {
                    Method method = new Method();
                    method.AddControl(this, (controlDevice) =>
                    {
                        AddButton addButton = new AddButton();
                        MainPage.BasePageView.AddChidren(addButton);
                        addButton.Show(controlDevice);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    });
                }
            };
            //完成点击事件
            saveView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                //移除所有界面
                MainPage.BasePageView.RemoveViewByTag("PirView");
                RefreshView();
 
            };
            #endregion
        }
        /// <summary>
        /// 刷新红外宝主界面
        /// </summary>
        void RefreshView()
        {
 
            //移除红外宝根界面
            MainPage.BasePageView.RemoveViewByTag("PirMain");
            //重新加载界面
            var page = new PirMain();
            MainPage.BasePageView.AddChidren(page);
            page.Show();
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
        }
    }
}