xm
2020-05-08 6bca8fcd37a48808a0b9c9342fc1be0adddfece6
ZigbeeApp/Shared/Phone/UserCenter/HideOption/HideOptionFileListForm.cs
New file
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.HideOption
{
    /// <summary>
    /// 本地缓存文件列表的界面
    /// </summary>
    public class HideOptionFileListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 解密
        /// </summary>
        private bool decryptPassword = false;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm(string directory)
        {
            //设置头部信息
            base.SetTitleText("文件列表");
            var btnButton = new NormalViewControl(200, 69, true);
            btnButton.Gravity = Gravity.CenterVertical;
            btnButton.X = bodyFrameLayout.Width - Application.GetRealWidth(200) - ControlCommonResourse.XXLeft;
            btnButton.TextColor = UserCenterColor.Current.TopLayoutTitleText;
            btnButton.TextAlignment = TextAlignment.BottomRight;
            btnButton.TextSize = 17;
            btnButton.Text = "翻译";
            topFrameLayout.AddChidren(btnButton);
            btnButton.ButtonClickEvent += (sender, e) =>
            {
                if (this.decryptPassword == false)
                {
                    this.decryptPassword = true;
                    //初始化中部信息
                    this.InitMiddleFrame(directory);
                }
            };
            //初始化中部信息
            this.InitMiddleFrame(directory);
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame(string directory)
        {
            this.ClearBodyFrame();
            var listAllFile = HdlAutoBackupLogic.GetFileFromDirectory(directory);
            listAllFile.Sort();
            var listView = new VerticalListControl(23);
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
            for (int i = 0; i < listAllFile.Count; i++)
            {
                this.AddRowControl(listView, listAllFile[i], directory, i != listAllFile.Count - 1);
            }
            listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(50));
            var btnButon = new BottomClickButton();
            btnButon.Text = "删除文件夹";
            bodyFrameLayout.AddChidren(btnButon);
            btnButon.ButtonClickEvent += (sender, e) =>
            {
                this.ShowMassage(ShowMsgType.Confirm, "是否清除该文件夹", () =>
                {
                    try
                    {
                        System.IO.Directory.Delete(directory, true);
                        this.CloseForm();
                    }
                    catch (Exception ex)
                    {
                        this.ShowMassage(ShowMsgType.Error, "清除缓存文件夹异常");
                        HdlLogLogic.Current.WriteLog(ex, "清除缓存文件夹异常");
                    }
                });
            };
            if (directory == UserCenterLogic.CombinePath())
            {
                btnButon.CanClick = false;
            }
        }
        private void AddRowControl(VerticalListControl listView, string fileName, string directory, bool addLine)
        {
            string fileNewName = fileName;
            if (decryptPassword == true && fileName.StartsWith("Device_") == false)
            {
                try
                {
                    fileNewName = UserCenterLogic.DecryptPassword(UserCenterResourse.FileEncryptKey, fileName);
                }
                catch { fileNewName = fileName; }
            }
            var row1 = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(row1);
            var btnName = row1.frameTable.AddLeftCaption(fileNewName, 800);
            btnName.IsMoreLines = true;
            if (addLine == true)
            {
                row1.frameTable.AddBottomLine();
            }
            row1.frameTable.AddRightArrow();
            var btnDelete = row1.AddDeleteControl();
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                this.ShowMassage(ShowMsgType.Confirm, "是否清除该缓存文件", () =>
                {
                    var myFile = UserCenterLogic.CombinePath(directory, fileName);
                    try
                    {
                        System.IO.File.Delete(myFile);
                        row1.RemoveFromParent();
                    }
                    catch (Exception ex)
                    {
                        this.ShowMassage(ShowMsgType.Error, "清除缓存文件异常");
                        HdlLogLogic.Current.WriteLog(ex, "清除缓存文件异常");
                    }
                });
            };
            row1.frameTable.ButtonClickEvent += (sender, e) =>
            {
                var form = new HideOptionFileContentForm();
                form.AddForm(UserCenterLogic.CombinePath(directory, fileName));
            };
        }
        #endregion
        #region ■ 一般方法___________________________
        #endregion
    }
}