private void MenuItem_FilePrint(object sender, RoutedEventArgs e) { PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; // Display the dialog. This returns true if the user presses the Print button. Nullable <Boolean> print = pDialog.ShowDialog(); if (print == true) { FlowDocument doc = new FlowDocument(); doc.PageHeight = pDialog.PrintableAreaHeight; doc.PageWidth = pDialog.PrintableAreaWidth; doc.ColumnWidth = doc.PageWidth; doc.FontFamily = new FontFamily("Courier"); doc.FontSize = 11; #region Print mash part StringBuilder strbcs = new StringBuilder(); StringBuilder strbmash = new StringBuilder(); StringBuilder strbferm = new StringBuilder(); foreach (GristPart g in Grist) { switch (g.Stage) { case FermentableStage.ColdSteep: strbcs.Append("Add " + g.ToString() + "\n"); break; case FermentableStage.Mash: strbmash.Append("Add " + g.ToString() + "\n"); break; case FermentableStage.Fermentor: strbferm.Append("Add " + g.ToString() + "\n"); break; default: break; } } var recepieHeading = new Paragraph(new Bold(new Run(String.Format("Recipe for {0}, approx. {1:F1} L in fermentor", NameTextBox.Text, Volumes.FinalBatchVolume)))); var mashHeading = new Paragraph(new Bold(new Run("Mash"))); mashHeading.FontSize = recepieHeading.FontSize = 18; doc.Blocks.Add(recepieHeading); doc.Blocks.Add(mashHeading); if (Grist.Any(x => x.Stage == FermentableStage.ColdSteep)) { Paragraph pcs = new Paragraph(); pcs.Inlines.Add(new Bold(new Run("Cold steep, 24 before brew start:\n"))); pcs.Inlines.Add(new Run(strbcs.ToString())); doc.Blocks.Add(pcs); } Paragraph pcsw = new Paragraph(); pcsw.Inlines.Add(new Run(String.Format("Mix with {0:F1} cold water\n", (Volumes.ColdSteepVolume * (1 - ColdSteep.COLDSTEEP_VOLUME_TO_SPARGE_RATIO))))); Paragraph pm = new Paragraph(); pm.Inlines.Add(new Bold(new Run("Normal step mash:\n"))); pm.Inlines.Add(new Run(String.Format("Add {0:F1} liters of water to Grainfather for mashing\n\n", GrainfatherCalculator.CalcMashVolume(GrainBillSize)))); pm.Inlines.Add(new Run(strbmash.ToString())); doc.Blocks.Add(pm); StringBuilder strmp = new StringBuilder(""); foreach (Domain.MashProfileStep mss in MashProfileList) { strmp.Append("Mash at " + mss.ToString() + "\n"); } Paragraph pmp = new Paragraph(); pmp.Inlines.Add(new Bold(new Run("Mash profile:\n"))); pmp.Inlines.Add(new Run(strmp.ToString())); pmp.Inlines.Add(new Run(String.Format("\nSparge with {0:F1} liters of 78 C water\n", GrainfatherCalculator.CalcSpargeWaterVolume(GrainBillSize, (Volumes.PreBoilVolume), TopUpMashWater)))); var prbg = GravityAlgorithms.GetGravity( Grist.Where(x => x.Stage == FermentableStage.Mash).Sum(x => x.GU), Volumes.PreBoilVolume); var pobg = GravityAlgorithms.GetGravity(Grist.Where(x => x.Stage != FermentableStage.Fermentor).Sum(x => x.GU), Volumes.PostBoilVolume); pmp.Inlines.Add(new Run(String.Format("\nExpected post-mash gravity is {0:F3}. Post-mash volume shall be {1:F1} liters", prbg, Volumes.PreBoilVolume + Volumes.PreBoilTapOff))); if (Volumes.PreBoilTapOff > 0) { pmp.Inlines.Add(new Run(String.Format("\nTap off {0:F1} liters wort before boil start. Expected Pre-boil volume is {1:F1} liters.\n", Volumes.PreBoilTapOff, Volumes.PreBoilVolume))); } doc.Blocks.Add(pmp); #endregion #region Boiling part var boilingHeader = (new Paragraph(new Bold(new Run("Boiling")))); boilingHeader.FontSize = 16; doc.Blocks.Add(boilingHeader); StringBuilder strbboil = new StringBuilder(""); StringBuilder str_ferms_boil = new StringBuilder(""); foreach (GristPart g in Grist) { if (g.Stage == FermentableStage.Boil) { str_ferms_boil.Append("Add " + g.ToString() + "\n"); } } StringBuilder strbdry = new StringBuilder(""); foreach (HopAddition g in BoilHops) { switch (g.Stage) { case HopAdditionStage.Boil: strbboil.Append("Add " + g.ToString() + "\n"); break; case HopAdditionStage.Fermentation: strbboil.Append("Add " + g.ToString() + "\n"); break; default: break; } } Paragraph pbh = new Paragraph(); pbh.Inlines.Add(new Bold(new Run("Hop additions:\n"))); pbh.Inlines.Add(new Run(strbboil.ToString())); var vm = Volumes.PreBoilVolume; var vcs = Volumes.ColdSteepVolume; foreach (GristPart g in Grist) { if (g.Stage == FermentableStage.ColdSteep) { pbh.Inlines.Add(new Run(String.Format("Add the runnings of {0} to the boil 10 minutes before end\n", g.FermentableAdjunct.Name))); } } if (Grist.Any(x => x.Stage == FermentableStage.ColdSteep)) { pbh.Inlines.Add(new Run(String.Format("\nSparge all runnings with {0:F1}L water.\n", Volumes.ColdSteepVolume * (ColdSteep.COLDSTEEP_VOLUME_TO_SPARGE_RATIO)))); } pbh.Inlines.Add(new Run(String.Format("Expected post-boil gravity is {0:F3}. Post-boil volume shall be {1:F1} liters", pobg, Volumes.PostBoilVolume))); doc.Blocks.Add(pbh); #endregion #region Print others part StringBuilder strbo = new StringBuilder(""); foreach (OtherIngredient g in OtherIngredientsList) { strbo.Append(String.Format("Add " + g.ToString() + "\n")); } if (OtherIngredientsList.Any()) { var othersHeading = new Paragraph(new Bold(new Run("Others"))); othersHeading.FontSize = 16; doc.Blocks.Add(othersHeading); Paragraph po = new Paragraph(new Run(strbo.ToString())); doc.Blocks.Add(po); } #endregion doc.Name = "FlowDoc"; // Create IDocumentPaginatorSource from FlowDocument IDocumentPaginatorSource idpSource = doc; // Call PrintDocument method to send document to printer pDialog.PrintDocument(idpSource.DocumentPaginator, NameTextBox.Text); } }
private void updateGuiText() { EstAttenTextBox.Text = EstAtten.ToString(); MashVolumeLabel.Content = new StringBuilder() .AppendFormat("Mash water volume: {0:F1} liters", GrainfatherCalculator.CalcMashVolume(GrainBillSize)).ToString(); SpargeVolumeLabel.Content = new StringBuilder() .AppendFormat("Sparge water volume: {0:F1} liters", GrainfatherCalculator.CalcSpargeWaterVolume(GrainBillSize, (Volumes.PreBoilVolume + Volumes.PreBoilTapOff), TopUpMashWater)) .ToString(); PreBoilDataLabel.Content = new StringBuilder() .AppendFormat("Expected pre-boil gravity is {0:F3}, preboil volume {1:F1} liters", GravityAlgorithms.GetGravity( Grist.Where(x => (x.Stage != FermentableStage.Fermentor && x.Stage != FermentableStage.ColdSteep)).Sum(x => x.GU), Volumes.PreBoilVolume), Volumes.PreBoilVolume).ToString(); PostBoilDataLabel.Content = new StringBuilder() .AppendFormat("Expected post-boil gravity is {0:F3}, postboil volume {1:F1} liters", OriginalGravity, Volumes.PostBoilVolume).ToString(); AbvDataLabel.Content = new StringBuilder().AppendFormat("Expected ABV is {0:F2} %", Abv.CalculateAbv(OriginalGravity, ((OriginalGravity - 1) * (1 - ((double)EstAtten / 100))) + 1)).ToString(); }