示例#1
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);
                }
            }
        }
 /// <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;
         }
     }
 }