Exemple #1
0
        public void PrintProducts(IEnumerable <Product> products, ProductBlock block = null)
        {
            try
            {
                var pathDocx = AppDomain.CurrentDomain.BaseDirectory + $"\\{Guid.NewGuid()}.docx";
                WordDocumentWriter docWriter = WordDocumentWriter.Create(pathDocx);
                docWriter.StartDocument();

                foreach (var product in products)
                {
                    docWriter.PrintParagraph($"{product}");
                    Print(docWriter, product, null, block);

                    var paragraphProperties = docWriter.CreateParagraphProperties();
                    paragraphProperties.PageBreakBefore = true;
                    docWriter.PrintParagraph(string.Empty, paragraphProperties);
                }


                docWriter.EndDocument();
                docWriter.Close();

                //var pathPdf = AppDomain.CurrentDomain.BaseDirectory + @"\ProductsDocument.pdf";
                //var documentCore = DocumentCore.Load(pathDocx);
                //documentCore.Save(pathPdf, SaveOptions.PdfDefault);

                System.Diagnostics.Process.Start(pathDocx);
                //System.Diagnostics.Process.Start(pathPdf);
            }
            catch (IOException ioException)
            {
                _container.Resolve <IMessageService>().ShowOkMessageDialog("Ошибка", ioException.PrintAllExceptions());
            }
        }
        /// <summary>
        /// Печать технических деталей ТКП
        /// </summary>
        /// <param name="docWriter"></param>
        /// <param name="offerUnitsGroupsByFacilities"></param>
        private void PrintTechnicalDetails(WordDocumentWriter docWriter, List <IGrouping <Facility, OfferUnitsGroup> > offerUnitsGroupsByFacilities)
        {
            var paragraphProperties = docWriter.CreateParagraphProperties();

            paragraphProperties.PageBreakBefore = true;

            Font fontHeader = docWriter.CreateFont();

            fontHeader.Bold = true;

            docWriter.PrintParagraph("Технические характеристики оборудования(в соответствии с позициями таблицы):", paragraphProperties, fontHeader);
            int positionNumber = 1;

            foreach (var offerUnitsGroupsByFacility in offerUnitsGroupsByFacilities)
            {
                foreach (var offerUnitsGroup in offerUnitsGroupsByFacility)
                {
                    docWriter.PrintParagraph($"{positionNumber++}. {offerUnitsGroup.Product} = {offerUnitsGroupsByFacility.Count()} шт.:");
                    _printProductService.Print(docWriter, offerUnitsGroup.Product.Model);

                    // включенное в состав оборудование
                    if (offerUnitsGroup.ProductsIncluded.Any())
                    {
                        docWriter.PrintParagraph("Дополнительное оборудование, включенное в состав:");
                        foreach (var productIncluded in offerUnitsGroup.ProductsIncluded)
                        {
                            docWriter.PrintParagraph($"{productIncluded.Model.Product} {productIncluded.Model.Amount} шт.:");
                            _printProductService.Print(docWriter, productIncluded.Model.Product);
                        }
                    }

                    docWriter.PrintParagraph(Environment.NewLine);
                }
            }
        }