Example #1
0
        private void MenuItem_SettingsMashEfficiency(object sender, RoutedEventArgs e)
        {
            var meWindow = new MashEffeciency((int)(gfc.MashEfficiency * 100d));

            meWindow.ShowDialog();

            double me = 0;

            if (meWindow.Gravity != 0 && meWindow.Volume != 0)
            {
                var measuredPts = GravityAlgorithms.GetPoints(meWindow.Gravity, meWindow.Volume);
                var possiblePts = Grist.Where(x => x.Stage == FermentableStage.Mash).
                                  Sum(v => v.GU);

                me = measuredPts / possiblePts;
                MessageBox.Show(String.Format("Mash efficiency updated to {0:F0}%, will update settings", me * 100));
            }
            else if (meWindow.MashEfficiency != 0)
            {
                me = (double)meWindow.MashEfficiency / 100d;
            }
            else
            {
                return;
            }


            gfc.MashEfficiency = me;
            WpfApplication1.Properties.Settings.Default["MashEfficiency"] = me;
            WpfApplication1.Properties.Settings.Default.Save();

            recalculateGrainBill();
            recalculateIbu();
        }
Example #2
0
        private void recalculateIbu()
        {
            var Gravity = GravityAlgorithms.GetGravity(Volumes.PreBoilVolume, Grist.Where(x => x.Stage == FermentableStage.Mash).ToList(), GrainfatherCalculator.mashEfficiency);
            var ibu     = IbuAlgorithms.CalcIbu(BoilHops.Where(x => x.Stage == HopAdditionStage.Boil), Gravity, Volumes.PostBoilVolume);
            var highIbu = ibu + IbuAlgorithms.IBU_TOLERANCE * ibu;
            var lowIbu  = ibu - IbuAlgorithms.IBU_TOLERANCE * ibu;

            IbuLabel.Content = string.Format("IBU: {0:F0} - {1:F0} ({2:F0})", lowIbu, highIbu, ibu);
        }
    private int addGrist(int i, string gristName, int gristTier)
    {
        i++;

        Grist tempGrist = new Grist(gristName, gristTier, i);

        grists.Add(gristName, tempGrist);

        return(i);
    }
Example #4
0
 private void MaltsListView_KeyDown(object sender, KeyEventArgs e)
 {
     if (Key.Delete == e.Key)
     {
         foreach (GristPart listViewItem in ((ListView)sender).SelectedItems)
         {
             Grist.Remove(listViewItem);
             MessageBox.Show(String.Format("Shit, want to remove {0}. That is {1} away", listViewItem.FermentableAdjunct.Name, listViewItem.Amount));
             break;
         }
     }
 }
Example #5
0
        private void addGrains_Click(object sender, RoutedEventArgs e)
        {
            var sum = Grist.Sum(g => g.Amount);
            var sw  = new SelectGrain(MaltRepo, sum);

            sw.ShowDialog();

            if (sw.Result != null)
            {
                Grist.Add(sw.Result);
                recalculateGrainBill();
            }
        }
Example #6
0
        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();
        }
Example #7
0
        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();
        }
Example #8
0
        private void MaltsListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (MaltsListView.SelectedIndex >= Grist.Count() || MaltsListView.SelectedIndex < 0)
            {
                return;
            }

            double sum = Grist.Sum(g => g.Amount);

            sum -= Grist.ToArray()[MaltsListView.SelectedIndex].Amount;
            var sw = new SelectGrain(MaltRepo, sum, Grist.ToArray()[MaltsListView.SelectedIndex]);

            sw.ShowDialog();
            if (sw.Result != null)
            {
                Grist.Remove((GristPart)MaltsListView.SelectedItem);
                Grist.Add(sw.Result);
                recalculateGrainBill();
            }
        }
Example #9
0
        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();
        }
Example #10
0
        private void recalculateGrainBill()
        {
            var sum = Grist.Sum(g => g.Amount);

            if (sum != 100)
            {
                sum           = -1;
                GrainBillSize = 0;
            }
            else
            {
                var preBoilTappOffLoss = (Volumes.PreBoilTapOff / (Volumes.PreBoilVolume + Volumes.PreBoilTapOff));

                var totalGravity = GravityAlgorithms.GetTotalGravity(Volumes.PostBoilVolume, OriginalGravity);


                Volumes.ColdSteepVolume = 0;

                var l = new List <GristPart>();
                foreach (var grain in Grist)
                {
                    grain.GU = totalGravity * ((double)grain.Amount / 100d);

                    if (grain.Stage == FermentableStage.ColdSteep)
                    {
                        grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, ColdSteep.COLDSTEEP_EFFICIENCY);

                        Volumes.ColdSteepVolume += ColdSteep.GetColdSteepWaterContibution(grain.AmountGrams);
                    }

                    if (grain.Stage == FermentableStage.Mash)
                    {
                        grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, gfc.MashEfficiency);

                        grain.AmountGrams += (int)Math.Round(grain.AmountGrams * preBoilTappOffLoss);
                    }

                    if (grain.Stage == FermentableStage.Fermentor)
                    {
                        grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, 1);

                        var boilerLossPercent = GrainfatherCalculator.GRAINFATHER_BOILER_TO_FERMENTOR_LOSS / (Volumes.PostBoilVolume);

                        grain.AmountGrams -= (int)Math.Round(boilerLossPercent * grain.AmountGrams);
                    }
                    if (grain.Stage == FermentableStage.Boil)
                    {
                        grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, 1);
                    }

                    l.Add(grain);
                }

                GrainBillSize = Grist.Where(x => x.Stage == FermentableStage.Mash).Sum(x => x.AmountGrams);

                foreach (var grain in l)
                {
                    Grist.Remove(grain);
                    Grist.Add(grain);
                }

                if (GrainBillSize > GrainfatherCalculator.SMALL_GRAINBILL || GrainBillSize == 0)
                {
                    TopUpMashWaterVolumeTextBox.Visibility = Visibility.Hidden;
                    TopUpMashWaterVolumeLabel.Visibility   = Visibility.Hidden;
                }
                else
                {
                    TopUpMashWaterVolumeTextBox.Visibility = Visibility.Visible;
                    TopUpMashWaterVolumeLabel.Visibility   = Visibility.Visible;
                }

                foreach (GridViewColumn c in MaltsGridView.Columns)
                {
                    c.Width = 0;          //set it to no width
                    c.Width = double.NaN; //resize it automatically
                }

                double ecb       = ColorAlgorithms.CalculateColor(Grist.ToList(), Volumes);
                string refString = ColorAlgorithms.GetReferenceBeer(ecb);
                ColorLabel.Content = String.Format("Color [ECB]: {0:F1} eqv. to {1}", ecb, refString);

                recalculateIbu();

                var ol = BoilHops.OrderBy(x => x).ToList();
                BoilHops.Clear();
                foreach (HopAddition h in ol)
                {
                    hopsCompositionChanged(h);
                }
            }
            updateGuiText();
        }
Example #11
0
        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);
            }
        }