コード例 #1
0
 /// <summary>
 /// Action quand la séléction d'un adhérent a changé
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void adherentsBindingSource_CurrentChanged(object sender, EventArgs e)
 {
     /// Si la ligne séléctionnée est présente (non-null)
     if (adherentsBindingSource.Current != null)
     {
         /// Je récupère celle-ci et Fill la liste des inscriptions de cet adhérent par rapport à son IdAdherent
         cda27_bd2DataSet.adherentsRow currentRow = (cda27_bd2DataSet.adherentsRow)((DataRowView)adherentsBindingSource.Current).Row;
         // TODO: cette ligne de code charge les données dans la table 'cda27_bd2DataSet.activite'. Vous pouvez la déplacer ou la supprimer selon les besoins.
         this.inscriptionsTableAdapter.Fill(this.cda27_bd2DataSet.inscriptions, currentRow.IdAdherent);
     }
     /// Si la liste des inscriptions contient quelque chose
     if (inscriptionsBindingSource.Count != 0)
     {
         /// Le bouton Désinscrire est actif
         buttonDesinscrireAdherent.Enabled         = true;
         buttonModifierInscriptionActivite.Enabled = true;
     }
     /// Sinon
     else
     {
         /// Le bouton est inactif
         buttonDesinscrireAdherent.Enabled         = false;
         buttonModifierInscriptionActivite.Enabled = false;
     }
 }
