Monday, September 23, 2013

DBManager

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace HRHO_Utilities
{

    /// <summary>
    /// This enum contains all the DataProvider types supported by the DBManager
    /// </summary>
    public enum DataProvider
    {
        Oracle, SqlServer, OleDb, Odbc
    }

    public interface IDBManager
    {
        /// <summary>
        /// Get or set Data Provider type
        /// </summary>
        DataProvider ProviderType
        {
            get;
            set;
        }

        /// <summary>
        /// Get or set connection string
        /// </summary>
        string ConnectionString
        {
            get;
            set;
        }

        /// <summary>
        /// Get connection object
        /// </summary>
        IDbConnection Connection
        {
            get;
        }

        /// <summary>
        /// Get transaction object
        /// </summary>
        IDbTransaction Transaction
        {
            get;
        }

        /// <summary>
        /// Get or set DataReader object
        /// </summary>
        IDataReader DataReader
        {
            get;
            set;
        }

        /// <summary>
        /// Get command object
        /// </summary>
        IDbCommand Command
        {
            get;
        }

        /// <summary>
        /// Get parameter array
        /// </summary>
        IDbDataParameter[] Parameters
        {
            get;
        }

        /// <summary>
        /// This method can be used to establish (open) a new connection with the data source.
        /// </summary>
        void Open();

        /// <summary>
        /// This method can be used to begin (start) an ADO.NET transaction.
        /// </summary>
        void BeginTransaction();

        /// <summary>
        /// This method can be used to commit (end) an ADO.NET transaction.
        /// </summary>
        void CommitTransaction();

        /// <summary>
        /// This method can be used to initialise 'n' number of parameters.
        /// </summary>
        /// <param name="paramsCount">Number of parameters to initialise</param>
        void CreateParameters(int paramsCount);

        /// <summary>
        /// This method can be used to add a parameter to already initialised parameter object.
        /// </summary>
        /// <param name="index">Index of the parameter object</param>
        /// <param name="paramName">Parameter name (as given in the T-SQL)</param>
        /// <param name="objValue">Parameter value</param>
        void AddParameters(int index, string paramName, object objValue);

        /// <summary>
        /// This method can be used to add a parameter to already initialised parameter object.
        /// </summary>
        /// <param name="index">Index of the parameter object</param>
        /// <param name="paramName">Parameter name (as given in the T-SQL)</param>
        /// <param name="objValue">Parameter value</param>
        /// <param name="direction">Parameter direction (can be Input, OutPut and InputOutPut)</param>
        void AddParameters(int index, string paramName, object objValue, ParameterDirection direction);

        /// <summary>
        /// This method can be used to add a parameter to already initialised parameter object.
        /// </summary>
        /// <param name="index">Index of the parameter object</param>
        /// <param name="paramName">Parameter name (as given in the T-SQL)</param>
        /// <param name="objValue">Parameter value</param>
        /// <param name="type">Parameter type</param>
        /// <param name="size">Size of the parameter</param>
        /// <param name="direction">Parameter direction (can be Input, OutPut and InputOutPut)</param>
        void AddParameters(int index, string paramName, object objValue, DbType type, int size, ParameterDirection direction);

        /// <summary>
        /// This method can be used to execute an ADO.NET DataReader.
        /// </summary>
        /// <param name="commandType">Command type (can be Text or Stored Procedure)</param>
        /// <param name="commandText">Command text (can be T-SQL statement or Stored Procedure name)</param>
        /// <returns>Returns an ADO.NET DataReader object</returns>
        IDataReader ExecuteReader(CommandType commandType, string commandText);

        /// <summary>
        /// This method can be used to fetch an ADO.NET DataSet.
        /// </summary>
        /// <param name="commandType">Command type (can be Text or Stored Procedure)</param>
        /// <param name="commandText">Command text (can be T-SQL statement or Stored Procedure name)</param>
        /// <returns>Returns an ADO.NET DataSet object</returns>
        DataSet ExecuteDataSet(CommandType commandType, string commandText);

        /// <summary>
        /// This method can be used to fetch a Scalar value.
        /// </summary>
        /// <param name="commandType">Command type (can be Text or Stored Procedure)</param>
        /// <param name="commandText">Command text (can be T-SQL statement or Stored Procedure name)</param>
        /// <returns>Returns a scalar value as object</returns>
        object ExecuteScalar(CommandType commandType, string commandText);

        /// <summary>
        /// This method can be used to execute a T-SQL statement.
        /// </summary>
        /// <param name="commandType">Command type (can be Text or Stored Procedure)</param>
        /// <param name="commandText">Command text (can be T-SQL statement or Stored Procedure name)</param>
        /// <returns>Returns the number of Rows affected by the statement</returns>
        int ExecuteNonQuery(CommandType commandType, string commandText);

        /// <summary>
        /// This method can be used to close an already oppened DataReader object.
        /// </summary>
        void CloseReader();
        void SQLBulkInsert(DataTable dt, string tableName);

        /// <summary>
        /// This method can be used to close an already oppened Connection object.
        /// </summary>
        void Close();

        /// <summary>
        /// This method will deallocate all the resources allocated to the DBManager object.
        /// </summary>
        void Dispose();

    }  

}

No comments: