private bool ParseMaxMinAcid(HopAcids aAcid, string aValueString) { Regex r = new Regex(@"[0-9]+[\,\.]?[0-9]?"); var m = r.Matches(aValueString); float floatVal; bool ret = true; int ix = 0; foreach (Match s in m) { if (float.TryParse(s.Value, out floatVal)) { if (ix != 0) { aAcid.Max = floatVal; } else { aAcid.Min = floatVal; } } else { ret = false; break; } ix++; } return(ret); }
private void button1_Click(object sender, RoutedEventArgs e) { Hops var = (Hops)HopsComboBox.SelectedItem; hop = new HopAddition(); if (var == null) { MessageBox.Show("Please select a hop in the drop down menu"); return; } hop.Hop = var; var stage = (HopAdditionStage)StageComboBox.SelectedItem; hop.Stage = stage; int timeMinutes; if (int.TryParse(TimeDurationTextBox.Text, out timeMinutes)) { hop.Duration = timeMinutes; } else { MessageBox.Show(String.Format("Unable to interpreter {0} as a integer value. Please provide a correct integer value in Time", TimeDurationTextBox.Text)); } float amount; if (float.TryParse(AmountTextBox.Text, out amount)) { if (UnitCheckBox.IsChecked == false) { hop.Bitterness = (int)Math.Round(amount, 0); hop.AmountUnit = HopAmountUnitE.IBU; } else { hop.Amount = Math.Round(amount, 2); hop.AmountUnit = HopAmountUnitE.GRAMS_PER_LITER; } } else { MessageBox.Show(String.Format("Unable to interpreter {0} as a float value. Please provide a correct float value in Part", AmountTextBox.Text)); } float alphaAcid; if (float.TryParse(AlphaAcidTextBox.Text, out alphaAcid)) { HopAcids acid = new HopAcids(); acid.Min = alphaAcid; hop.AlphaAcid = acid; } else { MessageBox.Show(String.Format("Unable to interpreter {0} as a float value. Please provide a correct float value in Part", AlphaAcidTextBox.Text)); } this.Close(); }