黄学彪
2019-11-13 8b9ce384b26c414db32f98e94e088f5334869c2d
ZigbeeApp/Shared/Phone/UserCenter/HdlBackup/HdlBackupListForm.cs
File was renamed from ZigbeeApp/Shared/Phone/UserCenter/HdlBackup/HdlManualBackUpForm.cs
@@ -1,13 +1,13 @@
using Shared.Common;
using System;
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.HdlBackup
{
    /// <summary>
    /// 备份画面
    /// 备份列表界面
    /// </summary>
    public class HdlManualBackUpForm : EditorCommonForm
    public class HdlBackupListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
@@ -26,7 +26,7 @@
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uBackupAndRecover));
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDataBackup));
            //右上添加按钮
            var btnTopIcon = new MostRightIconControl(69, 69);
@@ -75,30 +75,60 @@
            //进度条
            this.ShowProgressBar();
            //获取app的自动备份
            var autoData = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
            if (autoData == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //从云端获取数据
            var pageData = await HdlBackupLogic.Current.GetBackupListNameFromDB();
            if (pageData == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //关闭
            this.CloseProgressBar();
            if (pageData == null)
            HdlThreadLogic.Current.RunMain(() =>
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                if (this.Parent == null || listView == null)
                if (this.Parent == null)
                {
                    return;
                }
                listView.RemoveAll();
                int count = pageData.Count - 1;
                listView.RecoverHeight();
                //添加自动备份行
                if (autoData.Count == 0)
                {
                    this.AddNotAutoBackupRow(pageData.Count > 0);
                }
                else
                {
                    this.AddRowlayout(autoData[0], pageData.Count > 0, true);
                }
                //排序
                var dic = new Dictionary<string, BackupListNameInfo>();
                var listSort = new List<string>();
                for (int i = 0; i < pageData.Count; i++)
                {
                    //添加备份行
                    this.AddRowlayout(pageData[i], i != count);
                    listSort.Add(pageData[i].CreatedOnUtc);
                    dic[pageData[i].CreatedOnUtc] = pageData[i];
                }
                listSort.Sort();
                for (int i = listSort.Count - 1; i >= 0; i--)
                {
                    //添加备份行
                    this.AddRowlayout(dic[listSort[i]], i != 0, false);
                }
                listView.AdjustRealHeight(Application.GetRealHeight(23));
            });
        }
