黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.HideOption
{
    /// <summary>
    /// 隐匿功能的网关文件列表界面
    /// </summary>
    public class HideOptionGatewayListFileForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 网关对象
        /// </summary>
        private ZbGateway zbGateway = null;
        private BottomClickButton btnDelete = null;
        private List<string> listDeleteFile = new List<string>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_gateway"></param>
        public void ShowForm(ZbGateway i_gateway)
        {
            HdlFileLogic.Current.CreateDirectory(System.IO.Path.Combine(HdlFileNameResourse.LocalMemoryDirectory, "MyTempDir"), true);
            this.zbGateway = i_gateway;
            //设置标题信息
            base.SetTitleText("网关文件列表");
            //初始化中部控件
            this.InitMiddleFrame();
 
            var btnButton = new NormalViewControl(300, 69, true);
            btnButton.Gravity = Gravity.CenterVertical;
            btnButton.X = bodyFrameLayout.Width - Application.GetRealWidth(300) - HdlControlResourse.XXLeft;
            btnButton.TextColor = UserCenterColor.Current.TopLayoutTitleText;
            btnButton.TextAlignment = TextAlignment.CenterRight;
            btnButton.TextSize = 17;
            btnButton.Text = "一键删除";
            topFrameLayout.AddChidren(btnButton);
            btnButton.ButtonClickEvent += (sender, e) =>
            {
                btnDelete.Visible = true;
            };
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var listview = new VerticalListControl(29);
            listview.Height = bodyFrameLayout.Height;
            listview.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(listview);
 
            this.ShowProgressBar();
            HdlThreadLogic.Current.RunThread(async () =>
            {
                var result = await zbGateway.FileTransferLsDirAsync();
 
                this.CloseProgressBar();
                if (result == null || result.fileTransferLsDiResponseData == null)
                {
                    this.ShowMassage(ShowMsgType.Tip, "获取列表失败,网关没有回复");
                    return;
                }
                if (result.fileTransferLsDiResponseData.Result != 0)
                {
                    this.ShowMassage(ShowMsgType.Tip, "查看失败,好像网关不允许查看这个目录");
                    return;
                }
 
                var listFile = new List<string>();
                foreach (var data in result.fileTransferLsDiResponseData.Dir)
                {
                    string[] strArry = data.File.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                    listFile.Add(strArry[strArry.Length - 1]);
                }
                listFile.Sort();
                HdlThreadLogic.Current.RunMain(() =>
                {
                    foreach (var fileName in listFile)
                    {
                        var rowContr1 = new RowLayoutControl(listview.rowSpace / 2);
                        listview.AddChidren(rowContr1);
                        rowContr1.frameTable.AddLeftCaption(fileName, 700);
                        rowContr1.frameTable.AddBottomLine();
 
                        var btnSelect = new IconViewControl(58);
                        btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
                        btnSelect.Gravity = Gravity.Center;
                        rowContr1.frameTable.AddChidren(btnSelect);
                        btnSelect.Visible = false;
 
                        var btnDelete = rowContr1.AddDeleteControl();
                        btnDelete.ButtonClickEvent += (sender, e) =>
                        {
                            this.ShowMassage(ShowMsgType.Confirm, "是否删除网关的这个文件(需谨慎)", async () =>
                            {
                                var result9 = await zbGateway.DelFileOrDirAsync("/etc/hdlDat/" + fileName);
                                if (result9 == null || result9.delFileOrDirResponseData == null)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,网关没有回复");
                                    return;
                                }
                                if (result9.delFileOrDirResponseData.Result == 1)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,网关说这个东西不存在");
                                    return;
                                }
                                if (result9.delFileOrDirResponseData.Result == 2)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,网关说这个东西不允许删除");
                                    return;
                                }
                                if (result9.delFileOrDirResponseData.Result != 0)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,无法识别的状态码(" + result9.delFileOrDirResponseData.Result + ")");
                                    return;
                                }
                                rowContr1.RemoveFromParent();
                                this.ShowMassage(ShowMsgType.Tip, "删除文件成功");
                            });
                        };
                    }
 
                    listview.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
 
                    this.btnDelete = new BottomClickButton();
                    btnDelete.Text = "删除";
                    bodyFrameLayout.AddChidren(btnDelete);
                    btnDelete.Visible = false;
                    btnDelete.ButtonClickEvent += (sender, e) =>
                    {
                        this.ShowMassage(ShowMsgType.Confirm, "确定是否删除这些文件?", async () =>
                        {
                            foreach (var listfile in this.listDeleteFile)
                            {
                                var result9 = await zbGateway.DelFileOrDirAsync("/etc/hdlDat/" + listfile);
                                if (result9 == null || result9.delFileOrDirResponseData == null)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,网关没有回复");
                                    this.InitMiddleFrame();
                                    this.listDeleteFile = new List<string>();
                                    return;
                                }
                                if (result9.delFileOrDirResponseData.Result == 1)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,网关说这个东西不存在");
                                    this.InitMiddleFrame();
                                    this.listDeleteFile = new List<string>();
                                    return;
                                }
                                if (result9.delFileOrDirResponseData.Result == 2)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,网关说这个东西不允许删除");
                                    this.InitMiddleFrame();
                                    this.listDeleteFile = new List<string>();
                                    return;
                                }
                                if (result9.delFileOrDirResponseData.Result != 0)
                                {
                                    this.ShowMassage(ShowMsgType.Tip, "删除文件失败,无法识别的状态码(" + result9.delFileOrDirResponseData.Result + ")");
                                    this.InitMiddleFrame();
                                    this.listDeleteFile = new List<string>();
                                    return;
                                }
                            }
                            this.InitMiddleFrame();
                            this.listDeleteFile = new List<string>();
                        });
                    };
                });
            });
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            HdlFileLogic.Current.DeleteDirectory(System.IO.Path.Combine(HdlFileNameResourse.LocalMemoryDirectory, "MyTempDir"));
 
            base.CloseFormBefore();
        }
 
        #endregion
    }
}