c#条件定价问题(+=)

本文关键字:问题 条件 | 更新日期: 2023-09-27 18:13:06

我有一些代码在这里:(它基本上检查产品是否为套件产品,然后应用价格修改的新价格)

if (!newItem.m_IsAKit)
{
    NewPR = AppLogic.DetermineLevelPrice(newItem.m_VariantID, m_ThisCustomer.CustomerLevelID, out IsOnSale);
    Decimal PrMod = AppLogic.GetColorAndSizePriceDelta(DB.RSField(rs, "ChosenColor"), DB.RSField(rs, "ChosenSize"), DB.RSFieldInt(rs, "TaxClassID"), ThisCustomer, true, false);
    if (PrMod != System.Decimal.Zero)
    {
        NewPR += PrMod;
    }
}
else
{
    NewPR = DB.RSFieldDecimal(rs, "ProductPrice");
    if (LevelDiscountPercent != 0.0M)
    {
        NewPR = AppLogic.GetKitTotalPrice(m_ThisCustomer.CustomerID, m_ThisCustomer.CustomerLevelID, newItem.m_ProductID, newItem.m_VariantID, newItem.m_ShoppingCartRecordID);
    }
 }

我有一个产品,它是一个工具包产品,所以我引用else语句后的代码。

我需要应用NewPr += PrMod.

NewPr = 22
PrMod = 5

我试过添加以下代码:

Decimal PrMod = AppLogic.GetColorAndSizePriceDelta(DB.RSField(rs, "ChosenColor"), DB.RSField(rs, "ChosenSize"), DB.RSFieldInt(rs, "TaxClassID"), ThisCustomer, true, false);
if (PrMod != System.Decimal.Zero)
{
    NewPR += PrMod;
}

但是在调试过程中,PrMod似乎没有保存值。

你能给我指个正确的方向吗?

感谢

我有以下方法,但我似乎看不到问题在哪里。当产品是一个套件产品时,它工作得很好。

static public decimal GetColorAndSizePriceDelta(String ChosenColor, String ChosenSize, int TaxClassID, Customer ThisCustomer, bool WithDiscount, bool WithVAT)
        {
            bool VATEnabled = AppLogic.ProductIsMLExpress() == false && AppLogic.AppConfigBool("VAT.Enabled");
            bool VATOn = (VATEnabled && ThisCustomer.VATSettingReconciled == VATSettingEnum.ShowPricesInclusiveOfVAT);
            decimal CustLevelDiscountPct = 1.0M;
            decimal price = System.Decimal.Zero;
            String ColorPriceModifier = String.Empty;
            String SizePriceModifier = String.Empty;
            if (ThisCustomer.CustomerLevelID > 0 && WithDiscount)
            {
                decimal LevelDiscountPercent = System.Decimal.Zero;                
                using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                {
                    dbconn.Open();
                    string sSql = string.Format("select LevelDiscountPercent from CustomerLevel with (NOLOCK) where CustomerLevelID={0}", ThisCustomer.CustomerLevelID);
                    using (IDataReader rs = DB.GetRS(sSql, dbconn))
                    {
                        if (rs.Read())
                        {
                            LevelDiscountPercent = DB.RSFieldDecimal(rs, "LevelDiscountPercent");
                        }
                    }
                }               
                if (LevelDiscountPercent != System.Decimal.Zero)
                {
                    CustLevelDiscountPct -= LevelDiscountPercent / 100.0M;
                }
            }
            if (ChosenColor.IndexOf("[") != -1)
            {
                int i1 = ChosenColor.IndexOf("[");
                int i2 = ChosenColor.IndexOf("]");
                if (i1 != -1 && i2 != -1)
                {
                    ColorPriceModifier = ChosenColor.Substring(i1 + 1, i2 - i1 - 1);
                }
            }
            if (ChosenSize.IndexOf("[") != -1)
            {
                int i1 = ChosenSize.IndexOf("[");
                int i2 = ChosenSize.IndexOf("]");
                if (i1 != -1 && i2 != -1)
                {
                    SizePriceModifier = ChosenSize.Substring(i1 + 1, i2 - i1 - 1);
                }
            }
            if (ColorPriceModifier.Length != 0)
            {
                price += Localization.ParseDBDecimal(ColorPriceModifier);
            }
            if (SizePriceModifier.Length != 0)
            {
                price += Localization.ParseDBDecimal(SizePriceModifier);
            }
            if (VATOn && WithVAT)
            {
                decimal TaxRate = 0.0M;
                TaxRate = ThisCustomer.TaxRate(TaxClassID);
                Decimal TaxMultiplier = (1.0M + (TaxRate / 100.00M));
                price = TaxMultiplier * price;
            }
            return price * CustLevelDiscountPct;
        }

c#条件定价问题(+=)

为什么不初始化变量PrMod tp Zero

你需要调试AppLogic。GetColorAndSizePriceDelta方法,因为如果返回类型是Decimal,它至少应该返回一个默认值0.0M