wxr
2020-03-13 171bf03f3664226eeff2b20ee9bd2e914b63a17d
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
using System;
using HDL_ON.UI.CSS;
using Shared;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
    public partial class FloorsManagementPage : FrameLayout
    {
        FrameLayout bodyView;
        /// <summary>
        /// 楼层显示区域
        /// </summary>
        VerticalScrolViewLayout floorsListView;
        /// <summary>
        /// 显示区域
        /// </summary>
        FrameLayout contentView;
        /// <summary>
        /// 楼层标题按钮
        /// </summary>
        Button btnFloorTitle;
 
 
        /// <summary>
        /// 房间绑定楼层的确定按钮
        /// </summary>
        Button btnConfrim;
        /// <summary>
        /// 当页面是编辑楼层时,该变量为空
        /// 当页面是给房间绑定楼层时,该变量不为空
        /// </summary>
        Room room;
        /// <summary>
        /// 标题栏修改楼层之后的回调事件
        /// </summary>
        Action<string,string> topCallBack;
        /// <summary>
        /// 后退回调事件
        /// </summary>
        Action backAction;
 
        public FloorsManagementPage()
        {
            bodyView = this;
        }
 
        public FloorsManagementPage(Action action)
        {
            bodyView = this;
            backAction = action;
        }
        /// <summary>
        /// 加载界面
        /// </summary>
        public void LoadPage()
        {
            bodyView.RemoveAll();
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            topCallBack = (type,floor) => {
                ChangeFloorsListView(type, floor);
            };
            new TopViewDiv(bodyView, Language.StringByID(StringId.FloorsManagement)).LoadTopView("floors",topCallBack,backAction);
            //new PublicAssmebly().LoadTopView(bodyView, Language.StringByID(StringId.FloorsManagement),"floors",topCallBcak);
 
            int count = DB_ResidenceData.residenceData.floors.Count > 8 ? 8 : DB_ResidenceData.residenceData.floors.Count;
            var contentViewHeight = (count + 1) * Application.GetRealHeight(50);
 
            contentView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(80),
                Width = Application.GetRealWidth(343),
                Height = contentViewHeight,
                Radius = (uint)Application.GetRealHeight(5),
                BorderColor = 0x00FFFFFF,
                BorderWidth = 0,
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(contentView);
 
            
             btnFloorTitle = new Button()
            {
                Height = Application.GetRealHeight(50),
                TextID = StringId.Floors,
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            contentView.AddChidren(btnFloorTitle);
 
            floorsListView = new VerticalScrolViewLayout()
            {
                Y = btnFloorTitle.Bottom,
                Height = count * Application.GetRealHeight(50),
            };
            contentView.AddChidren(floorsListView);
 
            foreach(var floor in DB_ResidenceData.residenceData.floors)
            {
                LoadFloorRow(floor);
            }
        }
 
        /// <summary>
        /// 加载楼层Row
        /// </summary>
        /// <param name="floor"></param>
        void LoadFloorRow(string floor)
        {
            floorsListView.AddChidren(
                  new Button()
                  {
                      Height = Application.GetRealHeight(1),
                      BackgroundColor = CSS_Color.DividingLineColor,
                      Tag = floor + "line"
                  });
 
            var row = new RowLayout()
            {
                Height = Application.GetRealHeight(50),
                Tag = floor
            };
            floorsListView.AddChidren(row);
 
            var btnFloor = new Button()
            {
                Height = Application.GetRealHeight(50),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.TextualColor,
                SelectedTextColor = CSS_Color.MainColor,
                Text = floor,
            };
            row.AddChidren(btnFloor);
 
            if (room == null)
            {
                LoadEvent_FloorNamgeChange(floor, btnFloor);
 
                var btnDel = new Button()
                {
                    TextID = StringId.Del,
                    BackgroundColor = CSS_Color.WarningColor,
                    TextColor = CSS_Color.MainBackgroundColor,
                    Tag = floor
                };
                row.AddRightView(btnDel);
                LoadEvent_DelFloor(btnDel);
            }
            else {
                LoadEvent_FloorChoose(btnFloor);
            }
        }
 
        void ChangeFloorsListView(string changeType,string floorName)
        {
            int count = DB_ResidenceData.residenceData.floors.Count > 10 ? 10 : DB_ResidenceData.residenceData.floors.Count;
            floorsListView.Height = Application.GetRealHeight(50 * count);
            contentView.Height = Application.GetRealHeight(50 * (count + 1));
            switch (changeType)
            {
                case "add":
                    try
                    {
                        LoadFloorRow(floorName);
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log("add floor eroor : " + ex.Message);
                    }
                    break;
                case "edit":
                    for(int i=0;i<floorsListView.ChildrenCount;i++)
                    {
                        if(floorsListView.GetChildren(i).GetType() == typeof(Button))
                        {
                            Button btn = floorsListView.GetChildren(i) as Button;
                            if(floorName == "")
                            {
                                btn.Text = floorName;
                                return;
                            }
                            if(btn.Tag.ToString() == floorName|| btn.Tag.ToString() == floorName + "line")
                            {
                                btn.RemoveFromParent();
                            }
                        }
                    }
                    break;
                case "del":
                    for (int i = 0; i < floorsListView.ChildrenCount; i++)
                    {
                        //该楼层删除之后,绑定该楼层的房间要重置绑定的楼层
                        foreach (var r in DB_ResidenceData.residenceData.rooms)
                        {
                            if (r.floorIndex == DB_ResidenceData.residenceData.floors.IndexOf(floorName))
                            {
                                r.floorIndex = -1;
                            }
                        }
                        if (floorsListView.GetChildren(i).GetType() == typeof(Button))
                        {
                            Button btn = floorsListView.GetChildren(i) as Button;
                            if (btn.Tag == null)
                                continue;
                            if (btn.Tag.ToString() == floorName + "line")
                            {
                                btn.RemoveFromParent();
                            }
                        }
                        if (floorsListView.GetChildren(i).GetType() == typeof(RowLayout))
                        {
                            RowLayout row = floorsListView.GetChildren(i) as RowLayout;
                            if (row.Tag == null)
                                continue;
                            if (row.Tag.ToString() == floorName )
                            {
                                row.RemoveFromParent();
                            }
                        }
                    }
                    break;
            }
        }
 
        /// <summary>
        /// 分配给room楼层关系
        /// </summary>
        public void LoadPage(Room r)
        {
            room = r;
            LoadPage();
 
            btnConfrim = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(582),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Radius = (uint)Application.GetRealHeight(22),
                BackgroundColor = CSS_Color .MainColor,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
                TextID = StringId.Confirm,
            };
            bodyView.AddChidren(btnConfrim);
 
            LoadEvent_BindFloor();
        }
    }
}