コード例 #2
0
        /// <summary>
        /// Au bouton "Supprimer" (Supprimer l'adhérent)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSupprimer_Click(object sender, EventArgs e)
        {
            /// Je récupère la ligne adhérent du FormMain avec la variable BindingSource précédemment transférée (adherentbind)
            cda27_bd2DataSet.adherentsRow currentRow = (cda27_bd2DataSet.adherentsRow)((DataRowView)adherentbind.Current).Row;
            /// J'affiche un message de confirmation pour cette suppression
            DialogResult DiagResult = MessageBox.Show(String.Format(Properties.Resources.STR_MESSAGE_SUPPRESSION_ADHERENT, currentRow.Login),
                                                      String.Format(Properties.Resources.STR_TITRE_SUPPRESSION_ADHERENT, currentRow.Nom, currentRow.Prénom),
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Information,
                                                      MessageBoxDefaultButton.Button2
                                                      );;

            /// Si l'utilisateur accepte la suppression
            if (DiagResult == DialogResult.Yes)
            {
                /// Je supprime l'adhérent avec les valeurs de la ligne séléctionnée
                int nb = adherentTableAdapter.Delete(currentRow.IdAdherent,
                                                     currentRow.Nom,
                                                     currentRow.Prénom,
                                                     currentRow.Date_de_naissance,
                                                     currentRow.Adresse,
                                                     null,
                                                     currentRow.Code_postale,
                                                     currentRow.Ville,
                                                     currentRow.Email,
                                                     currentRow.Téléphone,
                                                     currentRow._Date_d_adhésion,
                                                     currentRow.Organisateur,
                                                     currentRow.Admin,
                                                     currentRow.Login,
                                                     currentRow.Password,
                                                     currentRow.Cylindrée,
                                                     currentRow.Activé);
                /// Si la requête n'a pas réussi
                if (nb == 0)
                {
                    /// Message d'erreur
                    MessageBox.Show(Properties.Resources.STR_MESSAGE_SUPPRESSION_FAIL,
                                    Properties.Resources.STR_TITRE_SUPPRESSION_FAIL,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                /// Si la requête a réussi
                else
                {
                    /// Variable IsClose est à 1, elle me servira dans le FormMain
                    IsClose = true;
                    /// Je close la fenêtre
                    Close();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Action du bouton Supprimer dans l'onglet Adhérent (Supprimer un adhérent)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSupprimerAdherent_Click(object sender, EventArgs e)
        {
            /// Je récupère la ligne de l'adhérent séléctionnée
            cda27_bd2DataSet.adherentsRow currentRow = (cda27_bd2DataSet.adherentsRow)((DataRowView)adherentsBindingSource.Current).Row;
            if (currentRow.IdAdherent == 100)
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_IMPOSSIBLE_SUPPRIMER_SECRETAIRE,
                                Properties.Resources.STR_TITRE_IMPOSSIBLE_SUPPRIMER_SECRETAIRE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            /// J'affiche un message de confirmation pour cette suppression
            DialogResult DiagResult = MessageBox.Show(String.Format(Properties.Resources.STR_MESSAGE_SUPPRESSION_ADHERENT, currentRow.Login),
                                                      String.Format(Properties.Resources.STR_TITRE_SUPPRESSION_ADHERENT, currentRow.Nom, currentRow.Prénom),
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Information,
                                                      MessageBoxDefaultButton.Button2
                                                      );;

            /// Si l'utilisateur accepte la suppression
            if (DiagResult == DialogResult.Yes)
            {
                /// Je supprime l'adhérent en me servant du TableAdapter de l'adhérent avec les données de la ligne active
                /// J'enregistre le résultat de la requête pour vérifier qu'elle a bien été exécutée
                int nb = adherentTableAdapter.Delete(currentRow.IdAdherent, currentRow.Nom, currentRow.Prénom, currentRow.Date_de_naissance, currentRow.Adresse,
                                                     null, currentRow.Code_postale, currentRow.Ville, currentRow.Email, currentRow.Téléphone, currentRow._Date_d_adhésion, currentRow.Organisateur,
                                                     currentRow.Admin, currentRow.Login, currentRow.Password, currentRow.Cylindrée, currentRow.Activé);
                /// Si la requête n'a pas aboutie
                if (nb == 0)
                {
                    /// J'affiche un message d'echec
                    MessageBox.Show(Properties.Resources.STR_MESSAGE_SUPPRESSION_FAIL, Properties.Resources.STR_TITRE_SUPPRESSION_FAIL, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                /// Je FillIntegral
                FillIntegral();
            }
        }
コード例 #4
0
        /// <summary>
        /// Au bouton "Modifier" (Modifier l'adhérent)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btModifier_Click(object sender, EventArgs e)
        {
            string Avatar = null;

            /// Je récupère la ligne courante de l'adhérent de la fenêtre MainForm par une variable transférée (adherentbind)
            cda27_bd2DataSet.adherentsRow currentRow = (cda27_bd2DataSet.adherentsRow)((DataRowView)adherentbind.Current).Row;
            /// Récupération de l'IdAdherent pour une récupération dans la fenêtre main pour un repositionnage sur l'adhérent
            LastInsert = currentRow.IdAdherent;
            /// J'initialise l'organisateur en short? (type short nullable
            short?Organisateur;

            /// Si le checkBox organisateur est coché alors Organisateur vaut 1
            if (checkBoxOrganisateur.Checked == true)
            {
                Organisateur = 1;
            }
            /// Sinon il vaut 0
            else
            {
                Organisateur = 0;
            }
            /// J'initialise Active en int
            int Active;

            /// Si Activé est coché alors Active vaut 1
            if (checkBoxActive.Checked == true)
            {
                Active = 1;
            }
            /// Sinon il vaut 0
            else
            {
                Active = 0;
            }
            /// Vérification de mes champs, si ils sont null ou comportent des espaces
            if (String.IsNullOrWhiteSpace(textBoxNom.Text) ||
                String.IsNullOrWhiteSpace(textBoxPrenom.Text) ||
                String.IsNullOrWhiteSpace(textBoxAdresse.Text) ||
                String.IsNullOrWhiteSpace(textBoxCodePostale.Text) ||
                String.IsNullOrWhiteSpace(textBoxVille.Text) ||
                String.IsNullOrWhiteSpace(textBoxTelephone.Text) ||
                String.IsNullOrWhiteSpace(textBoxLogin.Text) ||
                String.IsNullOrWhiteSpace(textBoxCylindree.Text) ||
                String.IsNullOrWhiteSpace(textBoxEmail.Text) ||
                String.IsNullOrWhiteSpace(textBoxAPropos.Text))
            {
                // Messsage d'erreur, un champs n'est pas saisie puis je quitte l'évenement
                MessageBox.Show(Properties.Resources.STR_MESSAGE_CHAMPS_NON_REMPLI,
                                Properties.Resources.STR_TITRE_CHAMPS_NON_REMPLI,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            /// Vérification de mes champs avec des Regex (expressions régulières)
            /// Message d'erreur si ils ne sont pas valides
            else if (!IsEmail(textBoxEmail.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_EMAIL_NON_VALIDE,
                                Properties.Resources.STR_TITRE_EMAIL_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (!IsPhoneNbr(textBoxTelephone.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_NUMERO_NON_VALIDE,
                                Properties.Resources.STR_TITRE_NUMERO_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (!IsName(textBoxNom.Text) || !IsName(textBoxNom.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_NOM_NON_VALIDE,
                                Properties.Resources.STR_TITRE_NOM_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (!IsCodePostale(textBoxCodePostale.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_CODEPOSTALE_NON_VALIDE,
                                Properties.Resources.STR_TITRE_CODEPOSTALE_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (!IsAdresse(textBoxAdresse.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_ADRESSE_NON_VALIDE,
                                Properties.Resources.STR_TITRE_ADRESSE_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (!IsVille(textBoxVille.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_VILLE_NON_VALIDE,
                                Properties.Resources.STR_TITRE_VILLE_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (!IsCylindree(textBoxCylindree.Text))
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_CYLINDREE_NON_VALIDE,
                                Properties.Resources.STR_TITRE_CYLINDREE_NON_VALIDE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (textBoxAPropos.Text.Length > 250)
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_ERREUR_APROPOS,
                                Properties.Resources.STR_TITRE_ERREUR_APROPOS,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            else if (textBoxLogin.Text.Length > 30)
            {
                MessageBox.Show(Properties.Resources.STR_MESSAGE_LOGIN_TROP_LONG,
                                Properties.Resources.STR_TITRE_LOGIN_TROP_LONG,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            /// Fin de vérification de mes champs avec des Regex (expressions régulières)
            /// Mise en variable de la requête de Count du Login
            int countNb = Convert.ToInt32(adherentsTableAdapter.Count(textBoxLogin.Text));

            /// Si il existe déjà et qu'il n'est pas le login current
            if (countNb == 1 && textBoxLogin.Text != Login)
            {
                /// Message d'erreur, un adhérent a déjà ce login
                MessageBox.Show(Properties.Resources.STR_MESSAGE_LOGIN_EXISTANT,
                                Properties.Resources.STR_TITRE_LOGIN_EXISTANT,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            /// Si toutes les vérifications sont OK
            else
            {
                if (currentRow.IsAvatarNull())
                {
                    Avatar = null;
                }
                else
                {
                    Avatar = currentRow.Avatar;
                }
                /// Je fais la mise à jour en utilisant tous les champs
                /// Comme anciennes valeurs j'utilise le currentRow du BindingSource précédemment transféré de la fenêtre MainForm
                int nb = adherentTableAdapter.Update(textBoxNom.Text,
                                                     textBoxPrenom.Text,
                                                     dateTimePickerDateDeNaissance.Value,
                                                     textBoxAdresse.Text,
                                                     null,
                                                     textBoxCodePostale.Text,
                                                     textBoxVille.Text,
                                                     textBoxEmail.Text,
                                                     textBoxTelephone.Text,
                                                     currentRow._Date_d_adhésion,
                                                     Organisateur,
                                                     0,
                                                     textBoxLogin.Text,
                                                     currentRow.Password,
                                                     textBoxCylindree.Text,
                                                     Avatar,
                                                     Active,
                                                     textBoxAPropos.Text,
                                                     currentRow.IdAdherent,
                                                     currentRow.Nom,
                                                     currentRow.Prénom,
                                                     currentRow.Date_de_naissance,
                                                     currentRow.Adresse,
                                                     null,
                                                     currentRow.Code_postale,
                                                     currentRow.Ville,
                                                     currentRow.Email,
                                                     currentRow.Téléphone,
                                                     currentRow._Date_d_adhésion,
                                                     currentRow.Organisateur,
                                                     currentRow.Admin,
                                                     currentRow.Login,
                                                     currentRow.Password,
                                                     currentRow.Cylindrée,
                                                     currentRow.Activé);
                /// Si la requête réussi
                if (nb == 1)
                {
                    /// Message de succès
                    MessageBox.Show(Properties.Resources.STR_MESSAGE_MODIFICATION_SUCCES,
                                    Properties.Resources.STR_TITRE_MODIFICATION_SUCCES,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    /// La fenêtre va se fermer, la variable sera utilisée dans une condition dans le FormMain
                    IsClose = true;
                    /// Je ferme la fenêtre
                    Close();
                }
                /// Sinon, il y a un problème dans l'ajout
                else
                {
                    /// Message d'erreur : Problème dans la modification de l'adhérent
                    MessageBox.Show(Properties.Resources.STR_MESSAGE_PROBLEME_MODIF_ADHERENT,
                                    Properties.Resources.STR_TITRE_PROBLEME_MODIF_ADHERENT,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Rafraîchissement intégral des dataGridViews
 /// TryCatch si la bdd est déconnectée alors on affiche un message d'erreur et on quitte le logiciel
 /// </summary>
 public void FillIntegral()
 {
     try
     {
         /// Si le filtre par date est coché
         if (checkBoxChoisirDate.Checked)
         {
             /// Je Fill entre les deux dates la liste des activités
             this.activitesTableAdapter.FillByDate(this.cda27_bd2DataSet.activites, dateTimePickerFirstDate.Value, dateTimePickerSecondDate.Value);;
         }
         else
         {
             /// Sinon je Fill tout court
             this.activitesTableAdapter.Fill(this.cda27_bd2DataSet.activites);
         }
         if (activitesBindingSourceListeAct.Current != null)
         {
             /// Je récupère la ligne d'activité séléctionnée
             cda27_bd2DataSet.activitesRow currentRow = (cda27_bd2DataSet.activitesRow)((DataRowView)activitesBindingSourceListeAct.Current).Row;
             /// Je Fill les inscriptions des adherents avec l'IdActivite de la ligne séléctionnée
             this.adherentinscriptionTableAdapter.FillBy(this.cda27_bd2DataSet1.adherentinscription, currentRow.IdActivite);
             /// Je Fill les adhérents non-inscrits
             this.adherents2TableAdapter.FillBy(this.cda27_bd2DataSet1.adherents2, currentRow.IdActivite);
             /// Je Fill les adherents
             this.adherentsTableAdapter.Fill(this.cda27_bd2DataSet.adherents);
             /// Je rends visible les datagrid inscrits et non inscrits car il y a une activité
             dataGridViewInscrits.Visible    = true;
             dataGridViewNonInscrits.Visible = true;
         }
         /// Sinon je les rends invisible
         else
         {
             dataGridViewInscrits.Visible    = false;
             dataGridViewNonInscrits.Visible = false;
         }
         if (adherentsBindingSource.Current != null)
         {
             /// Je récupère la ligne séléctionnée des adhérents
             cda27_bd2DataSet.adherentsRow currentRow2 = (cda27_bd2DataSet.adherentsRow)((DataRowView)adherentsBindingSource.Current).Row;
             /// Je Fill les inscriptions pour cet adhérent
             this.inscriptionsTableAdapter.Fill(this.cda27_bd2DataSet.inscriptions, currentRow2.IdAdherent);
             /// Si il y a un adhérent alors je rends visible ses inscriptions
             dataGridViewActiviteRelationAdherent.Visible = true;
         }
         /// Sinon je les rends invisible
         else
         {
             dataGridViewActiviteRelationAdherent.Visible = false;
         }
         /// Je Clear les selections des inscrits et non inscrits
         dataGridViewNonInscrits.ClearSelection();
         dataGridViewInscrits.ClearSelection();
     }
     catch (Exception ex)
     {
         VaSeFermer = true;
         MessageBox.Show(Properties.Resources.STR_MESSAGE_CONNEXION_BDD_ERROR,
                         Properties.Resources.STR_TITRE_CONNEXION_BDD_ERROR,
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Warning);
         this.Close();
     }
 }
コード例 #6
0
 /// <summary>
 /// Action du bouton Modifier dans l'onglet Adhérent (Modifier un adhérent)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btModifier_Click(object sender, EventArgs e)
 {
     /// Using de la formDetailAdherent (nouvelle fenêtre) pour faire un "dispose" à la fermeture
     using (formDetailAdherent formDetailAdherent = new formDetailAdherent())
     {
         /// Récupération de la ligne courrante pour une utilisation des valeurs de ses colonnes
         cda27_bd2DataSet.adherentsRow currentRow = (cda27_bd2DataSet.adherentsRow)((DataRowView)adherentsBindingSource.Current).Row;
         if (currentRow.IdAdherent == 100)
         {
             MessageBox.Show(Properties.Resources.STR_MESSAGE_IMPOSSIBLE_MODIFIER_SECRETAIRE,
                             Properties.Resources.STR_TITRE_IMPOSSIBLE_SUPPRIMER_SECRETAIRE,
                             MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
             return;
         }
         /// Mise des valeurs dans les TextBox et dateTimePicker correspondant à l'adhérent
         formDetailAdherent.textBoxNom.Text    = currentRow.Nom;
         formDetailAdherent.textBoxPrenom.Text = currentRow.Prénom;
         formDetailAdherent.textBoxAge.Text    = null;
         formDetailAdherent.dateTimePickerDateDeNaissance.Value = currentRow.Date_de_naissance;
         formDetailAdherent.dateTimePickerDateAdhesion.Value    = currentRow._Date_d_adhésion;
         formDetailAdherent.textBoxAdresse.Text     = currentRow.Adresse;
         formDetailAdherent.textBoxCodePostale.Text = currentRow.Code_postale;
         formDetailAdherent.textBoxVille.Text       = currentRow.Ville;
         formDetailAdherent.textBoxEmail.Text       = currentRow.Email;
         formDetailAdherent.textBoxTelephone.Text   = currentRow.Téléphone;
         formDetailAdherent.textBoxLogin.Text       = currentRow.Login;
         formDetailAdherent.Login           = currentRow.Login;
         formDetailAdherent.textBoxAge.Text = Convert.ToString(CalculAge(currentRow.Date_de_naissance)) + "ans";
         /// Si la colonne organisateur est à 1 alors la checkBox prévue à cet effet est cochée
         if (currentRow.Organisateur == 1)
         {
             formDetailAdherent.checkBoxOrganisateur.Checked = true;
         }
         /// Sinon décochée
         else
         {
             formDetailAdherent.checkBoxOrganisateur.Checked = false;
         }
         /// De même si la colonne activé est à 1 ...
         if (currentRow.Activé == 1)
         {
             formDetailAdherent.checkBoxActive.Checked = true;
         }
         else
         {
             formDetailAdherent.checkBoxActive.Checked = false;
         }
         formDetailAdherent.textBoxCylindree.Text = currentRow.Cylindrée;
         formDetailAdherent.textBoxAPropos.Text   = currentRow.A_propos;
         /// Fill du dataGridView des inscriptions de l'adhérent avec comme argument son IdAdherent
         formDetailAdherent.inscriptionsTableAdapter.Fill(formDetailAdherent.cda27_bd2DataSet.inscriptions, currentRow.IdAdherent);
         /// Si un avatar n'est pas défini il prendra une valeur par défaut
         string FileAvatar = currentRow.IsAvatarNull() ? Properties.Resources.STR_AVATAR_PAR_DEFAUT : currentRow.Avatar;
         /// La pictureBox ira alors chercher l'avatar sur internet (cda27.s1.2isa.org)
         formDetailAdherent.pictureBoxAvatar.ImageLocation = Properties.Resources.STR_ADRESSE_AVATAR + FileAvatar;
         /// Injection du bindingSource directement dans le code de la fenêtre fille
         formDetailAdherent.adherentbind = adherentsBindingSource;
         /// Ajouter devient invisible (pas besoin d'ajouter si l'on modifie)
         formDetailAdherent.btAjouter.Visible = false;
         /// On affiche la fenêtre en mode Dialog (Le using aurait été impossible sinon)
         formDetailAdherent.ShowDialog();
         /// Si la fenêtre se ferme
         if (formDetailAdherent.IsClose)
         {
             /// Je FillIntegral et me positionne sur l'adhérent que je viens de modifier
             FillIntegral();
             adherentsBindingSource.Position = adherentsBindingSource.Find("IdAdherent", formDetailAdherent.LastInsert);
             /// Je rétablie la valeur 0 à IsClose
             formDetailAdherent.IsClose = false;
         }
     }
 }