/// <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); } }
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); } } }
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(); } }
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(); } }
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()); } }
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(); } }