Click here to Skip to main content
15,880,891 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;
using Framework.Lib;
using Framework.baInterfaces;

namespace Framework.UI.baController
{
    public class TransactionStateCtrl
    {
        private object obejct2beManaged;
        private StateMachine stMachine = null;
        private TransactionStateCtrl() { }

        #region TransactionStateCtrl creator
        public static TransactionStateCtrl GetTransactionStateCtrl(object obj, ComponentUsage ComponentDefaultBehaviour)
        {
            try
            {
                TransactionStateCtrl tStateCtrl = new TransactionStateCtrl();
                tStateCtrl.obejct2beManaged = obj;
                tStateCtrl.stMachine = null;
                switch (ComponentDefaultBehaviour)
                {
                    case ComponentUsage.Search:
                        {
                            tStateCtrl.stMachine = tStateCtrl.SearchStateMachine(obj);
                            break;
                        }
                    case ComponentUsage.Use:
                        {
                            tStateCtrl.stMachine = tStateCtrl.UseStateMachine(obj);
                            break;
                        }
                }
                if (tStateCtrl.stMachine == null)
                    return null;
                else
                    return tStateCtrl;
            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }

        #endregion

        #region ConstructStateMachine & SetState
        private StateMachine SearchStateMachine(object obj)
        {
            try
            {
                StateMachine _stateMachine = new Lib.StateMachine();

                _stateMachine[TransactionStateKind.Add, obj] = new State(false);
                _stateMachine[TransactionStateKind.Edit, obj] = new State(false);
                _stateMachine[TransactionStateKind.Delete, obj] = new State(false);
                _stateMachine[TransactionStateKind.SearchOnly, obj] = new State(true);
                _stateMachine[TransactionStateKind.EditOnly, obj] = new State(false);
                _stateMachine[TransactionStateKind.AddEditOnly, obj] = new State(true);
                _stateMachine[TransactionStateKind.Initial, obj] = new State(true);
                _stateMachine[TransactionStateKind.Confirm, obj] = new State(true);
                _stateMachine[TransactionStateKind.Null, obj] = new State(false);
                _stateMachine[TransactionStateKind.EmptyDataSource, obj] = new State(false);
                return _stateMachine;

            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }

        private StateMachine UseStateMachine(object obj)
        {
            try
            {
                StateMachine _stateMachine = new Lib.StateMachine();

                _stateMachine[TransactionStateKind.Add, obj] = new State(true);
                _stateMachine[TransactionStateKind.Edit, obj] = new State(true);
                _stateMachine[TransactionStateKind.Delete, obj] = new State(false);
                _stateMachine[TransactionStateKind.EditOnly, obj] = new State(false);
                _stateMachine[TransactionStateKind.AddEditOnly, obj] = new State(false);
                _stateMachine[TransactionStateKind.SearchOnly, obj] = new State(false); 
                _stateMachine[TransactionStateKind.Initial, obj] = new State(false);
                _stateMachine[TransactionStateKind.Confirm, obj] = new State(false);
                _stateMachine[TransactionStateKind.Null, obj] = new State(false);
                _stateMachine[TransactionStateKind.EmptyDataSource, obj] = new State(false);
                return _stateMachine;
            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }

        public void SetTransactionStateState(TransactionStateKind tstate)
        {
            try
            {
                if (obejct2beManaged != null)
                    ((IState)obejct2beManaged).Enabled = ((IState)stMachine[tstate, obejct2beManaged]).Enabled;
            }
            catch (Exception baExp)
            {
                throw new baException(baExp, System.Reflection.MethodBase.GetCurrentMethod());
            }
        }
        #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 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