public FrmModifieEleve(int idAdherant) { InitializeComponent(); GestionAdherant.SetchaineConnexion(ConfigurationManager .ConnectionStrings["AssocAdherant"]); adherantAModifier = GestionAdherant.TrouverAdherant(idAdherant); textbox1 = new TextBox(); textBox2 = new TextBox(); textBox3 = new TextBox(); textBox4 = new TextBox(); textBox5 = new TextBox(); textBox6 = new TextBox(); listBox7 = new ListBox(); textBox8 = new TextBox(); textBox9 = new TextBox(); errorProvider1 = new ErrorProvider(); SuspendLayout(); txtNom.Name = "textBox1"; txtPrenom.Name = "textBox2"; txtDateNaissance.Name = "textBox3"; txtEmail.Name = "textBox4"; txtTelephone.Name = "textBox5"; txtNumParents.Name = "textBox6"; lstClasse.Name = "textBox7"; txtLogin.Name = "textBox8"; txtMDP.Name = "textBox9"; txtNom.TabIndex = 1; txtNom.Text = adherantAModifier.Nom; txtNom.Validating += new CancelEventHandler(txtNom_Validating); textBox2.TabIndex = 2; txtPrenom.Text = adherantAModifier.Prenom; textBox2.Validating += new CancelEventHandler(this.txtPrenom_Validating); textBox3.TabIndex = 3; txtDateNaissance.Text = adherantAModifier.Naissance.ToString("dd/MM/yyyy"); textBox3.Validating += new CancelEventHandler(this.txtDateNaissance_Validating); textBox4.TabIndex = 4; txtEmail.Text = adherantAModifier.Email; textBox4.Validating += new CancelEventHandler(this.txtEmail_Validating); textBox5.TabIndex = 5; txtTelephone.Text = adherantAModifier.NumTel.ToString(); textBox5.Validating += new CancelEventHandler(txtNumTelephone_Validating); textBox6.TabIndex = 6; txtNumParents.Text = adherantAModifier.NumParent.ToString(); textBox6.Validating += new CancelEventHandler(txtNumParents_Validating); listBox7.TabIndex = 7; lstClasse.SelectedItem = adherantAModifier.Classe; listBox7.Validating += new CancelEventHandler(txtClasse_Validating); textBox8.TabIndex = 8; txtLogin.Text = adherantAModifier.Login; textBox8.Validating += new CancelEventHandler(txtLogin_Validating); textBox9.TabIndex = 9; txtMDP.Text = adherantAModifier.Mdp; textBox9.Validating += new CancelEventHandler(txtMDP_Validating); if (adherantAModifier.Sexe != ' ') { if (adherantAModifier.Sexe == 'G') { optSexe1.Checked = true; } else { if (adherantAModifier.Sexe == 'F') { optSexe2.Checked = true; } } } if (adherantAModifier.Archive != ' ') { if (adherantAModifier.Archive == 'O') { optArchive1.Checked = true; } else { if (adherantAModifier.Archive == 'N') { optArchive2.Checked = true; } } } if (adherantAModifier.AutoPrelev != ' ') { if (adherantAModifier.AutoPrelev == 'O') { optPrelev1.Checked = true; } else { if (adherantAModifier.AutoPrelev == 'N') { optPrelev2.Checked = true; } } } }
public static void ModifierAdherant(AdherantBO unAdherant) { AdherantDAO.UpdateAdherant(unAdherant); }
private void btnEnregistrer_Click(object sender, EventArgs e) { char optionArchive = ' '; char optionPrelevement = ' '; char optionSexe = ' '; int numTelephone = ' '; int numTelephoneParents = ' '; DateTime dateNaissance = new DateTime(); DateTime dateMaj = DateTime.Now; // Les champs a remplir if (txtNom.Text == "") { MessageBox.Show("Erreur votre champ est vide." + " Veuillez saisir un nom", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } if (txtPrenom.Text == "") { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez saisir un prénom", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } if (txtDateNaissance.Text == "") { MessageBox.Show("Erreur votre champ est vide." + " Veuillez saisir une date de naissance", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } else { dateNaissance = Convert.ToDateTime(txtDateNaissance.Text); } if (txtEmail.Text == "") { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez saisir un email", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } if (txtTelephone.Text == "") { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez saisir un téléphone", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } else { numTelephone = (int)Int64.Parse(txtTelephone.Text); } if (txtNumParents.Text == "") { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez saisir un numéro des parents", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } else { numTelephoneParents = (int)Int64.Parse(txtNumParents.Text); } if (txtLogin.Text == "") { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez saisir un login", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } if (txtMDP.Text == "") { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez saisir un mot de passe", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } // Les options de sexe a cocher if (optSexe1.Checked == false && optSexe2.Checked == false) { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez selectionner un sexe", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } // Sexe if (optSexe1.Checked == true) { optionSexe = Convert.ToChar(optSexe1.Text); } else { if (optSexe2.Checked == true) { optionSexe = Convert.ToChar(optSexe2.Text); } } // Classe if (lstClasse.SelectedItem == null) { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez selectionner une classe", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } if (optPrelev1.Checked == false && optPrelev2.Checked == false) { MessageBox.Show("Erreur votre champ est vide. " + "Veuillez selectionner l'autorisation ou non de l'auto-prélèvement", "Erreur" , MessageBoxButtons.OK, MessageBoxIcon.Error); } // Auto-Prélèvement if (optPrelev1.Checked == true) { optionPrelevement = Convert.ToChar(optPrelev1.Text); } else { if (optPrelev2.Checked == true) { optionPrelevement = Convert.ToChar(optPrelev2.Text); } } // Archive if (optArchive1.Checked == true) { optionArchive = Convert.ToChar(optArchive1.Text); } else { if (optArchive2.Checked == true) { optionArchive = Convert.ToChar(optArchive2.Text); } } AdherantBO adh = new AdherantBO(txtNom.Text, txtPrenom.Text, dateNaissance, optionSexe, txtEmail.Text, numTelephone, dateMaj, numTelephoneParents, lstClasse.SelectedIndex, optionPrelevement, txtLogin.Text, txtMDP.Text, optionArchive); GestionAdherant.ModifierAdherant(adh); ActiveForm.Close(); }
public static void AjoutAdherant(AdherantBO unAdherant) { AdherantDAO.AjoutAdherant(unAdherant); }
// Cette méthode modifie un Adherant passé en paramètre dans la BD public static int UpdateAdherant(AdherantBO unAdherant) { int nbEnr; ConnexionBD.GetConnexionBD().CloseConnexion(); SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand("Update ADHERANT set nom_adherant = @Nom," + " prenom_adherant = @Prenom, ddn_adherant = @Naissance, sexe_adherant = @Sexe," + " email_adherant = @Email, numtel_adherant = @Numtel, numparent_adherant = @Telparent," + " autoprelev_adherant = @Autoprelev, login_adherant = @Login, mdp_adherant = @Mdp," + " archive_adherant = @Archive, id_classe = @Classe, date_maj_adherant = @DateMaj" + " WHERE id = @IdAdherant", maConnexion); SqlParameter adhDateMaj = new SqlParameter("@DateMaj", SqlDbType.DateTime); SqlParameter adhId = new SqlParameter("@IdAdherant", SqlDbType.Int); SqlParameter adhNom = new SqlParameter("@Nom", SqlDbType.VarChar); SqlParameter adhPrenom = new SqlParameter("@Prenom", SqlDbType.VarChar); SqlParameter adhDdn = new SqlParameter("@Naissance", SqlDbType.Date); SqlParameter adhSexe = new SqlParameter("@Sexe", SqlDbType.VarChar); SqlParameter adhEmail = new SqlParameter("@Email", SqlDbType.VarChar); SqlParameter adhTelPerso = new SqlParameter("@NumTel", SqlDbType.Int); SqlParameter adhTelParent = new SqlParameter("@TelParent", SqlDbType.Int); SqlParameter adhAutoPrelev = new SqlParameter("@Autoprelev", SqlDbType.Char); SqlParameter adhLogin = new SqlParameter("@Login", SqlDbType.VarChar); SqlParameter adhMdp = new SqlParameter("@Mdp", SqlDbType.VarChar); SqlParameter adhArchive = new SqlParameter("@Archive", SqlDbType.Char); SqlParameter adhClasse = new SqlParameter("@Classe", SqlDbType.Int); adhId.Value = unAdherant.Id; adhNom.Value = unAdherant.Nom; adhPrenom.Value = unAdherant.Prenom; adhDdn.Value = unAdherant.Naissance; adhSexe.Value = unAdherant.Sexe; adhEmail.Value = unAdherant.Email; adhTelPerso.Value = unAdherant.NumTel; adhTelParent.Value = unAdherant.NumParent; adhAutoPrelev.Value = unAdherant.AutoPrelev; adhArchive.Value = unAdherant.Archive; adhLogin.Value = unAdherant.Login; adhMdp.Value = unAdherant.Mdp; adhClasse.Value = unAdherant.Classe; adhDateMaj.Value = unAdherant.DateMaj; cmd.Parameters.Add(adhId); cmd.Parameters.Add(adhNom); cmd.Parameters.Add(adhPrenom); cmd.Parameters.Add(adhDdn); cmd.Parameters.Add(adhSexe); cmd.Parameters.Add(adhEmail); cmd.Parameters.Add(adhTelPerso); cmd.Parameters.Add(adhTelParent); cmd.Parameters.Add(adhAutoPrelev); cmd.Parameters.Add(adhArchive); cmd.Parameters.Add(adhLogin); cmd.Parameters.Add(adhMdp); cmd.Parameters.Add(adhClasse); cmd.Parameters.Add(adhDateMaj); nbEnr = cmd.ExecuteNonQuery(); // Fermeture de la connexion maConnexion.Close(); return(nbEnr); }
// Cette méthode insert un nouvel Adherant passé en paramètre dans //la BD public static int AjoutAdherant(AdherantBO unAdherant) { int nbEnr; ConnexionBD.GetConnexionBD().CloseConnexion(); SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand("Insert INTO ADHERANT(nom_adherant, prenom_adherant," + " ddn_adherant, sexe_adherant, email_adherant, numtel_adherant, numparent_adherant," + " autoprelev_adherant, login_adherant, mdp_adherant, archive_adherant, id_classe, date_maj_adherant)" + " values(@Nom, @Prenom, @Naissance, @Sexe, @Email, @Numtel, @Telparent," + " @Autoprelev, @Login, @Mdp, @Archive, @Classe, @dateMaj)", maConnexion); SqlParameter adhNom = new SqlParameter("@Nom", SqlDbType.VarChar); SqlParameter adhPrenom = new SqlParameter("@Prenom", SqlDbType.VarChar); SqlParameter adhDdn = new SqlParameter("@Naissance", SqlDbType.Date); SqlParameter adhSexe = new SqlParameter("@Sexe", SqlDbType.VarChar); SqlParameter adhEmail = new SqlParameter("@Email", SqlDbType.VarChar); SqlParameter adhTelPerso = new SqlParameter("@NumTel", SqlDbType.Int); SqlParameter adhTelParent = new SqlParameter("@TelParent", SqlDbType.Int); SqlParameter adhAutoPrelev = new SqlParameter("@Autoprelev", SqlDbType.Char); SqlParameter adhLogin = new SqlParameter("@Login", SqlDbType.VarChar); SqlParameter adhMdp = new SqlParameter("@Mdp", SqlDbType.VarChar); SqlParameter adhArchive = new SqlParameter("@Archive", SqlDbType.Char); SqlParameter adhClasse = new SqlParameter("@Classe", SqlDbType.Int); SqlParameter adhDateMaj = new SqlParameter("@dateMaj", SqlDbType.DateTime); adhNom.Value = unAdherant.Nom; adhPrenom.Value = unAdherant.Prenom; adhDdn.Value = unAdherant.Naissance; adhSexe.Value = unAdherant.Sexe; adhEmail.Value = unAdherant.Email; adhTelPerso.Value = unAdherant.NumTel; adhTelParent.Value = unAdherant.NumParent; adhAutoPrelev.Value = unAdherant.AutoPrelev; adhArchive.Value = 'N'; adhLogin.Value = unAdherant.Login; adhMdp.Value = unAdherant.Mdp; adhClasse.Value = unAdherant.Classe; adhDateMaj.Value = DateTime.Now; cmd.Parameters.Add(adhNom); cmd.Parameters.Add(adhPrenom); cmd.Parameters.Add(adhDdn); cmd.Parameters.Add(adhSexe); cmd.Parameters.Add(adhEmail); cmd.Parameters.Add(adhTelPerso); cmd.Parameters.Add(adhTelParent); cmd.Parameters.Add(adhAutoPrelev); cmd.Parameters.Add(adhArchive); cmd.Parameters.Add(adhLogin); cmd.Parameters.Add(adhMdp); cmd.Parameters.Add(adhClasse); cmd.Parameters.Add(adhDateMaj); nbEnr = cmd.ExecuteNonQuery(); // Fermeture de la connexion maConnexion.Close(); return(nbEnr); }
// Cette méthode retourne une List contenant les objets Adherants //contenus dans la table Identification public static List <AdherantBO> GetAdherants() { int id; string nom; string prenom; DateTime dateNaissance; char sexe; string email; int numeroTel; DateTime dateMaj; int numParent; int classe; char prelevement; string login; string mdp; char archive; AdherantBO unAdherant; // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); // Création d'une liste vide d'objets Adherants List <AdherantBO> lesAdherants = new List <AdherantBO>(); SqlCommand cmd = new SqlCommand(" SELECT * FROM ADHERANT Where archive_adherant = @Archive", maConnexion); SqlParameter adhArchive = new SqlParameter("@Archive", SqlDbType.Char); adhArchive.Value = 'N'; cmd.Parameters.Add(adhArchive); SqlDataReader monReader = cmd.ExecuteReader(); while (monReader.Read()) { id = Int32.Parse(monReader["id_adherant"].ToString()); if (monReader["nom_adherant"] == DBNull.Value) { nom = default(string); } else { nom = monReader["nom_adherant"].ToString(); } if (monReader["prenom_adherant"] == DBNull.Value) { prenom = default(string); } else { prenom = monReader["prenom_adherant"].ToString(); } dateNaissance = DateTime.Parse(monReader["ddn_adherant"].ToString()); sexe = Char.Parse(monReader["sexe_adherant"].ToString()); if (monReader["email_adherant"] == DBNull.Value) { email = default(string); } else { email = monReader["email_adherant"].ToString(); } numeroTel = Int32.Parse(monReader["numtel_adherant"].ToString()); dateMaj = DateTime.Parse(monReader["date_maj_adherant"].ToString()); numParent = Int32.Parse(monReader["numparent_adherant"].ToString()); classe = Int32.Parse(monReader["id_classe"].ToString()); prelevement = Char.Parse(monReader["autoprelev_adherant"].ToString()); if (monReader["login_adherant"] == DBNull.Value) { login = default(string); } else { login = monReader["login_adherant"].ToString(); } if (monReader["mdp_adherant"] == DBNull.Value) { mdp = default(string); } else { mdp = monReader["mdp_adherant"].ToString(); } archive = Char.Parse(monReader["archive_adherant"].ToString()); unAdherant = new AdherantBO(id, nom, prenom, dateNaissance, sexe, email, numeroTel, dateMaj, numParent, classe, prelevement, login, mdp, archive); lesAdherants.Add(unAdherant); } // Fermeture de la connexion maConnexion.Close(); return(lesAdherants); }
public static List <AdherantBO> FiltreAdherant(string textSaisie) { int id; string nom; string prenom; DateTime dateNaissance; char sexe; string email; int numeroTel; DateTime dateMaj; int numParent; int classe; char prelevement; string login; string mdp; char archive; AdherantBO unAdherant; List <AdherantBO> lesAdherants = new List <AdherantBO>(); // Connexion à la BD SqlConnection maConnexion = ConnexionBD.GetConnexionBD().GetSqlConnexion(); SqlCommand cmd = new SqlCommand("Select * from Adherant where nom_adherant Like @Nom" + " or prenom_adherant like @Prenom", maConnexion); SqlParameter adhNom = new SqlParameter("@Nom", SqlDbType.VarChar); SqlParameter adhPrenom = new SqlParameter("@Prenom", SqlDbType.VarChar); adhNom.Value = "%" + textSaisie + "%"; adhPrenom.Value = "%" + textSaisie + "%"; cmd.Parameters.Add(adhNom); cmd.Parameters.Add(adhPrenom); SqlDataReader monReader = cmd.ExecuteReader(); monReader.Read(); id = Int32.Parse(monReader["id_adherant"].ToString()); if (monReader["nom_adherant"] == DBNull.Value) { nom = default(string); } else { nom = monReader["nom_adherant"].ToString(); } if (monReader["prenom_adherant"] == DBNull.Value) { prenom = default(string); } else { prenom = monReader["prenom_adherant"].ToString(); } dateNaissance = DateTime.Parse(monReader["ddn_adherant"].ToString()); sexe = Char.Parse(monReader["sexe_adherant"].ToString()); if (monReader["email_adherant"] == DBNull.Value) { email = default(string); } else { email = monReader["email_adherant"].ToString(); } numeroTel = Int32.Parse(monReader["numtel_adherant"].ToString()); dateMaj = DateTime.Parse(monReader["date_maj_adherant"].ToString()); numParent = Int32.Parse(monReader["numparent_adherant"].ToString()); classe = Int32.Parse(monReader["id_classe"].ToString()); prelevement = Char.Parse(monReader["autoprelev_adherant"].ToString()); if (monReader["login_adherant"] == DBNull.Value) { login = default(string); } else { login = monReader["login_adherant"].ToString(); } if (monReader["mdp_adherant"] == DBNull.Value) { mdp = default(string); } else { mdp = monReader["mdp_adherant"].ToString(); } archive = Char.Parse(monReader["archive_adherant"].ToString()); unAdherant = new AdherantBO(id, nom, prenom, dateNaissance, sexe, email, numeroTel, dateMaj, numParent, classe, prelevement, login, mdp, archive); lesAdherants.Add(unAdherant); maConnexion.Close(); return(lesAdherants); }