예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ManipulationBD.ConnectionDataBase();

                RadioButton rb = null;
                for (int i = 0; i < groupBox1.Controls.Count; i++)
                {
                    rb = (RadioButton)groupBox1.Controls[i];    // On sort dès qu'on trouve le bouton sélectionné
                    if (rb.Checked)
                    {
                        break;
                    }
                }

                string Insertion = "insert into compte values (?,?,?,?,?,?,?)";

                MySqlCommand cmd = new MySqlCommand(Insertion, ManipulationBD.Cnn);

                MySqlParameter p1 = new MySqlParameter("id_cmp", Id.Text);
                cmd.Parameters.Add(p1);
                MySqlParameter p2 = new MySqlParameter("nom_cmp", nom.Text);
                cmd.Parameters.Add(p2);
                MySqlParameter p3 = new MySqlParameter("prenom", Prenom.Text);
                cmd.Parameters.Add(p3);
                MySqlParameter p5 = new MySqlParameter("tel_cmp", Tel.Text);
                cmd.Parameters.Add(p5);
                MySqlParameter p6 = new MySqlParameter("User_name", Username.Text);
                cmd.Parameters.Add(p6);
                MySqlParameter p7 = new MySqlParameter("Pwd", Pwd.Text);
                cmd.Parameters.Add(p7);
                MySqlParameter p4 = new MySqlParameter("type", rb.Text);
                cmd.Parameters.Add(p4);

                cmd.ExecuteNonQuery();

                if (rb.Text == "Administrateur")
                {
                    Administrateur.Administrateur a = new Administrateur.Administrateur();
                    this.Hide();
                    a.Show();
                }
                else
                {
                    Agent.Agent a = new Agent.Agent();
                    this.Hide();
                    a.Show();
                }
                //MessageBox.Show(rb.Text);
            }
            catch (Exception r)
            {
                MessageBox.Show(r.Message);
            }
            finally
            {
                ManipulationBD.DecoonectionDataBase();
            }
        }
예제 #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                ManipulationBD.ConnectionDataBase();

                string UserName = user.Text;
                string Password = pwd.Text;
                User_name = user.Text;

                MySqlCommand   cmd = new MySqlCommand(" Select * from compte where User_name = ? And Pwd = ? ", ManipulationBD.Cnn);
                MySqlParameter P1  = new MySqlParameter("P1", user.Text);
                cmd.Parameters.Add(P1);
                MySqlParameter P2 = new MySqlParameter("P2", pwd.Text);
                cmd.Parameters.Add(P2);

                MySqlDataReader dr = cmd.ExecuteReader();


                if (dr != null)
                {
                    while (dr.Read())
                    {
                        if ((string)dr["type_cmp"] == "Administrateur")
                        {
                            Administrateur.Administrateur a = new Administrateur.Administrateur();
                            a.Show();
                            this.Hide();
                        }
                        else
                        {
                            Agent.Agent a = new Agent.Agent();
                            this.Hide();
                            a.Show();
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
            finally
            {
                ManipulationBD.DecoonectionDataBase();
            }
        }