Open() public abstract method

public abstract Open ( ) : void
return void
Esempio n. 1
0
        /// <summary>
        /// 初次使用创建数据库
        /// </summary>
        public static void CreateDataBase()
        {
            try
            {
                bool isExist = File.Exists(DataPath);
                if (!isExist)
                {
                    SQLiteConnection.CreateFile(DataPath);
                }
                conn = new SQLiteConnection(ConnStr);
                conn.Open();
                comm = conn.CreateCommand();
                if (!isExist)
                {
                    String sql = "Create table ReceiveData(DeviceNum INTEGER , Temperature INTEGER , Humidity INTEGER , Tyrere INTEGER , MotorState INTEGER , ErrorNum INTEGER , CreateDate DateTime);";
                    comm.CommandText = sql;
                    comm.CommandType = CommandType.Text;
                    comm.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {

            }
        }
Esempio n. 2
0
        public void duiQuery(string QueryString)
        {
            using (_curConnection = _curDataObjFactory.CreateConnection())
            {
                try
                {
                    _curConnection.ConnectionString = _connectionString;
                    _curConnection.Open();

                    using (DbCommand curCommand = _curDataObjFactory.CreateCommand())
                    {
                        curCommand.Connection = _curConnection;
                        curCommand.CommandText = QueryString;

                        curCommand.ExecuteNonQuery();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    _curConnection.Close();
                }
            }
        }
        public override void Connect_To_Database(StorageConfig config)
        {
            
            myConfig = config as SQLiteConfig;
            if (myConfig == null)
                throw new Exception("Database Config is NULL");

            if (!FileNameLockObjects.ContainsKey(myConfig.DatabaseFile))
                FileNameLockObjects.Add(myConfig.DatabaseFile,new object());

            try
            {
                myDBConn = new SQLiteConnection(ConnectionString);
                myDBConn.Open();
                if (myDBConn.State != System.Data.ConnectionState.Open)
                    throw new Exception("Unable to Open Database. Storage:" + config.Name);
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
        public Manager(String fileName)
        {
            localization = new System.ComponentModel.ComponentResourceManager(typeof(WorkerTimeStrings));
            this.fileName = fileName;
            if (File.Exists(fileName)) {
                this.sqlConnection = new SQLiteConnection("Data Source=" + fileName );
                this.sqlCommand = this.sqlConnection.CreateCommand();
                sqlConnection.Open();
            } else {
                this.sqlConnection = new SQLiteConnection("Data Source=" + fileName);
                this.sqlCommand = this.sqlConnection.CreateCommand();
                sqlConnection.Open();

                ExecuteNonQuery("CREATE TABLE Tracks ([ID] INTEGER PRIMARY KEY AUTOINCREMENT, [ProjectID] INTEGER, [ActivityID] INTEGER, [Start] DATETIME, [End] DATETIME, [Duration] INTEGER)");
                ExecuteNonQuery("CREATE TABLE Projects ([ID] INTEGER PRIMARY KEY AUTOINCREMENT, [Name] TEXT)");
                ExecuteNonQuery("CREATE TABLE Activity ([ID] INTEGER PRIMARY KEY AUTOINCREMENT, [Name] TEXT, [ProjectID] INTEGER)");

                if (MessageBox.Show(localization.GetString("String10"), localization.GetString("String3"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes )
                {
                    ExecuteNonQuery("INSERT INTO Projects (Name) VALUES ('" + localization.GetString("String12") + " 1')");
                    ExecuteNonQuery("INSERT INTO Projects (Name) VALUES ('" + localization.GetString("String12") + " 2')");
                    ExecuteNonQuery("INSERT INTO Projects (Name) VALUES ('" + localization.GetString("String12") + " 3')");
                    ExecuteNonQuery("INSERT INTO Activity (Name,ProjectID) VALUES ('" + localization.GetString("String13") + " 1',1)");
                    ExecuteNonQuery("INSERT INTO Activity (Name,ProjectID) VALUES ('" + localization.GetString("String13") + " 2',1)");
                    ExecuteNonQuery("INSERT INTO Activity (Name,ProjectID) VALUES ('" + localization.GetString("String13") + " 3',1)");
                    ExecuteNonQuery("INSERT INTO Activity (Name,ProjectID) VALUES ('" + localization.GetString("String13") + " 1',2)");
                    ExecuteNonQuery("INSERT INTO Activity (Name,ProjectID) VALUES ('" + localization.GetString("String13") + " 2',2)");
                    ExecuteNonQuery("INSERT INTO Activity (Name,ProjectID) VALUES ('" + localization.GetString("String13") + " 3',2)");
                }
            }

            Update1();
        }
Esempio n. 5
0
 public SqlFuConnection(DbConnection cnx,DbEngine engine)
 {
     cnx.MustNotBeNull();
     _conex = cnx;
     _provider = ProviderFactory.GetProvider(engine);
     _conex.Open();
 }
Esempio n. 6
0
 public MachineParamsManager(Guid plowmachineId, Metadata.MetadataManager manager)
 {
     _plowMachineId = plowmachineId;
     _manager = manager;
     _connection = DBConnectionProvider.GetConnection();
     _connection.Open();
 }
Esempio n. 7
0
        /// <summary>
        /// Resolve at run time the appropriate set of DbParameters for a stored procedure
        /// </summary>
        /// <param name="transaction">A valid SqlTransaction object</param>
        /// <param name="connection">A valid SqlConnection object</param>
        /// <param name="storedProcedureName">The name of the stored procedure</param>
        /// <param name="includeReturnValueParameter">Whether or not to include their return value parameter</param>
        /// <returns>The parameter array discovered.</returns>
        private static IList<SqlParameter> DiscoverSpParameterSet(DbTransaction transaction, DbConnection connection, string storedProcedureName, bool includeReturnValueParameter)
        {
            using (SqlCommand cmd = new SqlCommand(storedProcedureName, connection as SqlConnection))
            {
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                cmd.CommandType = CommandType.StoredProcedure;
                if (transaction != null)
                {
                    cmd.Transaction = transaction as SqlTransaction;
                }

                SqlCommandBuilder.DeriveParameters(cmd);

                if (!includeReturnValueParameter)
                {
                    cmd.Parameters.RemoveAt(0);
                }

                SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count];

                cmd.Parameters.CopyTo(discoveredParameters, 0);

                return discoveredParameters;
            }
        }
 public void Setup()
 {
     var factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource());
     var db = factory.CreateDefault();
     connection = db.CreateConnection();
     connection.Open();
 }
Esempio n. 9
0
        }//Execute(string sql)

        /// <summary>
        /// 执行Sql语句
        /// </summary>
        /// <param name="sql">Sql语句</param>
        /// <param name="Conn">数据库连接对象</param>
        /// <param name="param">参数</param>
        /// <returns>返回受影响行数</returns>
        static public int Execute(string sql, System.Data.Common.DbConnection Conn, System.Data.Common.DbParameter[] param)
        {
            if (Conn == null)
            {
                DBClassHelper.ErrLog("DBClassHelper.Execute(string sql, System.Data.Common.DbConnection Conn, System.Data.Common.DbParameter[] param):连接对象为空!");
                return(0);
            }
            if (Conn.State == System.Data.ConnectionState.Closed)
            {
                Conn.Open();
            }
            System.Data.IDbCommand cmd = Conn.CreateCommand();
            cmd.CommandTimeout = 180;
            cmd.CommandText    = sql;
            for (int i = 0; i < param.Length; i++)
            {
                cmd.Parameters.Add(param[i]);
            }
            try
            {
                return(cmd.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                DBClassHelper.ErrLog("DBClassHelper.Execute(string sql, System.Data.Common.DbConnection Conn, System.Data.Common.DbParameter[] param):" + ex.Message + "/nsql=" + sql);
                return(0);
            }
        }//Execute(string sql,System.Data.IDataParameter[] param)
Esempio n. 10
0
        public bool DeleteProduct(int exchangeId, int productId)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("delete from Hishop_PointExChange_Products where [exChangeId]= @exChangeId and [ProductId] = @ProductId ");
                this.database.AddInParameter(sqlStringCommand, "exChangeId", System.Data.DbType.Int32, exchangeId);
                this.database.AddInParameter(sqlStringCommand, "ProductId", System.Data.DbType.Int32, productId);
                System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_PointExChange_PointExChanges set ProductNumber=ProductNumber-1 where Id=@Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, exchangeId);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Ham nay de mo ket noi den database
        /// </summary>
        /// <param name="ServerName"></param>
        /// <param name="DatabaseName"></param>
        /// <param name="UserId"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public static bool DB_OpenConnection(string ServerName, string DatabaseName, string UserId, string Password)
        {
            DbProviderFactory = System.Data.SqlClient.SqlClientFactory.Instance;
            DbConnectionStringBuilder DbConnectionStringBuilder = DbProviderFactory.CreateConnectionStringBuilder();

            DbConnectionStringBuilder.Add("Data Source", ServerName);
            DbConnectionStringBuilder.Add("User ID", UserId);
            DbConnectionStringBuilder.Add("Password", Password);
            DbConnectionStringBuilder.Add("Initial Catalog", DatabaseName);

            bool IsConnected;

            try
            {
                if (DbConnection == null)
                {
                    DbConnection = DbProviderFactory.CreateConnection();
                }
                if (DbConnection.State != ConnectionState.Open)
                {
                    DbConnection.ConnectionString = DbConnectionStringBuilder.ConnectionString;
                    DbConnection.Open();
                }
                IsConnected = true;
            }
            catch
            {
                IsConnected = false;
            }
            return(IsConnected);
        }
        public void select(DbConnection conn)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();

            DataTable tb = new DataTable();

            DbCommand dbCommand = conn.CreateCommand();

            string selectQuery = DISCOUNTCURVESETTING_Table_DAO.SelectQuery_;

            selectQuery = selectQuery.Replace("@KeyColumnValue@", this.KeyColumn_);

            dbCommand.CommandText = selectQuery;

            //DbDataAdapter dataAdapter = new DbDataAdapter(dbCommand, conn);
            DbDataAdapter dataAdapter = DataBaseConnectManager.CreateDataAdapter(dbCommand, conn);

            dataAdapter.Fill(tb);

            DataRow[] dr = tb.Select();
            int rowCount = dr.Length;

            if (!(rowCount == 0 || rowCount == 1))
            { throw new Exception(); }

            foreach (DataRow item in dr)
            {
                this.CURRENCY_ = item[0].ToString();
                this.CURVECODE_ = item[1].ToString();
                this.PROVIDER_ = item[2].ToString();
            }


        }
Esempio n. 13
0
 public void OpenConnection(DbConnection dbc)
 {
     if (dbc.State == ConnectionState.Closed)
     {
         dbc.Open();
     }
 }
Esempio n. 14
0
        public DatabaseAccessTests()
        {
            _conn = SQLitePortability.CreateConnection();
            _conn.Open();

            _db = new DatabaseAccess(_conn, new SQLiteDetails());
        }
Esempio n. 15
0
        public bool Fun_OpenDataBase()
        {
            String sConnect = "";

            try
            {
                if (this.DBConn != null)
                {
                    if (this.DBConn.State == System.Data.ConnectionState.Open)
                    {
                        this.DBConn.Close();
                    }
                }

                //sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBPath;
                sConnect  = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DBPath;
                DBConn    = new OleDbConnection();
                DBCommand = new OleDbCommand();

                DBConn.ConnectionString = sConnect;
                DBConn.Open();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 16
0
        public void Open(string aConnectionString, ServerType serverType)
        {
            dbCache.ConnectionString = aConnectionString;
            dbCache.ServerType = serverType;
            switch (serverType)
            {
                case ServerType.Firebird:
                    connection = new FbConnection {ConnectionString = aConnectionString};
                    break;
                case ServerType.MsSql:
                    connection = new SqlConnection { ConnectionString = aConnectionString };
                    break;
            }
            connection.Open();

            if (serverType==ServerType.Firebird)
                using (var transaction = connection.BeginTransaction())
                {
                    DbData.GetFieldValue(connection, transaction,
                        "select rdb$set_context('USER_SESSION','RPL_SERVICE','1') from rdb$database;");
                    transaction.Commit();
                }

            var t = new Thread(LoadData);
            t.Start();
        }
Esempio n. 17
0
 protected internal virtual IDbCommandWrap GetCommandWrap(IStatementSetting statement)
 {
     DbConnection connection;
     var closeConnectionOnCommandDisposed = true;
     if (this.IsInTransaction) {
         if (this.transaction == null) {
             lock (this.lockTransaction) {
                 if (this.transaction == null) {
                     connection = this.GetConnection(statement);
                     connection.Open();
                     if(this.DataService.Debug) {
                         LogService.WriteLog(this, LogLevel.DEBUG, "Connection open with transaction:" + connection.GetHashCode());
                     }
                     this.transaction = connection.BeginTransaction();
                 }
             }
         }
         connection = this.Transaction.Connection;
         closeConnectionOnCommandDisposed = false;
     } else {
         connection = this.GetConnection(statement);
         connection.Open();
         if(this.DataService.Debug) {
             LogService.WriteLog(this, LogLevel.DEBUG, "Connection open without transaction:" + connection.GetHashCode());
         }
     }
     var command = connection.CreateCommand();
     command.Transaction = this.Transaction;
     return new DbCommandWrap(command, closeConnectionOnCommandDisposed);
 }
Esempio n. 18
0
        public int ExecuteSqlNonQuery(StringBuilder sbSql, string providerName, string connectionString, out string strError)
        {
            int intEffected = -1;  // return number rows effected

            strError = "";

            try
            {
                conn = CreateDbConnection(providerName, connectionString, out strError);
                conn.Open();
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return(-1);
            }

            try
            {
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = sbSql.ToString();
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = conn;

                intEffected = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return(-1);
            }
            return(intEffected);
        }
Esempio n. 19
0
        public bool DeleteProducts(int actId, string ProductIds)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction     = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand  = this.database.GetSqlStringCommand(string.Format("Delete from Hishop_PointExChange_Products WHERE exChangeId ={0} and ProductId in ( {1} )", actId, ProductIds.ReplaceSingleQuoteMark()));
                System.Data.Common.DbCommand     sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_PointExChange_PointExChanges set ProductNumber=ProductNumber-1 where Id=@Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, actId);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Esempio n. 20
0
        }//ExecuteQueryToDataTable(string sql)

        /// <summary>
        /// 执行查询返回DataReader
        /// </summary>
        /// <param name="sql">Sql语句</param>
        /// <param name="Conn">连接对象</param>
        /// <returns>成功时返回Reader对象,失败时返回null</returns>
        static public System.Data.IDataReader ExecuteQuery(string sql, System.Data.Common.DbConnection Conn)
        {
            System.Data.IDataReader reader = null;
            if (Conn == null)
            {
                return(null);
            }
            try
            {
                if (Conn.State == System.Data.ConnectionState.Closed)
                {
                    Conn.Open();
                }
                System.Data.IDbCommand cmd = Conn.CreateCommand();
                cmd.CommandText    = sql;
                cmd.CommandTimeout = 180;
                reader             = cmd.ExecuteReader();
                return(reader);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("死锁"))
                {
                    WriteLog(ex.Message + " 再做列锁循环!ExecuteQuery");
                    System.Threading.Thread.Sleep(200);
                    return(ExecuteQuery(sql, Conn));
                }
                else
                {
                    DBClassHelper.ErrLog("DBClassHelper.ExecuteQuery(string sql, System.Data.Common.DbConnection Conn):" + ex.Message + ";  \n sql =" + sql);
                }
                return(null);
            }
        }//ExecuteQuery(string sql)
Esempio n. 21
0
        protected override void PreStart()
        {
            base.PreStart();

            _connection = CreateDbConnection();
            _connection.Open();
        }
 public void BeginTransaction()
 {
     _db = new SqlDatabase(_strConnection);
     _dbConn = _db.CreateConnection();
     _dbConn.Open();
     _dbTrans = _dbConn.BeginTransaction();
 }
Esempio n. 23
0
        public static bool UpdateVote(VoteInfo vote)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                VoteDao voteDao = new VoteDao();
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    if (!voteDao.UpdateVote(vote, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!voteDao.DeleteVoteItem(vote.VoteId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            int num = 0;
                            if (vote.VoteItems != null)
                            {
                                foreach (VoteItemInfo current in vote.VoteItems)
                                {
                                    current.VoteId    = vote.VoteId;
                                    current.ItemCount = 0;
                                    num += voteDao.CreateVoteItem(current, dbTransaction);
                                }
                                if (num < vote.VoteItems.Count)
                                {
                                    dbTransaction.Rollback();
                                    result = false;
                                    return(result);
                                }
                            }
                            dbTransaction.Commit();
                            result = true;
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 24
0
        internal AmnesiaDbConnection(System.Transactions.Transaction distributedTransaction, DbConnection real)
        {
            this.real = real;

            // join the transaction
            real.Open();
            real.EnlistTransaction(distributedTransaction);
        }
 /// <summary>
 /// Abertura de conexao, se fechada, e retorno o estado original da conexao para controle posterior
 /// se fecha ou nao ao conexao, ao fim da operacao
 /// </summary>
 /// <param name="connection">Conexao que vai estar aberta ao fim do metodo</param>
 /// <param name="estadoOriginal">Obtem o estado original da conexao, para controle se deve ou nao fechar a conexao</param>
 internal static void AbrirConexao(DbConnection connection, out ConnectionState estadoOriginal)
 {
     estadoOriginal = connection.State;
     if (connection.State == ConnectionState.Closed)
     {
         connection.Open();
     }
 }
		public static string ExecuteQueryToDisplayString(string query, DbConnection conn)
		{
			if (conn.State == ConnectionState.Closed)
			{
				conn.Open();
			}
			return ExecuteQueryToDisplayString(query, null, conn.CreateCommand);
		}
Esempio n. 27
0
 public DbTransaction BeginTransaction()
 {
     _db = DatabaseFactory.CreateDatabase();
     _connection = _db.CreateConnection();
     _connection.Open();
     _transaction = _connection.BeginTransaction();
     return _transaction;
 }
Esempio n. 28
0
        public DbHelper()
        {
            connection = ConnectProvider.CreateConnection();
            cmd = ConnectProvider.CreateCommand();

            connection.Open();
            cmd.Connection = connection;
        }
Esempio n. 29
0
 //private static
 private DataBaseHelper()
 {
     DbProviderFactory factory = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName);
     connection = factory.CreateConnection();
     connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
     connection.Open();
     factory.CreateDataAdapter();
 }
Esempio n. 30
0
 public OpenConnectionGuard(DbConnection connection, bool isExternalConnection)
 {
     _isExternalConnection = isExternalConnection;
     _connection = connection;
     _connectionWasOpen = _connection.State == System.Data.ConnectionState.Open;
     if (!_connectionWasOpen)
         _connection.Open();
 }
Esempio n. 31
0
 public SqlServerProcessor(DbConnection connection, IMigrationGenerator generator, IAnnouncer announcer, IMigrationProcessorOptions options, IDbFactory factory)
     : base(generator, announcer, options)
 {
     this.factory = factory;
     Connection = connection;
     connection.Open();
     BeginTransaction();
 }
Esempio n. 32
0
        public static string UpdateAdjustCommssions(string orderId, string itemid, decimal commssionmoney, decimal adjustcommssion)
        {
            string   text     = string.Empty;
            Database database = DatabaseFactory.CreateDatabase();
            string   result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    OrderInfo orderInfo = ShoppingProcessor.GetOrderInfo(orderId);
                    if (orderId == null)
                    {
                        result = "订单编号不合法";
                        return(result);
                    }
                    int userId = DistributorsBrower.GetCurrentDistributors(true).UserId;
                    if (orderInfo.ReferralUserId != userId || orderInfo.OrderStatus != OrderStatus.WaitBuyerPay)
                    {
                        result = "不是您的订单";
                        return(result);
                    }
                    LineItemInfo lineItemInfo = orderInfo.LineItems[itemid];
                    if (lineItemInfo == null || lineItemInfo.ItemsCommission < adjustcommssion)
                    {
                        result = "修改金额过大";
                        return(result);
                    }
                    lineItemInfo.ItemAdjustedCommssion = adjustcommssion;
                    lineItemInfo.IsAdminModify         = false;
                    if (!new LineItemDao().UpdateLineItem(orderId, lineItemInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                    }
                    if (!new OrderDao().UpdateOrder(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = "更新订单信息失败";
                        return(result);
                    }
                    dbTransaction.Commit();
                    text = "1";
                }
                catch (Exception ex)
                {
                    text = ex.ToString();
                    dbTransaction.Rollback();
                }
                finally
                {
                    dbConnection.Close();
                }
                result = text;
            }
            return(result);
        }
Esempio n. 33
0
 //connects to SQL Server here
 public DAL()
 {
     conn = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings["SqlServerConnectionString"].ProviderName).CreateConnection();
     conn.ConnectionString = ConfigurationManager.ConnectionStrings["SqlServerConnectionString"].ConnectionString;
     cmd = conn.CreateCommand();
     cmd.Connection = conn;
     conn.Open();
     cmd.CommandType = CommandType.Text;
 }
Esempio n. 34
0
        //методы открытия соединения - видимо нахер не нужны. подключени создаются внутри нижеследующих методов
        public void OpenConnection()
        {
            using (_curConnection = _curDataObjFactory.CreateConnection())
            {
                _curConnection.ConnectionString = _connectionString;
                _curConnection.Open();
            }

        }
Esempio n. 35
0
 public  DbConnection getConn()
 {
     if (conn == null)
     {
         conn = new SqlConnection(connectionString);
         conn.Open();
     }
     return conn;
 }
        public void Setup()
        {
            Connection = new SQLiteConnection(IntegrationTestOptions.SqlLite.ConnectionString);
            Processor = new SqliteProcessor(Connection, new SqliteGenerator(), new TextWriterAnnouncer(System.Console.Out),
                                            new ProcessorOptions(), new SqliteDbFactory());

            SchemaDumper = new SqliteSchemaDumper(Processor, new TextWriterAnnouncer(System.Console.Out));
            Connection.Open();
        }
Esempio n. 37
0
 public DatabaseInserter(DbConnection connection, string insertSql)
 {
     Connection = connection;
     _command = Connection.CreateCommand();
     _command.Connection = Connection;
     _command.CommandText = insertSql;
     Connection.Open();
     _sqLiteTransaction = Connection.BeginTransaction();
 }
        public void select(DbConnection conn)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();

            try
            {
                DataTable tb = new DataTable();

                this.DAOList_ = new List<MARKETDATA_SYMBOL_INFO_Table_DAO>();

                DbCommand dbCommand = conn.CreateCommand();

                string selectQuery = MARKETDATA_SYMBOL_INFO_Table_DAOManager.SelectQuery_;

                selectQuery = selectQuery.Replace("@SYMBOL_TYPEKeyColumnValue@", this.KeyColumn_SYMBOL_TYPE_);

                dbCommand.CommandText = selectQuery;

                //DbDataAdapter dataAdapter = new DbDataAdapter(dbCommand, conn);
                DbDataAdapter dataAdapter = DataBaseConnectManager.CreateDataAdapter(dbCommand, conn);

                dataAdapter.Fill(tb);

                DataRow[] dr = tb.Select();
                int rowCount = dr.Length;

                foreach (DataRow item in dr)
                {
                    MARKETDATA_SYMBOL_INFO_Table_DAO dao = new MARKETDATA_SYMBOL_INFO_Table_DAO();

                    dao.SYMBOL_ = item[0].ToString();
                    dao.NAME_ENG_ = item[1].ToString();
                    dao.NAME_KOR_ = item[2].ToString();
                    dao.SYMBOL_TYPE_ = item[3].ToString();
                    dao.PROVIDER_ = item[4].ToString();
                    dao.DESCRIPTION_ = item[5].ToString();
                    dao.TENOR_ = item[6].ToString();
                    dao.SUB_TYPE_ = item[7].ToString();
                    dao.LINKEDCURVE_ = item[8].ToString();
                    dao.RATE_TYPE_ = item[9].ToString();
                    dao.LEG_TENOR_ = item[10].ToString();
                    dao.CURRENCY_ = item[11].ToString();

                    this.DAOList_.Add(dao);
                }

                conn.Close();

            }
            catch (Exception)
            {
                conn.Close();
            }
            
        }
        public void select(DbConnection conn)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();

            DataTable tb = new DataTable();

            this.DAOList_ = new List<MATSER_INFO_Table_DAO>();

            DbCommand dbCommand = conn.CreateCommand();

            string selectQuery = MATSER_INFO_Table_DAOManager.SelectQuery_;



            //selectQuery = selectQuery.Replace("@KeyColumnValue@", this.KeyColumn_);

            dbCommand.CommandText = selectQuery;

            //DbDataAdapter dataAdapter = new DbDataAdapter(dbCommand, conn);
            DbDataAdapter dataAdapter = DataBaseConnectManager.CreateDataAdapter(dbCommand, conn);

            dataAdapter.Fill(tb);

            DataRow[] dr = tb.Select();
            int rowCount = dr.Length;

            foreach (DataRow item in dr)
            {
                MATSER_INFO_Table_DAO dao = new MATSER_INFO_Table_DAO();

                dao.ITEM_CODE_ = item[0].ToString();
                dao.ITEM_NAME_ = item[1].ToString();
                dao.NOTIONAL_ = item[2].ToString();
                dao.REMAIN_NOTIONAL_ = item[3].ToString();
                dao.CURRENCY_ = item[4].ToString();
                dao.TRADE_DATE_ = item[5].ToString();
                dao.MATURITY_DATE_ = item[6].ToString();
                dao.COUNTERPARTY_ = item[7].ToString();
                dao.EXPORT_ITEMCODE_ = item[8].ToString();
                dao.TRADE_ID_ = item[9].ToString();
                dao.TRADE_STATUS_ = item[10].ToString();
                dao.INSTRUMENT_TYPE_ = item[11].ToString();
                dao.UNDERLYING_TYPE_ = item[12].ToString();
                dao.UNDERLYING_DETAIL_TYPE_ = item[13].ToString();
                dao.CONTRACT_TYPE_ = item[14].ToString();
                dao.CONTRACT_SUBTYPE_ = item[15].ToString();
                dao.CONTRACT_DETAIL_TYPE_ = item[16].ToString();
                dao.BOOKING_TYPE_ = item[17].ToString();

                this.DAOList_.Add(dao);
            }



        }
Esempio n. 40
0
        public bool CreateReturn(ReturnsInfo returnInfo)//创建退回单
        {
            bool result;

            if (returnInfo == null)
            {
                result = false;
            }
            else
            {
                Database database = DatabaseFactory.CreateDatabase();
                using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
                {
                    dbConnection.Open();
                    System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                    try
                    {
                        if (!UpdateOrderStatusBeApplyForReturns(returnInfo.OrderId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                            return(result);
                        }
                        returnInfo.ReturnsId = AddReturnInfo(returnInfo, dbTransaction);
                        if (returnInfo.ReturnsId <= 0)
                        {
                            dbTransaction.Rollback();
                            result = false;
                            return(result);
                        }
                        if (returnInfo.ReturnsLineItem.Count > 0)
                        {
                            if (!AddReturnsItem(returnInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                                return(result);
                            }
                        }
                        dbTransaction.Commit();
                        result = true;
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Esempio n. 41
0
        protected override void InitConnection(System.Data.Common.DbConnection conn)
        {
            if (conn.State != System.Data.ConnectionState.Open)
            {
                conn.Open();
            }
            var connectionStringBuilder = new DbConnectionStringBuilder();

            connectionStringBuilder.ConnectionString = conn.ConnectionString;
            dbName = GetDatabaseName(connectionStringBuilder);
        }
Esempio n. 42
0
        public static bool UpdateLineItem(string string_0, OrderInfo order, int quantity)
        {
            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;
            bool     flag;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    SalesProvider salesProvider = SalesProvider.Instance();
                    order.LineItems[string_0].Quantity          = quantity;
                    order.LineItems[string_0].ShipmentQuantity  = quantity;
                    order.LineItems[string_0].ItemAdjustedPrice = order.LineItems[string_0].ItemListPrice;
                    if (!salesProvider.UpdateLineItem(order.OrderId, order.LineItems[string_0], dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    if (!salesProvider.UpdateOrderAmount(order, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    flag = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            if (flag)
            {
                EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "修改了订单号为\"{0}\"的订单商品数量", new object[]
                {
                    order.OrderId
                }));
            }
            result = flag;
            return(result);
        }
Esempio n. 43
0
        public static bool UpdateGroupBuy(GroupBuyInfo groupBuy)
        {
            Globals.EntityCoding(groupBuy, true);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    GroupBuyDao groupBuyDao = new GroupBuyDao();
                    if (!groupBuyDao.UpdateGroupBuy(groupBuy, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!groupBuyDao.DeleteGroupBuyCondition(groupBuy.GroupBuyId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!groupBuyDao.AddGroupBuyCondition(groupBuy.GroupBuyId, groupBuy.GroupBuyConditions, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch (Exception var_4_99)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 44
0
        public static bool UpdateBundlingProduct(BundlingInfo bundlingInfo)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    BundlingDao bundlingDao = new BundlingDao();
                    if (!bundlingDao.UpdateBundlingProduct(bundlingInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!bundlingDao.DeleteBundlingByID(bundlingInfo.BundlingID, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!bundlingDao.AddBundlingProductItems(bundlingInfo.BundlingID, bundlingInfo.BundlingItemInfos, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch (Exception var_4_91)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 45
0
        public static bool AddSiteSettings(SiteSettings siteSettings, int requestId, int siteQty)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    DistributorProvider distributorProvider = DistributorProvider.Instance();
                    if (!distributorProvider.AcceptSiteRequest(siteQty, requestId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!distributorProvider.AddSiteSettings(siteSettings, requestId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!DistributorProvider.Instance().AddInitData(siteSettings.UserId.Value, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 46
0
        public static bool DeleteOrderGift(OrderInfo order, int giftId)
        {
            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    SalesProvider salesProvider = SalesProvider.Instance();
                    OrderGiftInfo orderGift     = salesProvider.GetOrderGift(giftId, order.OrderId);
                    order.Gifts.Remove(orderGift);
                    if (!salesProvider.DeleteOrderGift(order.OrderId, orderGift.GiftId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!salesProvider.UpdateOrderAmount(order, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "删除了订单号为\"{0}\"的订单礼品", new object[]
                            {
                                order.OrderId
                            }));
                            result = true;
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 47
0
        public static bool ClearOrderGifts(OrderInfo order)
        {
            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;
            bool     flag;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    SalesProvider salesProvider = SalesProvider.Instance();
                    order.Gifts.Clear();
                    if (!salesProvider.ClearOrderGifts(order.OrderId, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    if (!salesProvider.UpdateOrderAmount(order, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    flag = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            if (flag)
            {
                EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "清空了订单号为\"{0}\"的订单礼品", new object[]
                {
                    order.OrderId
                }));
            }
            result = flag;
            return(result);
        }
Esempio n. 48
0
        public static bool UpdateGroupBuy(GroupBuyInfo groupBuy)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    if (!SubsitePromotionsProvider.Instance().UpdateGroupBuy(groupBuy, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!SubsitePromotionsProvider.Instance().DeleteGroupBuyCondition(groupBuy.GroupBuyId, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!SubsitePromotionsProvider.Instance().AddGroupBuyCondition(groupBuy.GroupBuyId, groupBuy.GroupBuyConditions, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                dbTransaction.Commit();
                                result = true;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 49
0
File: DAL.cs Progetto: morimizu/repo
        public static SDC.DbDataReader ReadData(string sproc, List <ParamStruct> paramList)
        {
            SDC.DbProviderFactory factory = SDC.DbProviderFactories.GetFactory(Properties.Settings.Default.provider);

            SDC.DbCommand comm = factory.CreateCommand();
            comm = BuildCommand(sproc, paramList);

            SDC.DbConnection conn = Connection(factory);
            comm.Connection = conn;

            conn.Open();
            SDC.DbDataReader dr = comm.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            return(dr);
        }
Esempio n. 50
0
 public bool TestConnection(string providerName, string connectionString, out string strError)
 {
     strError = "";
     try
     {
         conn = CreateDbConnection(providerName, connectionString, out strError);
         conn.Open();
         conn.Close();
         return(true);
     }
     catch (Exception ex)
     {
         strError = ex.Message;
         return(false);
     }
 }
Esempio n. 51
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="comType"></param>
    /// <param name="parameters"></param>
    /// <param name="strError"></param>
    /// <param name="intEffected"></param>
    /// <returns></returns>
    public DataSet GetDataSet(DbCommand cmd, CommandType comType, Dictionary <string, object> parameters, out string strError, out int intEffected)
    {
        intEffected = -1;
        strError    = "";

        try
        {
            conn = cmd.Connection;
            conn.Open();
        }
        catch (Exception ex)
        {
            strError = ex.Message;
            return(null);
        }

        DataSet           dataSet = new DataSet();
        DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);

        try
        {
            //System.Data.Common.DbCommand
            DbDataAdapter dbAdapter = factory.CreateDataAdapter();

            cmd.CommandType = comType;
            if ((parameters != null))
            {
                cmd.Parameters.Clear();
                if (parameters.Count > 0)
                {
                    SetCmd(ref cmd, parameters);
                }
            }

            dbAdapter.SelectCommand  = cmd;
            dbAdapter.FillLoadOption = LoadOption.PreserveChanges;
            intEffected = dbAdapter.Fill(dataSet);

            conn.Close();
        }
        catch (Exception ex)
        {
            strError = ex.Message;
            conn.Close();
        }
        return(dataSet);
    }
Esempio n. 52
0
    public bool TestConnection(out string strError)
    {
        strError = "";
        try
        {
            // conn = CreateDbConnection(out strError);  Connection has been created if you run  public DbCommand commandDB(out String strError, String connectionName = "")

            conn.Open();
            conn.Close();
            return(true);
        }
        catch (Exception ex)
        {
            strError = ex.Message;
            return(false);
        }
    }
Esempio n. 53
0
        }//Execute(string sql,System.Data.IDataParameter[] param)

        /// <summary>
        /// 执行一个事务
        /// </summary>
        /// <param name="sqls">Sql语句组</param>
        /// <returns>成功时返回true</returns>
        static public bool ExecuteTrans(string[] sqls, System.Data.Common.DbConnection Conn)
        {
            System.Data.IDbTransaction myTrans;
            if (Conn == null)
            {
                DBClassHelper.ErrLog("DBClassHelper.ExecuteTrans(string[] sqls):连接对象为空!");
                return(false);
            }
            if (Conn.State == System.Data.ConnectionState.Closed)
            {
                Conn.Open();
            }
            System.Data.IDbCommand cmd = Conn.CreateCommand();
            cmd.CommandTimeout = 180;
            myTrans            = Conn.BeginTransaction();
            cmd.Transaction    = myTrans;
            int i        = 0;
            var wrongsql = string.Empty;

            try
            {
                foreach (string sql in sqls)
                {
                    if (sql != null)
                    {
                        wrongsql        = sql;
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                    }
                }

                myTrans.Commit();
            }
            catch (Exception ex)
            {
                myTrans.Rollback();
                DBClassHelper.ErrLog("错误位置:" + i + "。错误sql:" + wrongsql + "。DBClassHelper.ExecuteTrans(string[] sqls):" + ex.Message);
                return(false);
            }
            finally
            {
                Conn.Close();
            }
            return(true);
        }//Execute(string sql)
Esempio n. 54
0
        public static bool UpdateAdjustCommssions(string orderId, string itemid, decimal adjustcommssion)
        {
            bool     flag     = false;
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    OrderInfo orderInfo = OrderHelper.GetOrderInfo(orderId);
                    if (orderInfo == null)
                    {
                        result = false;
                        return(result);
                    }
                    LineItemInfo lineItemInfo = orderInfo.LineItems[itemid];
                    lineItemInfo.ItemAdjustedCommssion = adjustcommssion;
                    if (!new LineItemDao().UpdateLineItem(orderId, lineItemInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                    }
                    if (!new OrderDao().UpdateOrder(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch (Exception var_6_9F)
                {
                    dbTransaction.Rollback();
                }
                finally
                {
                    dbConnection.Close();
                }
                result = flag;
            }
            return(result);
        }
Esempio n. 55
0
        public bool UpdateDiscountStatus(int Id, DiscountStatus status)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscount set Status=@Status WHERE LimitedTimeDiscountId = @Id");
                this.database.AddInParameter(sqlStringCommand, "Id", System.Data.DbType.Int32, Id);
                this.database.AddInParameter(sqlStringCommand, "Status", System.Data.DbType.Int32, (int)status);
                System.Data.Common.DbCommand sqlStringCommand2;
                if (DiscountStatus.Delete == status)
                {
                    sqlStringCommand2 = this.database.GetSqlStringCommand("delete Hishop_LimitedTimeDiscountProduct WHERE LimitedTimeDiscountId = @Id");
                    this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                }
                else
                {
                    sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_LimitedTimeDiscountProduct set Status=@Status WHERE LimitedTimeDiscountId = @Id");
                    this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                    this.database.AddInParameter(sqlStringCommand2, "Status", System.Data.DbType.Int32, (int)status);
                }
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
Esempio n. 56
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="comType"></param>
    /// <param name="parameters"></param>
    /// <param name="strError"></param>
    /// <returns></returns>
    public int ExecuteSqlNonQuery(DbCommand cmd, CommandType comType, Dictionary <string, object> parameters, out string strError)
    {
        int intEffected = -1;

        strError = "";

        try
        {
            conn = cmd.Connection;
            conn.Open();
        }
        catch (Exception ex)
        {
            strError = ex.Message;
            return(intEffected);
        }

        try
        {
            cmd.CommandType = comType;
            if ((parameters != null))
            {
                cmd.Parameters.Clear();
                if (parameters.Count > 0)
                {
                    SetCmd(ref cmd, parameters);
                }
            }

            intEffected = cmd.ExecuteNonQuery();
            conn.Close();
        }
        catch (Exception ex)
        {
            strError    = ex.Message;
            intEffected = -1;
        }
        finally
        {
            conn.Close();
        }

        return(intEffected);
    }
Esempio n. 57
0
        public static int AddPromotion(PromotionInfo promotion)
        {
            Database database = DatabaseFactory.CreateDatabase();
            int      result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    PromotionDao promotionDao = new PromotionDao();
                    int          num          = promotionDao.AddPromotion(promotion, dbTransaction);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        result = -1;
                    }
                    else
                    {
                        if (!promotionDao.AddPromotionMemberGrades(num, promotion.MemberGradeIds, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = -2;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = num;
                        }
                    }
                }
                catch (Exception var_5_76)
                {
                    dbTransaction.Rollback();
                    result = 0;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 58
0
        public static bool AddGroupBuy(GroupBuyInfo groupBuy)
        {
            Globals.EntityCoding(groupBuy, true);
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    int num = PromotionsProvider.Instance().AddGroupBuy(groupBuy, dbTransaction);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!PromotionsProvider.Instance().AddGroupBuyCondition(num, groupBuy.GroupBuyConditions, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = true;
                        }
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 59
0
        private bool CreateAnonymous(out string errorMsg)
        {
            System.Data.Common.DbConnection dbConnection = null;
            bool result;

            try
            {
                System.Data.Common.DbConnection dbConnection2;
                dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString()));
                try
                {
                    System.Data.Common.DbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
                    dbCommand.Connection  = dbConnection;
                    dbCommand.CommandType = System.Data.CommandType.Text;
                    dbCommand.CommandText = "INSERT INTO aspnet_Users  (UserName, LoweredUserName, IsAnonymous, UserRole, LastActivityDate, Password, PasswordFormat, PasswordSalt, IsApproved, IsLockedOut, CreateDate, LastLoginDate, LastPasswordChangedDate, LastLockoutDate, FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart) VALUES ('Anonymous', LOWER('Anonymous'), 1, @UserRole, @CreateDate, 'DVZTktxeMzDtXR7eik7Cdw==', 0, '', 1, 0, @CreateDate, @CreateDate, @CreateDate, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ))";
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserRole", UserRole.Anonymous));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreateDate", System.DateTime.Now));
                    dbConnection.Open();
                    dbCommand.ExecuteNonQuery();
                    dbConnection.Close();
                }
                finally
                {
                    if (dbConnection2 != null)
                    {
                        ((System.IDisposable)dbConnection2).Dispose();
                    }
                }
                errorMsg = null;
                result   = true;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                errorMsg = ex.Message;
                if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                }
                result = false;
            }
            return(result);
        }
Esempio n. 60
0
        public static bool AddBundlingProduct(BundlingInfo bundlingInfo)
        {
            Database database = DatabaseFactory.CreateDatabase();
            bool     result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    int num = PromotionsProvider.Instance().AddBundlingProduct(bundlingInfo, dbTransaction);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                    else
                    {
                        if (!PromotionsProvider.Instance().AddBundlingProductItems(num, bundlingInfo.BundlingItemInfos, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = true;
                        }
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }