Component File /DBCommander/Managers/DataPanelManager.cs (C#)
using System;  
using System.Data;  
using System.Data.OleDb;  
using System.Collections;  
using System.Windows.Forms;  
using YariSoft.DBUtil;  
  
namespace YariSoft.DBCommander  
{  
    public enum DetailLevel{  
        DBLevel = 0,  
        TableLevel ,  
        DataLevel      
    }  
    public class DataPanelManager  
    {  
        #region Local variables  
        private OleDbConnection connecton            = null;  
        private SchemaGenerator schema                = null;  
        private Stack            dataManagers        = null;  
        private bool            _identityOff        = false;  
  
        #endregion  
  
        #region Properties  
        public OleDbConnection Connection  
        {  
            get{ return this.connecton; }  
        }  
  
        public string ServerCaption  
        {  
            get{  
                string result = this.connecton.DataSource + "." + this.connecton.Database + ". ";  
                if( result.Length > 30 ){  
                    result = result.Substring( 0, 27 ) + "...";  
                }  
                return result;  
            }  
        }  
  
        public YariSoft.DBCommander.DetailLevel DetailLevel  
        {  
            get { return ( YariSoft.DBCommander.DetailLevel )this.dataManagers.Count; }  
        }  
  
        public bool NeedRefresh  
        {  
            get {  
                    IManager curManager = (IManager)this.dataManagers.Peek();  
                    return curManager.NeedRefresh;  
                }  
        }  
          
        public bool IdentityOff  
        {  
            get{ return this._identityOff; }  
            set{ this._identityOff = value; }  
        }  
  
        #endregion  
  
        #region Constructor/Destructor  
        public DataPanelManager( string ConnectionString )  
        {  
            this.connecton        = new OleDbConnection( ConnectionString );  
            this.schema            = new SchemaGenerator();  
            this.dataManagers    = new Stack ();  
        }  
  
        public void Dispose()  
        {  
            this.connecton.Dispose();  
            this.schema.Dispose();  
            while( this.dataManagers.Count > 0 ){  
                IManager curManager = ( IManager ) this.dataManagers.Pop();  
                curManager.Dispose();  
            }  
        }  
        #endregion  
  
        #region Public functions  
        public bool PrepareConnection()  
        {  
            return YariSoft.DBUtil.Util.PrepareConnectionString( this.connecton );  
        }  
  
        public bool MoveDown()  
        {  
            switch ( this.DetailLevel ){  
                case DetailLevel.DBLevel:  
                    this.dataManagers.Push( new DBManager ( this.connecton, this.schema ) );  
                    break;  
                case DetailLevel.TableLevel:  
                    this.dataManagers.Push( new TableManager ( this.connecton, this.schema ) );  
                    break;  
            }  
            return true;  
        }  
  
        public bool MoveUp()  
        {  
            if( this.dataManagers.Count > 0 ){  
                IManager curManager = ( IManager ) this.dataManagers.Pop();  
                curManager.Dispose();  
            }  
            return true;  
        }  
  
        public void Clear()  
        {  
            this.dataManagers.Clear();  
        }  
  
  
        public DataView FillData( object SelectValue )  
        {  
            IManager curManager = (IManager)this.dataManagers.Peek();  
            return curManager.FillData( SelectValue );  
        }  
  
        public DataView RefreshData( object SelectValue )  
        {  
            IManager curManager = (IManager)this.dataManagers.Peek();  
            return curManager.RefreshData( SelectValue );  
        }  
  
  
        public bool UpdateData( object UpdateObject )  
        {  
            IManager curManager = (IManager)this.dataManagers.Peek();  
            return curManager.UpdateData( UpdateObject );  
        }  
          
  
        public bool DeleteData( DataView Source, ArrayList SelectedRows )  
        {  
            bool status = false;  
            DBBaseOperation operation = null;  
            switch ( this.DetailLevel ){  
                case DetailLevel.TableLevel:  
                    operation = new TableDeleteOperation( this.connecton, Source, SelectedRows );  
                    break;  
                case DetailLevel.DataLevel:  
                    operation = new DataDeleteOperation( this.connecton, Source, SelectedRows );  
                    (( DataDeleteOperation )operation).OnSourceDataChanged += new YariSoft.DBUtil.DBBaseOperation.OnDataChangedEventHandler( this.UpdateData );  
                    break;  
            }  
            if( operation != null ){  
                status = operation.Exec();  
                operation.Dispose();  
            }  
            return status;  
        }  
  
        public bool CopyData( object Source, object Destination, ArrayList SelectedRows, DataPanelManager DestinationManager )  
        {  
            bool status = false;  
            DBBaseOperation operation = null;  
            switch ( this.DetailLevel ){  
                case DetailLevel.TableLevel:  
                    operation = new TableCopyOperation( ( DataSet )this.schema.Schema, DestinationManager.Connection, SelectedRows );  
                    break;  
                case DetailLevel.DataLevel:  
                    if( this._identityOff && IsIdentityColumnsExist( (( DataView )Destination).Table ) ){  
                        operation = new IdentityDataOperation( DestinationManager.Connection, (( DataView )Source), (( DataView )Destination), SelectedRows );  
                        status = (( IdentityDataOperation )operation ).Exec( new YariSoft.DBUtil.DBBaseOperation.OnDataChangedEventHandler( DestinationManager.UpdateData ));  
                    } else {      
                        operation = new DataCopyOperation( DestinationManager.Connection, (( DataView )Source), (( DataView )Destination), SelectedRows );  
                        (( DataCopyOperation  )operation ).OnDestinationDataChanged += new YariSoft.DBUtil.DBBaseOperation.OnDataChangedEventHandler( DestinationManager.UpdateData );  
                    }  
                    break;  
            }  
  
            if( ! ( operation is IdentityDataOperation ) ){  
                status = operation.Exec();  
            }  
            operation.Dispose();  
            return status;  
        }  
  
        public bool FillTableDataByFK ( string FKName )  
        {  
            IManager curManager = (IManager)this.dataManagers.Peek();  
            return curManager.FillTableDataByFK( FKName );  
        }  
        #endregion  
  
        #region Private functions  
        private bool IsIdentityColumnsExist ( DataTable Table )  
        {  
            foreach( DataColumn column in Table.Columns ){  
                if( column.AutoIncrement ){  
                    return true;  
                }  
            }  
            return false;  
        }  
        #endregion  
  
    }  
}