Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using MySql.Data.MySqlClient;
- using System.Diagnostics;
- namespace Salles
- {
- /// <summary>
- /// Logique d'interaction pour PageInscription.xaml
- /// </summary>
- public partial class PageInscription : UserControl
- {
- ContentControl pagePrincipale = new ContentControl();
- public PageInscription(ContentControl pagePrincipale)
- {
- InitializeComponent();
- this.pagePrincipale = pagePrincipale;
- // récup message d'erreur
- ErrorMessage("");
- // initialisation données date de naissance
- setBirthDay();
- }
- private void inscription(object sender, RoutedEventArgs e)
- {
- #region vérification de toutes les données du formulaire inscription
- // Trim supprime les "espaces"
- string nom = Nom_textBox.Text.Trim();
- string prenom = Prenom_textBox.Text.Trim();
- string sexe = definirSexe();
- DateTime dateDeNaissance = initializeBirthDay();
- string tel = Tel_textBox.Text;
- string mail = Mail_textBox.Text;
- string username = ChoixUser_textBox.Text.Trim();
- string password = Pw_passwordBox.Password.Trim();
- string confirmpassword = PwConfirm_passwordBox.Password.Trim();
- //bool loginExistantOuiNon = RecupLogin(username);
- ErrorMessage("");
- // verification que le nom n'est pas vide
- if (!nom.Equals(""))
- {
- // verification que le nom n'est pas vide
- if (!prenom.Equals(""))
- {
- // verification que le email n'est pas vide
- if (!mail.Equals(""))
- {
- // verification que le username n'est pas vide
- if (!username.Equals("") /*loginExistantOuiNon == false*/ )
- {
- if (password.Equals(confirmpassword) && (!password.Equals("")))
- {
- procedureIncription(nom, prenom, dateDeNaissance, sexe, mail, username, password, tel);
- // action d'incription si tout est rempli.
- }
- else
- {
- ErrorMessage("Veuillez vérifier votre mot de passe");
- }
- }
- else
- {
- ErrorMessage("Veuillez entrer votre pseudo");
- }
- }
- else
- {
- ErrorMessage("Veuillez entrer votre adresse mail");
- }
- }
- else
- {
- ErrorMessage("Veuillez entrer votre prénom");
- }
- }
- else
- {
- ErrorMessage("Veuillez entrer votre nom");
- }
- }
- #endregion
- #region procedure inscription
- private void procedureIncription(string nom, string prenom, DateTime birthDay, string sexe, string mail, string username, string password, string tel)
- {
- //connexion à la DB
- MySqlConnection connexion = new MySqlConnection();
- Connexion maConnexion = new Connexion(connexion, "localhost", "root", "");
- if (maConnexion.CreerConnexion())
- {
- if (maConnexion.SelectionnerBaseDeDonnee("sport"))
- //connexion etablie
- {
- //format de la date et de l'heure
- string format = "yyyy-MM-dd HH:mm:ss";
- //insertion des données dans la table proprio
- string requete = String.Format("INSERT INTO proprios(username, password, nom, prenom,sexe, birthdate,tel, mail)VALUE(\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\")", username, password, nom, prenom, sexe, birthDay.ToString(format), tel, mail);
- //insertion des donnés dans la DB
- if (Traitements.Inserer(requete, connexion))
- {
- // si tout est ok, la page d'acceuil revient avec l'username rempli
- Debug.WriteLine("INSCRIPTION REALISEE");
- pagePrincipale.Content = new PageAcceuil(pagePrincipale, username);
- }
- else
- //retour du message d'erreur eventuel si insertion non réussie
- {
- Debug.WriteLine("INSCRIPTION NON REALISEE");
- ErrorMessage("ERREUR INSCRIPTION NON REALISEE");
- }
- }
- else
- {
- ErrorMessage("ECHEC DE CONNEXION A LA DB");
- }
- }
- else
- {
- ErrorMessage("ECHEC DE CONNEXION A LA DB");
- }
- }
- #endregion
- #region Affichage des messages d'erreur
- // les messages d'erreur s'afficheront dans le contenu du Message_label
- private void ErrorMessage(string Erreur)
- {
- Message_label.Content = Erreur;
- }
- #endregion
- #region bouton annuler
- // lorsqu'on clique sur le bouton annuler, la page acceuil redevient la pagePrincipale
- private void retourAcceuil(object sender, RoutedEventArgs e)
- {
- this.pagePrincipale.Content = new PageAcceuil(pagePrincipale);
- }
- #endregion
- #region bouton radios pour le sexe
- private string definirSexe()
- {
- if ((bool)SexeF_radioBouton.IsChecked)
- {
- return "Féminin";
- }
- else if ((bool)SexeM_radioBouton.IsChecked)
- {
- return "Masculin";
- }
- return "indéfini";
- }
- #endregion
- #region gestion de la recuperation des données de date de naissance
- private DateTime initializeBirthDay()
- {
- int jour = 0;
- int mois = 0;
- int annee = 0;
- if (!Jour_comboBox.Text.Equals(""))
- {
- jour = int.Parse(Jour_comboBox.Text);
- }
- if (!Mois_comboBox.Text.Equals(""))
- {
- mois = int.Parse(Mois_comboBox.Text);
- }
- if (!Annee_comboBox.Text.Equals(""))
- {
- annee = int.Parse(Annee_comboBox.Text);
- }
- if (annee != 0 && mois != 0 && jour != 0)
- {
- return new DateTime(annee, mois, jour);
- }
- return new DateTime();
- }
- #endregion
- #region Date de naissance
- private void setBirthDay()
- {
- // les jours à afficher entre 1 et 31
- List<int> nombreJours = new List<int>();
- for (int j = 1; j < 32; j++)
- {
- nombreJours.Add(j);
- }
- Jour_comboBox.ItemsSource = nombreJours;
- // les mois à afficher entre 1 et 12
- List<int> nombreMois = new List<int>();
- for (int m = 1; m < 13; m++)
- {
- nombreMois.Add(m);
- }
- Mois_comboBox.ItemsSource = nombreMois;
- // les années à afficher
- {
- int now = DateTime.Now.Year;
- List<int> nombreAnnees = new List<int>();
- // 16 ans pour l'age minimum et jusqu'à 120 ans en arrière
- for (int a = now + 1 - 16; a > now - 120; a--)
- {
- nombreAnnees.Add(a);
- }
- Annee_comboBox.ItemsSource = nombreAnnees;
- }
- }
- #endregion
- //private bool RecupLogin(string nomUtilisateur)
- //{
- // MySqlConnection connexion = new MySqlConnection();
- // Connexion maConnexion = new Connexion(connexion, "localhost", "root", "");
- // if (maConnexion.CreerConnexion())
- // {
- // if (maConnexion.SelectionnerBaseDeDonnee("sport"))
- // //établissement de la connexion à la db
- // {
- // List<List<object>> resultat = new List<List<object>>();
- // string requete = String.Format("SELECT * FROM proprios WHERE username = \"{0}",nomUtilisateur);
- // resultat = Traitements.Selection(maConnexion, requete);
- // if (resultat.Count > 0)
- // {
- // return false;
- // }
- // }
- // }
- // return true;
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement