Demo entry 6412837

C3 2

   

Submitted by BAHAE EDDINE HALIM on May 25, 2017 at 12:08
Language: C#. Code size: 3.3 kB.

using Microsoft.VisualBasic;
using System.IO;



namespace ControleN4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        { //Ajouter
            stagiaire s = new stagiaire();
            s.code = int.Parse(textBox1.Text);
            s.nom = textBox2.Text;
            s.prenom = textBox3.Text;
            s.Note[0] = double.Parse(textBox4.Text);
            s.Note[1] = double.Parse(textBox5.Text);

            listes_stagiaires.col.Add(s);
            textBox1.Clear(); textBox2.Clear();
            textBox3.Clear(); textBox4.Clear();
            textBox5.Clear();

        }

        private void button2_Click(object sender, EventArgs e)
        {//Supprimer
            stagiaire ss;
            string x;
            DialogResult y = DialogResult.No;
            bool trouve = false;
            x=Interaction.InputBox("Saisir le code du Stagiaire","message","0",400,400);


            foreach (stagiaire s in stagiaire.code)
                if (s.code == int.Parse(x))
                    trouve = true;

            if(trouve==true)
            {
                y= MessageBox.Show("Voulez-vous supprimer ?");

                if(y==DialogResult.Yes)
                    for (int i = 0; i < stagiaire.col.Count; i++)
                    {
                        ss = (stagiaire)stagiaire.col[i];
                        if (ss.code == int.Parse(x))
                            stagiaire.col.RemoveAt(i);

                        MessageBox.Show("Le stagiaire est Supprimée !");
                    }
            }


        }

        private void button3_Click(object sender, EventArgs e)
        { //Modifier

            bool test = false;
            foreach(stagiaire s in stagiaire.col)
            {
                if(s.code==int.Parse(textBox1.Text))
                {
                    test = true;
                    s.nom = textBox2.Text;
                    s.prenom = textBox3.Text;
                    s.Note[0] = double.Parse(textBox4.Text);
                    s.Note[1] = double.Parse(textBox5.Text);

                    MessageBox.Show("Modification effectuée!");
                }
                else
                    MessageBox.Show("Le stagiaire n'existe pas dans la liste!");

            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            //Enregistrer
            FileStream fs = new FileStream("stagiaires.dat", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            foreach (stagiaire ss in stagiaire.col)
                sw.WriteLine(ss.ToString());
            sw.Close();
            fs.Close();
        }

         
        //MoyenneDesStagiaires;
        { 
            double y;
        int cp1=0;
        int cp2=0;
        foreach (stagiaire s in stagiaire.col)
	        {
		    y=(stagiaire.Note[0]+stagiaire.Note[1])/2; 
        dataGridview1.Rows.Add(stagiaire.code,stagiaire.nom;stagiaire.prenom);
        if(y>10)
        cp++;
        else
        cp2++;	        }


        }




    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).