From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 16 四月 2020 17:10:57 +0800
Subject: [PATCH] 请合并代码

---
 ZigbeeApp/Shared/Phone/UserCenter/HdlBackup/HdlBackupListForm.cs |  589 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 589 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/HdlBackup/HdlBackupListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/HdlBackup/HdlBackupListForm.cs
new file mode 100755
index 0000000..8f53bac
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/HdlBackup/HdlBackupListForm.cs
@@ -0,0 +1,589 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.UserCenter.HdlBackup
+{
+    /// <summary>
+    /// 澶囦唤鍒楄〃鐣岄潰
+    /// </summary>
+    public class HdlBackupListForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private VerticalListControl listView = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {
+            //璁剧疆鏍囬淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDataBackup));
+
+            //鍙充笂娣诲姞鎸夐挳
+            var btnTopIcon = new MostRightIconControl(69, 69);
+            btnTopIcon.UnSelectedImagePath = "Item/Add.png";
+            topFrameLayout.AddChidren(btnTopIcon);
+            btnTopIcon.InitControl();
+            btnTopIcon.ButtonClickEvent += (sender, e) =>
+            {
+                //鏄剧ず娣诲姞澶囪�冨悕鐢婚潰
+                this.ShowAddBackupForm();
+            };
+
+            //鍒濆鍖栦腑閮ㄦ帶浠�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄦ帶浠�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            listView = new VerticalListControl(29);
+            listView.BackgroundColor = UserCenterColor.Current.White;
+            listView.Height = bodyFrameLayout.Height;
+            bodyFrameLayout.AddChidren(listView);
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //浠庝簯绔幏鍙栨暟鎹�
+                this.SetBackupInfoToForm();
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 浠庝簯绔幏鍙栨暟鎹甠____________________
+
+        /// <summary>
+        /// 浠庝簯绔幏鍙栨暟鎹�
+        /// </summary>
+        private async void SetBackupInfoToForm()
+        {
+            //杩涘害鏉�
+            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();
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                if (this.Parent == null)
+                {
+                    return;
+
+                }
+                listView.RemoveAll();
+                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++)
+                {
+                    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));
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 娣诲姞澶囦唤琛宊________________________
+
+        /// <summary>
+        /// 娣诲姞澶囦唤琛�
+        /// </summary>
+        /// <param name="fileInfo"></param>
+        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 = "Item/DownLoad.png";
+
+            //澶囦唤鍚嶅瓧
+            var txtText = rowLayout.frameTable.AddTopView("", 700);
+            if (autoBack == true)
+            {
+                //鑷姩澶囦唤
+                txtText.Text = Language.StringByID(R.MyInternationalizationString.uAutoBackup);
+            }
+            else
+            {
+                txtText.Text = fileInfo.BackupName;
+            }
+            //鏃堕棿
+            var btnTime = rowLayout.frameTable.AddBottomView("", 600);
+            if (fileInfo.CreatedOnUtc.Length >= 19)
+            {
+                btnTime.Text = UserCenterLogic.ConvertUtcTimeToLocalTime(fileInfo.CreatedOnUtc).ToString("yyyy.MM.dd HH:mm:ss");
+            }
+            if (addLine == true)
+            {
+                //搴曠嚎
+                rowLayout.frameTable.AddBottomLine();
+            }
+
+            //绔嬪嵆涓嬭浇
+            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);
+                });
+            };
+
+            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 = rowLayout.AddDeleteControl();
+            btnDelete.ButtonClickEvent += (sender, e) =>
+            {
+                //纭鍒犻櫎璇ュ浠芥暟鎹�?
+                string msg = Language.StringByID(R.MyInternationalizationString.uDoDeleteBackupMsg);
+                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
+                {
+                    //鍒犻櫎澶囦唤鏂囨。
+                    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();
+                });
+            };
+        }
+
+        #endregion
+
+        #region 鈻� 璇诲彇澶囦唤鏂囨。_______________________
+
+        /// <summary>
+        /// 璇诲彇澶囦唤鏂囨。
+        /// </summary>
+        /// <param name="BackupClassId"></param>
+        private void LoadBackupInfo(string BackupClassId)
+        {
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                //浠庝簯绔幏鍙栧浠界殑鏂囦欢
+                bool result = await HdlBackupLogic.Current.LoadAppBackupInfo(BackupClassId);
+                if (result == false)
+                {
+                    //鏂囦欢鎭㈠澶辫触
+                    string msg2 = Language.StringByID(R.MyInternationalizationString.uFileRecoverFail);
+                    this.ShowMassage(ShowMsgType.Error, msg2);
+                    return;
+                }
+
+                Application.RunOnMainThread(() =>
+                {
+                    //鍏抽棴鎵�鏈夌晫闈�
+                    UserCenterLogic.CloseAllOpenForm();
+                    //鍒囨崲鍒颁富椤�
+                    UserView.UserPage.Instance.Fresh();
+                });
+
+                //鏂囦欢鎭㈠鎴愬姛
+                string msg = Language.StringByID(R.MyInternationalizationString.uFileRecoverSuccess);
+                this.ShowMassage(ShowMsgType.Normal, msg);
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 涓婁紶鎵嬪姩澶囦唤鏁版嵁___________________
+
+        /// <summary>
+        /// 涓婁紶鏁版嵁
+        /// </summary>
+        /// <param name="backName"></param>
+        private void UpLoadBackInfo(string backName)
+        {
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                //鍒涘缓涓�涓浠藉悕瀛�
+                string backupClassId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(backName);
+                if (backupClassId == null)
+                {
+                    //鍒涘缓澶囦唤鍚嶅瓧澶辫触
+                    string msg = Language.StringByID(R.MyInternationalizationString.uCreatBackupNameFail);
+                    this.ShowMassage(ShowMsgType.Error, msg);
+
+                    return;
+                }
+
+                //涓婁紶鏁版嵁鍒颁簯绔�
+                bool result = await HdlBackupLogic.Current.UpLoadBackupFileToDB(backupClassId);
+                if (result == false)
+                {
+                    //鏂囦欢涓婁紶澶辫触
+                    string msg = Language.StringByID(R.MyInternationalizationString.uFileUpLoadFail);
+                    this.ShowMassage(ShowMsgType.Error, msg);
+
+                    //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎
+                    this.DeleteBackInfo(backupClassId, ShowErrorMode.NO);
+
+                    return;
+                }
+
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    //浠庝簯绔幏鍙栨暟鎹�
+                    this.SetBackupInfoToForm();
+                });
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 涓婁紶鑷姩澶囦唤鏁版嵁___________________
+
+        /// <summary>
+        /// 涓婁紶鑷姩澶囦唤鏁版嵁
+        /// </summary>
+        private 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 鈻� 缂栬緫澶囦唤鍚嶇О_______________________
+
+        /// <summary>
+        /// 缂栬緫澶囦唤鍚嶇О
+        /// </summary>
+        /// <param name="BackupClassId"></param>
+        /// <param name="backName"></param>
+        private async void EditorBackInfo(string BackupClassId, string backName)
+        {
+            //寮�鍚繘搴︽潯
+            this.ShowProgressBar();
+
+            var Pra = new EditorBackUpNamePra();
+            Pra.BackupClassId = BackupClassId;
+            Pra.BackupName = backName;
+            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+            Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/UpdateHomeAppGatewayName", true, Pra);
+            if (result == false)
+            {
+                //缂栬緫澶囦唤鍚嶇О澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uEditorBackupNameFail);
+                this.ShowMassage(ShowMsgType.Error, msg);
+                //鍏抽棴
+                this.CloseProgressBar();
+                return;
+            }
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //浠庝簯绔幏鍙栨暟鎹�
+                this.SetBackupInfoToForm();
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍒犻櫎澶囦唤鏂囨。_______________________
+
+        /// <summary>
+        /// 鍒犻櫎澶囦唤鏂囨。
+        /// </summary>
+        /// <param name="BackupClassId"></param>
+        /// <param name="showMode"></param>
+        public async void DeleteBackInfo(string BackupClassId, ShowErrorMode showMode = ShowErrorMode.YES)
+        {
+            //杩涘害鏉�
+            this.ShowProgressBar();
+
+            bool success = await HdlBackupLogic.Current.DeleteDbBackupData(BackupClassId);
+
+            //鍏抽棴杩涘害鏉�
+            this.CloseProgressBar();
+
+            if (success == false)
+            {
+                if (showMode == ShowErrorMode.YES)
+                {
+                    //鍒犻櫎澶囦唤澶辫触
+                    string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBackupFail);
+                    this.ShowMassage(ShowMsgType.Error, msg);
+                }
+                return;
+            }
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //浠庝簯绔幏鍙栨暟鎹�
+                this.SetBackupInfoToForm();
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鏄剧ず缂栬緫澶囪�冨悕鐢婚潰_________________
+
+        /// <summary>
+        /// 鏄剧ず缂栬緫澶囪�冨悕鐢婚潰
+        /// </summary>
+        /// <param name="fileInfo"></param>
+        /// <returns></returns>
+        private void ShowEditorBackupForm(BackupListNameInfo fileInfo)
+        {
+            //鐢熸垚涓�涓脊绐楃敾闈�
+            var dialogForm = new DialogInputControl();
+            //缂栬緫澶囦唤
+            dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorBackup));
+            //璇疯緭鍏ュ浠藉悕绉�
+            dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName));
+            dialogForm.Text = fileInfo.BackupName;
+
+            //鎸変笅纭鎸夐挳
+            dialogForm.ComfirmClickEvent += ((textValue) =>
+            {
+                //妫�娴嬪鑰冨悕绉�
+                if (this.CheckBackupName(textValue) == false)
+                {
+                    return;
+                }
+
+                //鐢婚潰鍏抽棴
+                dialogForm.CloseDialog();
+
+                //鍚嶅瓧涓�鏍锋椂锛屼笉澶勭悊
+                if (textValue != fileInfo.BackupName)
+                {
+                    //缂栬緫澶囦唤鍚嶇О
+                    this.EditorBackInfo(fileInfo.Id, textValue);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ず娣诲姞澶囪�冨悕鐢婚潰
+        /// </summary>
+        /// <returns></returns>
+        private void ShowAddBackupForm()
+        {
+            //鐢熸垚涓�涓脊绐楃敾闈�
+            var dialogForm = new DialogInputControl();
+            //娣诲姞澶囦唤
+            dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddBackup));
+            //璇疯緭鍏ュ浠藉悕绉�
+            dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName));
+
+            //鎸変笅纭鎸夐挳
+            dialogForm.ComfirmClickEvent += ((textValue) =>
+            {
+                //妫�娴嬪鑰冨悕绉�
+                if (this.CheckBackupName(textValue) == false)
+                {
+                    return;
+                }
+
+                //鐢婚潰鍏抽棴
+                dialogForm.CloseDialog();
+
+                //涓婁紶澶囦唤
+                this.UpLoadBackInfo(textValue);
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鎶婃湰鍦版墍鏈夋枃浠剁Щ鍔ㄥ埌鑷姩澶囦唤鏂囦欢澶�
+        /// </summary>
+        private void CopyLocationAllFileToAutoBackDirectory()
+        {
+            List<string> listAllFile = Shared.Common.Global.FileListByHomeId();
+
+            string strroot = Common.Config.Instance.FullPath;
+            string autoPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
+            foreach (string file in listAllFile)
+            {
+                //鍒ゆ柇鏄惁鏄簲璇ヤ笂浼犵殑鏂囦欢
+                if (HdlBackupLogic.Current.IsNotUpLoadFile(file) == true)
+                {
+                    continue;
+                }
+                string sourseName = System.IO.Path.Combine(strroot, file);
+                string newName = System.IO.Path.Combine(autoPath, file);
+                System.IO.File.Copy(sourseName, newName, true);
+            }
+        }
+
+        /// <summary>
+        /// 妫�娴嬪鑰冨悕绉�
+        /// </summary>
+        /// <param name="backName"></param>
+        /// <returns></returns>
+        private bool CheckBackupName(string backName)
+        {
+            if (backName == string.Empty)
+            {
+                //璇疯緭鍏ュ浠藉悕绉�
+                string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName);
+                this.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
+            if (backName.Contains("##") == true)
+            {
+                //瀛樺湪闈炴硶瀛楃銆�##銆�
+                string msg = Language.StringByID(R.MyInternationalizationString.uErrorFieldIsEsixt);
+                if (msg.Contains("{0}") == true)
+                {
+                    msg = string.Format(msg, "##");
+                }
+                this.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
+
+            return true;
+        }
+        #endregion
+    }
+}

--
Gitblit v1.8.0