Example #1
0
        public static bool UpdateLineItem(string sku, OrderInfo order, int quantity)
        {
            bool flag;

            ManagerHelper.CheckPrivilege(Privilege.EditOrders);
            using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection())
            {
                connection.Open();
                DbTransaction dbTran = connection.BeginTransaction();
                try
                {
                    SalesProvider provider = SalesProvider.Instance();
                    int           userId   = order.UserId;
                    if (userId == 1100)
                    {
                        userId = 0;
                    }
                    Member user = Users.GetUser(userId) as Member;
                    if (user != null)
                    {
                        int     purchaseGiftId        = 0;
                        string  purchaseGiftName      = "";
                        int     giveQuantity          = 0;
                        int     wholesaleDiscountId   = 0;
                        string  wholesaleDiscountName = "";
                        decimal?discountRate          = null;

                        int gradeId = user.GradeId;

                        //GetLineItemPromotions(int productId, int quantity, out int purchaseGiftId, out string purchaseGiftName, out int giveQuantity, out int wholesaleDiscountId, out string wholesaleDiscountName, out decimal? discountRate, int gradeId);
                        provider.GetLineItemPromotions(order.LineItems[sku].ProductId, quantity, out purchaseGiftId, out purchaseGiftName, out giveQuantity, out wholesaleDiscountId, out wholesaleDiscountName, out discountRate, gradeId);

                        order.LineItems[sku].PurchaseGiftId        = purchaseGiftId;
                        order.LineItems[sku].PurchaseGiftName      = purchaseGiftName;
                        order.LineItems[sku].ShipmentQuantity      = quantity + giveQuantity;
                        order.LineItems[sku].WholesaleDiscountId   = wholesaleDiscountId;
                        order.LineItems[sku].WholesaleDiscountName = wholesaleDiscountName;
                        order.LineItems[sku].Quantity = quantity;

                        if (discountRate.HasValue && discountRate.Value != 0)
                        {
                            decimal itemListPrice = order.LineItems[sku].ItemListPrice;

                            order.LineItems[sku].ItemAdjustedPrice = Convert.ToDecimal((itemListPrice * discountRate) / 100M);
                        }
                        else
                        {
                            order.LineItems[sku].ItemAdjustedPrice = order.LineItems[sku].ItemListPrice;
                        }
                    }
                    else
                    {
                        order.LineItems[sku].Quantity          = quantity;
                        order.LineItems[sku].ShipmentQuantity  = quantity;
                        order.LineItems[sku].ItemAdjustedPrice = order.LineItems[sku].ItemListPrice;
                    }

                    if (!provider.UpdateLineItem(order.OrderId, order.LineItems[sku], dbTran))
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    if (!provider.UpdateOrderAmount(order, dbTran))
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    dbTran.Commit();
                    flag = true;
                }
                catch (Exception)
                {
                    dbTran.Rollback();
                    flag = false;
                }
                finally
                {
                    connection.Close();
                }
            }
            if (flag)
            {
                EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "修改了订单号为\"{0}\"的订单商品数量", new object[] { order.OrderId }));
            }
            return(flag);
        }