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(); } }
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 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(); } }
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(); }