public class Prix { private double taux = 0.2; private double ht; public double HT { get { return ht; } set { ht = value; TTC = ht * (1.0 + taux); } } private double ttc; public double TTC { get { return ttc; } set { ttc = value; HT = ttc / (1.0 + taux); } } }
public class Prix { private double taux = 0.2; private double ht; public double HT { get { return ht; } set { if (ht != value) { ht = value; TTC = ht * (1.0 + taux); } } } private double ttc; public double TTC { get { return ttc; } set { if(ttc != value) { ttc = value; HT = ttc / (1.0 + taux); } } } }
using System.ComponentModel; namespace exemple { public class Prix : INotifyPropertyChanged { private double taux = 0.2; private double ht; public double HT { get { return ht; } set { if (ht != value) { ht = value; GenerePropertyChanged("HT");//demande à signaler le chanagement de valeur de HT TTC = ht * (1.0 + taux); } } } private double ttc; public double TTC { get { return ttc; } set { if(ttc != value) { ttc = value; GenerePropertyChanged("TTC"); HT = ttc / (1.0 + taux); } } } #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; /// <summary> /// Génère l'évènement attendu par le binding, avec le nom de la propriété /// </summary> /// <param name="Propriete"></param> private void GenerePropertyChanged(string Propriete) { if (this.PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(Propriete)); } #endregion } }
private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text =="") { textBox1.Text = "0"; } int a1 = Convert.ToInt32(textBox1.Text); textBox2.Text = a1.ToString(); textBox3.Text = (a1 * 20).ToString(); textBox4.Text = (a1 * 10).ToString(); textBox5.Text = (a1 * 20).ToString(); textBox6.Text = (a1 * 30).ToString(); } private void textBox2_TextChanged(object sender, EventArgs e) { if (textBox2.Text == "") { textBox2.Text = "0"; } int a2 = Convert.ToInt32(textBox2.Text); textBox1.Text = a2.ToString(); textBox3.Text = (a2 * 20).ToString(); textBox4.Text = (a2 * 10).ToString(); textBox5.Text = (a2 * 20).ToString(); textBox6.Text = (a2 * 30).ToString(); } private void textBox3_TextChanged(object sender, EventArgs e) { if (textBox3.Text == "") { textBox3.Text = "0"; } int a3 = Convert.ToInt32(textBox3.Text); textBox1.Text = (a3 / 20).ToString(); textBox2.Text = (a3 / 20).ToString(); textBox4.Text = (a3 / 2).ToString(); textBox5.Text = a3.ToString(); textBox6.Text = (a3 * 3 / 2).ToString(); } private void textBox4_TextChanged(object sender, EventArgs e) { if (textBox4.Text == "") { textBox4.Text = "0"; } int a4 = Convert.ToInt32(textBox4.Text); textBox1.Text = (a4 / 10).ToString(); textBox2.Text = (a4 / 10).ToString(); textBox3.Text = (a4 * 2).ToString(); textBox5.Text = (a4 * 2).ToString(); textBox6.Text = (a4 * 3).ToString(); } private void textBox5_TextChanged(object sender, EventArgs e) { if (textBox5.Text == "") { textBox5.Text = "0"; } int a5 = Convert.ToInt32(textBox5.Text); textBox1.Text = (a5 / 20).ToString(); textBox2.Text = (a5 / 20).ToString(); textBox3.Text = a5.ToString(); textBox4.Text = (a5 / 2).ToString(); textBox6.Text = (a5 * 3 / 2).ToString(); } private void textBox6_TextChanged(object sender, EventArgs e) { if (textBox6.Text == "") { textBox6.Text = "0"; } int a6 = Convert.ToInt32(textBox6.Text); textBox1.Text = (a6 / 30).ToString(); textBox2.Text = (a6 / 30).ToString(); textBox3.Text = (a6 * 3 / 2).ToString(); textBox4.Text = (a6 / 30).ToString(); textBox6.Text = (a6 * 2).ToString(); }
if (textBox2.Text.Equals(NewValue)) return; textBox2.Text=NewValue;
private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text =="") { textBox1.Text = "0"; } int a1 = Convert.ToInt32(textBox1.Text); if (textBox2.Text.Equals(a1.ToString())) return; textBox2.Text = a1.ToString(); textBox3.Text = (a1 * 20).ToString(); textBox4.Text = (a1 * 10).ToString(); textBox5.Text = (a1 * 20).ToString(); textBox6.Text = (a1 * 30).ToString(); } private void textBox2_TextChanged(object sender, EventArgs e) { if (textBox2.Text == "") { textBox2.Text = "0"; } int a2 = Convert.ToInt32(textBox2.Text); textBox1.Text = a2.ToString(); textBox3.Text = (a2 * 20).ToString(); textBox4.Text = (a2 * 10).ToString(); textBox5.Text = (a2 * 20).ToString(); textBox6.Text = (a2 * 30).ToString(); } private void textBox3_TextChanged(object sender, EventArgs e) { if (textBox3.Text == "") { textBox3.Text = "0"; } int a3 = Convert.ToInt32(textBox3.Text); textBox1.Text = (a3 / 20).ToString(); textBox2.Text = (a3 / 20).ToString(); textBox4.Text = (a3 / 2).ToString(); textBox5.Text = a3.ToString(); textBox6.Text = (a3 * 3 / 2).ToString(); } private void textBox4_TextChanged(object sender, EventArgs e) { if (textBox4.Text == "") { textBox4.Text = "0"; } int a4 = Convert.ToInt32(textBox4.Text); textBox1.Text = (a4 / 10).ToString(); textBox2.Text = (a4 / 10).ToString(); textBox3.Text = (a4 * 2).ToString(); textBox5.Text = (a4 * 2).ToString(); textBox6.Text = (a4 * 3).ToString(); } private void textBox5_TextChanged(object sender, EventArgs e) { if (textBox5.Text == "") { textBox5.Text = "0"; } int a5 = Convert.ToInt32(textBox5.Text); textBox1.Text = (a5 / 20).ToString(); textBox2.Text = (a5 / 20).ToString(); textBox3.Text = a5.ToString(); textBox4.Text = (a5 / 2).ToString(); textBox6.Text = (a5 * 3 / 2).ToString(); } private void textBox6_TextChanged(object sender, EventArgs e) { if (textBox6.Text == "") { textBox6.Text = "0"; } int a6 = Convert.ToInt32(textBox6.Text); textBox1.Text = (a6 / 30).ToString(); textBox2.Text = (a6 / 30).ToString(); textBox3.Text = (a6 * 3 / 2).ToString(); textBox4.Text = (a6 / 30).ToString(); textBox6.Text = (a6 * 2).ToString(); }