Click here to Skip to main content
15,897,704 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 37.1K   770   41  
Xenta architecture overview
using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using SiberTek.Xenta.Enums;
using SiberTek.Xenta.Presentation;
using SiberTek.Xenta.Presentation.Presenters;
using SiberTek.Xenta.Presentation.Utils;
using SiberTek.Xenta.Presentation.Views;
using SiberTek.Xenta.Presentation.Resources;
using SiberTek.Xenta.Web.Controls;
using SiberTek.Xenta.Web.Utils;

namespace SiberTek.Xenta.Web.Forum.Modules
{
    public partial class ForumTopicGrid : ViewBase<ForumTopicPresenter>, IPageable, IGrid
    {
        #region Properties
        [Browsable(false)]
        public string SearchTerm
        {
            get
            {
                return Convert.ToString(ViewState["SearchTerm"]);
            }
            set
            {
                ViewState["SearchTerm"] = value;
            }
        }

        [Browsable(false)]
        public int? ForumID
        {
            get
            {
                return (int?)ViewState["ForumID"];
            }
            set
            {
                ViewState["ForumID"] = value;
            }
        }

        [Browsable(false)]
        public int? AuthorID
        {
            get
            {
                return (int?)ViewState["AuthorID"];
            }
            set
            {
                ViewState["AuthorID"] = value;
            }
        }

        [Browsable(false)]
        public ForumTopicType? Type
        {
            get
            {
                return (ForumTopicType?)ViewState["Type"];
            }
            set
            {
                ViewState["Type"] = value;
            }
        }

        public ForumTopicOrderBy OrderBy
        {
            get
            {
                return ViewState["OrderBy"] == null ? ForumTopicOrderBy.CreatedOn : (ForumTopicOrderBy)ViewState["OrderBy"];
            }
            set
            {
                ViewState["OrderBy"] = value;
            }
        }

        public ForumTopicType TopicType
        {
            get
            {
                return ViewState["TopicType"] == null ? ForumTopicType.Normal : (ForumTopicType)ViewState["TopicType"];
            }
            set
            {
                ViewState["TopicType"] = value;
            }
        }

        [Browsable(false)]
        public int PageIndex
        {
            get
            {
                return Convert.ToInt32(ViewState["PageIndex"]);
            }
            set
            {
                ViewState["PageIndex"] = value;
            }
        }

        public int PageSize
        {
            get
            {
                return ViewState["PageSize"] == null ? Int32.MaxValue : Convert.ToInt32(ViewState["PageSize"]);
            }
            set
            {
                ViewState["PageSize"] = value;
            }
        }

        [Browsable(false)]
        public int PageCount
        {
            get
            {
                return Convert.ToInt32(ViewState["PageCount"]);
            }
            private set
            {
                ViewState["PageCount"] = value;
            }
        }

        public int RowCount
        {
            get
            {
                return gvForumTopicGrid.Rows.Count;
            }
        }
        #endregion

        #region Methods
        public override void BindData()
        {
            DataContainer["SearchTerm"] = SearchTerm;
            DataContainer["ForumID"] = ForumID;
            DataContainer["AuthorID"] = AuthorID;
            DataContainer["Type"] = Type;
            DataContainer["ShowHidden"] = false;
            DataContainer["OrderBy"] = OrderBy; 
            DataContainer["StartIndex"] = PageIndex * PageSize;
            DataContainer["Type"] = TopicType;
            DataContainer["Count"] = PageSize;

            Presenter.LoadCollection();

            PageCount = (int)DataContainer["TotalCount"] % PageSize == 0 ? (int)DataContainer["TotalCount"] / PageSize : (int)DataContainer["TotalCount"] / PageSize + 1;

            gvForumTopicGrid.DataSource = DataContainer["ForumTopicCollection"];
            gvForumTopicGrid.DataBind();

            base.BindData();
        }

        public void SetColumnVisibility(int index, bool value)
        {
            if(index >= 0 && index < gvForumTopicGrid.Columns.Count)
            {
                gvForumTopicGrid.Columns[index].Visible = value;
            }
        }
        #endregion

        #region Handlers
        protected override void OnInit(EventArgs e)
        {
            if(!IsPostBack)
            {
                gvForumTopicGrid.Columns[0].HeaderText = StringManager.GetString("Forum.ForumTopicGrid.colDetails.HeaderText");
                gvForumTopicGrid.Columns[1].HeaderText = StringManager.GetString("Forum.ForumTopicGrid.colAuthor.HeaderText");
                gvForumTopicGrid.Columns[2].HeaderText = StringManager.GetString("Forum.ForumTopicGrid.colPostCount.HeaderText");
                gvForumTopicGrid.Columns[3].HeaderText = StringManager.GetString("Forum.ForumTopicGrid.colCreatedOn.HeaderText");
                gvForumTopicGrid.EmptyDataText = StringManager.GetString("Forum.ForumTopicGrid.EmptyDataText");
            }
            base.OnInit(e);
        }

        protected void GvForumTopicGrid_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;

            if(row.RowType == DataControlRowType.DataRow)
            {
                ViewDataContainer item = e.Row.DataItem as ViewDataContainer;

                if(item != null)
                {
                    Literal lblAuthor = row.FindControl("lblAuthor") as Literal;
                    HyperLink lnkDetails = row.FindControl("lnkDetails") as HyperLink;
                    Literal lblCreatedOn = row.FindControl("lblCreatedOn") as Literal;
                    Literal lblPostCount = row.FindControl("lblPostCount") as Literal;

                    lblAuthor.Text = MembershipHelper.GetUsername((int)item["AuthorID"]);
                    lnkDetails.Text = (string)item["Title"];
                    lnkDetails.NavigateUrl = UrlHelper.FormatUrl("forum", "topic/{0}.aspx", item["TopicID"]);
                    lnkDetails.Enabled = ForumHelper.IsUserHasForumTopicPermission((int)item["TopicID"], UserContext.Current.UserID, (int)ForumPermission.ForumRead);
                    lblPostCount.Text = item["PostCount"].ToString();
                    lblCreatedOn.Text = UserContext.Current.DateTimeToDateString((DateTime)item["CreatedOn"]);
                }
            }
        }
        #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