private void btnInscrire_Click(object sender, RoutedEventArgs e) { //si les champs obligatoires ont ete saisies, on cree un user if (txtCourriel.Text.Length > 0 && txtNom.Text.Length > 0) { if (Regex.IsMatch(txtCourriel.Text, @"^[a-zA-Z0-9\w\.-]*@[a-zA-Z0-9\w\.-]*\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { Personne personneAjoute = new Personne(); Contact contactAjoute = new Contact(); personneAjoute.Adresse = txtAdresse.Text; if (date.Text.Length <= 0) { personneAjoute.Aniversaire = null; } else { personneAjoute.Aniversaire = Convert.ToDateTime(date.Text); } personneAjoute.Celulaire = txtCel.Text; personneAjoute.Compagnie = txtCompagnie.Text; personneAjoute.Courriel = txtCourriel.Text; personneAjoute.LastVisit = null; personneAjoute.Nom = txtNom.Text; personneAjoute.Password = null; personneAjoute.IsUser = false; personneAjoute.IsVisible = false; personneAjoute.Pays = txtPays.Text; personneAjoute.Province = txtProvince.Text; personneAjoute.SiteWeb = txtSite.Text; personneAjoute.Telephone = txtTelephone.Text; personneAjoute.Ville = txtVille.Text; if (NewUrl == null) { personneAjoute.UrlPhoto = @"images\photoProfile.png";//utiliser une valeur par default } else { personneAjoute.UrlPhoto = NewUrl; } contactAjoute.IdUser = User.Id; contactAjoute.IsFavorite = (bool)chkFavorite.IsChecked; bool userCree = PersonneManager.InsertUser(personneAjoute); //tester si la insertion est bien passe if (userCree) { contactAjoute.IdContact = personneAjoute.Id; bool contCree = ContactManager.InsertContact(contactAjoute); if (contCree) { IsModifier = true; this.Close(); } else { IsModifier = false; } } else { txtMsgErreur.Text = "Le contact n'a pas ete cree, ressayez, svp."; } } else { txtMsgErreur.Text = "Entrez un courriel valide, svp."; } } else { txtMsgErreur.Text = "Saisir les champs obligatoires, svp!"; } }
private void btnInscrire_Click(object sender, RoutedEventArgs e) { //si les champs obligatoires ont ete saisies, on cree un user if (txtCourriel.Text.Length > 0 && txtPwd.Password.Length > 0 && txtNom.Text.Length > 0) { Personne personneInscrite = new Personne(); personneInscrite.Adresse = txtAdresse.Text; if (date.Text.Length <= 0) { personneInscrite.Aniversaire = null; } else { personneInscrite.Aniversaire = Convert.ToDateTime(date.Text); } personneInscrite.Celulaire = txtCel.Text; personneInscrite.Compagnie = txtCompagnie.Text; personneInscrite.Courriel = txtCourriel.Text; personneInscrite.IsUser = true; personneInscrite.IsVisible = (bool)chkVisible.IsChecked;//vient comme bool? par default personneInscrite.LastVisit = DateTime.Now; personneInscrite.ListeContact = new List <Contact>(); personneInscrite.ListePersonnes = new List <Personne>(); personneInscrite.Nom = txtNom.Text; personneInscrite.Password = txtPwd.Password; personneInscrite.Pays = txtPays.Text; personneInscrite.Province = txtProvince.Text; personneInscrite.SiteWeb = txtSite.Text; personneInscrite.Telephone = txtTelephone.Text; personneInscrite.Ville = txtVille.Text; if (newUrl == null) { personneInscrite.UrlPhoto = @"images\photoProfile.png";//utiliser une valeur par default } else { personneInscrite.UrlPhoto = newUrl; } bool userCree = PersonneManager.InsertUser(personneInscrite); //tester si la insertion est bien passe if (userCree) { //stocker le user dans la fenetre login MainWindow.User = personneInscrite; //nouvelles fenetres Contacts contactsWindow = new Contacts(personneInscrite); contactsWindow.Show(); this.Close(); } else { txtMsgErreur.Text = "L'utilisateur n'a pas ete cree, ressayez, svp."; } } else { txtMsgErreur.Text = "Saisir les champs obligatoires, svp!"; } }