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

时间:2011-11-03 10:50:16

标签: c# conditional-operator assignment-operator

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

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;
        }

1 个答案:

答案 0 :(得分:1)

为什么不初始化可变的PrMod tp Zero

你需要对appLogic.GetColorAndSizePriceDelta方法进行debbug,因为如果返回类型是Decimal,它应该至少返回一个deafult值为0.0M