public PhieuNhapHang_PrintPreview_ViewModel(string mapnk, string tennhanvien, string ngaylap, string tenncc, String diachi, string sdt, string fax, string tongtien, ObservableCollection <ListMatHangMua> list)
        {
            MaPhieuNhapKho = mapnk;
            TongTien       = tongtien;
            TenNhanVien    = tennhanvien;
            NgayLap        = ngaylap;
            TenNCC         = tenncc;
            DiaChi         = diachi;
            SDT            = sdt;
            Fax            = fax;
            ListMatHang    = list;
            Load();

            CloseWindowCommand = new RelayCommand <Window>((p) => { return(p == null ? false : true); }, (p) => {
                p.Close();
            });

            Print_Command = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) =>
            {
                var ex = p as Window;
                try
                {
                    System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(ex, "Print report");
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Cannot print");
                }
            });
        }
Beispiel #2
0
        private static PrintQueue GetPrintQueue()
        {
            PrintQueue printQueue = null;
            bool       finished   = false;

            //  window.Dispatcher.BeginInvoke(new Action(() =>
            // {
            System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();
            bool?bPrint = dlg.ShowDialog();

            if (bPrint.GetValueOrDefault())
            {
                printQueue = dlg.PrintQueue;
                try
                {
                    System.Printing.ValidationResult result = printQueue.MergeAndValidatePrintTicket(printQueue.UserPrintTicket, dlg.PrintTicket);
                    printQueue.UserPrintTicket = result.ValidatedPrintTicket;
                    printQueue.Commit();
                }
                catch (Exception ex)
                {
                }
            }
            //      finished = true;
            //   }));

            //   while (!finished)
            //       Thread.Sleep(10);

            return(printQueue);
        }
        /// <summary>
        /// Prints the screen image.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="rectangle">The rectangle.</param>
        public static void PrintScreenImage(UIElement source, double scale, Rectangle rectangle)
        {
            var dialog = new System.Windows.Controls.PrintDialog();

            var dialogResult = dialog.ShowDialog() ?? false;

            if (!dialogResult)
            {
                return;
            }

            using (var stream = GetScreenImageStream(source, scale, 100, new PngBitmapEncoder()))
            {
                var img = (Bitmap)Image.FromStream(stream);

                if (!rectangle.IsEmpty)
                {
                    img = img.Clone(rectangle.Contract(1), img.PixelFormat);
                }

                var bmpSource = BitmapToBitmapSource(img);

                var visual = new DrawingVisual();
                using (var dc = visual.RenderOpen())
                {
                    dc.DrawImage(bmpSource, new Rect {
                        Width = img.Width, Height = img.Height
                    });
                }

                var filename = $"screenshot_{DateTime.Now.ToString("yyyyMMddHHmm")}";

                dialog.PrintVisual(visual, filename);
            }
        }
        /// <summary>
        /// Prints this instance.
        /// </summary>
        public void Print()
        {
            using (new ApplicationWindowSession(ApplicationManager.MainWindow, true))
            {
                var dialog = new System.Windows.Controls.PrintDialog();

                var dialogResult = dialog.ShowDialog() ?? false;
                if (!dialogResult)
                {
                    return;
                }

                var flowDocument = new FlowDocument();

                var lines = this.Content.Split('\n');

                foreach (var line in lines)
                {
                    var myParagraph = new Paragraph {
                        Margin = new Thickness(0)
                    };
                    myParagraph.Inlines.Add(new Run(line));
                    flowDocument.Blocks.Add(myParagraph);
                }

                var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;

                dialog.PrintDocument(paginator, this.FullDisplayName);
            }
        }
Beispiel #5
0
        private void ButtonPrint_OnClick(object sender, RoutedEventArgs e)
        {
            var printDialog  = new System.Windows.Controls.PrintDialog();
            var dialogResult = printDialog.ShowDialog();

            ListBoxResult.Items.Add(dialogResult == true ? "DialogResult is true." : "DialogResult is false.");
        }
Beispiel #6
0
 private void Menu_print_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         printDialog.PrintVisual(image_main, "Page");
     }
 }
 public static void PrintArea(System.Windows.Media.Visual areaToPrint, string titleString)
 {
     System.Windows.Controls.PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
        if (printDlg.ShowDialog() == true)
        {
        printDlg.PrintVisual(areaToPrint, titleString);
        }
 }
 public void SavePrintTicket(PrintDialog dialog)
 {
     using (FileStream stream = new FileStream(Path.Combine(Settings.SessionFolder, ServiceProvider.Settings.DefaultSession.Name + "_printer.xml"), FileMode.Create))
     {
         dialog.PrintTicket.SaveTo(stream);
         stream.Close();
     }
 }
Beispiel #9
0
 public void Print()
 {
     System.Windows.Controls.PrintDialog dialog = new System.Windows.Controls.PrintDialog();
     if (dialog.ShowDialog() != true)
     {
         return;
     }
     dialog.PrintVisual(this, string.Empty);
 }
 protected void PrintCommandExecute()
 {
     System.Windows.Controls.PrintDialog dialog = new System.Windows.Controls.PrintDialog();
     if (dialog.ShowDialog() != true)
     {
         return;
     }
     dialog.PrintVisual(this, string.Empty);
 }
Beispiel #11
0
        private void PrintOnClick(object sender, RoutedEventArgs e)
        {
            var printDialog = new System.Windows.Controls.PrintDialog();

            if (printDialog.ShowDialog() == true)
            {
                printDialog.PrintVisual(GraphLayout, "Graph");
            }
        }
