Пример #1
0
        private void BoilTimeTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            BoilTimeTextBox = (TextBox)(sender);
            int val = 0;

            if (BoilTimeTextBox.Text.Equals(String.Empty))
            {
                return;
            }

            if (Grist != null &&
                Int32.TryParse(BoilTimeTextBox.Text, out val))
            {
                BoilTime            = val;
                Volumes.BoilOffLoss = GrainfatherCalculator.CalcBoilOffVolume(BoilTime);
                recalculateGrainBill();
            }
        }
Пример #2
0
        private void BatchSizeVolumeTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            BatchSizeVolumeTextBox = (TextBox)(sender);
            double val = 0;

            if (BatchSizeVolumeTextBox.Text.Equals(String.Empty) || Volumes == null)
            {
                return;
            }

            if (Grist != null &&
                Double.TryParse(BatchSizeVolumeTextBox.Text, out val))
            {
                if (val > (GrainfatherCalculator.GRAINFATHER_MAX_PREBOILVOLUME - GrainfatherCalculator.CalcBoilOffVolume(BoilTime)))
                {
                    MessageBox.Show("Batch size is to big. Please reduce it");
                    return;
                }
            }

            Volumes.FinalBatchVolume = val;
            recalculateGrainBill();
        }
Пример #3
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();
        }
Пример #4
0
        public MainWindow()
        {
            InitializeComponent();

            var assembly = Assembly.GetExecutingAssembly();
            var path     = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var fullpath = String.Format("{0}\\{1}", path, assembly.GetName().Name);

            try {
                if (!Directory.Exists(fullpath))
                {
                    Directory.CreateDirectory(fullpath);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Unable to create {0}. Exception {1}", fullpath, e));
            }
            HopsRepo = new HopsRepository();
            MaltRepo = new FermentableRepository();

            Grist = new ObservableCollection <GristPart>();
            MaltsListView.ItemsSource = Grist;
            BoilHops = new ObservableCollection <HopAddition>();
            HopsListView.ItemsSource = BoilHops;

            MashProfileList = new ObservableCollection <Domain.MashProfileStep>();
            MashStepListView.ItemsSource = MashProfileList;

            OtherIngredientsList = new ObservableCollection <OtherIngredient>();
            OtherIngredientsListView.ItemsSource = OtherIngredientsList;

            OriginalGravity = 1.05;
            BoilTime        = 60;

            Volumes                       = new BrewVolumes();
            Volumes.BoilOffLoss           = GrainfatherCalculator.CalcBoilOffVolume(BoilTime);
            Volumes.FinalBatchVolume      = 25;
            Volumes.BoilerToFermentorLoss = GrainfatherCalculator.GRAINFATHER_BOILER_TO_FERMENTOR_LOSS;
            Volumes.PreBoilTapOff         = 0;

            TopUpMashWater = 0;

            gfc = new GrainfatherCalculator();
            gfc.MashEfficiency = (double)WpfApplication1.Properties.Settings.Default["MashEfficiency"];
            EstAtten           = 78;
            updateGuiText();

            GrainBrainMenuItem.IsEnabled = false;

            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
            dispatcherTimer.Start();

            MashProfileList.CollectionChanged += this.OnCollectionChanged;

            BatchSizeVolumeTextBox.Text         = Volumes.FinalBatchVolume.ToString();
            ExpectedOriginalGravityTextBox.Text = OriginalGravity.ToString();
            BoilTimeTextBox.Text             = BoilTime.ToString();
            TopUpMashWaterVolumeTextBox.Text = TopUpMashWater.ToString();
            PreBoilVolumeTextBox.Text        = Volumes.PreBoilTapOff.ToString();
        }
Пример #5
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);
            }
        }