DataPanelManager.cs :  » SQL-Clients » Database-Commander » YariSoft » DBCommander » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » SQL Clients » Database Commander 
Database Commander » YariSoft » DBCommander » DataPanelManager.cs
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

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.