Click here to Skip to main content
15,881,248 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.Collections.Generic;
using System.Text;

namespace Framework.baInterfaces
{
    /// <summary>
    /// EventHandlers
    /// </summary>
    public delegate void TransactionStateChangeEventHandler(object sender, TransactionStateChangeArgs Was, TransactionStateChangeArgs Will);
    public delegate void TransactionStateConfirmedEventHandler(object sender, BindingManagerArgs e);
    public delegate void FetchDataEventHandler(object sender, BindingManagerArgs e);

    #region TransactionStateChangeArgs
    public class TransactionStateChangeArgs : System.EventArgs
    {
        private TransactionStateKind transactionState;
        public TransactionStateChangeArgs()
        {
        }
        public TransactionStateChangeArgs(TransactionStateKind transactionState)
        {
            this.transactionState = transactionState;
        }

        public TransactionStateKind TransactionState
        {
            get
            {
                return transactionState;
            }
            set
            {
                transactionState = value;
            }
        }
    }
    #endregion

    #region BindingManagerArgs
    public class BindingManagerArgs : System.EventArgs
    {
        private IBindingManager bindingManager;
        public BindingManagerArgs()
        {
        }
        public BindingManagerArgs(IBindingManager bindingManager)
        {
            this.bindingManager = bindingManager;
        }

        public IBindingManager BindingManager
        {
            get
            {
                return bindingManager;
            }
            set
            {
                bindingManager = value;
            }
        }
    }
    #endregion

    /// <summary>
    /// Manage the binding of a DataSet
    /// </summary>
    public interface IBindingManager
    {
        /// <summary>
        /// The name of the table that is being handled
        /// by this Binding Manager component. Usually 
        /// the DataSource property points to a DataTable
        /// that hast the name of the table as DataTabel.TableName
        /// </summary>
        string TableName
        {
            get;
            set;
        }

        /// <summary>
        /// This property includes the Where clouse of
        /// a SQL query that fetches the table data
        /// into DataSet passed to DataSource
        /// </summary>
        string Filter
        {
            get;
            set;
        }

        /// <summary>
        /// The DataSet that is being managed
        /// </summary>
        object DataSource
        {
            get;
            set;
        }

        /// <summary>
        /// Returns the value in the Column specified at the 
        /// datasource of the Binding Manager object
        /// </summary>
        /// <param name="columnName">Name of column </param>
        /// <returns>value of the column</returns>
        object this[object columnName]
        {
            get;
            set;
        }

        /// <summary>
        /// Binding manager should have a state that 
        /// is being used in binded controls to 
        /// verify the state of Binding Manager
        /// </summary>
        TransactionStateKind TransactionState
        {
            get;
            set;
        }

        /// <summary>
        /// The default Transaction State of the component
        /// It is usually in Initial or Null State
        /// </summary>
        TransactionStateKind DefaultTransactionState
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the total number of items in the underlying list. 
        /// </summary>
        int Count 
        { 
            get; 
        }

        /// <summary>
        /// Return true if theBinding Manager DataSource is empty
        /// </summary>
        bool IsEmpty
        {
            get;
        }

        /// <summary>
        /// Return true if theBinding Manager DataSource is empty
        /// </summary>
        bool Enabled
        {
            get;
            set;
        }


        /// <summary>
        /// Gets or sets the index of the current item in the underlying list. 
        /// </summary>
        int Position
        {
            get;
            set;
        }

        /// <summary>
        /// Find a row in the binded dataSource
        /// </summary>
        /// <param name="key">the primery key value to be search for</param>
        /// <returns>if founded return the index of the row otherwise return -1</returns>
        int Find(object key);


        /// <summary>
        /// Check if a key value exist in the binded table
        /// </summary>
        /// <param name="key">the primery key value to be search for</param>
        /// <returns>if founded return true otherwise return false</returns>
        bool Exist(object key);

        /// <summary>
        /// Move to the last row
        /// </summary>
        void MoveLast();

        /// <summary>
        /// Move to the first row
        /// </summary>
        void MoveFirst();

        /// <summary>
        /// Move to the previous node
        /// </summary>
        void MovePrevious();

        /// <summary>
        /// Move to the next node
        /// </summary>
        void MoveNext();

        /// <summary>
        /// Clear the Binding Manager Datasource
        /// as a Datatable
        /// </summary>
        void ClearDatasource();

        /// <summary>
        /// Returns the Oridignal value of a Column before
        /// any changes to the Binded control
        /// </summary>
        System.Collections.IDictionary Original
        {
            get;
        }

        /// <summary>
        /// Save the current Binding Manager values 
        /// </summary>
        /// <param name="storage">Where to save</param>
        void SaveRowData(System.Collections.IDictionary storage);

        /// <summary>
        /// Restore binding manager saved values
        /// </summary>
        /// <param name="storage">From where restore</param>
        void RestoreRowData(System.Collections.IDictionary storage);

        /// <summary>
        /// Fires Fetch Data Event
        /// </summary>
        void DoFetchData();

        /// <summary>
        /// Refresh the transaction state to be done
        /// again in order to fire transaction change events
        /// </summary>
        void Refresh();

        /// <summary>
        /// When binding manager row changed
        /// </summary>
        event EventHandler PositionChanged;

        /// <summary>
        /// This event gets fired when Binding 
        /// Transaction State changes.
        /// Here we can modify the Will transaction
        /// state, so transaction changed will use the 
        /// new modified transaction here.
        /// This event is the first event in Transaction change events.
        /// Usually components that want to modify the Transaction
        /// state of their Binding Manager are using this event. 
        /// Components like; Binding Relation that 
        /// affects the Binding Manager Transaction State
        /// </summary>
        event TransactionStateChangeEventHandler TransactionStateChange;

        /// <summary>
        /// This event gets fired when Binding 
        /// Transaction State is changeing.
        /// This event gets fire when the Transaction
        /// state changed somewhere in the code and the 
        /// changes of TransactionStateChange event cannot affect 
        /// the transaction state parameters passed to this event.
        /// This event is being cougth in components that they 
        /// need to use the main Transaction state changed in the code.
        /// The Add/Edit/Delete Confirmed events in Binding manager are
        /// using this event to befired
        /// </summary>
        event TransactionStateChangeEventHandler TransactionStateChanging;
        
        /// <summary>
        /// This event gets fired when Binding 
        /// Transaction State changed.
        /// This event gets fired after all the other 
        /// Transaction Changing Events get fired.
        /// The Will be changed event parameter of
        /// this event, is holding the value coming from
        /// TransactionChange event.
        /// </summary>
        event TransactionStateChangeEventHandler TransactionStateChanged;

        /// <summary>
        /// This event gets fired when Binding Manager
        /// was in Add state and it is becomming confirmed
        /// This event is the final event in Transaction change events.
        /// </summary>
        event TransactionStateConfirmedEventHandler AddConfirmed;

        /// <summary>
        /// This event gets fired when Binding Manager
        /// receieves a data fetch command to fill the
        /// Datasource contents
        /// </summary>
        event FetchDataEventHandler FetchData;
        
        /// <summary>
        /// This event gets fired when Binding Manager
        /// was in Delete state and it is becomming confirmed
        /// </summary>
        event TransactionStateConfirmedEventHandler DeleteConfirmed;

        /// <summary>
        /// This event gets fired when Binding Manager
        /// was in Edit state and it is becomming confirmed
        /// </summary>
        event TransactionStateConfirmedEventHandler EditConfirmed;

    }
}

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