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

namespace SiberTek.Xenta.Web.Admin.Modules
{
    public partial class CurrencyGrid : ViewBase<CurrencyPresenter>, IGrid, ICommandHandler
    {
        #region Properties
        [Browsable(false)]
        public DateTime? CreatedOnStart
        {
            get
            {
                return (DateTime?)ViewState["CreatedOnStart"];
            }
            set
            {
                ViewState["CreatedOnStart"] = value;
            }
        }

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

        public bool ShowHidden
        {
            get
            {
                return Convert.ToBoolean(ViewState["ShowHidden"]);
            }
            set
            {
                ViewState["ShowHidden"] = value;
            }
        }

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

        #region Methods
        public override void BindData()
        {
            DataContainer["CreatedOnStart"] = CreatedOnStart;
            DataContainer["CreatedOnEnd"] = CreatedOnEnd;
            DataContainer["ShowHidden"] = ShowHidden;

            Presenter.LoadCollection();

            gvCurrencyGrid.DataSource = DataContainer["CurrencyCollection"];
            gvCurrencyGrid.DataBind();

            base.BindData();
        }

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

        #region Handlers
        protected override void OnInit(EventArgs e)
        {
            if(!IsPostBack)
            {
                gvCurrencyGrid.Columns[1].HeaderText = StringManager.GetString("Admin.CurrencyGrid.colCurrencyID.HeaderText");
                gvCurrencyGrid.Columns[2].HeaderText = StringManager.GetString("Admin.CurrencyGrid.colDetails.HeaderText");
                gvCurrencyGrid.Columns[3].HeaderText = StringManager.GetString("Admin.CurrencyGrid.colName.HeaderText");
                gvCurrencyGrid.Columns[4].HeaderText = StringManager.GetString("Admin.CurrencyGrid.colDisplayName.HeaderText");
                gvCurrencyGrid.Columns[5].HeaderText = StringManager.GetString("Admin.CurrencyGrid.colDisplayName.HeaderText");
                gvCurrencyGrid.Columns[6].HeaderText = StringManager.GetString("Admin.CurrencyGrid.colActive.HeaderText");
                gvCurrencyGrid.EmptyDataText = StringManager.GetString("Admin.CurrencyGrid.EmptyDataText");
            }
            base.OnInit(e);
        }

        protected void GvCurrencyGrid_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 lblCurrencyID = row.FindControl("lblCurrencyID") as Literal;
                    HiddenField hfPriceFormat = row.FindControl("hfPriceFormat") as HiddenField;
                    HyperLink lnkDetails = row.FindControl("lnkDetails") as HyperLink;
                    TextBox txtName = row.FindControl("txtName") as TextBox;
                    TextBox txtDisplayName = row.FindControl("txtDisplayName") as TextBox;
                    CheckBox cbIsActive = row.FindControl("cbIsActive") as CheckBox;
                    Literal lblCreatedOn = row.FindControl("lblCreatedOn") as Literal;

                    lblCurrencyID.Text = item["CurrencyID"].ToString();
                    lnkDetails.NavigateUrl = UrlHelper.FormatUrl("admin", "localization/currencies/{0}.aspx", item["CurrencyID"]);
                    lnkDetails.ToolTip = StringManager.GetString("Admin.CurrencyGrid.lnkDetails.ToolTip");
                    txtName.Text = (string)item["Name"];
                    txtDisplayName.Text = (string)item["DisplayName"];
                    hfPriceFormat.Value = (string)item["PriceFormat"];
                    cbIsActive.Checked = (bool)item["IsActive"];
                    lblCreatedOn.Text = UserContext.Current.DateTimeToString((DateTime)item["CreatedOn"]);
                }
            }
        }

        public void OnCommand(object sender, CommandEventArgs e)
        {
            switch(e.CommandName)
            {
                case "Update":
                    {
                        try
                        {
                            List<ViewDataContainer> itemCollection = new List<ViewDataContainer>();

                            foreach(GridViewRow row in gvCurrencyGrid.Rows)
                            {
                                CheckBox cbSelected = row.FindControl("cbSelected") as CheckBox;

                                if(cbSelected.Checked)
                                {
                                    Literal lblCurrencyID = row.FindControl("lblCurrencyID") as Literal;
                                    HiddenField hfPriceFormat = row.FindControl("hfPriceFormat") as HiddenField;
                                    TextBox txtName = row.FindControl("txtName") as TextBox;
                                    TextBox txtDisplayName = row.FindControl("txtDisplayName") as TextBox;
                                    CheckBox cbIsActive = row.FindControl("cbIsActive") as CheckBox;

                                    ViewDataContainer item = new ViewDataContainer();

                                    item["CurrencyID"] = Int32.Parse(lblCurrencyID.Text);
                                    item["Name"] = StringHelper.StripTags(txtName.Text);
                                    item["DisplayName"] = StringHelper.StripTags(txtDisplayName.Text);
                                    item["PriceFormat"] = hfPriceFormat.Value;
                                    item["IsActive"] = cbIsActive.Checked;

                                    itemCollection.Add(item);
                                }
                            }

                            DataContainer["CurrencyCollection"] = itemCollection;

                            Presenter.UpdateCollection();
                        }
                        catch(Exception ex)
                        {
                            Page.ShowMessage(ex.Message);
                        }
                    }
                    break;
                case "Delete":
                    {
                        try
                        {
                            List<ViewDataContainer> itemCollection = new List<ViewDataContainer>();

                            foreach(GridViewRow row in gvCurrencyGrid.Rows)
                            {
                                CheckBox cbSelected = row.FindControl("cbSelected") as CheckBox;

                                if(cbSelected.Checked)
                                {
                                    Literal lblCurrencyID = row.FindControl("lblCurrencyID") as Literal;

                                    ViewDataContainer item = new ViewDataContainer();

                                    item["CurrencyID"] = Int32.Parse(lblCurrencyID.Text);

                                    itemCollection.Add(item);
                                }
                            }

                            DataContainer["CurrencyCollection"] = itemCollection;

                            Presenter.DeleteCollection();
                        }
                        catch(Exception ex)
                        {
                            Page.ShowMessage(ex.Message);
                        }
                    }
                    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