BeginTransaction() 공개 메소드

public BeginTransaction ( ) : DbTransaction
리턴 DbTransaction
예제 #1
0
		public static int Profile_DeleteProfiles(DbConnection connection, string applicationName, string [] userNames)
		{
			int deletedUsers = 0;
			string appId = DerbyApplicationsHelper.GetApplicationId (connection, applicationName);
			if (appId == null)
				return 0;

			OleDbTransaction trans = (OleDbTransaction) connection.BeginTransaction ();
			try {
				foreach (string username in userNames) {
					string userId = GetUserId (connection, trans, appId, username);
					if (userId == null)
						continue;

					string queryDelete = "DELETE FROM aspnet_Profile WHERE UserId = ?";
					OleDbCommand cmdDelete = new OleDbCommand (queryDelete, (OleDbConnection) connection);
					cmdDelete.Transaction = trans;
					AddParameter (cmdDelete, "UserId", userId);
					cmdDelete.Transaction = trans;
					deletedUsers += cmdDelete.ExecuteNonQuery ();
				}
				trans.Commit ();
				return deletedUsers;
			}
			catch (Exception e) {
				trans.Rollback ();
				throw e;
			}
		}
예제 #2
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();
        }
예제 #3
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);
        }
예제 #4
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);
        }
 public void BeginTransaction()
 {
     _db = new SqlDatabase(_strConnection);
     _dbConn = _db.CreateConnection();
     _dbConn.Open();
     _dbTrans = _dbConn.BeginTransaction();
 }
예제 #6
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);
        }
예제 #7
0
 /// <summary>
 /// 对象在构造是,会产生一个打开的数据库连接并打开事务,Command对象也会同时产生
 /// </summary>
 public TransactionFactory()
 {
     this.conn = DbHelper.CreateConnection(true);
     this.cmd = DbHelper.CreateCommand(conn);
     this.ts = conn.BeginTransaction();
     this.cmd.Connection = this.conn;
     this.cmd.Transaction = ts;
 }
예제 #8
0
 private static void ClearData(DbConnection conn)
 {
     DbTransaction tx = conn.BeginTransaction();
     DbCommand clearCmd = conn.CreateCommand();
     clearCmd.CommandText = "DELETE FROM data";
     clearCmd.ExecuteNonQuery();
     tx.Commit();
 }
예제 #9
0
 public DbTransaction BeginTransaction()
 {
     _db = DatabaseFactory.CreateDatabase();
     _connection = _db.CreateConnection();
     _connection.Open();
     _transaction = _connection.BeginTransaction();
     return _transaction;
 }
예제 #10
0
        public DbTransaction BeginTransaction()
        {
            Connection = _repo.Connection();

            Transaction = Connection.BeginTransaction();

            return Transaction;
        }
예제 #11
0
 public PostgresProcessor(DbConnection connection, IMigrationGenerator generator, IAnnouncer announcer, IMigrationProcessorOptions options, IDbFactory factory)
     : base(generator, announcer, options)
 {
     this.factory = factory;
     Connection = connection;
     connection.Open();
     Transaction = connection.BeginTransaction();
 }
예제 #12
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);
        }
예제 #13
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 BeginningTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)
		{
			if (connection is FbConnection
				&& interceptionContext.IsolationLevel == IsolationLevel.Serializable
				&& IsInMigrations())
			{
				interceptionContext.Result = connection.BeginTransaction(IsolationLevel.ReadCommitted);
			}
		}
예제 #15
0
        /// <summary>
        /// ��ʼ����
        /// </summary>
        /// <param name="conn">DbConnection ����</param>
        /// <returns>DbTransaction�������</returns>
        public DbTransaction BeginTransaction(DbConnection conn)
        {
            if (conn == null)
            {
                throw new ArgumentNullException("conn");
            }

            DbTransaction tran = conn.BeginTransaction();
            return tran;
        }
예제 #16
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);
        }
예제 #17
0
        public bool AddPO(PO po)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_PO_Insert);

                db.AddInParameter(dbCommand, "@sPOCode", DbType.String, po.POCode);
                db.AddInParameter(dbCommand, "@mPOAmount", DbType.Currency, po.POAmount);
                db.AddInParameter(dbCommand, "@mBalanceAmount", DbType.Currency, po.BalanceAmount);
                db.AddInParameter(dbCommand, "@iPOCreatedUser", DbType.Int32, po.POCreatedUser);
                db.AddInParameter(dbCommand, "@iSupId", DbType.Int32, po.SupId);
                db.AddInParameter(dbCommand, "@dtPODate", DbType.DateTime, po.PODate);

                db.AddInParameter(dbCommand, "@iRequestedBy", DbType.Int32, po.RequestedBy.Value);
                db.AddInParameter(dbCommand, "@sPOComment", DbType.String, po.POComment);

                db.AddOutParameter(dbCommand, "@iPOId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newPOID = (Int32)db.GetParameterValue(dbCommand, "@iPOId");
                    if (newPOID > 0)
                    {
                        po.POId = newPOID;
                        if (this.UpdatePOItems(po, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }

            }
            catch (System.Exception ex)
            {
                ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool AddPO(PO po)");
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return result;
        }
예제 #18
0
        public bool AddPR(PurchaseReturns pr)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_PR_Insert);

                db.AddInParameter(dbCommand, "@iGRNId", DbType.Int64, pr.GRNId);
                db.AddInParameter(dbCommand, "@iCreatedBy", DbType.Int32, pr.CreatedBy);
                db.AddInParameter(dbCommand, "@mTotalReturns", DbType.Currency, pr.TotalReturns);
                db.AddInParameter(dbCommand, "@sComment", DbType.String, pr.Comment);
                db.AddInParameter(dbCommand, "@dReturnDate", DbType.Date, pr.ReturnDate);

                db.AddOutParameter(dbCommand, "@iPRId", DbType.Int32, 4);
                db.AddOutParameter(dbCommand, "@sPRCode", DbType.String, 10);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newPRID = (Int32)db.GetParameterValue(dbCommand, "@iPRId");
                    string prCode = (string)db.GetParameterValue(dbCommand, "@sPRCode");
                    if (newPRID > 0)
                    {
                        pr.PRId = newPRID;
                        pr.PRCode = prCode;

                        if (this.UpdatePRItems(pr, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool AddPR(PurchaseReturns pr)");
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return result;
        }
예제 #19
0
 void CopyTableTransaction(DbConnection connection, string tableName, string createTableQuery)
 {
     using (var transaction = connection.BeginTransaction())
     {
         CopyTable(connection, tableName, createTableQuery);
         DropOldTable(connection, tableName);
         transaction.Commit();
     }
     Vacuum(connection);
     WriteLine("Upgrade succeeded.");
 }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
0
        void GameIdUpgrade(DbConnection connection)
        {
            //player.game_id was nullable prior to r348, should have been not null all along
            bool isAffected = false;
            using (var pragma = new DatabaseCommand("pragma table_info(player)", connection))
            {
                using (var reader = pragma.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string name = (string)reader.Get("name");
                        if (name != "game_id")
                            continue;
                        object notNullObject = reader.Get("notnull");
                        bool isNotNull = (int)(long)notNullObject == 1;
                        if (!isNotNull)
                        {
                            isAffected = true;
                            break;
                        }
                    }
                }
            }

            if (isAffected)
            {
                WriteLine("This database is affected by the pre-348 player.game_id bug. Attempting to upgrade it.");

                using (var transaction = connection.BeginTransaction())
                {
                    //Rename the old table to a temporary name
                    using (var renameTable = new DatabaseCommand("alter table player rename to broken_player", connection))
                        renameTable.Execute();
                    //Create the new table
                    using (var createTable = new DatabaseCommand(Properties.Resources.CreateTablePlayer, connection))
                        createTable.Execute();
                    //Insert the data from the old table into the new table
                    string fieldString = Properties.Resources.PlayerFields.Replace("\n", " ");
                    using (var insert = new DatabaseCommand(string.Format("insert into player ({0}) select {0} from broken_player", fieldString), connection))
                        insert.Execute();
                    //Remove the old table
                    using (var dropTable = new DatabaseCommand("drop table broken_player", connection))
                        dropTable.Execute();
                    //Commit the transaction
                    transaction.Commit();
                    //Vacuum
                    using (var vacuum = new DatabaseCommand("vacuum", connection))
                        vacuum.Execute();
                }
                WriteLine("Upgrade succeeded.");
            }
        }
예제 #23
0
        public bool AddGetPass(GetPass getPass)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);

                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand cmd = db.GetStoredProcCommand(Constant.SP_GetPass_Add);

                db.AddInParameter(cmd, "@sGPCode", DbType.String, getPass.GPCode);
                db.AddInParameter(cmd, "@iInvoiceId", DbType.Int32, getPass.InvoiceId);
                db.AddInParameter(cmd, "@iCreatedBy", DbType.Int32, getPass.CreatedBy);

                db.AddOutParameter(cmd, "@biGPId", DbType.Int64, 8);

                if (db.ExecuteNonQuery(cmd, transaction) > 0)
                {
                    Int32 newGatePassID = Convert.ToInt32(db.GetParameterValue(cmd, "@biGPId"));

                    if (newGatePassID > 0)
                    {
                        getPass.GPId = newGatePassID;
                        if (this.UpdateGetPassDetails(getPass, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }

            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                result = false;
                throw ex;
            }

            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
예제 #24
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);
        }
예제 #25
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);
        }
