DBBaseOperation.cs :  » SQL-Clients » Database-Commander » YariSoft » DBUtil » 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 » DBUtil » DBBaseOperation.cs
using System;
using System.Data;
using System.Data.OleDb;
using YariSoft.Utils;
using System.Windows.Forms;
using System.Collections;

namespace YariSoft.DBUtil{
  public enum RowOperation {
    RO_None,
    RO_Append,
    RO_Overwrite,
    RO_Overwrite_All,
    RO_Skip,
    RO_Skip_All
  }

  public class DBBaseOperation
  {
    public delegate bool OnDataChangedEventHandler( object Sender );

    public event OnDataChangedEventHandler OnSourceDataChanged  = null;
    public event OnDataChangedEventHandler OnDestinationDataChanged  = null;

    #region Protected variables
    protected DataView source      = null;
    protected DataView destination    = null;
    protected OleDbConnection connection= null;
    protected ArrayList selectedRows  = null;
    protected YProgress progress    = null;
    #endregion

    #region Local variables
    private bool _showProgress = true;
    protected bool increaseProgress = true;
    #endregion

    #region Properties
    public bool ShowProgress
    {
      set{ this._showProgress = value; }
      get{ return this._showProgress; }
    }
    #endregion

    #region Constructor/Destructor
    public DBBaseOperation()
    {
    }

    public DBBaseOperation( OleDbConnection Connection, ArrayList SelectedRows )
      :this( Connection, null, SelectedRows )
    {
    }

    public DBBaseOperation( OleDbConnection Connection, DataView Source, ArrayList SelectedRows )
    {
      this.source = Source;
      this.selectedRows = SelectedRows;
      this.connection = Connection;
    }

    ~DBBaseOperation(){
      this.Dispose();
    }

    public virtual void Dispose()
    {
      if( this.progress != null ){
        this.progress.Dispose();
      }
    }
    #endregion

    #region Public functions
    public virtual bool Exec()
    {
      bool status = true;
      ConnectionState previousConnectionState = this.connection.State;
      
      try{
        if( previousConnectionState == ConnectionState.Closed ){
          this.connection.Open();
        }

        this.PrepareProgress( this.selectedRows.Count, this.GetProgressCaption(),  this.GetProgressMessage());
        status = this.BeforeProcess();

        if( this.increaseProgress ){
          for( int i = 0; !this.progress.Cancel && status && i < this.selectedRows.Count; i++ ){
            this.Process( i, ref status );
          }
        } else {
          for( int i = this.selectedRows.Count - 1; !this.progress.Cancel && status && i >= 0; i-- ){
            this.Process( i, ref status );
          }
        }

        if( status ){
          status = this.AfterProcess();
        }

      } catch ( Exception Exp ) {
        string message = Exp.Message;
        message += "\r\nTrace:\r\n";
        message += Exp.StackTrace;

        YariSoft.Utils.YMessages.Show( message, "Error ( IOperation.Exec )", MessageBoxButtons.OK, MessageBoxIcon.Error );
        status = false;
      }

      if( previousConnectionState == ConnectionState.Closed ){
        this.connection.Close();
      }
      return status;    
    }
    #endregion

    #region Protected functions
    protected virtual string GetProgressCaption()
    {
      return "";
    }
    protected virtual string GetProgressMessage()
    {
      return "";
    }
    protected virtual bool ExecOperation( int Position )
    {
      return true;
    }
    protected virtual bool BeforeProcess()
    {
      return true;
    }
    protected virtual bool AfterProcess()
    {
      return true;
    }
    #endregion

    #region Private functions
    private void Process( int Position, ref bool Status )
    {
      Status = this.ExecOperation( Position );
      if( ! Status ){
        return;
      }
      this.SetProgressValue( Position );
      if( this.OnSourceDataChanged != null ){
        Status = this.OnSourceDataChanged ( this.source.Table );
      }
      if( this.OnDestinationDataChanged != null ){
        Status = this.OnDestinationDataChanged ( this.destination.Table );
      }

    }

    private void PrepareProgress( int Maximum, string ProgressFormText, string OperationText )
    {
      if( this.ShowProgress ){
        this.progress = new YariSoft.Utils.YProgress ();
        this.progress.Maximum = Maximum;
        this.progress.Text = ProgressFormText;
        this.progress.OperationCaption = OperationText;
      }
    }

    private void SetProgressValue( int Value )
    {
      if( this.ShowProgress ){
        this.progress.Value = Value;
      }
    }
    #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.