Beispiel #12
0
        private static void DoPrint(FrameworkElement grid)
        {
            var pd = new System.Windows.Controls.PrintDialog();

            if (pd.ShowDialog() == true)
            {
                pd.PrintVisual(grid, "appointments to print");
            }
        }
        private void BtnPrint_OnClick(object sender, RoutedEventArgs e)
        {
            PrintBtn.Visibility = Visibility.Hidden;

            PrintDialog print = new PrintDialog();

            print.PrintVisual(Grid, "Biografbilletter");

            PrintBtn.Visibility = Visibility.Visible;
        }
Beispiel #14
0
        public void PrintSalesReport(string receiptText)
        {
            try
            {
                var dlg = new PrintDialog();
                dlg.PrintTicket.CopyCount = 1;
                if (dlg.ShowDialog().GetValueOrDefault())
                {
                    // Create DrawingVisual and open DrawingContext.
                    DrawingVisual  vis = new DrawingVisual();
                    DrawingContext dc  = vis.RenderOpen();

                    FormattedText formtxt = new FormattedText(
                        receiptText,
                        CultureInfo.CurrentCulture,
                        FlowDirection.LeftToRight,
                        new Typeface(new FontFamily("GenericMonospace"),
                                     FontStyles.Normal, FontWeights.Bold,
                                     FontStretches.Normal),
                        12, Brushes.Black);

                    Size sizeText = new Size(formtxt.Width, formtxt.Height);

                    dc.DrawText(formtxt, new Point(_leftMargin, 25));
                    dc.Close();

                    switch (dlg.PrintTicket.PageOrientation)
                    {
                    case PageOrientation.Landscape:
                        vis.Transform =
                            new RotateTransform(-90, dlg.PrintableAreaWidth / 2,
                                                dlg.PrintableAreaWidth / 2);
                        break;

                    case PageOrientation.ReversePortrait:
                        vis.Transform =
                            new RotateTransform(180, dlg.PrintableAreaWidth / 2,
                                                dlg.PrintableAreaHeight / 2);
                        break;

                    case PageOrientation.ReverseLandscape:
                        vis.Transform =
                            new RotateTransform(90, dlg.PrintableAreaHeight / 2,
                                                dlg.PrintableAreaHeight / 2);
                        break;
                    }

                    // Finally, print the page.
                    dlg.PrintVisual(vis, "BB Copy");
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #15
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var section = new Section();

            section.Pane.ElementList.Add(new Text {
                Value = "My label"
            });
            var template = new Template(section);

            var documentProperties = new DocumentProperties();

            var sampleData = new DocumentData();

            DocumentData documentData = null;

            var debug = false;

            var dialog = new System.Windows.Controls.PrintDialog
            {
                UserPageRangeEnabled = false,
                SelectedPagesEnabled = false,
            };

            if (dialog.ShowDialog() == true)
            {
                var printerSettings = new PrinterSettings
                {
                    Copies      = (short)(dialog.PrintTicket.CopyCount ?? 1),
                    PrinterName = dialog.PrintQueue.FullName,
                };

                PageSizeInfo pageSizeInfo  = null;
                var          pageMediaSize = dialog.PrintTicket.PageMediaSize;
                if (pageMediaSize.PageMediaSizeName != null)
                {
                    try
                    {
                        pageSizeInfo = new PageSizeInfo(pageMediaSize.PageMediaSizeName.Value.ToString());
                    }
                    catch (ArgumentException)
                    {
                        pageSizeInfo = new PageSizeInfo((pageMediaSize.Width / 96) + "inch", (pageMediaSize.Height / 96) + "inch");
                    }
                }

                var renderer = new Renderer(template, documentData, documentProperties, pageSizeInfo, debug);

                //Send document to the printer
                renderer.Print(printerSettings);

                //Create a pdf for the same document
                var data = renderer.GetPdfBinary();
            }
        }
 private void btnPrint_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
     if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
     {
         Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
         // sizing of the element.
         stackPanelPrintArea.Measure(pageSize);
         stackPanelPrintArea.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));
         Printdlg.PrintVisual(stackPanelPrintArea, Title);
     }
 }
        private void printButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.PrintDialog prnt = new System.Windows.Controls.PrintDialog();

            if (prnt.ShowDialog() == true)
            {
                prnt.PrintVisual(EventInvoiceGrid, "Printing Grid");
            }
            EventsList    EL      = new EventsList(eventIdTextBlock.Text, EventCalculation.eventDate, EventCalculation.eventStartTime, EventCalculation.photographyCost, EventCalculation.decorationCost, EventCalculation.totalcenterCost, EventCalculation.vat, EventCalculation.discount, EventCalculation.totalCostWithVat, EventCalculation.advancePay, EventCalculation.remainingPay, EventCalculation.customerName, EventCalculation.customerContactNumber, EventCalculation.customerEmail, EventCalculation.customerAddress, "Pending");
            EventService  service = new EventService();
            int           x       = service.AddEvent(EL);
            CenterService cs      = new CenterService();

            cs.BookCenter(eventIdTextBlock.Text, EventCalculation.centerId);
            EventCalculation.eventDate            = "";
            EventCalculation.eventStartTime       = "";
            EventCalculation.eventEndTime         = "";
            EventCalculation.printedPhotos        = "";
            EventCalculation.eachPhotoCost        = "";
            EventCalculation.photographyCost      = 0;
            EventCalculation.decorationCost       = 0;
            EventCalculation.stage                = "";
            EventCalculation.homelight            = "";
            EventCalculation.homelightDuration    = "";
            EventCalculation.streetlight          = "";
            EventCalculation.streetlightDeuration = "";
            EventCalculation.gate                = "";
            EventCalculation.planaquin           = "";
            EventCalculation.centerName          = "";
            EventCalculation.centerLoaction      = "";
            EventCalculation.totalCostWithoutVat = 0;
            EventCalculation.totalcenterCost     = 0;
            EventCalculation.eventDuration       = "";
            EventCalculation.CostStage           = 0;
            EventCalculation.CostHomeLight       = 0;
            EventCalculation.CostStreetLight     = 0;
            EventCalculation.CostGate            = 0;
            EventCalculation.CostPlanaquin       = 0;
            EventCalculation.vat                   = 0;
            EventCalculation.discount              = 0;
            EventCalculation.totalCostWithVat      = 0;
            EventCalculation.customerName          = "";
            EventCalculation.customerContactNumber = "";
            EventCalculation.customerEmail         = "";
            EventCalculation.customerAddress       = "";
            EventCalculation.eventId               = "";
            EventCalculation.advancePay            = "";
            EventCalculation.remainingPay          = "";
            this.Close();
        }