예제 #26
0
        public void Add(Order order)
        {
            owner = GetOwner();
            vendor = GetVendor(order.VendorID);

            using (cn = dbContext.Database.Connection)
            {
                try
                {
                    cn.Open();
                    tran = cn.BeginTransaction();
                    DbCommand cmd = cn.CreateCommand();
                    cmd.Transaction = tran;
                    cmd.CommandText = @"INSERT INTO tblSO (SOCode, SODate, BranchId, CurrencyId, EmployeeId, VendorID, TermID, TaxID, SOGrossAmt, SONetAmt, StatusID, Operator, Computer, LastUpdate)
                      VALUES (@SOCode, @SODate, @BranchId, @CurrencyId, @EmployeeId, @VendorId, @TermId, 0, @SOGrossAmt, @SONetAmt, 0, @Operator, @Computer, @LastUpdate); SELECT IDENT_CURRENT('tblSO');";

                    cmd.Parameters.Add(new SqlParameter("@SOCode", order.SOCode));
                    cmd.Parameters.Add(new SqlParameter("@SODate", order.SODate));
                    cmd.Parameters.Add(new SqlParameter("@BranchId", order.BranchID));
                    cmd.Parameters.Add(new SqlParameter("@CurrencyId", order.CurrencyId));
                    cmd.Parameters.Add(new SqlParameter("@EmployeeId", owner.EmployeeId));
                    cmd.Parameters.Add(new SqlParameter("@VendorId", vendor.Id));
                    cmd.Parameters.Add(new SqlParameter("@TermId", owner.DefTerm));
                    cmd.Parameters.Add(new SqlParameter("@SOGrossAmt", order.SOGrossAmt));
                    cmd.Parameters.Add(new SqlParameter("@SONetAmt", order.SONetAmt));
                    cmd.Parameters.Add(new SqlParameter("@Operator", order.Username));
                    cmd.Parameters.Add(new SqlParameter("@Computer", System.Environment.MachineName));
                    cmd.Parameters.Add(new SqlParameter("@LastUpdate", DateTime.Now));

                    soId = Convert.ToInt32(cmd.ExecuteScalar());

                    foreach (OrderItem item in order.Items)
                    {
                        AddOrderItem(item);
                    }

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    if (tran != null)
                        tran.Rollback();

                    throw ex;
                }
                finally
                {
                    cn.Close();
                }
            }
        }
예제 #27
0
        /// <summary>
        /// Creates the cheque book and saves the cheques in tha dataset dsCheques property
        /// </summary>
        /// <param name="chqBook"></param>
        /// <returns></returns>
        public bool Create(ChequeBook chqBook)
        {
            bool success = true;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Cheque_Insert);

                db.AddInParameter(dbCommand, "@iNoOfCheques", DbType.Int32, chqBook.NoOfCheques);
                db.AddInParameter(dbCommand, "@biFirstChqNo", DbType.Int64, chqBook.FirstChqNo);
                db.AddInParameter(dbCommand, "@biLastChqNo", DbType.Int64, chqBook.LastChqNo);
                db.AddInParameter(dbCommand, "@iCreatedBy", DbType.Int32, chqBook.CreatedBy);
                db.AddInParameter(dbCommand, "@sBankName", DbType.String, chqBook.BankName);
                db.AddInParameter(dbCommand, "@sBankBranch", DbType.String, chqBook.BankBranch);

                db.AddOutParameter(dbCommand, "@iChqBookId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newChqBookId = Convert.ToInt32(db.GetParameterValue(dbCommand, "@iChqBookId"));
                    if (newChqBookId > 0)
                    {
                        chqBook.ChqBookId = newChqBookId;
                        if (this.UpdateCheques(chqBook, db, transaction))
                        {
                            transaction.Commit();
                            success = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                transaction.Rollback();
                ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool Create(ChequeBook chqBook)");
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return success;
        }
예제 #28
0
 public ITransaction BeginTransaction(IInternalSession session, DbConnection connection)
 {
     _Session = session;
     if (_Transaction == null || Ended)
     {
         Ended = false;
         _Transaction = connection.BeginTransaction();
     }
     else
     {
         BeginNestedTransaction();
     }
     return this;
 }
예제 #29
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);
        }
예제 #30
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);
        }
예제 #31
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);
        }
예제 #32
0
        private void ExecuteDeleteSql(DbConnection connection)
        {
            using (var tx = connection.BeginTransaction())
            using (var cmd = connection.CreateCommand())
            {
                cmd.CommandTimeout = CommandTimeout ?? cmd.CommandTimeout;
                cmd.CommandText = _deleteSql;
                cmd.Transaction = tx;

                cmd.ExecuteNonQuery();

                tx.Commit();
            }
        }
예제 #33
0
        public bool AddGroups(Group group)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Groups_Insert);

                db.AddInParameter(dbCommand, "@sGroupCode", DbType.String, group.GroupCode);
                db.AddInParameter(dbCommand, "@sGroupName", DbType.String, group.GroupName);
                db.AddInParameter(dbCommand, "@sDescription", DbType.String, group.Description);
                db.AddInParameter(dbCommand, "@tiItemCount", DbType.Int16, group.ItemCount);
                db.AddInParameter(dbCommand, "@bIsActive", DbType.Boolean, group.IsActive);

                db.AddOutParameter(dbCommand, "@tiGroupId", DbType.Int16, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int16 newGroupId = Convert.ToInt16(db.GetParameterValue(dbCommand, "@tiGroupId"));
                    if (newGroupId > 0)
                    {
                        group.GroupId = newGroupId;
                        if (this.UpdateGroupItems(group, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
예제 #34
0
        public bool AddItemTransfer(ItemTransfer itemTransfer)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Item_Transfer_Insert);

                db.AddInParameter(dbCommand, "@iInvoiceId", DbType.Int32, DBNull.Value);
                db.AddInParameter(dbCommand, "@iBranchFrom", DbType.Int32, itemTransfer.BranchFrom);
                db.AddInParameter(dbCommand, "@iBranchTo", DbType.Int32, itemTransfer.BranchTo);
                db.AddInParameter(dbCommand, "@iTransferQty", DbType.Int32, itemTransfer.TransferQty);
                db.AddInParameter(dbCommand, "@iTransferBy", DbType.Int32, itemTransfer.TransferBy);

                db.AddOutParameter(dbCommand, "@iTransferId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newTransferID = Convert.ToInt32(db.GetParameterValue(dbCommand, "@iTransferId"));
                    if (newTransferID > 0)
                    {
                        itemTransfer.TransferId = newTransferID;
                        if (this.AddItemTransferInvoice(itemTransfer, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
        /// <summary>
        /// Metodo que inicia transaccion en la base de datos
        /// </summary>
        public void BeginTransaction()
        {
            try
            {
                _dbconnection = (SqlConnection)_mlconnection.getDatabase().CreateConnection();  //Crea objeto de conexion de tipo SQLConnection
                _dbconnection.Open();
                _dbTransaction = _dbconnection.BeginTransaction();

            }
            catch (Exception)
            {

                throw;
            }
        }
예제 #36
0
파일: OrderHelper.cs 프로젝트: zwkjgs/XKD
        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);
        }
예제 #37
0
        public bool AddBrands(Brand brand)
        {
            bool result = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name);
                connection = db.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_Brands_Insert);

                db.AddInParameter(dbCommand, "@sBrandName", DbType.String, brand.BrandName);

                db.AddOutParameter(dbCommand, "@iBrandId", DbType.Int32, 4);

                if (db.ExecuteNonQuery(dbCommand, transaction) > 0)
                {
                    Int32 newBrandID = Convert.ToInt32(db.GetParameterValue(dbCommand, "@iBrandId"));
                    if (newBrandID > 0)
                    {
                        brand.BrandId = newBrandID;
                        if (this.UpdateBrandCategories(brand, db, transaction))
                        {
                            transaction.Commit();
                            result = true;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return result;
        }
예제 #38
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);
        }
예제 #39
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)
예제 #40
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);
        }
예제 #41
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);
        }
예제 #42
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);
        }
예제 #43
0
        void AccountIdUpgrade(DbConnection connection)
        {
            //In pre-r375 databases the account_id was marked as unique even though it shouldn't have been
            bool isAffected = false;
            using (var pragma = new DatabaseCommand("select sql from sqlite_master where tbl_name = 'summoner'", connection))
            {
                using (var reader = pragma.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        string query = reader.String();
                        if (query.IndexOf("account_id integer unique not null") >= 0)
                            isAffected = true;
                    }
                    else
                        throw new Exception("Unable to locate summoner table for upgrade check");
                }
            }

            if (isAffected)
            {
                WriteLine("This database is affected by the pre-375 summoner.account_id bug. Attempting to upgrade it.");
                using (var transaction = connection.BeginTransaction())
                {
                    CopyTable(connection, "summoner", Properties.Resources.CreateTableSummoner);
                    CopyTable(connection, "summoner_rating", Properties.Resources.CreateTableSummonerRating);

            CopyTable(connection, "summoner_ranked_statistics", Properties.Resources.CreateTableSummonerRankedStatistics);
                    CopyTable(connection, "player", Properties.Resources.CreateTablePlayer);
                    CopyTable(connection, "rune_page", Properties.Resources.CreateTableRunePage);
                    CopyTable(connection, "rune_slot", Properties.Resources.CreateTableRuneSlot);
                    DropOldTable(connection, "rune_slot");
                    DropOldTable(connection, "rune_page");
                    DropOldTable(connection, "player");
                    DropOldTable(connection, "summoner_ranked_statistics");
                    DropOldTable(connection, "summoner_rating");
                    DropOldTable(connection, "summoner");
                    transaction.Commit();
                }
                Vacuum(connection);
                WriteLine("Upgrade succeeded.");
            }
        }
