public override bool AddOrderGift(string orderId, OrderGiftInfo gift, int quantity, DbTransaction dbTran) { DbCommand sqlStringCommand = database.GetSqlStringCommand("select * from Hishop_OrderGifts where OrderId=@OrderId AND GiftId=@GiftId"); database.AddInParameter(sqlStringCommand, "OrderId", DbType.String, orderId); database.AddInParameter(sqlStringCommand, "GiftId", DbType.Int32, gift.GiftId); using (IDataReader reader = database.ExecuteReader(sqlStringCommand)) { if (reader.Read()) { DbCommand command2 = database.GetSqlStringCommand("update Hishop_OrderGifts set Quantity=@Quantity where OrderId=@OrderId AND GiftId=@GiftId"); database.AddInParameter(command2, "OrderId", DbType.String, orderId); database.AddInParameter(command2, "GiftId", DbType.Int32, gift.GiftId); database.AddInParameter(command2, "Quantity", DbType.Int32, ((int)reader["Quantity"]) + quantity); if (dbTran != null) { return (database.ExecuteNonQuery(command2, dbTran) == 1); } return (database.ExecuteNonQuery(command2) == 1); } DbCommand command = database.GetSqlStringCommand("INSERT INTO Hishop_OrderGifts(OrderId,GiftId,GiftName,CostPrice,ThumbnailsUrl,Quantity) VALUES(@OrderId,@GiftId,@GiftName,@CostPrice,@ThumbnailsUrl,@Quantity)"); database.AddInParameter(command, "OrderId", DbType.String, orderId); database.AddInParameter(command, "GiftId", DbType.Int32, gift.GiftId); database.AddInParameter(command, "GiftName", DbType.String, gift.GiftName); database.AddInParameter(command, "CostPrice", DbType.Currency, gift.CostPrice); database.AddInParameter(command, "ThumbnailsUrl", DbType.String, gift.ThumbnailsUrl); database.AddInParameter(command, "Quantity", DbType.Int32, quantity); if (dbTran != null) { return (database.ExecuteNonQuery(command, dbTran) == 1); } return (database.ExecuteNonQuery(command) == 1); } }
public static bool AddOrderGift(OrderInfo order, GiftInfo gift, int quantity) { bool flag; using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection()) { connection.Open(); DbTransaction dbTran = connection.BeginTransaction(); try { if (!SubsiteSalesProvider.Instance().AddOrderGift(order.OrderId, gift, quantity, dbTran)) { dbTran.Rollback(); return false; } bool flag2 = false; foreach (OrderGiftInfo info in order.Gifts) { if (info.GiftId == gift.GiftId) { flag2 = true; info.Quantity += quantity; } } if (!flag2) { OrderGiftInfo item = new OrderGiftInfo(); item.GiftId = gift.GiftId; item.OrderId = order.OrderId; item.GiftName = gift.Name; item.Quantity = quantity; item.CostPrice = gift.PurchasePrice; item.ThumbnailsUrl = gift.ThumbnailUrl40; order.Gifts.Add(item); } if (!SubsiteSalesProvider.Instance().UpdateOrderAmount(order, dbTran)) { dbTran.Rollback(); return false; } dbTran.Commit(); flag = true; } catch { dbTran.Rollback(); flag = false; } finally { connection.Close(); } } return flag; }
public static OrderGiftInfo PopulateOrderGift(IDataRecord reader) { if (null == reader) { return null; } OrderGiftInfo info2 = new OrderGiftInfo(); info2.OrderId = (string) reader["OrderId"]; info2.GiftId = (int) reader["GiftId"]; info2.GiftName = (string) reader["GiftName"]; info2.CostPrice = (reader["CostPrice"] == DBNull.Value) ? 0M : ((decimal) reader["CostPrice"]); info2.ThumbnailsUrl = (reader["ThumbnailsUrl"] == DBNull.Value) ? string.Empty : ((string) reader["ThumbnailsUrl"]); info2.Quantity = (reader["Quantity"] == DBNull.Value) ? 0 : ((int) reader["Quantity"]); return info2; }
public static bool AddOrderGift(OrderInfo order, GiftInfo giftinfo, 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(); OrderGiftInfo item = new OrderGiftInfo(); item.OrderId = order.OrderId; item.Quantity = quantity; item.GiftName = giftinfo.Name; decimal costPrice = item.CostPrice; item.CostPrice = Convert.ToDecimal(giftinfo.CostPrice); item.GiftId = giftinfo.GiftId; item.ThumbnailsUrl = giftinfo.ThumbnailUrl40; bool flag2 = false; foreach (OrderGiftInfo info2 in order.Gifts) { if (giftinfo.GiftId == info2.GiftId) { flag2 = true; info2.Quantity = quantity; break; } } if (!flag2) { order.Gifts.Add(item); } if (!provider.AddOrderGift(order.OrderId, item, quantity, dbTran)) { dbTran.Rollback(); return false; } if (!provider.UpdateOrderAmount(order, dbTran)) { dbTran.Rollback(); return false; } dbTran.Commit(); flag = true; } catch { dbTran.Rollback(); flag = false; } finally { connection.Close(); } } if (flag) { EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "成功的为订单号为\"{0}\"的订单添加了礼品", new object[] { order.OrderId })); } return flag; }
public abstract bool AddOrderGift(string orderId, OrderGiftInfo gift, int quantity, DbTransaction dbTran);
public static OrderInfo ConvertShoppingCartToOrder(ShoppingCartInfo shoppingCart, bool isGroupBuy, bool isCountDown, bool isSignBuy) { if ((shoppingCart.LineItems.Count == 0) && (shoppingCart.LineGifts.Count == 0)) { return null; } OrderInfo info = new OrderInfo(); info.ActivityId = shoppingCart.FeeFreeActivityId; info.ActivityName = shoppingCart.FeeFreeName; info.OrderOptionFree = shoppingCart.OrderOptionFree; info.ProcedureFeeFree = shoppingCart.ProcedureFeeFree; info.EightFree = shoppingCart.EightFree; info.DiscountId = shoppingCart.DiscountActivityId; info.DiscountName = shoppingCart.DiscountName; info.DiscountValue = shoppingCart.DiscountValue; info.DiscountValueType = shoppingCart.DiscountValueType; //OrderInfo info = info6; string skuIds = string.Empty; if (shoppingCart.LineItems.Values.Count > 0) { foreach (ShoppingCartItemInfo item in shoppingCart.LineItems.Values) { skuIds = skuIds + string.Format("'{0}',", item.SkuId); } } Dictionary<string, decimal> costPriceForItems = new Dictionary<string, decimal>(); if (!string.IsNullOrEmpty(skuIds)) { skuIds = skuIds.Substring(0, skuIds.Length - 1); costPriceForItems = ShoppingProvider.Instance().GetCostPriceForItems(skuIds); } if (shoppingCart.LineItems.Values.Count > 0) { foreach (ShoppingCartItemInfo info2 in shoppingCart.LineItems.Values) { decimal memberPrice = info2.MemberPrice; decimal costPrice = 0M; if (((info2.WholesaleDiscountId > 0) && !string.IsNullOrEmpty(info2.WholesaleDiscountName)) && info2.DiscountRate.HasValue) { memberPrice = info2.MemberPrice * (info2.DiscountRate.Value / 100M); } if ((isGroupBuy || isCountDown) || isSignBuy) { costPrice = ShoppingProvider.Instance().GetCostPrice(info2.SkuId); } else if (costPriceForItems.ContainsKey(info2.SkuId)) { costPrice = costPriceForItems[info2.SkuId]; } LineItemInfo info3 = new LineItemInfo(info2.SkuId, info2.ProductId, info2.SKU, info2.Quantity, info2.Quantity + info2.GiveQuantity, costPrice, info2.MemberPrice, memberPrice, info2.Name, info2.ThumbnailUrl40, info2.Weight, info2.PurchaseGiftId, info2.PurchaseGiftName, info2.WholesaleDiscountId, info2.WholesaleDiscountName, info2.SkuContent); info.LineItems.Add(info3.SkuId, info3); } } if (shoppingCart.LineGifts.Count > 0) { foreach (ShoppingCartGiftInfo info4 in shoppingCart.LineGifts) { OrderGiftInfo item = new OrderGiftInfo(); item.GiftId = info4.GiftId; item.GiftName = info4.Name; item.Quantity = info4.Quantity; item.ThumbnailsUrl = info4.ThumbnailUrl40; if (HiContext.Current.SiteSettings.IsDistributorSettings) { item.CostPrice = info4.PurchasePrice; } else { item.CostPrice = info4.CostPrice; } info.Gifts.Add(item); } } return info; }