public void ExecuteReader(DBSettingEntity dbSetting, Func <IDataReader, bool> funcProccessDataReader)
        {
            try
            {
                using (IDbConnection con = DBManagerFactory.BuilConnection(dbSetting.ProviderType, dbSetting.ConnectionString))
                {
                    con.Open();
                    IDbTransaction idbTransaction = null;

                    if (dbSetting.IsTransaction)
                    {
                        idbTransaction = con.BeginTransaction();
                    }

                    using (IDbCommand cmd = DBManagerFactory.BuildCommand(dbSetting.ProviderType, con, idbTransaction, dbSetting.CommandType, dbSetting.CommandText))
                    {
                        this.AttachParameters(cmd, dbSetting.Parameters, dbSetting.ProviderType);

                        using (IDataReader dr = cmd.ExecuteReader())
                        {
                            funcProccessDataReader.Invoke(dr);
                        }

                        if (idbTransaction != null)
                        {
                            idbTransaction.Commit();
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw this.TranslateException(ex);
            }
        }
 private void AttachParameters(IDbCommand command, List <DBParameterEntity> lstParams, DataProvider providerType)
 {
     foreach (DBParameterEntity item in lstParams)
     {
         command.Parameters.Add(DBManagerFactory.BuildParameter(providerType, item.ParameterName, item.ParameterValue));
     }
 }
Exemple #3
0
        public int ExecuteNonQuery(CommandType commandType, string commandText)
        {
            dbEntity.Command = DBManagerFactory.GetCommand(dbEntity.ProviderType);
            this.PrepareCommand(dbEntity.Command, dbEntity.Connection, dbEntity.Transaction, commandType, commandText, dbEntity.Parameters);
            int returnValue = dbEntity.Command.ExecuteNonQuery();

            dbEntity.Command.Parameters.Clear();

            return(returnValue);
        }
Exemple #4
0
        public void CreateAndOpenConnection()
        {
            dbEntity.Connection = DBManagerFactory.GetConnection(dbEntity.ProviderType);
            dbEntity.Connection.ConnectionString = dbEntity.ConnectionString;

            if (dbEntity.Connection.State != ConnectionState.Open)
            {
                dbEntity.Connection.Open();
            }
        }
Exemple #5
0
        public IDataReader ExecuteReader(CommandType commandType, string commandText)
        {
            dbEntity.Command            = DBManagerFactory.GetCommand(dbEntity.ProviderType);
            dbEntity.Command.Connection = dbEntity.Connection;
            PrepareCommand(dbEntity.Command, dbEntity.Connection, dbEntity.Transaction, commandType, commandText, dbEntity.Parameters);
            dbEntity.DataReader = dbEntity.Command.ExecuteReader();
            dbEntity.Command.Parameters.Clear();

            return(dbEntity.DataReader);
        }
Exemple #6
0
        public DataSet ExecuteDataSet(CommandType commandType, string commandText)
        {
            dbEntity.Command = DBManagerFactory.GetCommand(dbEntity.ProviderType);
            this.PrepareCommand(dbEntity.Command, dbEntity.Connection, dbEntity.Transaction, commandType, commandText, dbEntity.Parameters);
            IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(dbEntity.ProviderType);

            dataAdapter.SelectCommand = dbEntity.Command;
            DataSet dataSet = new DataSet();

            dataAdapter.Fill(dataSet);
            dbEntity.Command.Parameters.Clear();

            return(dataSet);
        }
        public object ExecuteScalar(DBSettingEntity dbSetting)
        {
            try
            {
                object result;

                using (IDbConnection con = DBManagerFactory.BuilConnection(dbSetting.ProviderType, dbSetting.ConnectionString))
                {
                    con.Open();
                    IDbTransaction idbTransaction = null;

                    if (dbSetting.IsTransaction)
                    {
                        idbTransaction = con.BeginTransaction();
                    }

                    using (IDbCommand cmd = DBManagerFactory.BuildCommand(dbSetting.ProviderType, con, idbTransaction, dbSetting.CommandType, dbSetting.CommandText))
                    {
                        this.AttachParameters(cmd, dbSetting.Parameters, dbSetting.ProviderType);

                        result = cmd.ExecuteScalar();

                        if (idbTransaction != null)
                        {
                            idbTransaction.Commit();
                        }
                    }
                }

                return(result);
            }
            catch (SqlException ex)
            {
                throw this.TranslateException(ex);
            }
        }
        public void ExecuteDataSet(DBSettingEntity dbSetting, Func <DataSet, bool> funcProccessDataSet)
        {
            try
            {
                using (IDbConnection con = DBManagerFactory.BuilConnection(dbSetting.ProviderType, dbSetting.ConnectionString))
                {
                    con.Open();
                    IDbTransaction idbTransaction = null;

                    if (dbSetting.IsTransaction)
                    {
                        idbTransaction = con.BeginTransaction();
                    }

                    using (IDbCommand cmd = DBManagerFactory.BuildCommand(dbSetting.ProviderType, con, idbTransaction, dbSetting.CommandType, dbSetting.CommandText))
                    {
                        this.AttachParameters(cmd, dbSetting.Parameters, dbSetting.ProviderType);

                        IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(dbSetting.ProviderType);
                        dataAdapter.SelectCommand = cmd;
                        DataSet dataSet = new DataSet();
                        dataAdapter.Fill(dataSet);
                        funcProccessDataSet.Invoke(dataSet);

                        if (idbTransaction != null)
                        {
                            idbTransaction.Commit();
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw this.TranslateException(ex);
            }
        }
Exemple #9
0
 public void CreateParameters(int paramsCount)
 {
     dbEntity.Parameters = new IDbDataParameter[paramsCount];
     dbEntity.Parameters = DBManagerFactory.GetParameters(dbEntity.ProviderType, paramsCount);
 }