Advertisement
Guest User

Untitled

a guest
Aug 27th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using MySql.Data.MySqlClient;
  16. using System.Diagnostics;
  17.  
  18. namespace Salles
  19. {
  20. /// <summary>
  21. /// Logique d'interaction pour PageInscription.xaml
  22. /// </summary>
  23. public partial class PageInscription : UserControl
  24.  
  25. {
  26. ContentControl pagePrincipale = new ContentControl();
  27. public PageInscription(ContentControl pagePrincipale)
  28. {
  29. InitializeComponent();
  30. this.pagePrincipale = pagePrincipale;
  31. // récup message d'erreur
  32. ErrorMessage("");
  33. // initialisation données date de naissance
  34. setBirthDay();
  35. }
  36.  
  37.  
  38. private void inscription(object sender, RoutedEventArgs e)
  39. {
  40. #region vérification de toutes les données du formulaire inscription
  41.  
  42. // Trim supprime les "espaces"
  43. string nom = Nom_textBox.Text.Trim();
  44. string prenom = Prenom_textBox.Text.Trim();
  45. string sexe = definirSexe();
  46. DateTime dateDeNaissance = initializeBirthDay();
  47. string tel = Tel_textBox.Text;
  48. string mail = Mail_textBox.Text;
  49. string username = ChoixUser_textBox.Text.Trim();
  50. string password = Pw_passwordBox.Password.Trim();
  51. string confirmpassword = PwConfirm_passwordBox.Password.Trim();
  52.  
  53. //bool loginExistantOuiNon = RecupLogin(username);
  54.  
  55. ErrorMessage("");
  56.  
  57. // verification que le nom n'est pas vide
  58.  
  59. if (!nom.Equals(""))
  60. {
  61. // verification que le nom n'est pas vide
  62.  
  63. if (!prenom.Equals(""))
  64. {
  65. // verification que le email n'est pas vide
  66.  
  67. if (!mail.Equals(""))
  68. {
  69. // verification que le username n'est pas vide
  70.  
  71. if (!username.Equals("") /*loginExistantOuiNon == false*/ )
  72. {
  73. if (password.Equals(confirmpassword) && (!password.Equals("")))
  74. {
  75.  
  76. procedureIncription(nom, prenom, dateDeNaissance, sexe, mail, username, password, tel);
  77.  
  78. // action d'incription si tout est rempli.
  79. }
  80. else
  81. {
  82. ErrorMessage("Veuillez vérifier votre mot de passe");
  83. }
  84. }
  85. else
  86. {
  87. ErrorMessage("Veuillez entrer votre pseudo");
  88. }
  89. }
  90. else
  91. {
  92. ErrorMessage("Veuillez entrer votre adresse mail");
  93. }
  94. }
  95. else
  96. {
  97. ErrorMessage("Veuillez entrer votre prénom");
  98. }
  99. }
  100. else
  101. {
  102. ErrorMessage("Veuillez entrer votre nom");
  103. }
  104. }
  105. #endregion
  106.  
  107. #region procedure inscription
  108. private void procedureIncription(string nom, string prenom, DateTime birthDay, string sexe, string mail, string username, string password, string tel)
  109. {
  110. //connexion à la DB
  111.  
  112. MySqlConnection connexion = new MySqlConnection();
  113. Connexion maConnexion = new Connexion(connexion, "localhost", "root", "");
  114. if (maConnexion.CreerConnexion())
  115. {
  116.  
  117. if (maConnexion.SelectionnerBaseDeDonnee("sport"))
  118. //connexion etablie
  119. {
  120. //format de la date et de l'heure
  121.  
  122. string format = "yyyy-MM-dd HH:mm:ss";
  123.  
  124. //insertion des données dans la table proprio
  125.  
  126. 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);
  127.  
  128. //insertion des donnés dans la DB
  129.  
  130. if (Traitements.Inserer(requete, connexion))
  131. {
  132. // si tout est ok, la page d'acceuil revient avec l'username rempli
  133. Debug.WriteLine("INSCRIPTION REALISEE");
  134. pagePrincipale.Content = new PageAcceuil(pagePrincipale, username);
  135. }
  136.  
  137. else
  138. //retour du message d'erreur eventuel si insertion non réussie
  139. {
  140. Debug.WriteLine("INSCRIPTION NON REALISEE");
  141. ErrorMessage("ERREUR INSCRIPTION NON REALISEE");
  142.  
  143. }
  144. }
  145. else
  146. {
  147. ErrorMessage("ECHEC DE CONNEXION A LA DB");
  148. }
  149. }
  150. else
  151. {
  152. ErrorMessage("ECHEC DE CONNEXION A LA DB");
  153. }
  154. }
  155. #endregion
  156.  
  157. #region Affichage des messages d'erreur
  158. // les messages d'erreur s'afficheront dans le contenu du Message_label
  159. private void ErrorMessage(string Erreur)
  160. {
  161. Message_label.Content = Erreur;
  162. }
  163. #endregion
  164.  
  165. #region bouton annuler
  166. // lorsqu'on clique sur le bouton annuler, la page acceuil redevient la pagePrincipale
  167. private void retourAcceuil(object sender, RoutedEventArgs e)
  168. {
  169. this.pagePrincipale.Content = new PageAcceuil(pagePrincipale);
  170. }
  171. #endregion
  172.  
  173. #region bouton radios pour le sexe
  174. private string definirSexe()
  175. {
  176. if ((bool)SexeF_radioBouton.IsChecked)
  177. {
  178. return "Féminin";
  179. }
  180. else if ((bool)SexeM_radioBouton.IsChecked)
  181. {
  182. return "Masculin";
  183. }
  184. return "indéfini";
  185.  
  186.  
  187. }
  188. #endregion
  189.  
  190. #region gestion de la recuperation des données de date de naissance
  191. private DateTime initializeBirthDay()
  192. {
  193. int jour = 0;
  194. int mois = 0;
  195. int annee = 0;
  196.  
  197. if (!Jour_comboBox.Text.Equals(""))
  198. {
  199. jour = int.Parse(Jour_comboBox.Text);
  200. }
  201. if (!Mois_comboBox.Text.Equals(""))
  202. {
  203. mois = int.Parse(Mois_comboBox.Text);
  204. }
  205. if (!Annee_comboBox.Text.Equals(""))
  206. {
  207. annee = int.Parse(Annee_comboBox.Text);
  208. }
  209. if (annee != 0 && mois != 0 && jour != 0)
  210. {
  211. return new DateTime(annee, mois, jour);
  212. }
  213. return new DateTime();
  214. }
  215. #endregion
  216.  
  217. #region Date de naissance
  218. private void setBirthDay()
  219. {
  220. // les jours à afficher entre 1 et 31
  221. List<int> nombreJours = new List<int>();
  222. for (int j = 1; j < 32; j++)
  223. {
  224. nombreJours.Add(j);
  225. }
  226. Jour_comboBox.ItemsSource = nombreJours;
  227.  
  228. // les mois à afficher entre 1 et 12
  229. List<int> nombreMois = new List<int>();
  230. for (int m = 1; m < 13; m++)
  231. {
  232. nombreMois.Add(m);
  233. }
  234. Mois_comboBox.ItemsSource = nombreMois;
  235.  
  236. // les années à afficher
  237. {
  238. int now = DateTime.Now.Year;
  239. List<int> nombreAnnees = new List<int>();
  240.  
  241. // 16 ans pour l'age minimum et jusqu'à 120 ans en arrière
  242. for (int a = now + 1 - 16; a > now - 120; a--)
  243. {
  244. nombreAnnees.Add(a);
  245. }
  246. Annee_comboBox.ItemsSource = nombreAnnees;
  247. }
  248. }
  249. #endregion
  250.  
  251. //private bool RecupLogin(string nomUtilisateur)
  252. //{
  253. // MySqlConnection connexion = new MySqlConnection();
  254. // Connexion maConnexion = new Connexion(connexion, "localhost", "root", "");
  255.  
  256. // if (maConnexion.CreerConnexion())
  257. // {
  258.  
  259. // if (maConnexion.SelectionnerBaseDeDonnee("sport"))
  260. // //établissement de la connexion à la db
  261. // {
  262. // List<List<object>> resultat = new List<List<object>>();
  263. // string requete = String.Format("SELECT * FROM proprios WHERE username = \"{0}",nomUtilisateur);
  264. // resultat = Traitements.Selection(maConnexion, requete);
  265.  
  266. // if (resultat.Count > 0)
  267. // {
  268. // return false;
  269. // }
  270. // }
  271. // }
  272. // return true;
  273. //}
  274. }
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement