Пример #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);
        }
Пример #2
0
        private bool CheckPricesSaleLessThanPurchase()
        {
            if (!BusinessDomain.AppConfiguration.WarnPricesSaleLowerThanPurchase)
            {
                return(true);
            }

            foreach (Entry txtPrice in priceGroupWarnings.Select(p => p.Key))
            {
                double price = Currency.ParseExpression(txtPrice.Text);
                if (item.TradeInPrice <= price || price <= 0)
                {
                    continue;
                }

                Entry  txt            = txtPrice;
                string priceGroupText = Currency.GetAllSalePriceGroups()
                                        .Where(priceGroup => priceGroup.Key == (int)txt.Data [0])
                                        .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 of {1}. Do you want to continue?"), priceGroupText, Currency.ToString(item.TradeInPrice, PriceType.Purchase)),
                           "Icons.Question32.png")) {
                    dialog.SetButtonText(MessageButtons.Remember, Translator.GetString("Do not warn me anymore"));
                    ResponseType responseType = dialog.Run();
                    BusinessDomain.AppConfiguration.WarnPricesSaleLowerThanPurchase = !dialog.RememberChoice;
                    switch (responseType)
                    {
                    case ResponseType.Yes:
                        if (dialog.RememberChoice)
                        {
                            return(true);
                        }
                        break;

                    default:
                        nbkMain.Page = (int)NotebookPages.Prices;
                        txtPrice.GrabFocus();
                        return(false);
                    }
                }
            }
            return(true);
        }