Beispiel #18
0
        /// <summary>
        /// Print Excel file
        /// </summary>
        /// <param name="filePath"></param>
        public void PrintFile(string filePath)
        {
            var printers     = PrinterSettings.InstalledPrinters;
            int printerIndex = 0;
            var printDlg     = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                var excelApp = new Excel.Application();

                // Open the Workbook
                var wb = excelApp.Workbooks.Open(
                    filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                // Get the first worksheet which corresponds to MTCodes. (Excel uses base 1 indexing, not base 0.)
                var ws = (Excel.Worksheet)wb.Worksheets[1];
                ws.PageSetup.FitToPagesWide = 1;
                ws.PageSetup.FitToPagesTall = false;
                ws.PageSetup.Zoom           = false;
                wb.Save();

                // Identify the printer index based on the selected printer's name
                foreach (var printer in printers)
                {
                    if (printer.Equals(printDlg.PrintQueue.FullName))
                    {
                        break;
                    }
                    printerIndex++;
                }

                // Print out 1 copy to the default printer:
                ws.PrintOut(Type.Missing, Type.Missing, 1, Type.Missing,
                            printers[printerIndex], Type.Missing, Type.Missing, Type.Missing);

                // Cleanup
                GC.Collect();
                GC.WaitForPendingFinalizers();

                Marshal.FinalReleaseComObject(ws);

                wb.Close(false, filePath, Type.Missing);
                Marshal.FinalReleaseComObject(wb);

                excelApp.Quit();
                Marshal.FinalReleaseComObject(excelApp);
            }
        }
 private void BImprimir_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         this.IsEnabled = false;
         System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
         if (printDialog.ShowDialog() == true)
         {
             printDialog.PrintVisual(print, "informe");
         }
     }
     finally
     {
         this.IsEnabled = true;
     }
 }
