//для печати документов заказов из МЛ, если есть при печати требуется их печать
        void PrintOrderDocumentsFromTheRouteList(RouteList routeList, IList <OrderDocumentType> orderDocumentTypes)
        {
            var orders = routeList.Addresses
                         .Where(a => a.Status != RouteListItemStatus.Transfered)
                         .Select(a => a.Order)
            ;

            foreach (var o in orders)
            {
                var orderPrinter = new EntitiyDocumentsPrinter(
                    o,
                    true,
                    //При массовой печати документов заказов из МЛ, в случае наличия у клиента признака UseSpecialDocFields, не будут печататься обычные счета и УПД
                    orderDocumentTypes.Where(t => !o.Client.UseSpecialDocFields || t != OrderDocumentType.UPD && t != OrderDocumentType.Bill).ToList()
                    );
                orderPrinter.PrintingCanceled += (sender, e) => {
                    cancelPrinting = true;
                    PrintingCanceled?.Invoke(sender, e);
                };
                ODTTemplateNotFoundMessages = string.Concat(orderPrinter.ODTTemplateNotFoundMessages);
                orderPrinter.Print();
                if (cancelPrinting)
                {
                    return;
                }
            }
        }
Example #2
0
        static public bool Print(IPrintableImage image)
        {
            currentImage = image;

            if (PrintSettings != null)
            {
                printOperationAction = PrintOperationAction.Print;
            }
            else
            {
                PrintSettings = new PrintSettings();
            }

            printOperation.PrintSettings = PrintSettings;
            PrintSettings.NCopies        = currentImage.CopiesToPrint;

            if (currentImage.Orientation == DocumentOrientation.Landscape)
            {
                printOperation.RequestPageSetup += PrintOperation_RequestPageSetup;
            }

            PrintSettings.Orientation = currentImage.Orientation == DocumentOrientation.Portrait ? PageOrientation.Portrait : PageOrientation.Landscape;

            printOperation.Run(printOperationAction, null);
            status = printOperation.Status;
            //если отмена из диалога печати
            if (status.HasValue && status.Value == PrintStatus.FinishedAborted)
            {
                PrintingCanceled?.Invoke(printOperation, new EventArgs());
                return(false);
            }

            PrintSettings = printOperation.PrintSettings;
            return(true);
        }
        private void DocPrinterInit()
        {
            MultiDocPrinter = new MultipleDocumentPrinter
            {
                PrintableDocuments = new GenericObservableList <SelectablePrintDocument>(DocumentsToPrint)
            };

            MultiDocPrinter.DocumentsPrinted += (o, args) => DocumentsPrinted?.Invoke(o, args);
            MultiDocPrinter.PrintingCanceled += (o, args) => PrintingCanceled?.Invoke(o, args);
        }
        public void PrintSelectedDocuments()
        {
            var prnbleDocs = PrintableDocuments.Where(d => d.Selected);

            if (!prnbleDocs.Any())
            {
                return;
            }

            List <IPrintableDocument> rdlToPrinter = new List <IPrintableDocument>();
            List <IPrintableDocument> odtToPrinter = new List <IPrintableDocument>();
            List <IPrintableDocument> imgToPrinter = new List <IPrintableDocument>();

            foreach (var document in prnbleDocs)
            {
                document.Document.CopiesToPrint = document.Copies;
                switch (document.Document.PrintType)
                {
                case PrinterType.ODT:
                    document.Document.CopiesToPrint = document.Copies;
                    odtToPrinter.Add(document.Document);
                    break;

                case PrinterType.RDL:
                    for (int i = 0; i < document.Copies; i++)
                    {
                        rdlToPrinter.Add(document.Document);
                    }
                    break;

                case PrinterType.Image:
                    for (int i = 0; i < document.Copies; i++)
                    {
                        imgToPrinter.Add(document.Document);
                    }
                    break;

                default:
                    throw new NotImplementedException("Печать документа не поддерживается");
                }
            }
            var printer = new DocumentPrinter(PrinterSettings);

            printer.DocumentsPrinted += (sender, e) => DocumentsPrinted?.Invoke(sender, e);
            printer.PrintingCanceled += (sender, e) => PrintingCanceled?.Invoke(sender, e);
            if (rdlToPrinter.Count > 0)
            {
                printer.PrintAll(rdlToPrinter);
            }
            DocumentPrinters.ImagePrinter?.Print(imgToPrinter.ToArray(), printer.PrintSettings);
            DocumentPrinters.OdtDocPrinter?.Print(odtToPrinter.ToArray(), printer.PrintSettings);
            PrinterSettings = printer.PrintSettings;
        }
 public void Print(SelectablePrintDocument document = null)
 {
     if (!cancelPrinting)
     {
         MultiDocPrinter.PrinterSettings = PrinterSettings;
         if (document == null)
         {
             MultiDocPrinter.PrintSelectedDocuments();
         }
         else
         {
             MultiDocPrinter.PrintDocument(document);
         }
         PrinterSettings = MultiDocPrinter.PrinterSettings;
     }
     else
     {
         PrintingCanceled?.Invoke(this, new EventArgs());
     }
 }
 void DocPrinterInit()
 {
     MultiDocPrinter = new MultipleDocumentPrinter {
         PrintableDocuments = new GenericObservableList <SelectablePrintDocument>(DocumentsToPrint)
     };
     MultiDocPrinter.DocumentsPrinted += (o, args) => {
         //если среди распечатанных документов есть МЛ, то выставляем его соответствующий признак в true
         if (args is EndPrintArgs endPrintArgs && endPrintArgs.Args.Cast <IPrintableDocument>().Any(d => d.Name == RouteListPrintableDocuments.RouteList.GetEnumTitle()))
         {
             using (IUnitOfWork uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                 var rl = uow.GetById <RouteList>(currentRouteList.Id);
                 rl.Printed = true;
                 uow.Save(rl);
                 uow.Commit();
             }
             uow?.Session?.Refresh(currentRouteList);
         }
         DocumentsPrinted?.Invoke(o, args);
     };
     MultiDocPrinter.PrintingCanceled += (o, args) => PrintingCanceled?.Invoke(o, args);
 }