黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.GatewayManage
{
    /// <summary>
    /// 网关数据上传及下载界面
    /// </summary>
    public class GatewayUploadAndDownLoadForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 网关ID
        /// </summary>
        private string gatewayId = string.Empty;
        /// <summary>
        /// 网关对象
        /// </summary>
        private ZbGateway realGateway = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_gatewayId">网关ID</param>
        public void ShowForm(string i_gatewayId)
        {
            this.gatewayId = i_gatewayId;
            HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, gatewayId);
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDataUploadAndDownLoad));
 
            //初始化中部信息
            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);
 
            var listView = new VerticalListControl(12);
            listView.Y = frameBack.Bottom;
            listView.Height = bodyFrameLayout.Height - frameBack.Height;
            listView.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(listView);
 
            //自动备份
            var frameAuto = new FrameRowControl(listView.rowSpace / 2);
            frameAuto.UseClickStatu = false;
            listView.AddChidren(frameAuto);
            frameAuto.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAutoBackup), 700);
            frameAuto.AddBottomLine();
            var btnSwicth = frameAuto.AddMostRightSwitchIcon();
            btnSwicth.ButtonClickEvent += (sender, e) =>
            {
                //设置状态
                if (HdlGatewayLogic.Current.SetGatewayAutoBackupStatu(this.realGateway, !btnSwicth.IsSelected) == true)
                {
                    btnSwicth.IsSelected = !btnSwicth.IsSelected;
                }
            };
 
            //上传数据至云端
            var frameUp = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(frameUp);
            frameUp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uUploadDataToDb), 700);
            frameUp.AddRightArrow();
            frameUp.AddBottomLine();
            frameUp.ButtonClickEvent += (sender, e) =>
            {
                if (this.realGateway == null)
                {
                    //错误:网关对象丢失
                    string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
                    this.ShowMassage(ShowMsgType.Error, msg);
                    return;
                }
 
                //生成一个弹窗画面
                this.ShowDialogInputForm(Language.StringByID(R.MyInternationalizationString.uUploadData),
                    Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName), null, (contr, textValue) =>
                {
                    //画面关闭
                    contr.CloseDialog();
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        //上传备份
                        HdlGatewayBackupLogic.Current.DoBackupGateway(this.realGateway.GwId, textValue);
                    });
                });
            };
 
            //从云端下载数据
            var frameDown = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(frameDown);
            frameDown.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uDwonloadDataFromDb), 700);
            frameDown.AddRightArrow();
            frameDown.ButtonClickEvent += (sender, e) =>
            {
                if (this.realGateway == null)
                {
                    //错误:网关对象丢失
                    string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
                    this.ShowMassage(ShowMsgType.Error, msg);
                    return;
                }
                var form = new GatewayBackUpListForm();
                form.AddForm(this.realGateway);
            };
            //调整真实高度
            listView.AdjustRealHeight(Application.GetRealHeight(23));
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //获取网关数据
                this.GetGatewayData(btnSwicth);
            });
        }
 
        #endregion
 
        #region ■ 获取数据___________________________
 
        /// <summary>
        /// 获取网关数据
        /// </summary>
        /// <param name="btnSwitch"></param>
        private void GetGatewayData(MostRightIconControl btnSwitch)
        {
            //打开进度条
            this.ShowProgressBar();
 
            //获取网关自动设置状态
            var statu = HdlGatewayLogic.Current.GetGatewayAutoBackupStatu(realGateway);
            if (statu == -1)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            if (statu == 1)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    btnSwitch.IsSelected = true;
                });
            }
 
            //关闭进度条
            this.CloseProgressBar();
        }
 
        #endregion
    }
}