Beispiel #20
0
        private void printimage(System.Windows.Media.ImageSource bi)
        {
            var vis = new System.Windows.Media.DrawingVisual();

            System.Windows.Media.DrawingContext dc = vis.RenderOpen();
            dc.DrawImage(bi, new System.Windows.Rect {
                Width = bi.Width, Height = bi.Height
            });
            dc.Close();

            var pdialog = new System.Windows.Controls.PrintDialog();
            //  if (pdialog.ShowDialog() == true)
            {
                pdialog.PrintVisual(vis, "My Image");
            }
        }
        public void Print(FlowDocument fd)
        {
            var pd = new System.Windows.Controls.PrintDialog();

            if (pd.ShowDialog().Value)
            {
                IDocumentPaginatorSource document = fd as IDocumentPaginatorSource;
                try
                {
                    pd.PrintDocument(document.DocumentPaginator, "Printing FlowDocument.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #22
0
        public void print_flowDocument()
        {
            // Create a PrintDialog
            var printDlg = new System.Windows.Controls.PrintDialog();

            // Create a FlowDocument dynamically.
            FlowDocument doc = CreateFlowDocument();

            doc.Name = "FlowDoc";

            // Create IDocumentPaginatorSource from FlowDocument
            IDocumentPaginatorSource idpSource = doc;

            // Call PrintDocument method to send document to printer
            //printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing.");
            printDlg.PrintVisual(this, "Hello WPF Printing.");
        }
Beispiel #23
0
 public ReportCardWindowsGUIMerger(Options options)
 {
     InitializeComponent();
     this.TemplateGood = false;
     this.DatasourceGood = false;
     this.templatepath = options.TemplateName;
     this.datasourcepath = options.DataSourceName;
     this.savetopath = options.SaveDir;
     this.SaveToGood = Directory.Exists(options.SaveDir);
     this.exportpdf = options.ExportPdf;
     this.exportpub = options.ExportPub;
     this.usewingdingticks = options.UseWingdingTicks;
     this.initialnames = options.Names;
     this.pdPrint = new System.Windows.Controls.PrintDialog();
     this.worker = new ReportCardWorker();
     this.worker.UseWingdingTicks = options.UseWingdingTicks;
 }
        public void LoadPrintTicket(PrintDialog dialog)
        {
            string configFile = Path.Combine(Settings.SessionFolder, ServiceProvider.Settings.DefaultSession.Name + "_printer.xml");

            PrintTicket defaultTicket;

            try
            {
                defaultTicket = dialog.PrintQueue.UserPrintTicket ?? dialog.PrintQueue.DefaultPrintTicket;
            }
            catch (Exception e)
            {
                Log.Error("Unable to load printer settings.", e);
                return;
            }

            if (File.Exists(configFile))
            {
                try
                {
                    using (FileStream stream = new FileStream(configFile, FileMode.Open))
                    {
                        PrintTicket newTicket = new PrintTicket(stream);

                        System.Printing.ValidationResult result = dialog.PrintQueue.MergeAndValidatePrintTicket(defaultTicket, newTicket);
                        dialog.PrintTicket = result.ValidatedPrintTicket;
                        stream.Close();
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Unable to load printer settings.", e);
                    dialog.PrintTicket = defaultTicket;
                }
            }
            else
            {
                if (defaultTicket != null)
                {
                    dialog.PrintTicket = defaultTicket;
                }
            }
        }
Beispiel #25
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var a = true;

            if (a)
            {
                return;
            }

            System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
            if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
            {
                Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
                // sizing of the element.
                dataGrid1.Measure(pageSize);
                dataGrid1.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));
                Printdlg.PrintVisual(dataGrid1, Title);
            }
        }
Beispiel #26
0
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            //<Print>
            // Configure printer dialog box
            var dialog = new System.Windows.Controls.PrintDialog();

            dialog.PageRangeSelection   = System.Windows.Controls.PageRangeSelection.AllPages;
            dialog.UserPageRangeEnabled = true;

            // Show save file dialog box
            bool?result = dialog.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Document was printed
            }
            //</Print>
        }
 public override void ExecutePrint(object parameter)
 {
     try
     {
         var printDialog = new System.Windows.Controls.PrintDialog();
         printDialog.PrintQueue  = CurrentPrinter;
         printDialog.PrintTicket = CurrentPrinter.UserPrintTicket;
         ShowProgressDialog();
         ((VisualPaginator)Paginator).PageCreated += PrintControlPresenterPageCreated;
         printDialog.PrintDocument(Paginator, "");
     }
     catch (Exception)
     {
     }
     finally
     {
         ProgressDialog.Hide();
     }
 }
        private void PrintBill()
        {
            // print
            try
            {
                PrintDialog   printDialog   = new PrintDialog();
                PrintDocument printDocument = new PrintDocument();

                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(_CreateReceipt); //add an event handler that will do the printing

                if (printDialog.ShowDialog() == true)
                {
                    printDocument.Print();
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #29
0
 public override void ExecutePrint(object parameter)
 {
     try
     {
         var printDialog = new System.Windows.Controls.PrintDialog();
         printDialog.PrintQueue  = CurrentPrinter;
         printDialog.PrintTicket = CurrentPrinter.UserPrintTicket;
         ShowProgressDialog();
         ((VisualPaginator)Paginator).PageCreated += PrintControlPresenterPageCreated;
         printDialog.PrintDocument(Paginator, "");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     finally
     {
         ProgressDialog.Hide();
     }
 }
 public override void ExecutePrint(object parameter)
 {
     try
     {
         var printDialog = new System.Windows.Controls.PrintDialog();
         printDialog.PrintQueue = CurrentPrinter;
         printDialog.PrintTicket = CurrentPrinter.UserPrintTicket;
         ShowProgressDialog();
         ((VisualPaginator)Paginator).PageCreated += PrintControlPresenterPageCreated;
         printDialog.PrintDocument(Paginator, "");
     }
     catch (Exception)
     {
     }
     finally
     {
         ProgressDialog.Hide();
     }
 }
    /// <summary>
    /// Handles the Click event of the menuItemPrint control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    private void OnPrintMenuItemClick(object sender, EventArgs e)
    {
      System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
      if (printDialog.ShowDialog().Equals(false))
      {
        return;
      }

      using (ContextHelper.CreatePrintScope(this.elementHost.Child as DiagramViewer, printDialog))
      {
        // nothing to do here
        Logger.Current.Info(string.Format(CultureInfo.InvariantCulture, "Diagram printed to {0}", printDialog.PrintQueue.FullName));
      }
    }
Beispiel #32
0
        private void PrintDayOfTicket(List <SaleItem> items, string name, DateTime date, string orderNumber,
                                      string tableNumber, bool isToGo, bool isWalkUp, string printerName, bool isPrintQrCode, string notes, string footer)
        {
            try
            {
                var dlg = new PrintDialog();
                if (!string.IsNullOrEmpty(printerName))
                {
                    try
                    {
                        dlg.PrintQueue = new PrintQueue(new PrintServer(), printerName);
                    }
                    catch
                    {
                    }
                }
                dlg.PrintTicket.CopyCount = 1;

                if (dlg.ShowDialog().GetValueOrDefault())
                {
                    // Create DrawingVisual and open DrawingContext.
                    DrawingVisual  vis = new DrawingVisual();
                    DrawingContext dc  = vis.RenderOpen();

                    var receiptText = "Most Precious Blood" + Environment.NewLine + "Catholic Church" + Environment.NewLine + Environment.NewLine;
                    receiptText += "Lenten Fish Fry" + Environment.NewLine + Environment.NewLine;
                    receiptText += "Presented by the" + Environment.NewLine + "Men's Fellowship" + Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += "Order Number: " + Environment.NewLine + orderNumber + Environment.NewLine + Environment.NewLine;
                    receiptText += "Transaction Date: " + Environment.NewLine;
                    receiptText += DateTime.Now.ToString("MM/dd/yy HH:mm:ss") + Environment.NewLine + Environment.NewLine;
                    receiptText += "Name: " + Environment.NewLine + name.ToUpper() + Environment.NewLine + Environment.NewLine;
                    receiptText += "Seating Time: " + Environment.NewLine + date.ToString("MM/dd/yy HH:mm") + Environment.NewLine + Environment.NewLine;

                    var    itemList     = items.OrderByDescending(x => x.Price).ThenBy(x => x.Name).Select(x => x.Name).Distinct();
                    double runningTotal = 0;
                    foreach (var item in itemList)
                    {
                        var count = items.Count(x => x.Name == item);
                        var price = items.First(x => x.Name == item).Price;
                        var total = count * price;
                        runningTotal += total;
                        //Full Fried (5 x $5).......... $25
                        receiptText += string.Format("{0} ({1} x ${2})....... ${3}{4}", item, count, price, total, Environment.NewLine);
                    }
                    receiptText += Environment.NewLine + Environment.NewLine + "Total Sale: $" + runningTotal;

                    if (!string.IsNullOrEmpty(notes))
                    {
                        receiptText += Environment.NewLine + Environment.NewLine + "Notes:" + Environment.NewLine;
                        if (!ShouldBreakUpNotes(notes))
                        {
                            receiptText += notes + Environment.NewLine;
                        }
                        else
                        {
                            //while (notes.Length >= _notesCharacters)
                            //{
                            //var line = "";
                            //while (line.Length < _notesCharacters && (notes.Contains(" ") || notes.Contains(Environment.NewLine)))
                            //{
                            //    var index = 0;
                            //    var delimeter = " ";
                            //    if (notes.IndexOf(" ") > 0)
                            //    {
                            //        index = notes.IndexOf(" ");
                            //    }
                            //    if (notes.IndexOf(Environment.NewLine) > 0 &&
                            //        notes.IndexOf(Environment.NewLine) < index)
                            //    {
                            //        index = notes.IndexOf(Environment.NewLine);
                            //        delimeter = Environment.NewLine;
                            //    }
                            //    if (line.Length > 0)
                            //    {
                            //        line += delimeter;
                            //    }
                            //    if (index == 0)
                            //    {
                            //        index = _notesCharacters;
                            //    }

                            //    line += notes.Substring(0, index).Trim();
                            //    notes = notes.Substring(index).Trim();
                            //    if (delimeter == Environment.NewLine)
                            //    {
                            //        break;
                            //    }
                            //}
                            receiptText += notes.Replace(" ", Environment.NewLine) + Environment.NewLine;
                            //}
                        }
                        receiptText += Environment.NewLine;
                        receiptText += Environment.NewLine;
                        receiptText += "." + Environment.NewLine;
                        receiptText += Environment.NewLine;
                    }

                    double top = 25;

                    if (!string.IsNullOrEmpty(tableNumber))
                    {
                        FormattedText formattedTextTableNumber = new FormattedText(
                            tableNumber + Environment.NewLine,
                            CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight,
                            new Typeface(new FontFamily("GenericMonospace"),
                                         FontStyles.Normal, FontWeights.Bold,
                                         FontStretches.Normal),
                            36, Brushes.Black);
                        Size sizeTableNumberText = new Size(formattedTextTableNumber.Width,
                                                            formattedTextTableNumber.Height);
                        dc.DrawText(formattedTextTableNumber, new Point(_leftMargin, top));
                        top += sizeTableNumberText.Height;
                    }

                    FormattedText formtxt = new FormattedText(
                        receiptText,
                        CultureInfo.CurrentCulture,
                        FlowDirection.LeftToRight,
                        new Typeface(new FontFamily("GenericMonospace"),
                                     FontStyles.Normal, FontWeights.Bold,
                                     FontStretches.Normal),
                        12, Brushes.Black);

                    Size sizeText = new Size(formtxt.Width, formtxt.Height);
                    dc.DrawText(formtxt, new Point(_leftMargin, top));
                    top += sizeText.Height;

                    if (isPrintQrCode)
                    {
                        var image = GetCode(orderNumber);

                        BitmapImage imgSrc = new BitmapImage();
                        imgSrc.BeginInit();
                        imgSrc.StreamSource = new MemoryStream(ImageToByte(image));
                        imgSrc.EndInit();

                        dc.DrawImage(imgSrc, new Rect(new Point(_leftMargin, top), new Point(_leftMargin + 200, 225 + top)));
                        top += 225;
                    }

                    if (isToGo)
                    {
                        FormattedText formattedTextToGo = new FormattedText(
                            Environment.NewLine + "TAKE OUT" + Environment.NewLine,
                            CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight,
                            new Typeface(new FontFamily("GenericMonospace"),
                                         FontStyles.Normal, FontWeights.Bold,
                                         FontStretches.Normal),
                            36, Brushes.Black);
                        dc.DrawText(formattedTextToGo, new Point(_leftMargin, top));
                        Size sizeTextToGo = new Size(formattedTextToGo.Width, formattedTextToGo.Height);
                        top += sizeTextToGo.Height;
                    }

                    if (isWalkUp)
                    {
                        FormattedText formattedTextWalkUp = new FormattedText(
                            Environment.NewLine + "WALK UP" + Environment.NewLine + Environment.NewLine,
                            CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight,
                            new Typeface(new FontFamily("GenericMonospace"),
                                         FontStyles.Normal, FontWeights.Bold,
                                         FontStretches.Normal),
                            36, Brushes.Black);
                        dc.DrawText(formattedTextWalkUp, new Point(_leftMargin, top));
                    }
                    if (!string.IsNullOrEmpty(footer))
                    {
                        FormattedText footerText = new FormattedText(
                            footer,
                            CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight,
                            new Typeface(new FontFamily("GenericMonospace"),
                                         FontStyles.Normal, FontWeights.Bold,
                                         FontStretches.Normal),
                            12, Brushes.Black);

                        dc.DrawText(footerText, new Point(_leftMargin, top));
                    }
                    dc.Close();

                    switch (dlg.PrintTicket.PageOrientation)
                    {
                    case PageOrientation.Landscape:
                        vis.Transform =
                            new RotateTransform(-90, dlg.PrintableAreaWidth / 2,
                                                dlg.PrintableAreaWidth / 2);
                        break;

                    case PageOrientation.ReversePortrait:
                        vis.Transform =
                            new RotateTransform(180, dlg.PrintableAreaWidth / 2,
                                                dlg.PrintableAreaHeight / 2);
                        break;

                    case PageOrientation.ReverseLandscape:
                        vis.Transform =
                            new RotateTransform(90, dlg.PrintableAreaHeight / 2,
                                                dlg.PrintableAreaHeight / 2);
                        break;
                    }

                    // Finally, print the page.
                    dlg.PrintVisual(vis, "BB Copy");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #33
0
        private void GenerateReport()
        {
            System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
            if ((bool)printDialog.ShowDialog().GetValueOrDefault())
            {
                FlowDocument  flowDocument = new FlowDocument();
                Paragraph     paragraph;
                Table         table = new Table();
                TableRowGroup rg    = new TableRowGroup();
                TableRow      row   = new TableRow();

                table.CellSpacing        = 0;
                row.FontFamily           = new System.Windows.Media.FontFamily("Calibri");
                row.FontSize             = 10;
                flowDocument.ColumnWidth = printDialog.PrintableAreaWidth;
                flowDocument.PageHeight  = printDialog.PrintableAreaHeight;

                int columnCount = 9;

                //Report Header and Simulation Parameters and Settings
                //Title and Haskell Logo
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 36;
                paragraph.Inlines.Add(new Run("Simulation Report"));

                BitmapImage bm = new BitmapImage(new Uri(@"C:\Users\acduniga\source\repos\OEE_Utility\OEE_ExcelAddIn_2010\Resources\Images\Haskell_Logo.png", UriKind.Absolute));
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Height = 50;
                image.Width  = 300;
                image.Source = bm;
                Figure figure = new Figure();
                figure.Height           = new FigureLength(100);
                figure.Width            = new FigureLength(310);
                figure.HorizontalAnchor = FigureHorizontalAnchor.PageRight;
                figure.VerticalAnchor   = FigureVerticalAnchor.PageTop;
                figure.Blocks.Add(new BlockUIContainer(image));

                paragraph.Inlines.Add(figure);
                flowDocument.Blocks.Add(paragraph);

                //Simulation Number of Runs
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Number of Runs: {0}", num_runs));
                flowDocument.Blocks.Add(paragraph);

                //Simulation Minutes per Run
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Minutes per Run: {0}", Sim_Time_Minutes));
                flowDocument.Blocks.Add(paragraph);

                //Simulation Start Time
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Simulation Started at: {0}", DateTime.Now.ToString()));
                flowDocument.Blocks.Add(paragraph);

                //Simulation Computation Time
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Simulation Computation Time: {0} seconds", simtime));
                flowDocument.Blocks.Add(paragraph);

                //
                paragraph        = new Paragraph();
                paragraph.Margin = new Thickness(0);
                paragraph.Inlines.Add(new Run(" "));
                flowDocument.Blocks.Add(paragraph);

                //Overall run OEE Statistics header
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 24;
                paragraph.Inlines.Add("OEE Performance Statistics");
                paragraph.TextAlignment = TextAlignment.Center;
                flowDocument.Blocks.Add(paragraph);

                //Average OEE
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Average OEE: {0}%", average));
                paragraph.TextAlignment = TextAlignment.Center;
                flowDocument.Blocks.Add(paragraph);

                //Maximum OEE
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Maximum OEE: {0}%", max));
                paragraph.TextAlignment = TextAlignment.Center;
                flowDocument.Blocks.Add(paragraph);

                //Minimum OEE
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("Minimum OEE: {0}%", min));
                paragraph.TextAlignment = TextAlignment.Center;
                flowDocument.Blocks.Add(paragraph);

                //Standard Deviation of OEEs
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("OEE Standard Deviation: {0}%", stddev));
                paragraph.TextAlignment = TextAlignment.Center;
                flowDocument.Blocks.Add(paragraph);

                //95% quantile of OEE
                paragraph            = new Paragraph();
                paragraph.Margin     = new Thickness(0);
                paragraph.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                paragraph.FontSize   = 14;
                paragraph.Inlines.Add(String.Format("95% OEE Quantile: {0}%", high_quantile));
                paragraph.TextAlignment = TextAlignment.Center;
                flowDocument.Blocks.Add(paragraph);

                //
                paragraph        = new Paragraph();
                paragraph.Margin = new Thickness(0);
                paragraph.Inlines.Add(new Run(" "));
                flowDocument.Blocks.Add(paragraph);

                //Table of unit op data
                for (int i = 0; i < columnCount; i++)
                {
                    table.Columns.Add(new TableColumn());

                    switch (i)
                    {
                    case 0:
                        table.Columns[i].Name  = "Unit_Op";
                        table.Columns[i].Width = new GridLength(140);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Unit Op"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Left;
                        break;

                    case 1:
                        table.Columns[i].Name  = "Design_Speed";
                        table.Columns[i].Width = new GridLength(70);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Design Speed"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 2:
                        table.Columns[i].Name  = "Actual_Speed";
                        table.Columns[i].Width = new GridLength(70);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Actual Speed"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 3:
                        table.Columns[i].Name  = "MTTR";
                        table.Columns[i].Width = new GridLength(40);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("MTTR"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 4:
                        table.Columns[i].Name  = "MTBF";
                        table.Columns[i].Width = new GridLength(40);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("MTBF"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 5:
                        table.Columns[i].Name  = "Availability_Percentage";
                        table.Columns[i].Width = new GridLength(70);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Availability (%)"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 6:
                        table.Columns[i].Name  = "Quality_Loss_Percentage";
                        table.Columns[i].Width = new GridLength(75);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Quality Loss (%)"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 7:
                        table.Columns[i].Name  = "Buffer";
                        table.Columns[i].Width = new GridLength(35);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Buffer"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;

                    case 8:
                        table.Columns[i].Name  = "Average_OEE";
                        table.Columns[i].Width = new GridLength(60);
                        row.Cells.Add(new TableCell(new Paragraph(new Run("Average OEE"))));
                        row.Cells[i].BorderThickness = new Thickness(0, 0, 0, 0.5);
                        row.Cells[i].BorderBrush     = new SolidColorBrush(Colors.DarkGray);
                        row.Cells[i].TextAlignment   = TextAlignment.Right;
                        break;
                    }
                }
                rg.Rows.Add(row);

                int  k          = 0; //Used to track Unit_Ops
                bool alternator = false;
                foreach (IOperations iop in process.Activities)
                {
                    row            = new TableRow();
                    row.FontFamily = new System.Windows.Media.FontFamily("Calibri");
                    row.FontSize   = 10;

                    if (iop.IsUnitOp())
                    {
                        Unit_Op  op = (Unit_Op)iop;
                        string   temp_availability = Math.Round(((double)op.MTBF / (double)(op.MTTR + op.MTBF)) * 100, 2).ToString();
                        string   temp_qualityloss  = (op.QualityLoss * 100).ToString();
                        string   temp_averageoee   = Math.Round((oee[k].Average()) * 100, 2).ToString();
                        string[] precise_strings   = UnifyStringPrecision(temp_availability, temp_qualityloss, temp_averageoee);

                        row.Cells.Add(new TableCell(new Paragraph(new Run(op.Name))));
                        row.Cells[0].TextAlignment = TextAlignment.Left;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(op.DesignSpeed.ToString()))));
                        row.Cells[1].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run((op.DesignSpeed - op.SpeedLoss).ToString()))));
                        row.Cells[2].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run((op.MTTR / 60).ToString()))));
                        row.Cells[3].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run((op.MTBF / 60).ToString()))));
                        row.Cells[4].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(precise_strings[0]))));
                        row.Cells[5].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(precise_strings[1]))));
                        row.Cells[6].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run("-"))));
                        row.Cells[7].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(precise_strings[2]))));
                        row.Cells[8].TextAlignment = TextAlignment.Right;
                        k++;
                    }
                    else if (iop.IsBuffer())
                    {
                        Buffer buff = (Buffer)iop;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(buff.Name))));
                        row.Cells[0].TextAlignment = TextAlignment.Left;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(buff.DesignSpeed.ToString()))));
                        row.Cells[1].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(buff.DesignSpeed.ToString()))));
                        row.Cells[2].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run("-"))));
                        row.Cells[3].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run("-"))));
                        row.Cells[4].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run("-"))));
                        row.Cells[5].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run("-"))));
                        row.Cells[6].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run(buff.Buffer_Capacity.ToString()))));
                        row.Cells[7].TextAlignment = TextAlignment.Right;
                        row.Cells.Add(new TableCell(new Paragraph(new Run("-"))));
                        row.Cells[8].TextAlignment = TextAlignment.Right;
                    }

                    rg.Rows.Add(row);
                    if (!alternator)
                    {
                        //rg.Rows[rg.Rows.Count - 1].Background = new SolidColorBrush(Colors.LightGray);
                        alternator = true;
                    }
                    else
                    {
                        alternator = false;
                    }
                }

                table.CellSpacing = 0;
                table.RowGroups.Add(rg);

                int table_width = 0;
                foreach (TableColumn column in table.Columns)
                {
                    table_width = table_width + (int)column.Width.Value;
                }
                table.Margin = new Thickness(((int)flowDocument.ColumnWidth - table_width - 50) / 2, 0, 0, 0);
                flowDocument.Blocks.Add(table);

                for (int i = 0; i < buffer_fill.Count; i++)
                {
                    int[] xvals = new int[buffer_fill[i].Length];
                    for (int j = 0; j < buffer_fill[i].Length; j++)
                    {
                        xvals[j] = j + 1;
                    }

                    Chart buff_chart = new Chart();
                    buff_chart.Size = new System.Drawing.Size(1600, 450);
                    ChartArea area = new ChartArea();
                    area.Name        = buffers[i].Name;
                    area.AxisX.Title = "Simulation Minutes";
                    area.AxisY.Title = "Buffer Fill (%)";
                    area.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
                    area.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
                    area.AxisX.LabelStyle.Font     = new Font("Calibri", 10);
                    area.AxisY.LabelStyle.Font     = new Font("Calibri", 10);
                    buff_chart.ChartAreas.Add(area);

                    Series series = new Series();
                    series.Name       = "Buffer Fill (%)";
                    series.ChartType  = SeriesChartType.Line;
                    series.XValueType = ChartValueType.Int32;
                    series.YValueType = ChartValueType.Auto;
                    buff_chart.Series.Add(series);

                    buff_chart.Titles.Add(buffers[i].Name);
                    buff_chart.Titles[0].Font = new Font("Calibra", 14, System.Drawing.FontStyle.Bold);
                    buff_chart.Titles[0].DockedToChartArea = buffers[i].Name;

                    double[] yvalues = buffer_fill[i].Select(x => (double)x / ((Buffer)process.Activities[3]).Buffer_Capacity).ToArray();

                    buff_chart.Series["Buffer Fill (%)"].Points.DataBindXY(xvals, yvalues);

                    buff_chart.Invalidate();
                    Bitmap chart_bmp = new Bitmap(buff_chart.Size.Width, buff_chart.Size.Height);
                    buff_chart.DrawToBitmap(chart_bmp, new Rectangle(0, 0, chart_bmp.Size.Width, chart_bmp.Size.Height));

                    BitmapImage chart_bi = new BitmapImage();
                    chart_bi = chart_bmp.ToBitmapImage();
                    System.Windows.Controls.Image chart_img = new System.Windows.Controls.Image();
                    chart_img.Height        = 210;
                    chart_img.Width         = 700;
                    chart_img.Source        = chart_bi;
                    figure                  = new Figure();
                    figure.Height           = new FigureLength(220);
                    figure.Width            = new FigureLength(700);
                    figure.HorizontalAnchor = FigureHorizontalAnchor.ColumnCenter;
                    figure.Blocks.Add(new BlockUIContainer(chart_img));

                    paragraph = new Paragraph();
                    paragraph.Inlines.Add(figure);
                    flowDocument.Blocks.Add(paragraph);
                }

                DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
                printDialog.PrintDocument(paginator, "Simulation Report " + DateTime.Now.ToString());
            }
        }
