Exemple #1
0
        private void write(IDataAccessor da)
        {
            bool exx = false;
            AbstractConnection  connection  = null;
            AbstractTransaction transaction = null;

            try
            {
                connection = DBFactory.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();
                da.Update(connection, transaction, dataSet);
                transaction.Commit();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                exx = true;
                transaction.Rollback();
            }
            finally
            {
                connection.Close();
            }
            Assert.IsFalse(exx, "Exceptions not throwed");
        }
Exemple #2
0
        private DbConnection CreateConnection()
        {
            DbConnection dbconn = DBFactory.CreateConnection();

            dbconn.ConnectionString = ConnectionString;
            return(dbconn);
        }
Exemple #3
0
        private void read(IDataAccessor da)
        {
            bool exx = false;
            AbstractConnection  connection  = null;
            AbstractTransaction transaction = null;

            dataSet = new UPrintDataSet();
            try
            {
                connection = DBFactory.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();
                da.Read(connection, transaction, dataSet);
                transaction.Commit();
            }
            catch (Exception e)
            {
                transaction.Rollback();
            }
            finally
            {
                connection.Close();
            }
            Assert.IsFalse(exx, "Exceptions not throwed");
        }
Exemple #4
0
        /// <summary>
        /// 执行无结果集的数据的操作命令
        /// </summary>
        /// <param name="ConnString">数据库连接字符串</param>
        /// <param name="Trans">Sql事务对象</param>
        /// <param name="CmdType">执行命令的类型</param>
        /// <param name="CmdText">存储过程或T-SQL语句等</param>
        /// <param name="CommandParameters">执行命令所需的参数数组</param>
        /// <returns>执行数据库操作所影响的行数</returns>
        public static int ExecuteNonQuery(string ConnString, IDbTransaction Trans, CommandType CmdType, string CmdText, params IDbDataParameter[] CommandParameters)
        {
            IDbCommand cmd = DBFactory.CreateCommand();

            using (IDbConnection conn = String.IsNullOrEmpty(ConnString) ? DBFactory.CreateConnection() : DBFactory.CreateConnection(ConnString, Config.DataBase.DbType.SQLSERVER)) {
                PrepareCommand(cmd, conn, Trans, CmdType, CmdText, CommandParameters);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                return(val);
            }
        }
Exemple #5
0
        public bool InsertDepthChart(List <DepthChart> dCharts)
        {
            List <bool> insertList = null;

            string storeProc = "sp_InsertDepthChart";

            IDbConnection sqlConn = null;
            IDbCommand    sqlCmd  = null;

            IDbDataParameter[] parameters = null;

            IConnection connection = DBFactory.CreateConnection(DBType.SQL);

            sqlConn = connection.GetConnection();
            sqlConn.Open();

            foreach (DepthChart chart in dCharts)
            {
                try
                {
                    sqlCmd             = new SqlCommand();
                    sqlCmd.CommandText = storeProc;
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Connection  = sqlConn;

                    insertList = new List <bool>();

                    parameters = CreateParameters(chart);

                    foreach (IDbDataParameter d in parameters)
                    {
                        sqlCmd.Parameters.Add(d);
                    }

                    int returnValue = sqlCmd.ExecuteNonQuery();

                    if (returnValue == 1)
                    {
                        insertList.Add(true);
                    }
                    else
                    {
                        insertList.Add(false);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Concat(ex.Message, ": From InsertDepthChart method in DAL"));
                }
            }

            return(!insertList.Contains(false));
        }
