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

Win-Form/Web-Form Generic Components using the same Controller

Rate me:
Please Sign up or sign in to vote.
4.00/5 (7 votes)
5 Oct 2008CPOL7 min read 43K   1.1K   36  
A framework to develop Win-Form and Web-Form applications using generic components
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Framework.UI.baController;
using Framework.baInterfaces;
using Framework.Lib;

namespace Framework.UI.baWebControls
{

	/// <summary>
	/// Web Form Control
	/// Summary description for AddEditDelete
	/// </summary>
	[DefaultProperty("Text"), 
		ToolboxData("<{0}:AddEditDelete runat=server></{0}:AddEditDelete>")]
	public class AddEditDelete : System.Web.UI.WebControls.WebControl, INamingContainer, IAddEditDelete
	{
		private baButton baAddButton;
		private baButton baEditButton;
		private baButton baDeleteButton;
		private baButton baConfirmButton;
		private AddEditDelCtrl addEditDelCtrl;
        private TransactionStateKind oTransactionState;
        private TransactionStateKind oOldTransactionState;
        private IBindingManager oBindingManager;

		public event AddEditDelEventHandler AddClick;
		public event AddEditDelEventHandler ConfirmClick;
		public event AddEditDelEventHandler DeleteClick;
		public event AddEditDelEventHandler EditClick;
        public event AddEditDelEventHandler TransactionStateChanged;