@@ -110,65 +140,145 @@
        /// 添加备份行
        /// </summary>
        /// <param name="fileInfo"></param>
        private void AddRowlayout(BackupListNameInfo fileInfo, bool addLine)
        private void AddRowlayout(BackupListNameInfo fileInfo, bool addLine, bool autoBack)
        {
            //行
            var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(rowLayout);
            if (autoBack == true)
            {
                rowLayout.frameTable.UseClickStatu = false;
            }
            //图标
            var btnPoint = rowLayout.frameTable.AddLeftIcon();
            btnPoint.UnSelectedImagePath = "Center/Backup.png";
            btnPoint.UnSelectedImagePath = "Item/DownLoad.png";
            //备份名字
            var txtText = rowLayout.frameTable.AddLeftCaption(fileInfo.BackupName, 700);
            var txtText = rowLayout.frameTable.AddLeftCaption("", 700, 60);
            if (autoBack == true)
            {
                //自动备份
                txtText.Text = Language.StringByID(R.MyInternationalizationString.uAutoBackup);
            }
            else
            {
                txtText.Text = fileInfo.BackupName;
            }
            txtText.TextSize = 15;
            //这个坐标有点特殊
            txtText.Y = Application.GetRealHeight(12) + rowLayout.chidrenYaxis;
            rowLayout.frameTable.AddChidren(txtText, ChidrenBindMode.BindEventOnly);
            //时间
            var btnTime = rowLayout.frameTable.AddLeftCaption("", 600, 50, true);
            //这个坐标有点特殊
            btnTime.Y = Application.GetRealHeight(72) + rowLayout.chidrenYaxis;
            btnTime.TextSize = 12;
            btnTime.TextColor = UserCenterColor.Current.TextGrayColor1;
            rowLayout.frameTable.AddChidren(btnTime, ChidrenBindMode.BindEventOnly);
            if (fileInfo.CreatedOnUtc.Length >= 19)
            {
                btnTime.Text = fileInfo.CreatedOnUtc.Replace("-", ".").Replace("T", " ");
            }
            if (addLine == true)
            {
                //底线
                rowLayout.frameTable.AddBottomLine();
            }
            //编辑备注名
            rowLayout.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //显示编辑备考名画面
                this.ShowEditorBackupForm(fileInfo);
            };
            //下载图标
            var btnLoad = rowLayout.frameTable.AddMostRightEmptyIcon(81, 81);
            rowLayout.frameTable.ChangedChidrenBindMode(btnLoad, ChidrenBindMode.NotBind);
            //启用点亮功能
            btnLoad.UseClickStatu = true;
            btnLoad.UnSelectedImagePath = "Item/DownLoad.png";
            btnLoad.SelectedImagePath = "Item/DownLoadSelected.png";
            //立即下载
            var btnLoad = new NormalViewControl(Application.GetRealWidth(200), rowLayout.frameTable.Height, false);
            btnLoad.X = rowLayout.frameTable.Width - Application.GetRealWidth(200 + 127);
            btnLoad.TextID = R.MyInternationalizationString.uDownLoadNow;
            btnLoad.TextAlignment = TextAlignment.CenterRight;
            btnLoad.TextSize = 12;
            btnLoad.TextColor = UserCenterColor.Current.TextOrangeColor;
            rowLayout.frameTable.AddChidren(btnLoad, ChidrenBindMode.NotBind);
            btnLoad.ButtonClickEvent += (sender, e) =>
            {
                //是否要下载并恢复数据?
                string msg = Language.StringByID(R.MyInternationalizationString.uDownLoadAndRecoverMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                 {
                     //读取备份文档
                     this.LoadBackupInfo(fileInfo.Id);
                 });
                {
                    //读取备份文档
                    this.LoadBackupInfo(fileInfo.Id);
                });
            };
            if (autoBack == true)
            {
                //上传
                var btnUpLoad = rowLayout.AddEditorControl();
                btnUpLoad.TextID = R.MyInternationalizationString.uUpload;
                btnUpLoad.ButtonClickEvent += (sender, e) =>
                {
                    //确认是否上传数据到服务器?
                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uSynchronizeDataToServiceMsg), () =>
                    {
                        //上传自动备份数据
                        this.UpLoadAutoBackupInfo();
                    });
                };
            }
            else
            {
                //编辑备注名
                rowLayout.frameTable.ButtonClickEvent += (sender, e) =>
                {
                    //显示编辑备考名画面
                    this.ShowEditorBackupForm(fileInfo);
                };
            }
            //删除
            var btnDelete = new NormalViewControl(Application.GetRealWidth(177), rowLayout.Height, false);
            btnDelete.BackgroundColor = UserCenterColor.Current.RowDeleteButtonColor;
            btnDelete.TextAlignment = TextAlignment.Center;
            btnDelete.TextColor = UserCenterColor.Current.White;
            btnDelete.TextID = R.MyInternationalizationString.uDelete;
            rowLayout.AddRightView(btnDelete);
            var btnDelete = rowLayout.AddDeleteControl();
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //确定要删除文件吗?
                string msg = Language.StringByID(R.MyInternationalizationString.uDoDeleteFileMsg);
                //确认删除该备份数据?
                string msg = Language.StringByID(R.MyInternationalizationString.uDoDeleteBackupMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                 {
                     //删除备份文档
                     this.DeleteBackInfo(fileInfo.Id, ShowErrorMode.YES);
                 });
                {
                    //删除备份文档
                    this.DeleteBackInfo(fileInfo.Id, ShowErrorMode.YES);
                });
            };
        }
        /// <summary>
        /// 添加没有自动备份数据的行
        /// </summary>
        /// <param name="addLine"></param>
        private void AddNotAutoBackupRow(bool addLine)
        {
            //行
            var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(rowLayout);
            rowLayout.frameTable.UseClickStatu = false;
            //图标
            var btnPoint = rowLayout.frameTable.AddLeftIcon();
            btnPoint.UnSelectedImagePath = "Item/DownLoad.png";
            //备份名字
            var txtText = rowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAutoBackup), 700);
            txtText.TextSize = 15;
            if (addLine == true)
            {
                //底线
                rowLayout.frameTable.AddBottomLine();
            }
            //上传
            var btnUpLoad = rowLayout.AddEditorControl();
            btnUpLoad.TextID = R.MyInternationalizationString.uUpload;
            btnUpLoad.ButtonClickEvent += (sender, e) =>
            {
                //确认是否上传数据到服务器?
                this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uSynchronizeDataToServiceMsg), () =>
                {
                    //上传自动备份数据
                    this.UpLoadAutoBackupInfo();
                });
            };
        }
