黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.GatewayManage
{
    /// <summary>
    /// 网关备份的列表界面
    /// </summary>
    public class GatewayBackUpListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 网关对象(这个是真实物理网关对象)
        /// </summary>
        private ZbGateway realGateway = null;
        /// <summary>
        /// 当前选择的备份ID
        /// </summary>
        private string nowSelectBackId = string.Empty;
        /// <summary>
        /// 当前选择的控件
        /// </summary>
        private MostRightIconControl nowbtnSelect = null;
        /// <summary>
        /// 下载按钮
        /// </summary>
        private BottomClickButton btnDownload = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_zbGateway"></param>
        public void ShowForm(ZbGateway i_zbGateway)
        {
            this.realGateway = i_zbGateway;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDwonloadData));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(11);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
 
            listView = new VerticalListControl(12);
            listView.Y = frameBack.Bottom;
            listView.Height = bodyFrameLayout.Height - frameBack.Height;
            listView.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(listView);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //从云端获取数据
                this.SetBackupInfoToForm();
            });
        }
 
        #endregion
 
        #region ■ 从云端获取数据_____________________
 
        /// <summary>
        /// 从云端获取数据
        /// </summary>
        private void SetBackupInfoToForm()
        {
            this.nowSelectBackId = string.Empty;
            this.nowbtnSelect = null;
 
            //进度条
            this.ShowProgressBar();
 
            //获取自动备份的数据
            var listAutoData = HdlGatewayBackupLogic.Current.GetGatewayBackupListFromDb(realGateway.GwId, BackUpMode.A自动备份);
            if (listAutoData == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
 
            //从云端获取手动备份数据 
            var listHandData = HdlGatewayBackupLogic.Current.GetGatewayBackupListFromDb(realGateway.GwId, BackUpMode.A手动备份);
            if (listHandData == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //关闭进度条
            this.CloseProgressBar();
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                listView.RemoveAll();
                listView.RecoverHeight();
                if (listAutoData.Count > 0)
                {
                    //添加自动备份行
                    this.AddRowlayout(listAutoData[0], listAutoData.Count > 0, true);
                }
 
                for (int i = 0; i < listHandData.Count; i++)
                {
                    //添加备份行
                    this.AddRowlayout(listHandData[i], i != listHandData.Count - 1, false);
                }
 
                this.btnDownload?.RemoveFromParent();
                if (listAutoData.Count > 0 || listHandData.Count > 0)
                {
                    //下载
                    this.btnDownload = new BottomClickButton();
                    btnDownload.TextID = R.MyInternationalizationString.uDownLoad;
                    bodyFrameLayout.AddChidren(btnDownload);
                    btnDownload.ButtonClickEvent += (sender, e) =>
                    {
                        if (this.nowSelectBackId == string.Empty)
                        {
                            return;
                        }
                        //是否要下载并恢复数据?
                        string msg = Language.StringByID(R.MyInternationalizationString.uDownLoadAndRecoverMsg);
                        this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                         {
                             HdlThreadLogic.Current.RunThread(() =>
                             {
                                 //读取备份文档
                                 bool result = HdlGatewayBackupLogic.Current.RecoverGateway(this.realGateway.GwId, this.nowSelectBackId);
                                 if (result == true)
                                 {
                                     HdlThreadLogic.Current.RunMain(() =>
                                     {
                                         //关闭这个界面
                                         this.CloseForm();
                                     });
                                 }
                             });
                         });
                    };
                    //调整真实高度
                    listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
                }
            });
        }
 
        #endregion
 
        #region ■ 添加备份行_________________________
 
        /// <summary>
        /// 添加备份行
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <param name="addLine"></param>
        /// <param name="isAuto"></param>
        private void AddRowlayout(BackupListNameInfo fileInfo, bool addLine, bool isAuto)
        {
            var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(rowLayout);
 
            //备份名字
            var txtText = rowLayout.frameTable.AddTopView(fileInfo.FolderName, 700);
            if (isAuto == true)
            {
                txtText.TextID = R.MyInternationalizationString.uAutoBackup;
            }
 
            //时间
            var btnTime = rowLayout.frameTable.AddBottomView("", 600);
            if (fileInfo.ModifyTime.Length == 13)
            {
                btnTime.Text = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime2(fileInfo.ModifyTime).ToString("yyyy.MM.dd HH:mm:ss");
            }
            //底线
            if (addLine == true)
            {
                rowLayout.frameTable.AddBottomLine();
            }
 
            //选择
            var btnSelect = rowLayout.frameTable.AddMostRightEmptyIcon(58, 58);
            btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png";
            btnSelect.SelectedImagePath = "Item/ItemSelected.png";
            rowLayout.frameTable.ButtonClickEvent += (sender, e) =>
            {
                btnSelect.IsSelected = !btnSelect.IsSelected;
                if (btnSelect.IsSelected == true)
                {
                    this.nowSelectBackId = fileInfo.Id;
                    if (nowbtnSelect != null)
                    {
                        nowbtnSelect.IsSelected = false;
                    }
                    nowbtnSelect = btnSelect;
                }
                else
                {
                    this.nowSelectBackId = string.Empty;
                    this.nowbtnSelect = null;
                }
            };
 
            //自动备份不允许编辑
            if (isAuto == false)
            {
                //编辑
                var btnEditor = rowLayout.AddEditorControl();
                btnEditor.ButtonClickEvent += (sender, e) =>
                {
                    //显示编辑备考名画面
                    this.ShowEditorBackupForm(fileInfo);
                };
 
                //删除
                var btnDelete = rowLayout.AddDeleteControl();
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //确认删除该备份数据?
                    string msg = Language.StringByID(R.MyInternationalizationString.uDoDeleteBackupMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        //删除备份文档
                        this.DeleteBackInfo(fileInfo.Id);
                    });
                };
            }
        }
 
        #endregion
 
        #region ■ 编辑备份名称_______________________
 
        /// <summary>
        /// 编辑备份名称
        /// </summary>
        /// <param name="backupClassId"></param>
        /// <param name="backName"></param>
        private void EditorBackInfo(string backupClassId, string backName)
        {
            var result = HdlGatewayBackupLogic.Current.EditorGatewayBackupName(backupClassId, backName);
            if (result == false)
            {
                return;
            }
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //从云端获取数据
                this.SetBackupInfoToForm();
            });
        }
 
        #endregion
 
        #region ■ 删除备份文档_______________________
 
        /// <summary>
        /// 删除备份文档
        /// </summary>
        /// <param name="backupClassId"></param>
        private void DeleteBackInfo(string backupClassId)
        {
            bool success = HdlGatewayBackupLogic.Current.DeleteGatewayBackup(this.realGateway.GwId, backupClassId);
            if (success == false)
            {
                return;
            }
            if (this.nowSelectBackId == backupClassId)
            {
                this.nowSelectBackId = string.Empty;
                this.nowbtnSelect = null;
            }
            HdlThreadLogic.Current.RunThread(() =>
            {
                //从云端获取数据
                this.SetBackupInfoToForm();
            });
        }
 
        #endregion
 
        #region ■ 显示编辑备考名画面_________________
 
        /// <summary>
        /// 显示编辑备考名画面
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <returns></returns>
        private void ShowEditorBackupForm(BackupListNameInfo fileInfo)
        {
            //生成一个弹窗画面
            this.ShowDialogInputForm(Language.StringByID(R.MyInternationalizationString.uEditorBackup), fileInfo.FolderName,
                Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName), (contr, txtvalue) =>
            {
                //画面关闭
                contr.CloseDialog();
                //名字一样时,不处理
                if (txtvalue != fileInfo.FolderName)
                {
                    //编辑备份名称
                    this.EditorBackInfo(fileInfo.Id, txtvalue);
                }
            });
        }
 
        #endregion
    }
}