Example #1
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 #2
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();
        }