From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/Common/Logic/HdlFormLogic.cs |  324 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 324 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlFormLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlFormLogic.cs
new file mode 100644
index 0000000..01135e5
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlFormLogic.cs
@@ -0,0 +1,324 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone
+{
+    /// <summary>
+    /// 鐣岄潰鐩稿叧鐨勯�昏緫
+    /// </summary>
+    public class HdlFormLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鐣岄潰鐩稿叧鐨勯�昏緫
+        /// </summary>
+        private static HdlFormLogic m_Current;
+        /// <summary>
+        /// 鐣岄潰鐩稿叧鐨勯�昏緫
+        /// </summary>
+        public static HdlFormLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlFormLogic();
+                }
+                return m_Current;
+            }
+        }
+
+        /// <summary>
+        /// <para>褰撳墠宸茬粡鎵撳紑浜嗙殑鐢婚潰(缁ф壙浜嶶serCenterCommonForm鎵嶈兘浣跨敤)銆�</para>
+        /// <para>鐢婚潰鎵撳紑鏃讹紝浼氳嚜鍔ㄨ拷鍑伙紝鐢婚潰鍏抽棴鏃讹紝鑷姩绉婚櫎銆�</para>
+        /// <para>鏂版坊鍔犵殑鐣岄潰浼氭斁鍦ㄥ墠闈�</para>
+        /// </summary>
+        private List<CommonFormBase> ListActionForm = new List<CommonFormBase>();
+        /// <summary>
+        /// 褰撳墠姝e湪鎿嶄綔鐨勭敾闈D(娌′汉浼氭噦瀹冧负浣曡瀛樺湪)
+        /// </summary>
+        public string NowActionFormID
+        {
+            get
+            {
+                return ListActionForm.Count > 0 ? ListActionForm[0].FormID : string.Empty;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 娣诲姞鐣岄潰鐩稿叧_______________________
+
+        /// <summary>
+        /// 妫�娴嬭兘鍚︽坊鍔犵敾闈�
+        /// </summary>
+        /// <returns>true:鍙互杩藉姞 false:涓嶅彲杩藉姞</returns>
+        /// <param name="form">Form</param>
+        public bool CheckCanAddForm(CommonFormBase form)
+        {
+            //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
+            string formId = GetFormID(form);
+
+            //鏆傛椂杩欐牱寮勭湅鐪嬶紝濡傛灉閲嶅锛屽垯鍏抽棴鎺夊師鏉ョ殑鐣岄潰
+            var formTemp = this.GetFormByName(formId);
+            formTemp?.CloseForm();
+
+            return true;
+        }
+
+        /// <summary>
+        /// 鎶婃墦寮�鐨勭敾闈㈡坊鍔犲埌鍐呭瓨涓�
+        /// </summary>
+        /// <param name="form">Form.</param>
+        public void AddActionForm(CommonFormBase form)
+        {
+            //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
+            string formId = GetFormID(form);
+
+            //鍐呭瓨娣诲姞
+            form.FormID = formId;
+            this.ListActionForm.Insert(0, form);
+        }
+
+        /// <summary>
+        /// 浠庡垪琛ㄤ腑绉婚櫎鐢婚潰
+        /// </summary>
+        /// <param name="i_closeForm">鍏抽棴鐨勭晫闈�</param>
+        public void RemoveActionForm(CommonFormBase i_closeForm)
+        {
+            //鑾峰彇鐢婚潰ID
+            string formId = GetFormID(i_closeForm);
+            var removeForm = this.GetFormByName(formId);
+            if (removeForm == null)
+            {
+                return;
+            }
+            //绉婚櫎鐢婚潰
+            this.ListActionForm.Remove(removeForm);
+
+            var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
+            if (actionForm == null)
+            {
+                return;
+            }
+            //濡傛灉鍏抽棴鐨勭晫闈㈡槸DialogCommonForm绫诲瀷,鍒欎笉闇�瑕佽Е鍙戞縺娲诲嚱鏁�
+            if (i_closeForm is DialogCommonForm)
+            {
+                return;
+            }
+            //鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊�
+            else if ((i_closeForm is EditorCommonForm) && (actionForm is EditorCommonForm))
+            {
+                //鎺ヤ笅鏉ユ縺娲荤殑鐣岄潰
+                try
+                {
+                    var Myform = actionForm as EditorCommonForm;
+                    //閲嶇疆宸︽粦浣胯兘
+                    Myform.ScrollEnabled = Myform.ScrollEnabled;
+                    //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
+                    int value = Myform.FormActionAgainEvent();
+                    if (value == 1)
+                    {
+                        //Log鍑哄姏
+                        HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+                    }
+                }
+                catch (Exception ex)
+                {
+                    //Log鍑哄姏
+                    HdlLogLogic.Current.WriteLog(ex, "鐣岄潰閲嶆柊婵�娲诲紓甯� " + this.NowActionFormID);
+                }
+            }
+            else if (actionForm is UserView.UserPage)
+            {
+                //杩欓噷瀹冨凡缁忛��鍒颁富椤典簡
+                var nowForm = UserView.UserPage.Instance.GetNowActionForm();
+                nowForm?.FormActionAgainEvent();
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鐢婚潰ID
+        /// </summary>
+        /// <returns>The form name.</returns>
+        /// <param name="form">Form.</param>
+        private string GetFormID(CommonFormBase form)
+        {
+            if (form.FormID != string.Empty)
+            {
+                return form.FormID;
+            }
+            //灏嗗懡鍚嶇┖闂村幓鎺�
+            string[] Arry = form.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
+            string formName = Arry[Arry.Length - 1].Trim();
+            return formName;
+        }
+
+        #endregion
+
+        #region 鈻� 鍏抽棴鐣岄潰鐩稿叧_______________________
+
+        /// <summary>
+        /// 鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
+        /// </summary>
+        /// <param name="tagetFrom">鐩爣鐣岄潰,濡傛灉鎸囧畾浜嗙殑璇�,鍒欏叧闂洰鏍囩晫闈笂灞傜殑鍏ㄩ儴鐣岄潰(瀹冭嚜韬笉鍏抽棴)</param>
+        /// <param name="refreshMainPage">褰撳叧闂殑鐣岄潰杈惧埌涓婚〉鏃�,鏄惁鍒锋柊涓婚〉</param>
+        public void CloseAllOpenForm(string tagetFrom = null, bool refreshMainPage = true)
+        {
+            while (UserView.HomePage.Instance.ChildrenCount > 0)
+            {
+                var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
+                //(鍥犲簳灞傛帶浠朵慨鏀逛簡, 鐖舵帶浠剁Щ闄ゆ椂, 涓嶈Е鍙戝瓙鎺т欢鐨勭Щ闄や簨浠�)
+                if (view is ViewGroup)
+                {
+                    //鍏抽棴鍔犺浇鍦╒iewGroup閲岄潰鐨勮嚜瀹氫箟鐣岄潰Form
+                    CloseViewGroupChildren((ViewGroup)view);
+                }
+
+                if (view is CommonFormBase)
+                {
+                    if (((CommonFormBase)view).FormID == tagetFrom)
+                    {
+                        //鍙叧闂埌鎸囧畾鐩爣鐣岄潰
+                        return;
+                    }
+                    ((CommonFormBase)view).CloseForm();
+                }
+                else if (view is UserView.UserPage)
+                {
+                    //鍒锋柊涓婚〉
+                    if (refreshMainPage == true)
+                    {
+                        UserView.UserPage.Instance.ReFreshControl();
+                    }
+                    return;
+                }
+                else
+                {
+                    view.RemoveFromParent();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鍏抽棴鍔犺浇鍦╒iewGroup閲岄潰鐨勮嚜瀹氫箟鐣岄潰Form(鍥犲簳灞傛帶浠朵慨鏀逛簡,鐖舵帶浠剁Щ闄ゆ椂,涓嶈Е鍙戝瓙鎺т欢鐨勭Щ闄や簨浠�)
+        /// </summary>
+        /// <param name="group"></param>
+        private void CloseViewGroupChildren(ViewGroup group)
+        {
+            for (int i = 0; i < group.ChildrenCount; i++)
+            {
+                var view = group.GetChildren(i);
+                if (view is CommonFormBase)
+                {
+                    ((CommonFormBase)view).CloseForm();
+                    i--;
+                }
+            }
+        }
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠姝e湪婵�娲荤殑鐣岄潰
+        /// </summary>
+        /// <returns></returns>
+        public CommonFormBase GetNowActionForm()
+        {
+            return this.ListActionForm.Count > 0 ? this.ListActionForm[0] : null;
+        }
+
+        /// <summary>
+        /// 鏍规嵁鍚嶅瓧鑾峰彇鎸囧畾宸茬粡鎵撳紑浜嗙殑鐣岄潰
+        /// </summary>
+        /// <param name="i_formName"></param>
+        /// <returns></returns>
+        public CommonFormBase GetFormByName(string i_formName)
+        {
+            for (int i = 0; i < this.ListActionForm.Count; i++)
+            {
+                if (this.ListActionForm[i].FormID == i_formName)
+                {
+                    return this.ListActionForm[i];
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// 鍏抽棴鎸囧畾鐨勭敾闈�
+        /// </summary>
+        /// <param name="formName">鎸囧畾瑕佸叧闂殑鐢婚潰鑻辨枃鍚嶅瓧</param>
+        public void CloseFormByFormName(string formName)
+        {
+            var form = this.GetFormByName(formName);
+            //鍏抽棴鎸囧畾鐢婚潰
+            form?.CloseForm();
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇鎸囧畾鐨勭晫闈㈡槸鍚︽墦寮�
+        /// </summary>
+        /// <param name="formId"></param>
+        /// <returns></returns>
+        public bool IsFormOpen(string formId)
+        {
+            var form = this.GetNowActionForm();
+
+            return form != null ? form.FormID == formId : false;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍏ㄩ儴宸茬粡鎵撳紑浜嗙殑鐣岄潰
+        /// </summary>
+        /// <returns></returns>
+        public List<CommonFormBase> GetAllOpenForm()
+        {
+            var list = new List<CommonFormBase>();
+            try
+            {
+                for (int i = 0; i < this.ListActionForm.Count; i++)
+                {
+                    list.Add(this.ListActionForm[i]);
+                }
+                return list;
+            }
+            catch { return list; }
+        }
+
+        #endregion
+
+        #region 鈻� 寮曞鐣岄潰___________________________
+
+        /// <summary>
+        /// 鏄剧ず寮曞鐣岄潰
+        /// </summary>
+        /// <param name="result">鍚屾缁撴灉 -1锛氬紓甯�   0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�  1锛氭甯稿悓姝�  2:娌℃湁鑷姩澶囦唤鏁版嵁</param>
+        public void ShowGuideForm(int result)
+        {
+            var checkFile = HdlFileNameResourse.GuideFile;
+            if (System.IO.File.Exists(checkFile) == true)
+            {
+                //涓嶉渶瑕佹樉绀�
+                return;
+            }
+            if (result == 2 && Common.Config.Instance.Home.IsOtherShare == false)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var form = new UserCenter.Guide.GuideHouseForm();
+                    form.ShowFrom();
+                });
+            }
+
+            //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚寮曞)
+            var file = System.IO.File.Create(checkFile);
+            file.Close();
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0