Beispiel #34
0
        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
          System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
          if (printDialog.ShowDialog().Equals(false))
          {
            return;
          }

          using (ContextHelper.CreatePrintScope(this.elementHost.Child as DiagramViewer, printDialog))
          {
            // Print scope will print out the file to the appropriate printer.
            // no further processing necessary at this point (for now).
            Logger.Current.Info(string.Format("Diagram printed to {0}", printDialog.PrintQueue.FullName));
          }
        }
Beispiel #35
0
 private void PrintOnClick(object sender, RoutedEventArgs e)
 {
     var printDialog = new System.Windows.Controls.PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         printDialog.PrintVisual(GraphLayout, "Graph");
     }
 }
Beispiel #36
0
        protected MatrixBase()
        {
            this.CommandCopyToClipboard = new DelegateCommand(
                this.CopyToClipboard,
                () =>
            {
                return(this.HasData);
            });

            this.CommandPrint = new DelegateCommand(
                () =>
            {
                var section           = Helpers.FormatHelper.MatrixToFlowDocumentSectionWithTable(this);
                var flowDocument      = new System.Windows.Documents.FlowDocument(section);
                flowDocument.FontSize = 11d;

                System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
                System.Printing.PrintTicket pt         = new System.Printing.PrintTicket();
                pt.PageOrientation = System.Printing.PageOrientation.Landscape;
                pd.PrintTicket     = pd.PrintQueue.MergeAndValidatePrintTicket(pd.PrintQueue.DefaultPrintTicket, pt).ValidatedPrintTicket;

                System.Windows.Documents.IDocumentPaginatorSource fdd = flowDocument;
                flowDocument.PageWidth   = pd.PrintableAreaWidth;
                flowDocument.PageHeight  = pd.PrintableAreaHeight;
                flowDocument.ColumnWidth = pd.PrintableAreaWidth;
                flowDocument.PagePadding = new Thickness(30.0, 50.0, 20.0, 30.0);
                flowDocument.IsOptimalParagraphEnabled = true;
                flowDocument.IsHyphenationEnabled      = true;

                var ms = new System.IO.MemoryStream();
                using (var pkg = System.IO.Packaging.Package.Open(ms, System.IO.FileMode.Create))
                {
                    using (System.Windows.Xps.Packaging.XpsDocument doc = new System.Windows.Xps.Packaging.XpsDocument(pkg))
                    {
                        System.Windows.Xps.XpsDocumentWriter writer = System.Windows.Xps.Packaging.XpsDocument.CreateXpsDocumentWriter(doc);
                        writer.Write(fdd.DocumentPaginator);
                    }
                }

                ms.Position = 0;
                var pkg2    = System.IO.Packaging.Package.Open(ms);

                // Read the XPS document into a dynamically generated
                // preview Window
                var url = new Uri("memorystream://printstream");
                System.IO.Packaging.PackageStore.AddPackage(url, pkg2);
                try
                {
                    using (System.Windows.Xps.Packaging.XpsDocument doc = new System.Windows.Xps.Packaging.XpsDocument(pkg2, System.IO.Packaging.CompressionOption.SuperFast, url.AbsoluteUri))
                    {
                        System.Windows.Documents.FixedDocumentSequence fds = doc.GetFixedDocumentSequence();

                        Window wnd = new Window();
                        wnd.Title  = string.Format("Предварительный просмотр :: {0}", this.Header);
                        wnd.Owner  = Application.Current.MainWindow;
                        System.Windows.Media.TextOptions.SetTextFormattingMode(wnd, System.Windows.Media.TextFormattingMode.Display);
                        wnd.Padding = new Thickness(2);
                        wnd.Content = new System.Windows.Controls.DocumentViewer()
                        {
                            Document = fds,
                        };
                        wnd.ShowDialog();
                    }
                }
                finally
                {
                    System.IO.Packaging.PackageStore.RemovePackage(url);
                }
            },
                () =>
            {
                return(this.HasData);
            });

            this.CommandRefresh = new DelegateCommand(this.Build, () => this.HasData);
        }
        public override void ExecutePrint(object parameter)
        {
            try
            {
                var printDialog = new System.Windows.Controls.PrintDialog();
                printDialog.PrintQueue = CurrentPrinter;
                printDialog.PrintTicket = CurrentPrinter.UserPrintTicket;
                ShowProgressDialog();
                ((VisualPaginator)Paginator).PageCreated += PrintControlPresenterPageCreated;
				printDialog.PrintDocument(Paginator, "");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ProgressDialog.Hide();
            }
        }