Click here to Skip to main content
15,892,298 members
Articles / Web Development / ASP.NET

Open Source Extensible Enterprise n-tier Application Framework with Multilayered Architecture

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
3 Dec 2010MIT3 min read 37K   770   41  
Xenta architecture overview
using System;
using System.Web.UI;
using SiberTek.Xenta.Presentation.Resources;
using SiberTek.Xenta.Web.Controls;
using System.Web.UI.WebControls;

namespace SiberTek.Xenta.Web.Admin.Modules
{
    public partial class DataPager : UserControlBase, ICommandHandler
    {
        #region Fields
        private UserControlBase _tgtControl;
        #endregion

        #region Constructors
        public DataPager()
        {
            _tgtControl = null;
        }
        #endregion

        #region Properties
        public string TargetControlID
        {
            get
            {
                return Convert.ToString(ViewState["TargetControlID"]);
            }
            set
            {
                ViewState["TargetControlID"] = value;
            }
        }

        public override bool Visible
        {
            get
            {
                return base.Visible && ((TargertControl as IPageable) != null) && ((TargertControl as IPageable).PageCount > 1);
            }
            set
            {
                base.Visible = value;
            }
        }

        private UserControlBase TargertControl
        {
            get
            {
                if(_tgtControl == null)
                {
                    _tgtControl = Page.FindControlRecursive(TargetControlID) as UserControlBase;
                }
                return _tgtControl;
            }
        }
        #endregion

        #region Handlers
        protected override void OnInit(EventArgs e)
        {
            if(!IsPostBack)
            {
                btnNext.CommandName = "Next";
                btnPrev.CommandName = "Previous";
                btnPrev.ToolTip = StringManager.GetString("Admin.DataPager.btnPrev.ToolTip");
                lblPage.Text = StringManager.GetString("Admin.DataPager.lblPage.Text");
                lblOf.Text = StringManager.GetString("Admin.DataPager.lblOf.Text");
                btnNext.ToolTip = StringManager.GetString("Admin.DataPager.btnNext.ToolTip");
            }

            btnNext.Command += OnCommand;
            btnPrev.Command += OnCommand;

            base.OnInit(e);
        }

        protected override void OnPreRender(EventArgs e)
        {
            IPageable pageableView = TargertControl as IPageable;

            if(pageableView != null)
            {
                if(pageableView.PageCount > 1)
                {
                    btnPrev.Visible = (pageableView.PageIndex - 1 >= 0);
                    txtPageIndex.Text = (pageableView.PageIndex + 1).ToString();
                    lblPageCount.Text = pageableView.PageCount.ToString();
                    btnNext.Visible = (pageableView.PageIndex + 1 < pageableView.PageCount);
                    Visible = true;
                }
            }
            base.OnPreRender(e);
        }

        protected void TxtPageIndex_OnTextChanged(object sender, EventArgs e)
        {
            int newIndex = 0;

            if(Int32.TryParse(txtPageIndex.Text, out newIndex))
            {
                IPageable pageableView = TargertControl as IPageable;

                if(pageableView != null)
                {
                    if(newIndex <= 1)
                    {
                        newIndex = 1;
                    }
                    else
                    {
                        if(newIndex >= pageableView.PageCount)
                        {
                            newIndex = pageableView.PageCount;
                        }
                    }
                    pageableView.PageIndex = newIndex - 1;
                    TargertControl.BindData();
                }
            }
        }

        public void OnCommand(object sender, CommandEventArgs e)
        {
            switch(e.CommandName)
            {
                case "Previous":
                    {
                        IPageable pageableView = TargertControl as IPageable;

                        if(pageableView != null)
                        {
                            pageableView.PageIndex -= 1;
                            TargertControl.BindData();
                        }
                    }
                    break;
                case "Next":
                    {
                        IPageable pageableView = TargertControl as IPageable;

                        if(pageableView != null)
                        {
                            pageableView.PageIndex += 1;
                            TargertControl.BindData();
                        }
                    }
                    break;
            }
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions