Exemplo n.º 1
0
        private bool CellEvaluate(string newValue, PriceGroup groupColumn)
        {
            bool ret;
            int  row = grid.EditedCell.Row;

            Item   item     = entities [row];
            double oldPrice = item.GetPriceGroupPrice(groupColumn);
            double newPrice;

            if (Currency.TryParseExpression(newValue, out newPrice))
            {
                if (BusinessDomain.AppConfiguration.WarnPricesSaleLowerThanPurchase &&
                    item.TradeInPrice > newPrice && newPrice > 0)
                {
                    string priceGroupText = Currency.GetAllSalePriceGroups()
                                            .Where(priceGroup => priceGroup.Key == (int)groupColumn)
                                            .Select(priceGroup => priceGroup.Value)
                                            .First();

                    using (MessageYesNoRemember dialog = new MessageYesNoRemember(Translator.GetString("Sale Price Lower than Purchase Price"), string.Empty,
                                                                                  string.Format(Translator.GetString("The value you entered for \"{0}\" is lower than the purchase price. Do you want to continue?"), priceGroupText), "Icons.Question32.png")) {
                        dialog.SetButtonText(MessageButtons.Remember, Translator.GetString("Do not warn me anymore"));
                        ret = dialog.Run() == ResponseType.Yes;
                        BusinessDomain.AppConfiguration.WarnPricesSaleLowerThanPurchase = !dialog.RememberChoice;
                    }
                }
                else
                {
                    ret = true;
                }

                if (ret)
                {
                    item.SetPriceGroupPrice(groupColumn, newPrice);
                }
            }
            else
            {
                item.SetPriceGroupPrice(groupColumn, 0);
                ret = false;
            }

            if (ret && !oldPrice.IsEqualTo(newPrice) && !dirtyItems.Contains(item))
            {
                btnNew.Sensitive = true;
                dirtyItems.Add(item);
            }

            return(ret);
        }
Exemplo n.º 2
0
        public void Apply <T> (T operationDetail, Operation <T> operation) where T : OperationDetail
        {
            if (error)
            {
                return;
            }

            switch (Type)
            {
            case PriceRule.ActionType.AddGood:
                if (operation != null)
                {
                    foreach (T detail in GetDetailsForPromotionalItems <T> (formula))
                    {
                        if (operation.OperationType == OperationType.RestaurantOrder)
                        {
                            detail.LotId = Int32.MinValue;
                        }
                        detail.PromotionForDetailHashCode = operationDetail.GetHashCode();
                        operation.Details.Add(detail);
                        operationDetail.AppliedPriceRules |= PriceRule.AppliedActions.PromotionalItemSource;
                    }
                }
                break;

            case PriceRule.ActionType.Price:
                PriceGroup priceGroup;
                string []  parts = GetPriceExpressionParts(formula, out priceGroup);
                if (parts.Length > 1)
                {
                    double price;
                    switch (priceGroup)
                    {
                    case PriceGroup.TradeInPrice:
                        price = operationDetail.OriginalPriceIn;
                        break;

                    case PriceGroup.RegularPriceInOperation:
                        price = operationDetail.OriginalPriceOut;
                        break;

                    default:
                        Item item = Item.GetById(operationDetail.ItemId);
                        price = item.GetPriceGroupPrice(priceGroup);
                        break;
                    }

                    try {
                        operationDetail.OriginalPriceOut = RPNCalculator.EvaluateExpression(price + parts [1] + parts [2]);
                    } catch (Exception ex) {
                        ErrorHandling.LogException(ex);
                        break;
                    }
                }
                else
                {
                    operationDetail.OriginalPriceOut = Double.Parse(parts [0], CultureInfo.InvariantCulture);
                }

                operationDetail.PriceOutEvaluate();
                operationDetail.AppliedPriceRules |= PriceRule.AppliedActions.PriceChanged;
                break;

            case PriceRule.ActionType.Discount:
                operationDetail.DiscountEvaluate((double)values [0]);
                operationDetail.AppliedPriceRules |= PriceRule.AppliedActions.DiscountChanged;
                break;
            }
        }