using System; using System.Data; using System.Data.Odbc; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void conexion_Click(object sender, EventArgs e) { cnx(); } void cnx() { OdbcConnection cnx = new OdbcConnection("DSN=KINGMINDONGO"); try { cnx.Open(); } catch { MessageBox.Show("Erreure de la Connexion"); } finally { OdbcCommand commd; commd = new OdbcCommand("select * from utilisateur where login=? and mot_de_passe=?", cnx); commd.Parameters.Add("login", compte.Text); commd.Parameters.Add("mot_de_passe", mot_de_passe.Text); commd.Connection = cnx; OdbcDataReader dtr; try { dtr = commd.ExecuteReader(); if (dtr.Read()) { if (dtr.GetString(2) == "a") { this.Hide (); Form2 f=new Form2 (); f.Show (); } else { if (dtr.GetString(2) == "u") { this.Hide (); Form3 f=new Form3 (); f.Show (); } else MessageBox.Show(this, "Login ou Mot de passe invalide", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception KINGREX) { MessageBox.Show(this, "Login ou Mot de passe invalide", "", MessageBoxButtons.OK, MessageBoxIcon.Error); compte.Text = KINGREX.ToString(); } } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprivate void conexion_Click(object sender,System.EventArgs e) { Connexion(); } //----------------------------------- void Connexion() { if (this.MdiParent.Menu.MenuItems[0].MenuItems[0].Text =="SeConnecter") { OdbcConnection cnx = new OdbcConnection("DSN=KINGMINDONGO"); try { cnx.Open(); } catch { MessageBox.Show("Erreure de la Connexion"); } finally { OdbcCommand commd; commd = new OdbcCommand("select * from utilisateur where login=? and mot_de_passe=?", cnx); commd.Parameters.Add("login", compte.Text); commd.Parameters.Add("mot_de_passe", mot_de_passe.Text); commd.Connection = cnx; OdbcDataReader dtr; try { dtr = commd.ExecuteReader(); if (dtr.Read()) { if //ici, remplace juste le a,u selon tes champs pcq moi j ai essayé juste avec deux user admin et Utilisateur (dtr.GetString(2) == "a") { //c'est ici que tu donnera les accès et les limites selon tes Admin central,Admin Region et User this.MdiParent.Menu.MenuItems[1].Visible = true; this.MdiParent.Menu.MenuItems[2].Visible = true; this.MdiParent.Menu.MenuItems[3].Visible = true; this.MdiParent.Menu.MenuItems[4].Visible = true; this.MdiParent.Menu.MenuItems[5].Visible = true; } else { this.MdiParent.Menu.MenuItems[3].Visible = true; this.MdiParent.Menu.MenuItems[4].Visible = true; } this.MdiParent.Menu.MenuItems[0].MenuItems[0].Text = "Deconnecter"; this.MdiParent.Text = this.MdiParent.Text + " *********** La personne connectée est: " + dtr.GetString(5) + " " + dtr.GetString(3) + " " + dtr.GetString(4) + " ***********"; this.Close(); } else MessageBox.Show(this, "Login ou Mot de passe invalide", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception KINGREX) { MessageBox.Show(this, "Login ou Mot de passe invalide", "", MessageBoxButtons.OK, MessageBoxIcon.Error); compte.Text = KINGREX.ToString(); } } } }