Exemplo n.º 1
0
        private void AddDishparagraph(DishPackageFlightOrder Pak)
        {
            string s = $"({Pak.Dish.Barcode}) {Pak.Dish.Name} - {Pak.Amount.ToString("0.##")} порц.";

            if (Pak.Comment.Trim() != "")
            {
                try
                {
                    /*
                     * var d = new XamlFormatProvider().Import(Pak.Comment);
                     * var pr = new TxtFormatProvider();
                     */
                    string Comment = Utils.TextHelper.GetTextFromRadDocText(Pak.Comment);
                    if (Comment.Trim() != "")
                    {
                        s += $" ({Comment})";
                    }
                }
                catch (Exception e)
                {
                    logger.Debug($"AddDishparagraph comment error {e.Message}");
                }
            }
            Paragraph p2 = new Paragraph();

            p2.FontSize     = 16;
            p2.SpacingAfter = 0;
            p2.Children.Add(new Span(s)
            {
                FontFamily = new System.Windows.Media.FontFamily("Times New Roman"),
                FontSize   = 16,
            });
            document.Sections.First().Children.Add(p2);
        }
        private bool Parce(Microsoft.Office.Interop.Excel.Worksheet ws, out List <OrderFlight> orderFlights)
        {
            orderFlights = new List <OrderFlight>();
            try
            {
                int             sColumn   = 1;
                int             row       = 3;
                List <DateTime> skipDates = new List <DateTime>();
                while (GetExcelCellValue(ws, row, sColumn) == "Дата")
                {
                    row++;
                    while (GetExcelCellValue(ws, row, sColumn) != "Итого" && row < maxExcelRow)
                    {
                        bool dateParceRes = true;
                        if (!GetDt(GetExcelCellValue(ws, row, sColumn), out DateTime dt))
                        {
                            return(false);
                        }
                        if (skipDates.Contains(dt))
                        {
                            dateParceRes = false;
                        }
                        var order = new OrderFlight();
                        if (orderFlights.Any(a => a.DeliveryDate == dt))
                        {
                            order = orderFlights.FirstOrDefault(a => a.DeliveryDate == dt);
                        }
                        else
                        {
                            order = new OrderFlight()
                            {
                                AirCompanyId  = 67,
                                AirCompany    = DataExtension.DataCatalogsSingleton.Instance.AllAirCompanies.SingleOrDefault(a => a.Id == 67),
                                FlightNumber  = dt.ToString("dd.MM.yyyy"),
                                DeliveryPlace = DataExtension.DataCatalogsSingleton.Instance.DeliveryPlaces.SingleOrDefault(a => a.Id == 4),
                                DeliveryDate  = dt,
                                CreatedById   = Authorization.CurentUser.Id,
                                DishPackages  = new List <DishPackageFlightOrder>(),
                                OrderStatus   = OrderStatus.InWork
                            };
                        }

                        while (GetExcelCellValue(ws, row, sColumn + 1) != "Итого" && row < maxExcelRow)
                        {
                            if (!dateParceRes)
                            {
                                row++; continue;
                            }
                            ;

                            try
                            {
                                int     rCode = Convert.ToInt32(GetExcelCellValue(ws, row, sColumn + 1));
                                decimal count = GetExcelCellValueDec(ws, row, sColumn + 3);
                                if (!DataExtension.DataCatalogsSingleton.Instance.Dishes.Any(a => a.SHGastroId == rCode))
                                {
                                    string name = GetExcelCellValue(ws, row, sColumn + 2);
                                    var    qres = UI.UIModify.ShowPromt($"Нашел неопознанное блюдо {Environment.NewLine}" +
                                                                        $" Дата {dt.ToString("dd.MM.yyyy")} {Environment.NewLine} " +
                                                                        $" {rCode}. {name} {Environment.NewLine} " +
                                                                        $"Продолжить без этого блюда?",
                                                                        header: "Неопознанное блюдо", confirm: true);

                                    if (!qres.DialogResult.GetValueOrDefault())
                                    {
                                        dateParceRes = false;
                                        skipDates.Add(dt);
                                        continue;
                                    }
                                    ;
                                    row++;
                                    continue;
                                }
                                var dish = DataExtension.DataCatalogsSingleton.Instance.Dishes.FirstOrDefault(a => a.SHGastroId == rCode);
                                var d    = new DishPackageFlightOrder()
                                {
                                    DishId          = dish.Id,
                                    Amount          = count,
                                    Printed         = true,
                                    TotalPrice      = dish.PriceForFlight,
                                    DishName        = dish.Name,
                                    PositionInOrder = order.DishPackages.Count + 1,
                                    Dish            = dish
                                };
                                order.DishPackages.Add(d);
                                row++;
                            }
                            catch (Exception e)
                            {
                                var qres = UI.UIModify.ShowPromt($"Ошибка в строке №{row} {Environment.NewLine}" +
                                                                 $" Дата {dt.ToString("dd.MM.yyyy")} {Environment.NewLine} " +
                                                                 $" Текст ошибки: {Environment.NewLine}  {e.Message} {Environment.NewLine} " +
                                                                 $"Продолжить без этой строки?",
                                                                 header: "Ошибка разбора xlsx", confirm: true);
                                dateParceRes = !qres.DialogResult.GetValueOrDefault();
                                if (!dateParceRes)
                                {
                                    skipDates.Add(dt);
                                }
                                continue;
                            }
                        }
                        if (dateParceRes)
                        {
                            if (order.DishPackages.Count > 0)
                            {
                                if (!orderFlights.Any(a => a.DeliveryDate == dt))
                                {
                                    orderFlights.Add(order);
                                }
                            }
                        }
                        row++;
                    }
                    sColumn += 5;
                    row      = 3;
                }
                return(true);
            }
            catch (Exception e)
            {
                UI.UIModify.ShowAlert($"Ошибка Parce {e.Message}");
                return(false);
            }
        }