@@ -210,7 +320,7 @@
        #endregion
        #region ■ 上传数据___________________________
        #region ■ 上传手动备份数据___________________
        /// <summary>
        /// 上传数据
@@ -253,6 +363,37 @@
            });
        }
        #endregion
        #region ■ 上传自动备份数据___________________
        /// <summary>
        /// 上传自动备份数据
        /// </summary>
        public void UpLoadAutoBackupInfo()
        {
            HdlThreadLogic.Current.RunThread(async () =>
            {
                int result = await HdlAutoBackupLogic.DoUpLoadAutoBackupData();
                if (result == -1)
                {
                    //文件上传失败
                    string msg = Language.StringByID(R.MyInternationalizationString.uFileUpLoadFail);
                    this.ShowMassage(ShowMsgType.Error, msg);
                    return;
                }
                //数据成功同步到服务器
                string msg2 = Language.StringByID(R.MyInternationalizationString.uSynchronizeDataToServiceSuccessMsg);
                this.ShowMassage(ShowMsgType.Normal, msg2);
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //从云端获取数据
                    this.SetBackupInfoToForm();
                });
            });
        }
        #endregion
        #region ■ 编辑备份名称_______________________
@@ -340,8 +481,8 @@
        private void ShowEditorBackupForm(BackupListNameInfo fileInfo)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputFrameControl(this, DialogFrameMode.OnlyInput);
            var dialogForm = new DialogInputForm();
            dialogForm.AddForm(DialogFrameMode.OnlyInput);
            //编辑备份
            dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorBackup));
            //请输入备注名称
@@ -358,7 +499,7 @@
                }
                //画面关闭
                dialogForm.CloseDialog();
                dialogForm.CloseForm();
                //名字一样时,不处理
                if (textValue != fileInfo.BackupName)
@@ -376,8 +517,8 @@
        private void ShowAddBackupForm()
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputFrameControl(this, DialogFrameMode.OnlyInput);
            var dialogForm = new DialogInputForm();
            dialogForm.AddForm(DialogFrameMode.OnlyInput);
            //添加备份
            dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddBackup));
            //请输入备注名称
@@ -393,7 +534,7 @@
                }
                //画面关闭
                dialogForm.CloseDialog();
                dialogForm.CloseForm();
                //上传备份
                this.UpLoadBackInfo(textValue);
@@ -409,7 +550,7 @@
        /// </summary>
        private void CopyLocationAllFileToAutoBackDirectory()
        {
            List<string> listAllFile = Global.FileListByHomeId();
            List<string> listAllFile = Shared.Common.Global.FileListByHomeId();
            string strroot = Common.Config.Instance.FullPath;
            string autoPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);