Demo entry 6412397

C sharp

   

Submitted by anonymous on May 25, 2017 at 11:28
Language: C#. Code size: 6.1 kB.

class Ville
    {
        public int IdVille;
        public string NomVille;
        public int CodePostal;
        public int IdPays;

        public override string ToString()
        {
            return this.IdVille + " " + this.NomVille + " " + this.CodePostal + " " + this.IdPays;
        }
    }


 class Pays
    {
        public int IdPays;
        public string NomPays;

        public override string ToString()
        {
            return this.IdPays + " " + this.NomPays ;
        }
    }


  class Les_Pays
    {
        public static List<Ville> Liste_Ville = new List<Ville>();
        public static List<Pays> Liste_pays = new List<Pays>();
    }


    private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Gestion des pays";
            AcceptButton = button1;
        }
        private void Form1_Shown(object sender, EventArgs e)
        {
            textBox1.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Pays p=new Pays();
            p.IdPays = int.Parse(textBox1.Text);
            p.NomPays = textBox2.Text;
            Les_Pays.Liste_pays.Add(p);
            textBox1.Clear();
            textBox2.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool trouve = false;
            foreach (Pays p in Les_Pays.Liste_pays)
                if (p.IdPays == int.Parse(textBox1.Text))
                { 
                    p.NomPays = textBox2.Text;
                    MessageBox.Show("Modification efféctuée","Modifier",MessageBoxButtons.OK);
                    trouve = true;
                }
            if(trouve==false)
                MessageBox.Show("Pays n'exist pas", "Modifier", MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
            textBox1.Clear();
            textBox2.Clear();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.Show();
            this.Hide();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form3 f = new Form3();
            f.Show();
            this.Hide();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form4 f = new Form4();
            f.Show();
            this.Hide();
        }

        
 private void Form2_Load(object sender, EventArgs e)
        {
            
            this.Text = "Suppression des pays";
            for (int i = 0; i < Les_Pays.Liste_pays.Count; i++)
                comboBox1.Items.Add(Les_Pays.Liste_pays[i].IdPays);
            

        }

        private void Form2_Shown(object sender, EventArgs e)
        {
            button1.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for(int i=0;i<Les_Pays.Liste_pays.Count;i++)
            {
                Les_Pays.Liste_pays.RemoveAt(i);
                comboBox1.Items.RemoveAt(i);
                MessageBox.Show("Le Pays et Supprimer", "suppression", MessageBoxButtons.OKCancel);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }


   private void Form3_Load(object sender, EventArgs e)
        {
            this.Text = "Gestion des Ville par Pays";

            AcceptButton = button1;

            for (int i = 0; i < Les_Pays.Liste_pays.Count; i++)
                comboBox1.Items.Add(Les_Pays.Liste_pays[i].IdPays);

        }
        private void Form3_Shown(object sender, EventArgs e)
        {
            textBox1.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Ville v = new Ville();
            v.IdVille = int.Parse(textBox1.Text);
            v.NomVille = textBox2.Text;
            v.CodePostal = int.Parse(textBox3.Text);
            v.IdPays = int.Parse(comboBox1.Text);
            Les_Pays.Liste_Ville.Add(v);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            comboBox1.Text="";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool trouve = false;
            foreach(Ville v in Les_Pays.Liste_Ville)
                if(v.IdVille==int.Parse(textBox1.Text))
                {
                    textBox2.Text = v.NomVille;
                    textBox3.Text = v.CodePostal.ToString();
                        MessageBox.Show("rechercher effictuée","rechercher",MessageBoxButtons.OKCancel);
                        trouve = true;
                }
            if(trouve==false)
                MessageBox.Show("la Ville n'exist pas", "rechercher", MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
        }

        
  
   private void Form4_Load(object sender, EventArgs e)
        {
            this.Text = "Liste des Ville Par Pays";
            for (int i = 0; i < Les_Pays.Liste_pays.Count; i++)
                comboBox1.Items.Add(Les_Pays.Liste_pays[i].IdPays);
        }

        

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach(Pays p in Les_Pays.Liste_pays)
                if (p.IdPays == int.Parse(comboBox1.Text))
                    label4.Text = p.ToString();

            
             foreach(Ville v in Les_Pays.Liste_Ville)
                if(v.IdPays==int.Parse(comboBox1.Text))
                 {  
                  dataGridView1.Rows.Add(v.IdVille, v.NomVille);
                       
                 }
                  textBox1.Text = dataGridView1.Rows.Count.ToString();
              
  


        }

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).