SoFunction
Updated on 2025-03-07

C# Page is used for inheriting function examples of each page

/// <summary>
/// Basic category of the entire site page
/// </summary>
public class BasePage : , IBasePage
{
        private static readonly DataRowCollection EmptyRows = new DataTable().Rows;

        private DbCache cacheHelp;
        private ViewDataDict viewData;
        private ViewDataDict viewDataM;
private int userFunCount = 0;//Number of permission usage
private int dbCount = 0;//Number of database connections

        private TempListHandler tempList;

        protected bool IsOpenXingNengTongji = true;

#region Search keywords
        //private string _searchStr;
        public string searchStr
        {
            get
            {
                //if (this._searchStr == null)
                //{
                //    return ;
                //}

                return ViewData["keyword"].ToString();
            }
            set
            {
                //this._searchStr = value;
                ViewData["keyword"] = value;
            }
        }
        #endregion

#region Save data in page control ViewDataPage
        /// <summary>
/// Save data in page control
        /// </summary>
        public string ViewDataPage
        {
            get
            {
                return ("__viewdatapage");
            }
            set
            {
                ("__viewdatapage", value);

                //((), "__urlreferrer", "<input id=\"__urlreferrer\" name=\"__urlreferrer\" type=\"hidden\" value=\"" + value + "\" />");
            }
        }
        #endregion

        public BasePage()
        {
            cacheHelp = new DbCache();
            viewData = new ViewDataDict();
            viewDataM = new ViewDataDict("model_");

            tempList = new TempListHandler();
        }

        private DateTime __time1;
        private DateTime __time2;
        private static int __i = 0;

#region and root URL rewrite to get parameters
        /// <summary>
/// Rewrite the root URL to get parameters
        /// </summary>
        private UrlQuery _UQ;

        protected override void OnInit(EventArgs e)
        {
            _UQ = new UrlQuery(true);

            __time1 = ;

            (e);
        }

        protected override void OnPreInit(EventArgs e)
        {
            //"OnPreInit".WriteLine();
            (e);
        }
        #endregion

#region Basic Information Statistics
        protected override void Render( writer)
        {
            //"Render".WriteLine();
            (writer);
            __i++;
            __time2 = ;
            TimeSpan ts = __time2 - __time1;

            if (IsOpenXingNengTongji)
                (@"<div style=""text-align:center;color:#ccc"">Number:" + __i + ", Time:" + + "ms, DB=" + + ",fun=" + + "</div>");
        }
        #endregion

        protected override void OnUnload(EventArgs e)
        {
            //"OnUnload".WriteLine();
            (e);
        }

#region Display the searched results as eye-catching
        /// <summary>
/// Display the searched results as eye-catching
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string ReplaceSearchText(object str)
        {
            if (searchStr == null || == 0)
                return ();

            //return ().Replace(searchStr, "<strong style=\"color:#F00\">" + searchStr + "</strong>");

            return ((), (searchStr), "<strong style=\"color:#F00\">" + searchStr + "</strong>", );
        }
        #endregion

#region IBasePage Member
        /// <summary>
/// Data cache class
        /// </summary>
        public DbCache CacheHelp
        {
            get { return ; }
        }

        /// <summary>
/// Page view, used for page-level access, imitating MVC
        /// </summary>
        public ViewDataDict ViewData
        {
            get { return ; }
        }

        /// <summary>
/// Page view (Model), used for page-level access, imitating MVC
        /// </summary>
        public ViewDataDict ViewDataM
        {
            get { return ; }
        }

        /// <summary>
/// Get, this method will not cause any errors or exceptions
        /// </summary>
        /// <param name="pName"></param>
        /// <returns></returns>
        public DataRowCollection ViewDataRows(string pName)
        {
            DataTable dt = ViewData[pName] as DataTable;

            if (dt == null)
            {
                return EmptyRows;
            }
            return ;
        }

        public bool IsViewData(string pName)
        {
            return viewData[pName].ToString() == "1";
        }

        public UrlQuery UQ
        {
            get { return this._UQ; }
        }

        ///// <summary>
////// Get system configuration
        ///// </summary>
        ///// <param name="key"></param>
        ///// <returns></returns>
        //public string SysConfig(string key)
        //{
        //    return (key).ToString();
        //}

        public TempListHandler TempList
        {
            get { return ; }
        }

        public int UserFunCount
        {
            get { return ; }
            set { = value; }
        }

        public int DbCount
        {
            get { return ; }
            set { = value; }
        }
        #endregion

#region ITrace Member
        //private int dbConnectionCount;
        ///// <summary>
////// Number of database connections
        ///// </summary>
        //public int DbConnectionCount
        //{
        //    get
        //    {
        //        return ;
        //    }
        //    set
        //    {
        //        dbConnectionCount = value;
        //    }
        //}

        #endregion

#region Gets or sets the path returned after submission. If not specified, it is the current url
        /// <summary>
/// Get or set the path returned after submission. If not specified, it is the current url
        /// </summary>
        public string UrlReferrer
        {
            get
            {
                string s = ("___urlreferrer");
                if ( == 0)
                {
                    s = ViewData["___urlreferrer"].ToString();
                }

                if ( == 0)
                {
                    s = ();
                }

                return s;
            }
            set
            {
                ViewData["___urlreferrer"] = value;

                ("___urlreferrer", value);\" type=\"hidden\" value=\"" + value + "\" />");
            }
        }
        #endregion
}