wxr
2020-04-21 f718d23a262a5a8e1241fdeaeb4153399f95e79d
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
using System;
using Shared;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
    public partial class RoomEditPage
    {
        /// <summary>
        /// 加载事件列表
        /// </summary>
        void LoadEventList()
        {
            LoadEvent_PictureOptionView();
            LoadEvent_EditRoomName();
            LoadEvent_SkinBindFloor();
            LoadEvent_SkipEditFunctionList();
            LoadEvent_Option();
        }
 
        /// <summary>
        /// 底部按钮事件
        /// </summary>
        void LoadEvent_Option()
        {
            btnOption.MouseUpEventHandler += (sender, e) =>
            {
                if (btnOption.TextID == StringId.Save)
                {
                    if (string.IsNullOrEmpty(room.name))
                    {
                        new Tip()
                        {
                            CloseTime = 3,
                            Text = Language.StringByID(StringId.RoomNameCannotBeEmpty),
                            Direction = AMPopTipDirection.None,
                        }.Show(bodyView);
                        return;
                    }
                    foreach (var tempRoom in DB_ResidenceData.residenceData.rooms)
                    {
                        if (room.name == tempRoom.name)
                        {
                            new PublicAssmebly().TipMsg(StringId.Tip, StringId.AddingFailed_RoomAlreadyExists);
                            return;
                        }
                    }
                    room.sid = Guid.NewGuid().ToString();
                    DB_ResidenceData.residenceData.rooms.Add(room);
                    DB_ResidenceData.residenceData.SaveResidenceData();
                    backAction();
                    this.RemoveFromParent();
                }
                if (btnOption.TextID == StringId.DeleteRoom)
                {
                    Action action = () =>
                    {
                        foreach (var f in DB_ResidenceData.residenceData.functionList.functions)
                        {
                            if (f.roomIdList.Contains(room.sid))
                            {
                                f.roomIdList.Remove(room.sid);
                            }
                        }
                        room.sid = "";
                        DB_ResidenceData.residenceData.rooms.Remove(room);
                        DB_ResidenceData.residenceData.SaveResidenceData();
                        backAction();
                        this.RemoveFromParent();
                    };
                    new PublicAssmebly().TipMsg(StringId.Tip, StringId.DeleteRoomTip, action);
                };
            };
        }
 
        /// <summary>
        /// 显示背景图选择选项
        /// </summary>
        void LoadEvent_PictureOptionView()
        {
            btnRoomBg.MouseUpEventHandler = (sender, e) =>
            {
                LoadPictureOptionView();
            };
        }
 
        /// <summary>
        /// 加载修改房间名称窗口事件
        /// </summary>
        void LoadEvent_EditRoomName()
        {
            Action<string> callBack = (str) =>
            {
                //房间名称不能为空
                if (string.IsNullOrEmpty(str))
                {
                    new Tip()
                    {
                        CloseTime = 3,
                        Text = Language.StringByID(StringId.RoomNameCannotBeEmpty),
                        Direction = AMPopTipDirection.None,
                    }.Show(bodyView);
                    return;
                }
                btnRoomName.Text = btnTipRoomName.Text = str;
                room.name = str;
                if (pageTitleId == StringId.EditRoomInfo)
                {
                    DB_ResidenceData.residenceData.SaveResidenceData();
                }
            };
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.name, callBack);
            };
            btnEditRoomNameIcon.MouseUpEventHandler = eventHandler;
            roomNameRow.MouseUpEventHandler = eventHandler;
            btnRoomName.MouseUpEventHandler = eventHandler;
        }
 
        /// <summary>
        /// 跳转绑定楼层界面
        /// </summary>
        void LoadEvent_SkinBindFloor()
        {
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                Action floorsCallBackAction = () =>
                {
                    btnFloorInfo.Text = room.floor;
                };
                var residentialManagePage = new FloorsManagementPage(floorsCallBackAction);
                MainPage.BasePageView.AddChidren(residentialManagePage);
                residentialManagePage.LoadPage(room);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            btnFloorInfo.MouseUpEventHandler = eventHandler;
            floorView.MouseUpEventHandler = eventHandler;
        }
 
        /// <summary>
        /// 跳转到编辑房间功能界面
        /// </summary>
        void LoadEvent_SkipEditFunctionList()
        {
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                var residentialManagePage = new RoomEditFunctionPage(room);
                MainPage.BasePageView.AddChidren(residentialManagePage);
                residentialManagePage.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            btnFunctionManagementRight.MouseUpEventHandler = eventHandler;
            functionManagemantView.MouseUpEventHandler = eventHandler;
        }
 
 
        /// <summary>
        /// 加载背景图选择区域事件列表
        /// </summary>
        void LoadEvent_PictureOptionViewEventList()
        {
            pictureOptionView.MouseUpEventHandler = (sender, e) =>
            {
                pictureOptionView.RemoveFromParent();
            };
 
            btnCancel.MouseUpEventHandler = (sender, e) =>
            {
                pictureOptionView.RemoveFromParent();
            };
            btnTakePicture.MouseDownEventHandler = (sender, e) => {
                btnTakePicture.IsSelected = true;
            };
            btnTakePicture.MouseUpEventHandler = (sender, e) =>
            {
                btnTakePicture.IsSelected = false;
                var pid = Guid.NewGuid();
                CropImage.TakePicture((imagePath) =>
                {
                    if (imagePath != null)
                    {
                        btnRoomBg.UnSelectedImagePath = imagePath.ToString();
                        room.backgroundImage = btnRoomBg.UnSelectedImagePath;
                        MainPage.Log("SelectPicture 裁剪图片返回路径: " + imagePath);
                    }
                }, pid.ToString(), 16, 9);
                if (pageTitleId == StringId.EditRoomInfo)
                {
                    DB_ResidenceData.residenceData.SaveResidenceData();
                }
                pictureOptionView.RemoveFromParent();
            };
            btnAlbum.MouseDownEventHandler = (sender, e) => {
                btnAlbum.IsSelected = true;
            };
 
            btnAlbum.MouseUpEventHandler = (sender, e) =>
            {
                btnAlbum.IsSelected = false;
                var pid = Guid.NewGuid();
                CropImage.SelectPicture((imagePath) =>
                {
                    if (imagePath != null)
                    {
                        btnRoomBg.UnSelectedImagePath = imagePath.ToString();
                        room.backgroundImage = btnRoomBg.UnSelectedImagePath;
                        MainPage.Log("SelectPicture 裁剪图片返回路径: " + imagePath);
#if DEBUG
                        new Tip() { CloseTime = 5, Text = imagePath }.Show(MainPage.BasePageView);
#endif
                    }
                }, pid.ToString(), 16, 9);
                if (pageTitleId == StringId.EditRoomInfo)
                {
                    DB_ResidenceData.residenceData.SaveResidenceData();
                }
                pictureOptionView.RemoveFromParent();
            };
        }
    }
}