public Ajouter(etudiant e) { InitializeComponent(); fillWithStudent(e); mode = "modifie"; etu = e; button.Content = "Modifie"; }
private void Button_Click(object sender, RoutedEventArgs e) { DataClasses1DataContext cl = new DataClasses1DataContext(); if (datep.SelectedDate == null || textsexe.Text == "" || textcne.Text == "" || textnom.Text == "" || textprenom.Text == "" || textfiliere.SelectedItem == null) { MessageBox.Show("Merci de remplire tous les champs"); } else { var nom = textnom.Text; var prenom = textprenom.Text; var filiere = textfiliere.SelectedItem; var date = datep.SelectedDate; var image = image_file.FilePath; var sexe = textsexe.Text; var telephone = texttele.Text; var cne = textcne.Text; byte[] b = image_file.FilePath == "" ? etu.picture.ToArray() : File.ReadAllBytes(image_file.FilePath); if (mode == "ajoute") { etu = new etudiant(); } else { etu = (from c in cl.etudiant where c.id_etudiant == etu.id_etudiant select c).FirstOrDefault(); } etu.sexe = sexe[0]; etu.cne = cne; etu.tele = telephone; etu.prenom = prenom; etu.nom = nom; etu.date_naissance = date; etu.id_filiere = ((filiere)filiere).id_filiere; etu.picture = b; if (mode == "ajoute") { cl.etudiant.InsertOnSubmit(etu); } cl.SubmitChanges(); MessageBox.Show("Etudiant " + mode + " avec succes"); Gestion_Etudiants ge = new Gestion_Etudiants(); ge.Show(); this.Close(); } }
private void fillWithStudent(etudiant e) { textnom.Text = e.nom; textprenom.Text = e.prenom; textfiliere.Text = e.filiere.nom_filiere; datep.SelectedDate = e.date_naissance; image_file.FilePath = ""; textsexe.Text = e.sexe.ToString(); texttele.Text = e.tele; textcne.Text = e.cne; image.Source = byteArrayToImage(e.picture.ToArray()); }
private void BtnModifier_Click(object sender, RoutedEventArgs e) { if (grido.SelectedItem == null) { MessageBox.Show("Veuillez selectionner un etudiant"); } else { etudiant selected = (etudiant)grido.SelectedItem; Ajouter a = new Ajouter(selected); a.Show(); this.Close(); } }
private void btnSupprimer_Click(object sender, RoutedEventArgs e) { if (grido.SelectedItem == null) { MessageBox.Show("Veuillez selectionner un etudiant"); } else { MessageBoxResult message = MessageBox.Show("Vous etes sure?", "Confirmation de suppression", System.Windows.MessageBoxButton.YesNo); if (message == MessageBoxResult.Yes) { etudiant selected = (etudiant)grido.SelectedItem; var s = from st in cl.etudiant where st.id_etudiant == selected.id_etudiant select st; cl.etudiant.DeleteOnSubmit(s.FirstOrDefault()); cl.SubmitChanges(); grido.Items.Refresh(); MessageBox.Show("Etudiant supprimer avec succes"); } } }
partial void Deleteetudiant(etudiant instance);
partial void Updateetudiant(etudiant instance);
partial void Insertetudiant(etudiant instance);
private void detach_etudiant(etudiant entity) { this.SendPropertyChanging(); entity.filiere = null; }
private void attach_etudiant(etudiant entity) { this.SendPropertyChanging(); entity.filiere = this; }