        #region CreateChildControls()
        protected override  void  CreateChildControls()
		{
            try
            {
                base.CreateChildControls();
                baConfirmButton = new baButton();
                baConfirmButton.ID = "ConfirmButton";
                baConfirmButton.Cursor = System.Windows.Forms.Cursors.Hand;

                baDeleteButton = new baButton();
                baDeleteButton.ID = "DeleteButton";
                baDeleteButton.Cursor = System.Windows.Forms.Cursors.Hand;

                baEditButton = new baButton();
                baEditButton.ID = "EditButton";
                baEditButton.Cursor = System.Windows.Forms.Cursors.Hand;

                baAddButton = new baButton();
                baAddButton.ID = "AddButton";
                baAddButton.Cursor = System.Windows.Forms.Cursors.Hand;

                baAddButton.Click += new EventHandler(AddButton_Click);
                baEditButton.Click += new EventHandler(EditButton_Click);
                baDeleteButton.Click += new EventHandler(DeleteButton_Click);
                baConfirmButton.Click += new EventHandler(ConfirmButton_Click);

                Controls.Add(baAddButton);
                Controls.Add(baEditButton);
                Controls.Add(baDeleteButton);
                Controls.Add(baConfirmButton);

                addEditDelCtrl = new AddEditDelCtrl(this, this.TransactionState);
                /// June 16, 06
                oBindingManager_TransactionStateChanged(this, new TransactionStateChangeArgs(this.OldTransactionState),
                                                                new TransactionStateChangeArgs(this.TransactionState));
            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
        #endregion

        #region OnPreRender(EventArgs e)
        protected override void OnPreRender(EventArgs e)
		{
            try
            {
                baConfirmButton.Width = 83;
                baConfirmButton.Height = 23;

                baDeleteButton.Width = 83;
                baDeleteButton.Height = 23;

                baEditButton.Width = 83;
                baEditButton.Height = 23;

                baAddButton.Width = 83;
                baAddButton.Height = 23;
                base.OnPreRender(e);
            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
        #endregion

        #region AddButton
        public IButton AddButton
		{
			get
			{
				return baAddButton;
			}
        }
        #endregion 

        #region ConfirmButton
        public IButton ConfirmButton
		{
			get
			{
				return baConfirmButton;
			}
        }
        #endregion

        #region DeleteButton
        public IButton DeleteButton
		{
			get
			{
				return baDeleteButton;
			}
        }
        #endregion

        #region EditButton
        public IButton EditButton
		{
			get
			{
				return baEditButton;
			}
        }
        #endregion 

        #region TransactionState
        public TransactionStateKind TransactionState
		{
			set
			{
                try
                {
                    this.ViewState["TransactionState"] = value;
                    oTransactionState = value;
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
			}
			get
			{
                try
                {
                    if (this.ViewState["TransactionState"] == null)
                        return TransactionStateKind.Null;
                    else
                    {
                        oTransactionState = (TransactionStateKind)this.ViewState["TransactionState"];
                        return oTransactionState;
                    }
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
			}
        }
        #endregion 

        #region OldTransactionState
        public TransactionStateKind OldTransactionState
        {
            set
            {
                try
                {
                    this.ViewState["OldTransactionState"] = value;
                    oOldTransactionState = value;
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
            get
            {
                try
                {
                    if (this.ViewState["OldTransactionState"] == null)
                        return TransactionStateKind.Null;
                    else
                    {
                        oOldTransactionState = (TransactionStateKind)this.ViewState["OldTransactionState"];
                        return oOldTransactionState;
                    }
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
        }
        #endregion 

        #region AddButton_Click(object sender, EventArgs e)
        private void AddButton_Click(object sender, EventArgs e)
		{
			if(AddClick!=null)
				AddClick( sender, new AddEditDelEventArgs(TransactionState) );
        }
        #endregion 

        #region EditButton_Click(object sender, EventArgs e)
        private void EditButton_Click(object sender, EventArgs e)
		{
			if(EditClick!=null)
				EditClick( sender, new AddEditDelEventArgs(TransactionState) );            
        }
        #endregion 

        #region DeleteButton_Click(object sender, EventArgs e)
        private void DeleteButton_Click(object sender, EventArgs e)
		{
			if(DeleteClick!=null)
				DeleteClick( sender, new AddEditDelEventArgs(TransactionState) );

        }
        #endregion 

        #region ConfirmButton_Click(object sender, EventArgs e)
        private void ConfirmButton_Click(object sender, EventArgs e)
		{
            if (ConfirmClick != null)
            {
                ConfirmClick(sender, new AddEditDelEventArgs(TransactionState));

            }
        }
        #endregion

        #region Location
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public System.Drawing.Point Location
        {
            get
            {
                try
                {
                    return new System.Drawing.Point(int.Parse(Style["LEFT"].Replace("px", "")),
                                                        int.Parse(Style["TOP"].Replace("px", "")));
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
            set
            {
                try
                {
                    Style["LEFT"] = value.X.ToString();
                    Style["TOP"] = value.Y.ToString();
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
        }
        #endregion

        #region IController Controller
        public object Controller
        {
            get
            {
                return addEditDelCtrl;
            }
        }
        #endregion

        #region BindingManager
        public IBindingManager BindingManager
        {
            get
            {
                return oBindingManager;
            }
            set
            {
                try
                {
                    oBindingManager = value;
                    if (oBindingManager != null)
                    {
                        oBindingManager.TransactionStateChanged += new TransactionStateChangeEventHandler(oBindingManager_TransactionStateChanged);
                    }
                }
                catch (Exception baExp)
                {
                    throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
                }
            }
        }
        #endregion

        #region oBindingManager_TransactionStateChanged(object sender, TransactionStateChangeArgs Was, TransactionStateChangeArgs Will)
        void oBindingManager_TransactionStateChanged(object sender, TransactionStateChangeArgs Was, TransactionStateChangeArgs Will)
        {
            try
            {
                this.TransactionState = Will.TransactionState;
                if (TransactionStateChanged != null)
                    TransactionStateChanged(sender, new AddEditDelEventArgs(Will.TransactionState));
            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
        #endregion

        protected override void Render(HtmlTextWriter writer)
        {
            if (this.DesignMode)
                writer.Write("<b>AddEditDelete:</b>" + this.ID);
            else
                base.Render(writer);
        }
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
Software development experience since 1993

Skills
- Programming Languages: C# .NET, Delphi, C++, Java and VB
- Development Methodologies (SDLC): RUP, Scrum and XP
- Database: SQL server, Oracle, Apollo database and MS Access.

Educations & Certificates
- Microsoft® Certified Professional (MCP)
- Sun® Certified Java2 Programmer
- B.S. in computer science

Comments and Discussions