public int Compare(object a, object b) { if (a == b) { return(0); } if (a == null) { return(1); } if (b == null) { return(-1); } Huile h1 = a as Huile; Huile h2 = b as Huile; if (h1.Stock == h2.Stock) { return(0); } else if (h1.Stock < h2.Stock) { return(1); } else { return(-1); } // return -string.Compare(h1.Stock.ToString(), h2.Stock.ToString()); }
private void buttonAjouter_Click(object sender, EventArgs e) { this.pictureBoxErreur1.Visible = false; this.pictureBoxErreur2.Visible = false; this.pictureBoxErreur3.Visible = false; this.pictureBoxErreur4.Visible = false; this.pictureBoxErreur5.Visible = false; this.pictureBoxErreur6.Visible = false; bool erreur = false; // Nom huile string nom = this.richTextBoxNom.Text; if (nom == "") { this.pictureBoxErreur1.Visible = true; erreur = true; } // Petrolier string petrolier = this.richTextBoxPetrolier.Text; if (petrolier == "") { this.pictureBoxErreur2.Visible = true; erreur = true; } // VF int vf = -1; if (this.VF0.Checked) { vf = Convert.ToInt32(this.VF0.Text); } else if (this.VF5.Checked) { vf = Convert.ToInt32(this.VF5.Text); } else if (this.VF10.Checked) { vf = Convert.ToInt32(this.VF10.Text); } else if (this.VF15.Checked) { vf = Convert.ToInt32(this.VF15.Text); } else if (this.VF20.Checked) { vf = Convert.ToInt32(this.VF20.Text); } else { this.pictureBoxErreur5.Visible = true; erreur = true; } // VC int vc = -1; if (this.VC30.Checked) { vc = Convert.ToInt32(this.VC30.Text); } else if (this.VC40.Checked) { vc = Convert.ToInt32(this.VC40.Text); } else if (this.VC50.Checked) { vc = Convert.ToInt32(this.VC50.Text); } else { this.pictureBoxErreur6.Visible = true; erreur = true; } // prix double prix = 0; if (this.richTextBoxPrix.Text == "" || (prix = Convert.ToDouble(this.richTextBoxPrix.Text)) <= 0) { this.pictureBoxErreur3.Visible = true; erreur = true; } // stock int stock = 0; if (this.richTextBoxStock.Text == "" || (stock = Convert.ToInt32(this.richTextBoxStock.Text)) < 0) { this.pictureBoxErreur4.Visible = true; erreur = true; } if (!erreur) { Huile h = new Huile(nom, vf, vc, prix, stock, petrolier); T.Add(h); foreach (Huile x in T) { Console.WriteLine(x.ToString()); } string message = "Huile a bien été ajouté."; string caption = "Information"; MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; result = MessageBox.Show(message, caption, buttons, MessageBoxIcon.Information); } }