private void AddOtherIngredientsButton_Click(object sender, RoutedEventArgs e) { var w = new AddOtherIngredients(); w.ShowDialog(); if (w.Result != null) { OtherIngredientsList.Add(w.Result); } }
private void PopulateGUI(Recepie aRecepie) { Grist.Clear(); foreach (GristPart g in aRecepie.Fermentables) { Grist.Add(g); } BoilHops.Clear(); foreach (HopAddition h in aRecepie.BoilHops) { BoilHops.Add(h); } MashProfileList.Clear(); foreach (Domain.MashProfileStep mps in aRecepie.MashProfile) { MashProfileList.Add(mps); } OtherIngredientsList.Clear(); foreach (OtherIngredient o in aRecepie.OtherIngredients) { OtherIngredientsList.Add(o); } Volumes.FinalBatchVolume = aRecepie.BatchVolume; BatchSizeVolumeTextBox.Text = Volumes.FinalBatchVolume.ToString(); Volumes.PreBoilTapOff = aRecepie.PreBoilTapOffVolume; PreBoilVolumeTextBox.Text = Volumes.PreBoilTapOff.ToString(); TopUpMashWater = aRecepie.TopUpMashWater; TopUpMashWaterVolumeTextBox.Text = TopUpMashWater.ToString(); OriginalGravity = aRecepie.OriginalGravity; ExpectedOriginalGravityTextBox.Text = OriginalGravity.ToString(); BoilTime = aRecepie.BoilTime; BoilTimeTextBox.Text = BoilTime.ToString(); NameTextBox.Text = aRecepie.Name; recalculateGrainBill(); recalculateIbu(); updateGuiText(); }
private void MenuItem_FileSave(object sender, RoutedEventArgs e) { var r = new Recepie(); r.Fermentables = Grist.ToList(); r.BoilHops = BoilHops.ToList(); r.MashProfile = MashProfileList.ToList(); r.OtherIngredients = OtherIngredientsList.ToList(); r.Name = NameTextBox.Text; r.BatchVolume = Volumes.FinalBatchVolume; r.PreBoilTapOffVolume = Volumes.PreBoilTapOff; r.TopUpMashWater = 0; r.OriginalGravity = OriginalGravity; r.BoilTime = BoilTime; // Create OpenFileDialog Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = ".gsrx"; dlg.Filter = "Grainfather recipe files (*.gsrx)|*.gsrx"; dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlg.FileName = NameTextBox.Text; // Display OpenFileDialog by calling ShowDialog method Nullable <bool> result = dlg.ShowDialog(); if (result != true) { return; } XmlSerializer serializer = new XmlSerializer(typeof(Recepie)); FileStream saveStream = new FileStream(dlg.FileName, FileMode.OpenOrCreate, FileAccess.Write); serializer.Serialize(saveStream, r); saveStream.Close(); }
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); } }