我有一个非常有趣的案例:在我的购物过程中,有两个视图需要显示订单的总价和运费,这个部分视图是通过
奇怪的问题是,在上周的两种情况下,我的SQL Server数据库中仅有
我想知道问题可能是什么,我能否编写一些脚本来记录是否出现了某种错误,无论是在SQL Server还是IIS中?
ShowCartDiscountsPrices
操作呈现的。最后,我需要使用Entity Framework将MinDeliveryPrice
、MinDeliveryPriceDDS
、DeliveryPrice
和DeliveryPriceDDS
插入到数据库中。奇怪的问题是,在上周的两种情况下,我的SQL Server数据库中仅有
DeliveryPrice
的值,而其他三列在我的SQL Server数据库中却是null。当我查看问题并以相同的文章下单一个小时后再次查看时,所有四列都被填充了,在此期间没有人对数据库进行任何更改。我想知道问题可能是什么,我能否编写一些脚本来记录是否出现了某种错误,无论是在SQL Server还是IIS中?
public ActionResult ShowCartDiscountsPrices(OrderDiscountPriceModel model, bool? ischange, int? deliverypreference)
{
var cart = ShoppingCart.GetCart(WebsiteContext.CurrentUser != null ? (int?)WebsiteContext.CurrentUser.UserID : null);
decimal mindeliveryprice = 0;
decimal mindeliverypricedds = 0;
if (deliverypreference != null || Session["DeliveryPreference"] != null)
{
var parsedelprice = deliverypreference.HasValue ? deliverypreference.Value == 1 ? Decimal.TryParse(Settings.GetSettingByName("Eshop_SpeedyMinDeliveryPrice"), out mindeliveryprice) :Decimal.TryParse(Settings.GetSettingByName("Eshop_HomeMinDeliveryPrice"), out mindeliveryprice) : Decimal.TryParse(Session["MinDeliveryPrice"].ToString(), out mindeliveryprice );
var parsedelpricedds = deliverypreference.HasValue ? deliverypreference.Value == 1 ? Decimal.TryParse(Settings.GetSettingByName("Eshop_SpeedyMinDeliveryPriceDDS"), out mindeliverypricedds) : Decimal.TryParse(Settings.GetSettingByName("Eshop_HomeMinDeliveryPriceDDS"), out mindeliverypricedds) : Decimal.TryParse(Session["MinDeliveryPriceDDS"].ToString(), out mindeliverypricedds );
decimal deliveryprice;
decimal deliverypricedds;
ShoppingCartHelper.CalculateArticlesDeliveryPrice(mindeliveryprice, mindeliverypricedds, cart.ComputeTotalTransport(), cart.ComputeTotalTransportDDS(), out deliveryprice, out deliverypricedds);
model.DeliveryPrice = deliveryprice;
model.DeliveryPriceDDS = deliverypricedds;
model.DeliveryPreference = deliverypreference.HasValue ? deliverypreference.Value : (int)Session["DeliveryPreference"];
model.MinDeliveryPrice = mindeliveryprice;
model.MinDeliveryPriceDDS = mindeliverypricedds;
model.FinalSum += deliverypricedds;
}
else
{
if (isFromLastStep != null && bool.Parse(isFromLastStep.ToString()) == true)
ViewBag.IncludeDelivery = true;
}
if (deliverypreference != null)
{
Session["DeliveryPreference"] = deliverypreference;
Session["MinDeliveryPrice"] = mindeliveryprice;
Session["MinDeliveryPriceDDS"] = mindeliverypricedds;
}
ViewData.TemplateInfo.HtmlFieldPrefix = "OrderDiscoutPrice";
return PartialView("_CartDiscountsPrices", model);
}
以下是我的辅助函数,它们仅遍历包含文章的集合并计算总交付价格。
public decimal ComputeTotalTransport()
{
decimal totalarticletransport = 0;
decimal articletransport;
foreach (var article in lineCollection)
{
if (decimal.TryParse(article.Article.Transport.ToString(), out articletransport))
{
totalarticletransport += article.Article.Quantity * articletransport;
articletransport = 0;
}
}
return totalarticletransport;
}
public decimal ComputeTotalTransportDDS()
{
decimal totaltransportdds = 0;
decimal articletransportdds;
foreach (var article in lineCollection)
{
if (decimal.TryParse(article.Article.TransportDDS.ToString(), out articletransportdds))
{
totaltransportdds += article.Article.Quantity * articletransportdds;
articletransportdds = 0;
}
}
return totaltransportdds;
}