Exemple #1
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);
        }
Exemple #2
0
        public static bool DeleteOrderGift(OrderInfo order, int giftId)
        {
            bool flag;

            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection())
            {
                connection.Open();
                DbTransaction dbTran = connection.BeginTransaction();
                try
                {
                    SalesProvider provider  = SalesProvider.Instance();
                    OrderGiftInfo orderGift = provider.GetOrderGift(giftId, order.OrderId);
                    order.Gifts.Remove(orderGift);
                    if (!provider.DeleteOrderGift(order.OrderId, orderGift.GiftId, dbTran))
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    if (!provider.UpdateOrderAmount(order, dbTran))
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    dbTran.Commit();
                    EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "删除了订单号为\"{0}\"的订单礼品", new object[] { order.OrderId }));
                    flag = true;
                }
                catch
                {
                    dbTran.Rollback();
                    flag = false;
                }
                finally
                {
                    connection.Close();
                }
            }
            return(flag);
        }