private void Redshift_Validating(object sender, CancelEventArgs e) { try { // try setting it since the set method includes validation, but only if the value has changed if (cosmology.Redshift.ToString() != Redshift.Text) { cosmology.Redshift = Convert.ToDouble(Redshift.Text); } } catch (Exception ex) { // cancel the event, select the text, and set an error e.Cancel = true; Redshift.Select(0, Redshift.Text.Length); errorProvider1.SetError(Redshift, ex.Message); } }
private void accept_Click(object sender, RoutedEventArgs e) { NGCObjects NGCObject = new WPF_Material_Design.Source.NGCObjects(); decimal?apparent_Star_Magnitude; decimal?redshift; ulong?distance; try { apparent_Star_Magnitude = Convert.ToDecimal(Apparent_Star_Magnitude.Text); } catch (Exception ex) { Apparent_Star_Magnitude.Clear(); MessageBox.Show("Введите заново"); return; } try { redshift = Convert.ToDecimal(Redshift.Text); } catch (Exception ex) { Redshift.Clear(); MessageBox.Show("Введите заново"); return; } try { distance = Convert.ToUInt64(Distance.Text); } catch (Exception ex) { Distance.Clear(); MessageBox.Show("Введите заново"); return; } if (new_NGCObject) { NGCObject.Create(Name.Text, Constellatoin.Text, Declination.Text, Right_Ascension.Text, apparent_Star_Magnitude, redshift, distance, Type.Text, Info.Text); NGCObjects.Add(NGCObject); } else { this.NGCObject.Create(Name.Text, Constellatoin.Text, Declination.Text, Right_Ascension.Text, apparent_Star_Magnitude, redshift, distance, Type.Text, Info.Text); } Close(); }