Пример #1
0
        public decimal GetTotal()
        {
            decimal markdown;

            total = 0;
            foreach (KeyValuePair <string, decimal> LineItem in Receipt)
            {
                if (Specials.ContainsKey(LineItem.Key))
                {
                    decimal val            = 0;
                    decimal itemsLeft      = LineItem.Value;
                    Special GenericSpecial = Specials[LineItem.Key];
                    if (GenericSpecial.GetType() == typeof(SpecialBuyNgetMatXPctOff))
                    {
                        SpecialBuyNgetMatXPctOff special = (SpecialBuyNgetMatXPctOff)GenericSpecial;
                        while (itemsLeft > 0)
                        {
                            if ((itemsLeft > special.m) && (LineItem.Value - itemsLeft < special.limit))
                            {
                                val       += special.m;
                                itemsLeft -= special.m;
                                if (itemsLeft < special.n)
                                {
                                    val      += itemsLeft * (1 - special.pct);
                                    itemsLeft = 0;
                                }
                                else
                                {
                                    val       += special.n * (1 - special.pct);
                                    itemsLeft -= special.n;
                                }
                            }
                            else
                            {
                                val      += itemsLeft;
                                itemsLeft = 0;
                            }
                        }
                        total += (costList[LineItem.Key].cost - (MarkDownList.TryGetValue(LineItem.Key, out markdown) ? markdown : 0)) * val;
                    }
                    else if (GenericSpecial.GetType() == typeof(SpecialNForX))
                    {
                        SpecialNForX special = (SpecialNForX)GenericSpecial;
                        while ((itemsLeft >= special.n) && (LineItem.Value - itemsLeft < special.limit))
                        {
                            itemsLeft -= special.n;
                            total     += (special.cost - (MarkDownList.TryGetValue(LineItem.Key, out markdown) ? markdown : 0)) * special.n;
                        }
                        total += (costList[LineItem.Key].cost - (MarkDownList.TryGetValue(LineItem.Key, out markdown) ? markdown : 0)) * itemsLeft;
                    }
                }
                else
                {
                    total += (costList[LineItem.Key].cost - (MarkDownList.TryGetValue(LineItem.Key, out markdown) ? markdown : 0)) * LineItem.Value;
                }
            }
            return(total);
        }
Пример #2
0
        public void AddSpecialBuyNgetMatXPctOff(string name, int M, int N, decimal pct, int limit = Int16.MaxValue)
        {
            SpecialBuyNgetMatXPctOff special = new SpecialBuyNgetMatXPctOff(name, M, N, pct);

            special.limit = limit;
            if (Specials.ContainsKey(name))
            {
                Specials[name] = special;
            }
            else
            {
                Specials.Add(name, special);
            }
        }