예제 #44
0
        public static int EditPromotion(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
                {
                    if (!PromotionsProvider.Instance().EditPromotion(promotion, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        result = -1;
                    }
                    else
                    {
                        if (!PromotionsProvider.Instance().AddPromotionMemberGrades(promotion.ActivityId, promotion.MemberGradeIds, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = -2;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = 1;
                        }
                    }
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    result = 0;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
예제 #45
0
        internal static void ExecuteNonQuery(string command, DbConnection conn, SQLiteFactory factory)
        {
            DbTransaction trans = conn.BeginTransaction(System.Data.IsolationLevel.Serializable);

            try
            {
                conn.Open();

                ExecuteNonQuery(command, conn, factory, trans);
                trans.Commit();
            }
            catch (Exception)
            {
                trans.Rollback();
            }
            finally
            {
                conn.Close();
            }
        }
예제 #46
0
        public static void Insert(DbConnection con, int count, int batch, DateTime since)
        {
            var random = new Random();

            for (int i = 0; i < count; i += batch)
            {
                var trans = con.BeginTransaction();
                for (int j = i; j < batch + i; j += 1)
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.Transaction = trans;
                        cmd.CommandText = @"INSERT INTO dbo.TABLE_Insert VALUES(@timestamp, @value, @importId)";
                        var par = cmd.CreateParameter();
                        //par.Value = j;
                        //par.ParameterName = "id";
                        //cmd.Parameters.Add(par);

                        par = cmd.CreateParameter();
                        par.Value = since.AddMinutes(j);
                        par.ParameterName = "timestamp";
                        cmd.Parameters.Add(par);

                        par = cmd.CreateParameter();
                        par.Value = random.NextDouble();
                        par.ParameterName = "value";
                        cmd.Parameters.Add(par);

                        par = cmd.CreateParameter();
                        par.Value = random.Next();
                        par.ParameterName = "importId";
                        cmd.Parameters.Add(par);

                        cmd.ExecuteNonQuery();
                    }
                }

                trans.Commit();
            }
        }
예제 #47
0
 public override void BeginTransaction()
 {
     try
     {
         if (isInTransaction == false)
         {
             connection = database.CreateConnection();
             connection.Open();
             transaction = connection.BeginTransaction();
             isInTransaction = true;
         }
         else
         {
             throw new Exception("事务正在进行,一个对象不能同时开启多个事务!");
         }
     }
     catch (Exception e)
     {
         connection.Close();
         isInTransaction = false;
         throw new Exception("事务启动失败,请再试一次!\n" + e.Message);
     }
 }
예제 #48
0
        public bool Delete(int Id)
        {
            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_Activities WHERE ActivitiesId = @Id");
                this.database.AddInParameter(sqlStringCommand, "Id", System.Data.DbType.Int32, Id);
                System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand("DELETE FROM Hishop_Activities_Detail WHERE ActivitiesId = @Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, Id);
                System.Data.Common.DbCommand sqlStringCommand3 = this.database.GetSqlStringCommand("DELETE FROM Hishop_Activities_Product WHERE ActivitiesId = @Id");
                this.database.AddInParameter(sqlStringCommand3, "Id", System.Data.DbType.Int32, Id);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand3, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
예제 #49
0
		public RelationalDatabaseWriter( DocumentDatabase database, SqlReplicationConfig cfg, SqlReplicationStatistics replicationStatistics)
		{
			this.database = database;
			this.cfg = cfg;
			this.replicationStatistics = replicationStatistics;

			providerFactory = GetDbProviderFactory(cfg);

			commandBuilder = providerFactory.CreateCommandBuilder();
			connection = providerFactory.CreateConnection();

			Debug.Assert(connection != null);
			Debug.Assert(commandBuilder != null);

			connection.ConnectionString = cfg.ConnectionString;

			try
			{
				connection.Open();
			}
			catch (Exception e)
			{
				database.AddAlert(new Alert
				{
					AlertLevel = AlertLevel.Error,
					CreatedAt = SystemTime.UtcNow,
					Exception = e.ToString(),
					Title = "Sql Replication could not open connection",
					Message = "Sql Replication could not open connection to " + connection.ConnectionString,
					UniqueKey = "Sql Replication Connection Error: " + connection.ConnectionString
				});
				throw;
			}

			tx = connection.BeginTransaction();
		}
예제 #50
0
        public static bool UpdateProduct(ProductInfo product, Dictionary <string, decimal> skuSalePrice, IList <int> tagIdList)
        {
            bool result;

            if (null == product)
            {
                result = false;
            }
            else
            {
                Globals.EntityCoding(product, true);
                int decimalLength = HiContext.Current.SiteSettings.DecimalLength;
                if (product.MarketPrice.HasValue)
                {
                    product.MarketPrice = new decimal?(Math.Round(product.MarketPrice.Value, decimalLength));
                }
                using (System.Data.Common.DbConnection dbConnection = DatabaseFactory.CreateDatabase().CreateConnection())
                {
                    dbConnection.Open();
                    System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                    try
                    {
                        if (!SubsiteProductProvider.Instance().UpdateProduct(product, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                        }
                        else
                        {
                            if (!SubsiteProductProvider.Instance().AddSkuSalePrice(product.ProductId, skuSalePrice, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                            }
                            else
                            {
                                if (!SubSiteProducthelper.DeleteProductTags(product.ProductId, dbTransaction))
                                {
                                    dbTransaction.Rollback();
                                    result = false;
                                }
                                else
                                {
                                    if (tagIdList != null && tagIdList.Count > 0 && !SubSiteProducthelper.AddProductTags(product.ProductId, tagIdList, dbTransaction))
                                    {
                                        dbTransaction.Rollback();
                                        result = false;
                                    }
                                    else
                                    {
                                        dbTransaction.Commit();
                                        result = true;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        result = false;
                    }
                }
            }
            return(result);
        }
예제 #51
0
		public static int Membership_CreateUser (DbConnection connection, string applicationName, string username, string password, string passwordSalt, string email, string pwdQuestion, string pwdAnswer, bool isApproved, DateTime currentTimeUtc, DateTime createDate, bool uniqueEmail, int passwordFormat, ref object userId)
		{
			string applicationId = (string) DerbyApplicationsHelper.Applications_CreateApplication (connection, applicationName);
			string newUserId = (string) userId;

			OleDbTransaction trans = (OleDbTransaction) connection.BeginTransaction ();

			try {
				int returnValue = Users_CreateUser (connection, trans, applicationId, username, false, createDate, ref userId);
				if (returnValue == 1) {
					// the user exists in users table, this can occure when user
					// does not have membership information, but has other information
					// like roles, etc.
					if (userId != null && newUserId != null && newUserId != (string) userId) {
						trans.Rollback ();
						return 9; // wrong userid provided
					}
				}
				else if (returnValue == 2) {
					// another user with provided id already exists
					trans.Rollback ();
					return 10; // wrong userid provided
				}
				newUserId = (string) userId;

				string selectQueryMbrUserId = "SELECT UserId FROM aspnet_Membership WHERE UserId = ?";
				OleDbCommand selectCmdMbrUserId = new OleDbCommand (selectQueryMbrUserId, (OleDbConnection) connection);
				selectCmdMbrUserId.Transaction = trans;
				AddParameter (selectCmdMbrUserId, "UserId", newUserId);
				using (OleDbDataReader reader = selectCmdMbrUserId.ExecuteReader ()) {
					if (reader.Read ()) {
						trans.Rollback ();
						return 2; // user with such userId already exists
					}
				}

				if (uniqueEmail) {
					string queryMbrEmail = "SELECT * FROM  aspnet_Membership WHERE ApplicationId = ? AND LoweredEmail = ?";
					OleDbCommand cmdMbrEmail = new OleDbCommand (queryMbrEmail, (OleDbConnection) connection);
					cmdMbrEmail.Transaction = trans;
					AddParameter (cmdMbrEmail, "ApplicationId", applicationId);
					AddParameter (cmdMbrEmail, "LoweredEmail", email.ToLowerInvariant ());
					using (OleDbDataReader reader = cmdMbrEmail.ExecuteReader ()) {
						if (reader.Read ()) {
							trans.Rollback ();
							return 3; // user with such email already exists
						}
					}
				}

				if (returnValue == 1) {
					// if user was not created, but found existing and correct
					// update it's activity (membership create) time.
					string queryUpdActivity = "UPDATE aspnet_Users SET LastActivityDate = ? WHERE UserId = ?";
					OleDbCommand cmdUpdActivity = new OleDbCommand (queryUpdActivity, (OleDbConnection) connection);
					cmdUpdActivity.Transaction = trans;
					AddParameter (cmdUpdActivity, "LastActivityDate", createDate);
					AddParameter (cmdUpdActivity, "UserId", newUserId);
					cmdUpdActivity.ExecuteNonQuery ();
				}

				string queryInsertMbr = "INSERT INTO aspnet_Membership (ApplicationId, UserId, Password, PasswordFormat, PasswordSalt, Email, " +
					"LoweredEmail, PasswordQuestion, PasswordAnswer, IsApproved, IsLockedOut, CreateDate, LastLoginDate, " +
					"LastPasswordChangedDate, LastLockoutDate, FailedPasswordAttemptCount, FailedPwdAttemptWindowStart, " +
					"FailedPwdAnswerAttemptCount, FailedPwdAnswerAttWindowStart) " +
					"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
				OleDbCommand cmdInsertMbr = new OleDbCommand (queryInsertMbr, (OleDbConnection) connection);
				cmdInsertMbr.Transaction = trans;
				AddParameter (cmdInsertMbr, "ApplicationId", applicationId);
				AddParameter (cmdInsertMbr, "UserId", newUserId);
				AddParameter (cmdInsertMbr, "Password", password);
				AddParameter (cmdInsertMbr, "PasswordFormat", passwordFormat);
				AddParameter (cmdInsertMbr, "PasswordSalt", passwordSalt);
				AddParameter (cmdInsertMbr, "Email", email);
				AddParameter (cmdInsertMbr, "LoweredEmail", email != null ? email.ToLowerInvariant () : null);
				AddParameter (cmdInsertMbr, "PasswordQuestion", pwdQuestion);
				AddParameter (cmdInsertMbr, "PasswordAnswer", pwdAnswer);
				AddParameter (cmdInsertMbr, "IsApproved", isApproved);
				AddParameter (cmdInsertMbr, "IsLockedOut", 0);
				AddParameter (cmdInsertMbr, "CreateDate", createDate);
				AddParameter (cmdInsertMbr, "LastLoginDate", DefaultDateTime);
				AddParameter (cmdInsertMbr, "LastPasswordChangedDate", createDate);
				AddParameter (cmdInsertMbr, "LastLockoutDate", DefaultDateTime);
				AddParameter (cmdInsertMbr, "FailedPasswordAttemptCount", 0);
				AddParameter (cmdInsertMbr, "FailedPwdAttemptWindowStart", DefaultDateTime);
				AddParameter (cmdInsertMbr, "FailedPwdAnswerAttemptCount", 0);
				AddParameter (cmdInsertMbr, "FailedPwdAnswerAttWindowStart", DefaultDateTime);
				cmdInsertMbr.ExecuteNonQuery ();

				trans.Commit ();
			}
			catch (Exception e) {
				trans.Rollback ();
				throw e;
			}

			return 0;
		}
예제 #52
0
        private bool AddBuiltInRoles(out string errorMsg)
        {
            System.Data.Common.DbConnection  dbConnection  = null;
            System.Data.Common.DbTransaction dbTransaction = null;
            bool result;

            try
            {
                System.Data.Common.DbConnection dbConnection2;
                dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString()));
                try
                {
                    dbConnection.Open();
                    System.Data.Common.DbCommand dbCommand = dbConnection.CreateCommand();
                    dbTransaction         = dbConnection.BeginTransaction();
                    dbCommand.Connection  = dbConnection;
                    dbCommand.Transaction = dbTransaction;
                    dbCommand.CommandType = System.Data.CommandType.Text;
                    dbCommand.CommandText = "INSERT INTO aspnet_Roles(RoleName, LoweredRoleName) VALUES(@RoleName, LOWER(@RoleName))";
                    System.Data.Common.DbParameter value = new System.Data.SqlClient.SqlParameter("@RoleName", System.Data.SqlDbType.NVarChar, 256);
                    dbCommand.Parameters.Add(value);
                    RolesConfiguration rolesConfiguration = HiConfiguration.GetConfig().RolesConfiguration;
                    dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.Manager;
                    dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.Member;
                    dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.SystemAdministrator;
                    dbCommand.ExecuteNonQuery();
                    dbTransaction.Commit();
                    dbConnection.Close();
                }
                finally
                {
                    if (dbConnection2 != null)
                    {
                        ((System.IDisposable)dbConnection2).Dispose();
                    }
                }
                errorMsg = null;
                result   = true;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                errorMsg = ex.Message;
                if (dbTransaction != null)
                {
                    try
                    {
                        dbTransaction.Rollback();
                    }
                    catch (System.Exception ex2)
                    {
                        errorMsg = ex2.Message;
                    }
                }
                if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                }
                result = false;
            }
            return(result);
        }
예제 #53
0
        public static bool CreatOrder(OrderInfo orderInfo)
        {
            bool flag = false;

            if (orderInfo.GetTotal() == 0m)
            {
                orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid;
            }
            Database database = DatabaseFactory.CreateDatabase();
            int      quantity = orderInfo.LineItems.Sum((KeyValuePair <string, LineItemInfo> item) => item.Value.Quantity);
            bool     result;

            lock (ShoppingProcessor.createOrderLocker)
            {
                if (orderInfo.GroupBuyId > 0)
                {
                    ShoppingProcessor.checkCanGroupBuy(quantity, orderInfo.GroupBuyId);
                }
                using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
                {
                    dbConnection.Open();
                    System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                    try
                    {
                        orderInfo.ClientShortType = (ClientShortType)Globals.GetClientShortType();
                        if (!new OrderDao().CreatOrder(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                            return(result);
                        }
                        if (orderInfo.LineItems.Count > 0)
                        {
                            if (!new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                                return(result);
                            }
                        }
                        if (!string.IsNullOrEmpty(orderInfo.CouponCode))
                        {
                            if (!new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                                return(result);
                            }
                        }
                        ICollection values        = orderInfo.LineItems.Values;
                        MemberInfo  currentMember = MemberProcessor.GetCurrentMember();
                        foreach (LineItemInfo lineItemInfo in values)
                        {
                            if (lineItemInfo.Type == 1)
                            {
                                if (lineItemInfo.ExchangeId > 0)
                                {
                                    PointExchangeChangedInfo pointExchangeChangedInfo = new PointExchangeChangedInfo();
                                    pointExchangeChangedInfo.exChangeId   = lineItemInfo.ExchangeId;
                                    pointExchangeChangedInfo.exChangeName = new OrderDao().GetexChangeName(pointExchangeChangedInfo.exChangeId);
                                    pointExchangeChangedInfo.ProductId    = lineItemInfo.ProductId;
                                    pointExchangeChangedInfo.PointNumber  = lineItemInfo.PointNumber;
                                    pointExchangeChangedInfo.MemberID     = orderInfo.UserId;
                                    pointExchangeChangedInfo.Date         = DateTime.Now;
                                    pointExchangeChangedInfo.MemberGrades = currentMember.GradeId;
                                    if (!new OrderDao().InsertPointExchange_Changed(pointExchangeChangedInfo, dbTransaction, lineItemInfo.Quantity))
                                    {
                                        dbTransaction.Rollback();
                                        result = false;
                                        return(result);
                                    }
                                    IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo();
                                    integralDetailInfo.IntegralChange     = -lineItemInfo.PointNumber;
                                    integralDetailInfo.IntegralSource     = "积分兑换商品-订单号:" + orderInfo.OrderMarking;
                                    integralDetailInfo.IntegralSourceType = 2;
                                    integralDetailInfo.Remark             = "积分兑换商品";
                                    integralDetailInfo.Userid             = orderInfo.UserId;
                                    integralDetailInfo.GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId;
                                    integralDetailInfo.IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.IntegralExchange);
                                    if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction))
                                    {
                                        dbTransaction.Rollback();
                                        result = false;
                                        return(result);
                                    }
                                }
                            }
                        }
                        if (orderInfo.PointExchange > 0)
                        {
                            IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo();
                            integralDetailInfo.IntegralChange     = -orderInfo.PointExchange;
                            integralDetailInfo.IntegralSource     = "积分抵现-订单号:" + orderInfo.OrderMarking;
                            integralDetailInfo.IntegralSourceType = 2;
                            integralDetailInfo.Remark             = "积分抵现";
                            integralDetailInfo.Userid             = orderInfo.UserId;
                            integralDetailInfo.GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId;
                            integralDetailInfo.IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.NowArrived);
                            if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                                return(result);
                            }
                        }
                        if (orderInfo.RedPagerID > 0)
                        {
                            if (!new OrderDao().UpdateCoupon_MemberCoupons(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                                return(result);
                            }
                        }
                        dbTransaction.Commit();
                        flag = true;
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        throw;
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
            }
            result = flag;
            return(result);
        }
예제 #54
0
        public bool Fun_TransCTRL(enTrans iTrans, System.Data.IsolationLevel LockLevel = System.Data.IsolationLevel.Unspecified, bool bDBClose = false)
        {
            try
            {
                if (this.DBConn == null)
                {
                    if (this.Fun_OpenDataBase() == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (this.DBConn.State != System.Data.ConnectionState.Open)
                    {
                        if (this.Fun_OpenDataBase() == false)
                        {
                            return(false);
                        }
                    }
                }

                if (DBConn.State != System.Data.ConnectionState.Open)
                {
                    return(false);
                }

                switch (iTrans)
                {
                case enTrans.BEGIN:
                    if (LockLevel == System.Data.IsolationLevel.Unspecified)
                    {
                        DBTran = DBConn.BeginTransaction();
                    }
                    else
                    {
                        DBTran = DBConn.BeginTransaction(LockLevel);
                    }
                    break;

                case enTrans.COMMIT:
                    DBTran.Commit();
                    break;

                case enTrans.ROLLBACK:
                    DBTran.Rollback();
                    break;

                default:
                    return(false);
                }

                if (bDBClose == true && (iTrans == enTrans.COMMIT || iTrans == enTrans.ROLLBACK))
                {
                    Fun_CloseDB();
                }

                return(false);
            }
            catch (Exception)
            {
                DBTran.Rollback();
                return(false);
            }
        }
예제 #55
0
        private bool ExecuteTest()
        {
            this.errorMsgs = new System.Collections.Generic.List <string>();
            System.Data.Common.DbTransaction dbTransaction = null;
            System.Data.Common.DbConnection  dbConnection  = null;
            string item;

            try
            {
                if (this.ValidateConnectionStrings(out item))
                {
                    System.Data.Common.DbConnection dbConnection2;
                    dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString()));
                    try
                    {
                        dbConnection.Open();
                        System.Data.Common.DbCommand dbCommand = dbConnection.CreateCommand();
                        dbTransaction         = dbConnection.BeginTransaction();
                        dbCommand.Connection  = dbConnection;
                        dbCommand.Transaction = dbTransaction;
                        dbCommand.CommandText = "CREATE TABLE installTest(Test bit NULL)";
                        dbCommand.ExecuteNonQuery();
                        dbCommand.CommandText = "DROP TABLE installTest";
                        dbCommand.ExecuteNonQuery();
                        dbTransaction.Commit();
                        dbConnection.Close();
                        goto IL_94;
                    }
                    finally
                    {
                        if (dbConnection2 != null)
                        {
                            ((System.IDisposable)dbConnection2).Dispose();
                        }
                    }
                }
                this.errorMsgs.Add(item);
                IL_94 :;
            }
            catch (System.Exception ex)
            {
                this.errorMsgs.Add(ex.Message);
                if (dbTransaction != null)
                {
                    try
                    {
                        dbTransaction.Rollback();
                    }
                    catch (System.Exception ex2)
                    {
                        this.errorMsgs.Add(ex2.Message);
                    }
                }
                if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                }
            }
            string folderPath = base.Request.MapPath(Globals.ApplicationPath + "/config/test.txt");

            if (!Install.TestFolder(folderPath, out item))
            {
                this.errorMsgs.Add(item);
            }
            try
            {
                Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath);
                if (configuration.ConnectionStrings.ConnectionStrings["HidistroSqlServer"].ConnectionString == "none")
                {
                    configuration.ConnectionStrings.ConnectionStrings["HidistroSqlServer"].ConnectionString = "required";
                }
                else
                {
                    configuration.ConnectionStrings.ConnectionStrings["HidistroSqlServer"].ConnectionString = "none";
                }
                configuration.Save();
            }
            catch (System.Exception ex3)
            {
                this.errorMsgs.Add(ex3.Message);
            }
            folderPath = base.Request.MapPath(Globals.ApplicationPath + "/storage/test.txt");
            if (!Install.TestFolder(folderPath, out item))
            {
                this.errorMsgs.Add(item);
            }
            return(this.errorMsgs.Count == 0);
        }
예제 #56
0
        public bool UpdateShippingTemplate(FreightTemplate freightTemplate, string templateName)
        {
            bool result;

            if (freightTemplate.TemplateId == 0)
            {
                this.Error = "模板ID不存在!";
                result     = false;
            }
            else
            {
                bool flag = false;
                System.Data.Common.DbCommand sqlStringCommand = this.database.GetSqlStringCommand("select name from Hishop_FreightTemplate_Templates where name=@Name and name<>@ReName");
                this.database.AddInParameter(sqlStringCommand, "Name", System.Data.DbType.String, freightTemplate.Name);
                this.database.AddInParameter(sqlStringCommand, "ReName", System.Data.DbType.String, templateName);
                System.Data.IDataReader dataReader = this.database.ExecuteReader(sqlStringCommand);
                if (!dataReader.Read())
                {
                    StringBuilder stringBuilder = new StringBuilder("UPDATE Hishop_FreightTemplate_Templates SET Name=@Name,FreeShip=@FreeShip,MUnit=@MUnit,HasFree=@HasFree WHERE TemplateId=@TemplateId;");
                    System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand(stringBuilder.ToString());
                    this.database.AddInParameter(sqlStringCommand2, "Name", System.Data.DbType.String, freightTemplate.Name);
                    this.database.AddInParameter(sqlStringCommand2, "FreeShip", System.Data.DbType.Int16, freightTemplate.FreeShip);
                    this.database.AddInParameter(sqlStringCommand2, "MUnit", System.Data.DbType.Int16, freightTemplate.MUnit);
                    this.database.AddInParameter(sqlStringCommand2, "TemplateId", System.Data.DbType.Int32, freightTemplate.TemplateId);
                    this.database.AddInParameter(sqlStringCommand2, "HasFree", System.Data.DbType.Int16, freightTemplate.HasFree);
                    using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
                    {
                        dbConnection.Open();
                        System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                        try
                        {
                            flag = (this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction) > 0);
                            System.Data.Common.DbCommand sqlStringCommand3 = this.database.GetSqlStringCommand(" ");
                            StringBuilder stringBuilder2 = new StringBuilder();
                            if (flag)
                            {
                                this.database.AddInParameter(sqlStringCommand3, "TemplateId", System.Data.DbType.Int32, freightTemplate.TemplateId);
                                stringBuilder2.Append("delete from Hishop_FreightTemplate_SpecifyRegionGroups WHERE TemplateId=@TemplateId;");
                                stringBuilder2.Append("delete from Hishop_FreightTemplate_FreeShipping WHERE TemplateId=@TemplateId;");
                                stringBuilder2.Append("delete from Hishop_FreightTemplate_FreeShippingRegions WHERE TemplateId=@TemplateId;");
                                stringBuilder2.Append("delete from Hishop_FreightTemplate_SpecifyRegions WHERE TemplateId=@TemplateId;");
                                sqlStringCommand3.CommandText = stringBuilder2.ToString();
                                this.database.ExecuteNonQuery(sqlStringCommand3, dbTransaction);
                            }
                            if (flag && !freightTemplate.FreeShip)
                            {
                                if (freightTemplate.FreeShippings != null && freightTemplate.FreeShippings.Count > 0)
                                {
                                    sqlStringCommand3 = this.database.GetSqlStringCommand(" ");
                                    this.database.AddInParameter(sqlStringCommand3, "TemplateId", System.Data.DbType.Int32, freightTemplate.TemplateId);
                                    stringBuilder2.Clear();
                                    int num  = 0;
                                    int num2 = 0;
                                    stringBuilder2.Append("DECLARE @ERR INT; Set @ERR =0;");
                                    stringBuilder2.Append(" DECLARE @FreeId Int;");
                                    foreach (FreeShipping current in freightTemplate.FreeShippings)
                                    {
                                        stringBuilder2.Append(" INSERT INTO Hishop_FreightTemplate_FreeShipping(TemplateId,ModeId,ConditionNumber,ConditionType) VALUES( @TemplateId,").Append("@ModeId").Append(num).Append(",@ConditionNumber").Append(num).Append(",@ConditionType").Append(num).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                        this.database.AddInParameter(sqlStringCommand3, "ModeId" + num, System.Data.DbType.Int32, current.ModeId);
                                        this.database.AddInParameter(sqlStringCommand3, "ConditionNumber" + num, System.Data.DbType.String, current.ConditionNumber);
                                        this.database.AddInParameter(sqlStringCommand3, "ConditionType" + num, System.Data.DbType.Int32, current.ConditionType);
                                        stringBuilder2.Append("Set @FreeId =@@identity;");
                                        if (current.FreeShippingRegions != null)
                                        {
                                            foreach (FreeShippingRegion current2 in current.FreeShippingRegions)
                                            {
                                                stringBuilder2.Append(" INSERT INTO Hishop_FreightTemplate_FreeShippingRegions(FreeId,TemplateId,RegionId) VALUES(@FreeId,@TemplateId").Append(",@RegionId").Append(num2).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                                this.database.AddInParameter(sqlStringCommand3, "RegionId" + num2, System.Data.DbType.Int32, current2.RegionId);
                                                num2++;
                                            }
                                        }
                                        num++;
                                    }
                                    sqlStringCommand3.CommandText = stringBuilder2.Append("SELECT @ERR;").ToString();
                                    int num3 = (int)this.database.ExecuteScalar(sqlStringCommand3, dbTransaction);
                                    if (num3 != 0)
                                    {
                                        dbTransaction.Rollback();
                                        flag = false;
                                    }
                                }
                                if (flag && freightTemplate.SpecifyRegionGroups != null && freightTemplate.SpecifyRegionGroups.Count > 0)
                                {
                                    sqlStringCommand3 = this.database.GetSqlStringCommand(" ");
                                    this.database.AddInParameter(sqlStringCommand3, "TemplateId", System.Data.DbType.Int32, freightTemplate.TemplateId);
                                    stringBuilder2.Clear();
                                    int num  = 0;
                                    int num2 = 0;
                                    stringBuilder2.Append("DECLARE @ERR INT; Set @ERR =0;");
                                    stringBuilder2.Append(" DECLARE @GroupId Int;");
                                    foreach (SpecifyRegionGroup current3 in freightTemplate.SpecifyRegionGroups)
                                    {
                                        stringBuilder2.Append(" INSERT INTO Hishop_FreightTemplate_SpecifyRegionGroups(TemplateId,ModeId,FristNumber,FristPrice,AddNumber,AddPrice,IsDefault) VALUES(@TemplateId,").Append("@ModeId").Append(num).Append(",@FristNumber").Append(num).Append(",@FristPrice").Append(num).Append(",@AddNumber").Append(num).Append(",@AddPrice").Append(num).Append(",@IsDefault").Append(num).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                        this.database.AddInParameter(sqlStringCommand3, "ModeId" + num, System.Data.DbType.Int16, current3.ModeId);
                                        this.database.AddInParameter(sqlStringCommand3, "FristNumber" + num, System.Data.DbType.Decimal, current3.FristNumber);
                                        this.database.AddInParameter(sqlStringCommand3, "FristPrice" + num, System.Data.DbType.Currency, current3.FristPrice);
                                        this.database.AddInParameter(sqlStringCommand3, "AddPrice" + num, System.Data.DbType.Currency, current3.AddPrice);
                                        this.database.AddInParameter(sqlStringCommand3, "AddNumber" + num, System.Data.DbType.Decimal, current3.AddNumber);
                                        this.database.AddInParameter(sqlStringCommand3, "IsDefault" + num, System.Data.DbType.Int16, current3.IsDefault);
                                        stringBuilder2.Append("Set @GroupId =@@identity;");
                                        if (current3.SpecifyRegions != null)
                                        {
                                            foreach (SpecifyRegion current4 in current3.SpecifyRegions)
                                            {
                                                stringBuilder2.Append(" INSERT INTO Hishop_FreightTemplate_SpecifyRegions(TemplateId,GroupId,RegionId) VALUES(@TemplateId,@GroupId").Append(",@RegionId").Append(num2).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                                this.database.AddInParameter(sqlStringCommand3, "RegionId" + num2, System.Data.DbType.Int32, current4.RegionId);
                                                num2++;
                                            }
                                        }
                                        num++;
                                    }
                                    sqlStringCommand3.CommandText = stringBuilder2.Append("SELECT @ERR;").ToString();
                                    int num3 = (int)this.database.ExecuteScalar(sqlStringCommand3, dbTransaction);
                                    if (num3 != 0)
                                    {
                                        dbTransaction.Rollback();
                                        flag = false;
                                    }
                                }
                            }
                            if (flag)
                            {
                                dbTransaction.Commit();
                            }
                            else
                            {
                                dbTransaction.Rollback();
                            }
                        }
                        catch
                        {
                            if (dbTransaction.Connection != null)
                            {
                                dbTransaction.Rollback();
                            }
                            flag = false;
                        }
                        finally
                        {
                            dbConnection.Close();
                        }
                    }
                    result = flag;
                }
                else
                {
                    dataReader.Close();
                    result = false;
                }
            }
            return(result);
        }
예제 #57
0
        public bool CreateShippingTemplate(FreightTemplate freightTemplate)
        {
            this.Error = "";
            bool flag = false;

            System.Data.Common.DbCommand sqlStringCommand = this.database.GetSqlStringCommand("select name from Hishop_FreightTemplate_Templates where name=@Name");
            this.database.AddInParameter(sqlStringCommand, "Name", System.Data.DbType.String, freightTemplate.Name);
            System.Data.IDataReader dataReader = this.database.ExecuteReader(sqlStringCommand);
            bool result;

            if (!dataReader.Read())
            {
                System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand("INSERT INTO Hishop_FreightTemplate_Templates(Name,FreeShip,MUnit,HasFree)VALUES(@Name,@FreeShip,@MUnit,@HasFree)");
                this.database.AddInParameter(sqlStringCommand2, "Name", System.Data.DbType.String, freightTemplate.Name);
                this.database.AddInParameter(sqlStringCommand2, "FreeShip", System.Data.DbType.Int16, freightTemplate.FreeShip);
                this.database.AddInParameter(sqlStringCommand2, "MUnit", System.Data.DbType.Int16, freightTemplate.MUnit);
                this.database.AddInParameter(sqlStringCommand2, "HasFree", System.Data.DbType.Int16, freightTemplate.HasFree);
                using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
                {
                    dbConnection.Open();
                    System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                    try
                    {
                        this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                        sqlStringCommand2 = this.database.GetSqlStringCommand("SELECT @@Identity");
                        object obj = this.database.ExecuteScalar(sqlStringCommand2, dbTransaction);
                        int    num = 0;
                        if (obj != null && obj != DBNull.Value)
                        {
                            int.TryParse(obj.ToString(), out num);
                            this.Error = num.ToString();
                            flag       = (num > 0);
                        }
                        if (flag && !freightTemplate.FreeShip)
                        {
                            System.Data.Common.DbCommand sqlStringCommand3 = this.database.GetSqlStringCommand(" ");
                            this.database.AddInParameter(sqlStringCommand3, "TemplateId", System.Data.DbType.Int32, num);
                            if (freightTemplate.FreeShippings != null && freightTemplate.FreeShippings.Count > 0)
                            {
                                StringBuilder stringBuilder = new StringBuilder();
                                int           num2          = 0;
                                int           num3          = 0;
                                stringBuilder.Append("DECLARE @ERR INT; Set @ERR =0;");
                                stringBuilder.Append(" DECLARE @FreeId Int;");
                                foreach (FreeShipping current in freightTemplate.FreeShippings)
                                {
                                    stringBuilder.Append(" INSERT INTO Hishop_FreightTemplate_FreeShipping(TemplateId,ModeId,ConditionNumber,ConditionType) VALUES( @TemplateId,").Append("@ModeId").Append(num2).Append(",@ConditionNumber").Append(num2).Append(",@ConditionType").Append(num2).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                    this.database.AddInParameter(sqlStringCommand3, "ModeId" + num2, System.Data.DbType.Int32, current.ModeId);
                                    this.database.AddInParameter(sqlStringCommand3, "ConditionNumber" + num2, System.Data.DbType.String, current.ConditionNumber);
                                    this.database.AddInParameter(sqlStringCommand3, "ConditionType" + num2, System.Data.DbType.Int32, current.ConditionType);
                                    stringBuilder.Append("Set @FreeId =@@identity;");
                                    if (current.FreeShippingRegions != null)
                                    {
                                        foreach (FreeShippingRegion current2 in current.FreeShippingRegions)
                                        {
                                            stringBuilder.Append(" INSERT INTO Hishop_FreightTemplate_FreeShippingRegions(FreeId,TemplateId,RegionId) VALUES(@FreeId,@TemplateId,").Append("@RegionId").Append(num3).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                            this.database.AddInParameter(sqlStringCommand3, "RegionId" + num3, System.Data.DbType.Int32, current2.RegionId);
                                            num3++;
                                        }
                                    }
                                    num2++;
                                }
                                sqlStringCommand3.CommandText = stringBuilder.Append("SELECT @ERR;").ToString();
                                int num4 = (int)this.database.ExecuteScalar(sqlStringCommand3, dbTransaction);
                                if (num4 != 0)
                                {
                                    this.Error = "指定包邮信息部份有错误,请查检!";
                                    dbTransaction.Rollback();
                                    flag = false;
                                }
                            }
                            if (flag && freightTemplate.SpecifyRegionGroups != null && freightTemplate.SpecifyRegionGroups.Count > 0)
                            {
                                sqlStringCommand3 = this.database.GetSqlStringCommand(" ");
                                this.database.AddInParameter(sqlStringCommand3, "TemplateId", System.Data.DbType.Int32, num);
                                StringBuilder stringBuilder = new StringBuilder();
                                int           num2          = 0;
                                int           num3          = 0;
                                stringBuilder.Append("DECLARE @ERR INT; Set @ERR =0;");
                                stringBuilder.Append(" DECLARE @GroupId Int;");
                                foreach (SpecifyRegionGroup current3 in freightTemplate.SpecifyRegionGroups)
                                {
                                    stringBuilder.Append(" INSERT INTO Hishop_FreightTemplate_SpecifyRegionGroups(TemplateId,ModeId,FristNumber,FristPrice,AddNumber,AddPrice,IsDefault) VALUES(@TemplateId,").Append("@ModeId").Append(num2).Append(",@FristNumber").Append(num2).Append(",@FristPrice").Append(num2).Append(",@AddNumber").Append(num2).Append(",@AddPrice").Append(num2).Append(",@IsDefault").Append(num2).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                    this.database.AddInParameter(sqlStringCommand3, "ModeId" + num2, System.Data.DbType.Int16, current3.ModeId);
                                    this.database.AddInParameter(sqlStringCommand3, "FristNumber" + num2, System.Data.DbType.Decimal, current3.FristNumber);
                                    this.database.AddInParameter(sqlStringCommand3, "FristPrice" + num2, System.Data.DbType.Currency, current3.FristPrice);
                                    this.database.AddInParameter(sqlStringCommand3, "AddPrice" + num2, System.Data.DbType.Currency, current3.AddPrice);
                                    this.database.AddInParameter(sqlStringCommand3, "AddNumber" + num2, System.Data.DbType.Decimal, current3.AddNumber);
                                    this.database.AddInParameter(sqlStringCommand3, "IsDefault" + num2, System.Data.DbType.Int16, current3.IsDefault);
                                    stringBuilder.Append("Set @GroupId =@@identity;");
                                    if (current3.SpecifyRegions != null)
                                    {
                                        foreach (SpecifyRegion current4 in current3.SpecifyRegions)
                                        {
                                            stringBuilder.Append(" INSERT INTO Hishop_FreightTemplate_SpecifyRegions(TemplateId,GroupId,RegionId) VALUES(@TemplateId,@GroupId").Append(",@RegionId").Append(num3).Append("); SELECT @ERR=@ERR+@@ERROR;");
                                            this.database.AddInParameter(sqlStringCommand3, "RegionId" + num3, System.Data.DbType.Int32, current4.RegionId);
                                            num3++;
                                        }
                                    }
                                    num2++;
                                }
                                sqlStringCommand3.CommandText = stringBuilder.Append("SELECT @ERR;").ToString();
                                int num4 = (int)this.database.ExecuteScalar(sqlStringCommand3, dbTransaction);
                                if (num4 != 0)
                                {
                                    this.Error = "运送方式部份信息有错误,请查检!";
                                    dbTransaction.Rollback();
                                    flag = false;
                                }
                            }
                        }
                        dbTransaction.Commit();
                    }
                    catch
                    {
                        if (dbTransaction.Connection != null)
                        {
                            dbTransaction.Rollback();
                        }
                        flag = false;
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
                result = flag;
            }
            else
            {
                dataReader.Close();
                result = false;
            }
            return(result);
        }
예제 #58
0
        public static string UpdateAndCreateOrderByOrderSplitInfo(IList <OrderSplitInfo> infoList, OrderInfo oldorderinfo)
        {
            string   text     = "1";
            Database database = DatabaseFactory.CreateDatabase();
            string   result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                StringBuilder stringBuilder = new StringBuilder();
                try
                {
                    decimal num = 0m;
                    foreach (OrderSplitInfo current in infoList)
                    {
                        OrderInfo orderInfo = new OrderInfo();
                        if (current.OrderIDNum != 1)
                        {
                            string itemList = current.ItemList;
                            if (string.IsNullOrEmpty(itemList))
                            {
                                dbTransaction.Rollback();
                                result = "订单拆分失败";
                                return(result);
                            }
                            string   text2 = oldorderinfo.OrderId + "-" + current.OrderIDNum.ToString();
                            decimal  num2  = 0m;
                            decimal  d     = 0m;
                            string[] array = itemList.Split(new char[]
                            {
                                ','
                            });
                            string[] array2 = array;
                            for (int i = 0; i < array2.Length; i++)
                            {
                                string       s            = array2[i];
                                LineItemInfo lineItemInfo = new LineItemDao().GetLineItemInfo(Globals.ToNum(s), "");
                                if (lineItemInfo == null)
                                {
                                    dbTransaction.Rollback();
                                    result = "订单详情更新失败";
                                    return(result);
                                }
                                num2 += lineItemInfo.ItemWeight * lineItemInfo.Quantity;
                                num  += num2;
                                d    += lineItemInfo.ItemAdjustedPrice * lineItemInfo.Quantity;
                            }
                            stringBuilder.Append("," + itemList.Trim(new char[]
                            {
                                ','
                            }));
                            if (!new LineItemDao().UpdateLineItemOrderID(itemList, text2, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = "订单详情更新失败";
                                return(result);
                            }
                            orderInfo.OrderId          = text2;
                            orderInfo.OrderMarking     = oldorderinfo.OrderMarking;
                            orderInfo.ClientShortType  = oldorderinfo.ClientShortType;
                            orderInfo.Remark           = oldorderinfo.Remark;
                            orderInfo.ManagerMark      = oldorderinfo.ManagerMark;
                            orderInfo.AdjustedDiscount = 0m;
                            orderInfo.OrderStatus      = oldorderinfo.OrderStatus;
                            orderInfo.CloseReason      = oldorderinfo.CloseReason;
                            orderInfo.OrderDate        = oldorderinfo.OrderDate;
                            orderInfo.PayDate          = oldorderinfo.PayDate;
                            orderInfo.ShippingDate     = oldorderinfo.ShippingDate;
                            orderInfo.FinishDate       = oldorderinfo.FinishDate;
                            orderInfo.UserId           = oldorderinfo.UserId;
                            orderInfo.Username         = oldorderinfo.Username;
                            orderInfo.EmailAddress     = oldorderinfo.EmailAddress;
                            orderInfo.RealName         = oldorderinfo.RealName;
                            orderInfo.QQ                          = oldorderinfo.QQ;
                            orderInfo.Wangwang                    = oldorderinfo.Wangwang;
                            orderInfo.MSN                         = oldorderinfo.MSN;
                            orderInfo.ShippingRegion              = oldorderinfo.ShippingRegion;
                            orderInfo.Address                     = oldorderinfo.Address;
                            orderInfo.ZipCode                     = oldorderinfo.ZipCode;
                            orderInfo.ShipTo                      = oldorderinfo.ShipTo;
                            orderInfo.TelPhone                    = oldorderinfo.TelPhone;
                            orderInfo.CellPhone                   = oldorderinfo.CellPhone;
                            orderInfo.ShipToDate                  = oldorderinfo.ShipToDate;
                            orderInfo.ShippingModeId              = oldorderinfo.ShippingModeId;
                            orderInfo.ModeName                    = oldorderinfo.ModeName;
                            orderInfo.RealShippingModeId          = oldorderinfo.RealShippingModeId;
                            orderInfo.RealModeName                = oldorderinfo.RealModeName;
                            orderInfo.RegionId                    = oldorderinfo.RegionId;
                            orderInfo.Freight                     = current.AdjustedFreight;
                            orderInfo.AdjustedFreight             = current.AdjustedFreight;
                            orderInfo.ShipOrderNumber             = oldorderinfo.ShipOrderNumber;
                            orderInfo.Weight                      = num2;
                            orderInfo.Weight                      = oldorderinfo.Weight;
                            orderInfo.ExpressCompanyName          = oldorderinfo.ExpressCompanyName;
                            orderInfo.ExpressCompanyAbb           = oldorderinfo.ExpressCompanyAbb;
                            orderInfo.PaymentTypeId               = oldorderinfo.PaymentTypeId;
                            orderInfo.PaymentType                 = oldorderinfo.PaymentType;
                            orderInfo.PayCharge                   = oldorderinfo.PayCharge;
                            orderInfo.RefundStatus                = oldorderinfo.RefundStatus;
                            orderInfo.RefundAmount                = oldorderinfo.RefundAmount;
                            orderInfo.RefundRemark                = oldorderinfo.RefundRemark;
                            orderInfo.Gateway                     = oldorderinfo.Gateway;
                            orderInfo.Points                      = 0;
                            orderInfo.DiscountAmount              = 0m;
                            orderInfo.ActivitiesId                = "";
                            orderInfo.ActivitiesName              = "";
                            orderInfo.ReducedPromotionId          = 0;
                            orderInfo.ReducedPromotionName        = "";
                            orderInfo.ReducedPromotionAmount      = 0m;
                            orderInfo.IsReduced                   = false;
                            orderInfo.SentTimesPointPromotionId   = 0;
                            orderInfo.SentTimesPointPromotionName = "";
                            orderInfo.FreightFreePromotionId      = 0;
                            orderInfo.FreightFreePromotionName    = "";
                            orderInfo.IsFreightFree               = oldorderinfo.IsFreightFree;
                            orderInfo.GatewayOrderId              = oldorderinfo.GatewayOrderId;
                            orderInfo.IsPrinted                   = oldorderinfo.IsPrinted;
                            orderInfo.InvoiceTitle                = oldorderinfo.InvoiceTitle;
                            orderInfo.ReferralUserId              = oldorderinfo.ReferralUserId;
                            orderInfo.ReferralPath                = oldorderinfo.ReferralPath;
                            orderInfo.RedPagerID                  = null;
                            orderInfo.RedPagerActivityName        = "";
                            orderInfo.RedPagerOrderAmountCanUse   = 0m;
                            orderInfo.RedPagerAmount              = 0m;
                            orderInfo.PointToCash                 = 0m;
                            orderInfo.PointExchange               = 0;
                            if (!new OrderDao().CreatOrder(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = "生成新订单失败";
                                return(result);
                            }
                            if (!new OrderDao().UpdateOrderSplitState(orderInfo.OrderId, 2, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = "更新订单状态失败";
                                return(result);
                            }
                        }
                    }
                    foreach (OrderSplitInfo current in infoList)
                    {
                        if (current.OrderIDNum == 1)
                        {
                            decimal num3 = oldorderinfo.Weight - num;
                            if (num3 > 0m)
                            {
                                oldorderinfo.Weight = num3;
                            }
                            oldorderinfo.AdjustedFreight = current.AdjustedFreight;
                            if (!new OrderDao().UpdateOrder(oldorderinfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = "更新订单失败";
                                return(result);
                            }
                            if (!new OrderDao().UpdateOrderSplitState(oldorderinfo.OrderId, 1, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = "更新主订单状态失败";
                                return(result);
                            }
                            if (!new OrderSplitDao().DelOrderSplitByOrderID(oldorderinfo.OrderId, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = "删除拆分记录失败";
                                return(result);
                            }
                        }
                    }
                    dbTransaction.Commit();
                    foreach (OrderSplitInfo current in infoList)
                    {
                        OrderInfo orderInfo2 = new OrderDao().GetOrderInfo(current.OldOrderId + ((current.OrderIDNum == 1) ? "" : ("-" + current.OrderIDNum.ToString())));
                        if (orderInfo2 != null)
                        {
                            if (oldorderinfo.PayDate.HasValue)
                            {
                                orderInfo2.PayDate = oldorderinfo.PayDate;
                            }
                            int num4 = 0;
                            foreach (LineItemInfo current2 in orderInfo2.LineItems.Values)
                            {
                                if (current2.OrderItemsStatus.ToString() == OrderStatus.Refunded.ToString() || current2.OrderItemsStatus.ToString() == OrderStatus.Returned.ToString())
                                {
                                    num4++;
                                }
                            }
                            if (orderInfo2.LineItems.Values.Count == num4)
                            {
                                orderInfo2.OrderStatus = OrderStatus.Closed;
                            }
                            new OrderDao().UpdateOrder(orderInfo2, null);
                        }
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    text = "系统错误";
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            result = text;
            return(result);
        }
예제 #59
0
        public static int CreatOrder(OrderInfo orderInfo, bool isUseBalance, decimal remainingMondy)
        {
            int num = 0;

            if (orderInfo.GetTotal() <= 0m)
            {
                orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid;
                orderInfo.PayDate     = new DateTime?(DateTime.Now);
            }
            if (orderInfo.PaymentType == null && orderInfo.PointExchange > 0)
            {
                orderInfo.PaymentType   = "积分抵现";
                orderInfo.Gateway       = "hishop.plugins.payment.pointtocach";
                orderInfo.PaymentTypeId = 77;
            }
            else if (orderInfo.PaymentType == null && orderInfo.RedPagerID.HasValue && orderInfo.RedPagerID.Value > 0)
            {
                orderInfo.PaymentType   = "优惠券抵扣";
                orderInfo.Gateway       = "hishop.plugins.payment.coupontocach";
                orderInfo.PaymentTypeId = 55;
            }
            MemberInfo currentMember = MemberProcessor.GetCurrentMember();
            Database   database      = DatabaseFactory.CreateDatabase();
            int        quantity      = orderInfo.LineItems.Sum((KeyValuePair <string, LineItemInfo> item) => item.Value.Quantity);
            int        result;

            lock (ShoppingProcessor.createOrderLocker)
            {
                if (orderInfo.GroupBuyId > 0)
                {
                    ShoppingProcessor.checkCanGroupBuy(quantity, orderInfo.GroupBuyId);
                }
                using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
                {
                    dbConnection.Open();
                    System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                    try
                    {
                        orderInfo.ClientShortType = (ClientShortType)Globals.GetClientShortType();
                        if (!new OrderDao().CreatOrder(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = 0;
                            return(result);
                        }
                        if (orderInfo.LineItems.Count > 0)
                        {
                            if (orderInfo.OrderStatus == OrderStatus.BuyerAlreadyPaid)
                            {
                                foreach (LineItemInfo lineItemInfo in orderInfo.LineItems.Values)
                                {
                                    lineItemInfo.OrderItemsStatus = OrderStatus.BuyerAlreadyPaid;
                                }
                            }
                            if (!new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = 0;
                                return(result);
                            }
                        }
                        if (!string.IsNullOrEmpty(orderInfo.CouponCode))
                        {
                            if (!new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = 0;
                                return(result);
                            }
                        }


                        ICollection values = orderInfo.LineItems.Values;
                        foreach (LineItemInfo lineItemInfo in values)
                        {
                            if (lineItemInfo.Type == 1)
                            {
                                if (lineItemInfo.ExchangeId > 0)
                                {
                                    PointExchangeChangedInfo pointExchangeChangedInfo = new PointExchangeChangedInfo();
                                    pointExchangeChangedInfo.exChangeId   = lineItemInfo.ExchangeId;
                                    pointExchangeChangedInfo.exChangeName = new OrderDao().GetexChangeName(pointExchangeChangedInfo.exChangeId);
                                    pointExchangeChangedInfo.ProductId    = lineItemInfo.ProductId;
                                    pointExchangeChangedInfo.PointNumber  = lineItemInfo.PointNumber;
                                    pointExchangeChangedInfo.MemberID     = orderInfo.UserId;
                                    pointExchangeChangedInfo.Date         = DateTime.Now;
                                    pointExchangeChangedInfo.MemberGrades = currentMember.GradeId;
                                    if (!new OrderDao().InsertPointExchange_Changed(pointExchangeChangedInfo, dbTransaction, lineItemInfo.Quantity))
                                    {
                                        dbTransaction.Rollback();
                                        result = 0;
                                        return(result);
                                    }
                                    IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo();
                                    integralDetailInfo.IntegralChange     = -lineItemInfo.PointNumber;
                                    integralDetailInfo.IntegralSource     = "积分兑换商品-订单号:" + orderInfo.OrderMarking;
                                    integralDetailInfo.IntegralSourceType = 2;
                                    integralDetailInfo.Remark             = "积分兑换商品";
                                    integralDetailInfo.Userid             = orderInfo.UserId;
                                    integralDetailInfo.GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId;
                                    integralDetailInfo.IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.IntegralExchange);
                                    if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction))
                                    {
                                        dbTransaction.Rollback();
                                        result = 0;
                                        return(result);
                                    }
                                }
                            }
                        }
                        if (orderInfo.PointExchange > 0)
                        {
                            IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo();
                            integralDetailInfo.IntegralChange     = -orderInfo.PointExchange;
                            integralDetailInfo.IntegralSource     = "积分抵现,订单号:" + orderInfo.OrderId;
                            integralDetailInfo.IntegralSourceType = 2;
                            integralDetailInfo.Remark             = "";
                            integralDetailInfo.Userid             = orderInfo.UserId;
                            integralDetailInfo.GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId;
                            integralDetailInfo.IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.NowArrived);
                            if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = 0;
                                return(result);
                            }
                        }
                        if (orderInfo.RedPagerID > 0)
                        {
                            if (!new OrderDao().UpdateCoupon_MemberCoupons(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = 0;
                                return(result);
                            }
                        }
                        dbTransaction.Commit();
                        num = 1;
                        if (orderInfo.OrderStatus == OrderStatus.BuyerAlreadyPaid)
                        {
                            num = 2;
                        }
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        throw;
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
            }
            if (isUseBalance && num == 1)
            {
                orderInfo = new OrderDao().GetOrderInfo(orderInfo.OrderId);
                lock (ShoppingProcessor.BalanceUpdateLock)
                {
                    num = ShoppingProcessor.OrderBalanceUpdate(orderInfo, currentMember.UserId, remainingMondy);
                }
            }
            result = num;
            return(result);
        }
예제 #60
0
        private bool CreateAdministrator(out int newUserId, out string errorMsg)
        {
            System.Data.Common.DbConnection  dbConnection  = null;
            System.Data.Common.DbTransaction dbTransaction = null;
            bool result;

            try
            {
                System.Data.Common.DbConnection dbConnection2;
                dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString()));
                try
                {
                    dbConnection.Open();
                    RolesConfiguration           rolesConfiguration = HiConfiguration.GetConfig().RolesConfiguration;
                    System.Data.Common.DbCommand dbCommand          = dbConnection.CreateCommand();
                    dbTransaction         = dbConnection.BeginTransaction();
                    dbCommand.Connection  = dbConnection;
                    dbCommand.Transaction = dbTransaction;
                    dbCommand.CommandType = System.Data.CommandType.Text;
                    dbCommand.CommandText = "SELECT RoleId FROM aspnet_Roles WHERE [LoweredRoleName] = LOWER(@RoleName)";
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RoleName", rolesConfiguration.SystemAdministrator));
                    System.Guid guid = (System.Guid)dbCommand.ExecuteScalar();
                    dbCommand.Parameters["@RoleName"].Value = rolesConfiguration.Manager;
                    System.Guid guid2 = (System.Guid)dbCommand.ExecuteScalar();
                    dbCommand.Parameters.Clear();
                    dbCommand.CommandText = "INSERT INTO aspnet_Users  (UserName, LoweredUserName, IsAnonymous, UserRole, LastActivityDate, Password, PasswordFormat, PasswordSalt, IsApproved, IsLockedOut, CreateDate, LastLoginDate, LastPasswordChangedDate, LastLockoutDate, FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart, Email, LoweredEmail) VALUES (@Username, LOWER(@Username), 0, @UserRole, @CreateDate, @Password, @PasswordFormat, @PasswordSalt, 1, 0, @CreateDate, @CreateDate, @CreateDate, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), 0, CONVERT( datetime, '17540101', 112 ), @Email, LOWER(@Email));SELECT @@IDENTITY";
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Username", this.username));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserRole", UserRole.SiteManager));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreateDate", System.DateTime.Now));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", this.password));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PasswordFormat", System.Web.Security.MembershipPasswordFormat.Clear));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PasswordSalt", ""));
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Email", this.email));
                    newUserId = System.Convert.ToInt32(dbCommand.ExecuteScalar());
                    dbCommand.Parameters.Clear();
                    dbCommand.CommandText = "INSERT INTO aspnet_Managers(UserId) VALUES(@UserId)";
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserId", newUserId));
                    dbCommand.ExecuteNonQuery();
                    dbCommand.CommandText = "INSERT INTO aspnet_UsersInRoles(UserId, RoleId) VALUES(@UserId, @RoleId)";
                    dbCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RoleId", guid2));
                    dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters["@RoleId"].Value = guid;
                    dbCommand.ExecuteNonQuery();
                    dbTransaction.Commit();
                    dbConnection.Close();
                }
                finally
                {
                    if (dbConnection2 != null)
                    {
                        ((System.IDisposable)dbConnection2).Dispose();
                    }
                }
                errorMsg = null;
                result   = true;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                errorMsg  = ex.Message;
                newUserId = 0;
                if (dbTransaction != null)
                {
                    try
                    {
                        dbTransaction.Rollback();
                    }
                    catch (System.Exception ex2)
                    {
                        errorMsg = ex2.Message;
                    }
                }
                if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                }
                result = false;
            }
            return(result);
        }