Exemple #6
0
        public bool InsertStatData(List <Stat> stats)
        {
            string      storeProc  = "sp_InsertStat";
            List <bool> insertList = null;

            IDbConnection sqlConn = null;
            IDbCommand    sqlCmd  = null;

            IDbDataParameter[] parameters = null;

            IConnection connection = DBFactory.CreateConnection(DBType.SQL);

            sqlConn = connection.GetConnection();
            sqlConn.Open();

            insertList = new List <bool>();

            foreach (Stat s in stats)
            {
                try
                {
                    sqlCmd             = new SqlCommand();
                    sqlCmd.CommandText = storeProc;
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Connection  = sqlConn;

                    parameters = CreateParameters(s);

                    foreach (IDbDataParameter p in parameters)
                    {
                        sqlCmd.Parameters.Add(p);
                    }

                    int returnValue = sqlCmd.ExecuteNonQuery();

                    if (returnValue == 1)
                    {
                        insertList.Add(true);
                    }
                    else
                    {
                        insertList.Add(false);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            return(!insertList.Contains(false));
        }
Exemple #7
0
        public bool InsertPlayersData(List <Player> players)
        {
            bool          returnState = false;
            string        storeProc   = "sp_InsertPlayer";
            IDbConnection sqlConn     = null;
            IDbCommand    sqlCmd      = null;

            IDbDataParameter[] parameters = null;

            IConnection connection = DBFactory.CreateConnection(DBType.SQL);

            sqlConn = connection.GetConnection();
            sqlConn.Open();

            foreach (Player player in players)
            {
                try
                {
                    sqlCmd             = new SqlCommand();
                    sqlCmd.CommandText = storeProc;
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Connection  = sqlConn;

                    parameters = CreateParameters(player);

                    foreach (IDbDataParameter p in parameters)
                    {
                        sqlCmd.Parameters.Add(p);
                    }

                    int returnValue = sqlCmd.ExecuteNonQuery();

                    if (returnValue == 1)
                    {
                        returnState = true;
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            return(returnState);
        }
Exemple #8
0
        internal DbConnection CreateConn(string connectionString)
        {
            DbConnection _DBConn = DBFactory.CreateConnection();

            if (!string.IsNullOrWhiteSpace(connectionString))
            {
                _DBConn.ConnectionString = connectionString;
            }
            else
            {
                _DBConn.ConnectionString = this.ConnectionString;
            }
            _Database = _DBConn.Database;
            return(_DBConn);
        }
Exemple #9
0
        /// <summary>
        /// 执行有结果集的数据的操作指令
        /// </summary>
        /// <param name="ConnString">数据库连接字符串</param>
        /// <param name="Trans">Sql事务对象</param>
        /// <param name="CmdType">执行命令的类型</param>
        /// <param name="CmdText">存储过程或T-SQL语句等</param>
        /// <param name="CommandParameters">执行命令所需的参数数组</param>
        /// <returns>结果集</returns>
        public static IDataReader ExecuteReader(string ConnString, IDbTransaction Trans, CommandType CmdType, string CmdText, params IDbDataParameter[] CommandParameters)
        {
            IDbCommand    cmd  = DBFactory.CreateCommand();
            IDbConnection conn = String.IsNullOrEmpty(ConnString) ? DBFactory.CreateConnection() : DBFactory.CreateConnection(ConnString, Config.DataBase.DbType.SQLSERVER);

            try {
                PrepareCommand(cmd, conn, Trans, CmdType, CmdText, CommandParameters);
                cmd.CommandTimeout = 500;
                IDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return(rdr);
            } catch (Exception ex) {
                conn.Close();
                throw new Exception(ex.ToString());
            }
        }
        private IDbConnection GetConnection()
        {
            try
            {
                ConnectionStringSettings settings   = ConfigurationManager.ConnectionStrings[this.Config.DBConfig.Connection];
                IDbConnection            connection = DBFactory.CreateConnection(settings.ProviderName);
                connection.ConnectionString = settings.ConnectionString;

                return(connection);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;

                // todo some extra error handling
            }
        }
Exemple #11
0
    /// <summary>
    /// ��ʼ��autofac
    /// </summary>
    public static void InitAutofac()
    {
        var builder = new ContainerBuilder();

        //���ýӿ�����
        builder.RegisterInstance <IDbConnection>(DBFactory.CreateConnection()).As <IDbConnection>();
        builder.RegisterGeneric(typeof(GenericRepository <>)).As(typeof(IGenericRepository <>));

        //ע��ִ���
        builder.RegisterAssemblyTypes(Assembly.Load("Demo.Repository"))
        .Where(x => x.Name.EndsWith("Repository"))
        .AsImplementedInterfaces();

        //����quartz.net����ע��
        builder.RegisterModule(new QuartzAutofacFactoryModule());
        builder.RegisterModule(new QuartzAutofacJobsModule(Assembly.GetExecutingAssembly()));

        _container = builder.Build();
    }
Exemple #12
0
        /// <summary>
        /// 查询数据填充到数据集DataSet中
        /// </summary>
        /// <param name="ConnString">数据库连接字符串</param>
        /// <param name="Trans">Sql事务对象</param>
        /// <param name="CmdType">执行命令的类型</param>
        /// <param name="CmdText">存储过程或T-SQL语句等</param>
        /// <param name="CommandParameters">执行命令所需的参数数组</param>
        /// <returns>DataSet数据集</returns>
        public static DataSet ExecuteDataSet(string ConnString, IDbTransaction Trans, CommandType CmdType, string CmdText, params IDbDataParameter[] CommandParameters)
        {
            DataSet       ds   = new DataSet();
            IDbCommand    cmd  = DBFactory.CreateCommand();
            IDbConnection conn = String.IsNullOrEmpty(ConnString) ? DBFactory.CreateConnection() : DBFactory.CreateConnection(ConnString, Config.DataBase.DbType.SQLSERVER);

            try {
                PrepareCommand(cmd, conn, Trans, CmdType, CmdText, CommandParameters);
                IDataAdapter sda = DBFactory.CreateDataAdapter(cmd);
                sda.Fill(ds);
                return(ds);
            }
            catch (Exception ex) {
                throw new Exception(ex.ToString());
            }
            finally {
                conn.Close();
                cmd.Dispose();
            }
        }
Exemple #13
0
        private void read(IDataAccessor da)
        {
            AbstractConnection  connection  = null;
            AbstractTransaction transaction = null;

            dataSet = new UPrintDataSet();
            try
            {
                connection = DBFactory.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();
                da.Read(connection, transaction, dataSet);
                transaction.Commit();
            }
            catch (Exception e)
            {
                transaction.Rollback();
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #14
0
        public bool InsertNBAStandings(IEnumerable <NBAStanding> standings)
        {
            string      storeProc  = "sp_InsertNBAStanding";
            List <bool> insertList = null;

            IDbConnection sqlConn = null;
            IDbCommand    sqlCmd  = null;

            IDbDataParameter[] parameters = null;

            try
            {
                IConnection connection = DBFactory.CreateConnection(DBType.SQL);
                sqlConn = connection.GetConnection();
                sqlConn.Open();

                insertList = new List <bool>();

                foreach (NBAStanding s in standings)
                {
                    sqlCmd             = new SqlCommand();
                    sqlCmd.CommandText = storeProc;
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Connection  = sqlConn;

                    parameters = CreateParameters(s);

                    foreach (IDbDataParameter parameter in parameters)
                    {
                        sqlCmd.Parameters.Add(parameter);
                    }

                    int returnValue = sqlCmd.ExecuteNonQuery();

                    if (returnValue == 1)
                    {
                        insertList.Add(true);
                    }
                    else
                    {
                        insertList.Add(false);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                CloseAll(sqlCmd, sqlConn);
            }

            if (!insertList.Contains(false))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }