public InsertData(string etat, Quartiers ele, QuartiersViewModel view) { InitializeComponent(); this.DataContext = viewVM = view; Etat = etat; if (etat == "AJOUT") { this.Title = "Enregistrement d'un Quartier"; } else { this.Title = "Modification d'un Quartier"; } }
private void btnValider_Click(object sender, RoutedEventArgs e) { try { QuartiersViewModel vm = this.DataContext as QuartiersViewModel; Quartiers ent = vm.SelectedData; if (Etat == "AJOUT") { try { ent.Etat = "ACTIF"; ent.idHotel = 1; viewVM.model.Quartiers.Add(ent); viewVM.model.SaveChanges(); Msg = "OK"; this.Close(); } catch (Exception ex) { Msg = "Error"; ErrorMsg = ex.Message; } } else { try { viewVM.model.SaveChanges(); Msg = "OK"; this.Close(); } catch (Exception ex) { Msg = "Error"; ErrorMsg = ex.Message; } } } catch (Exception) { } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { //if (GlobalData.VerificationDroit("CanAddQuartiers")) //{ var result = MessageBox.Show("Voulez vous vraiment supprimer ?", "Message", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { if (dataGrid.SelectedItem != null) { try { viewM = this.Main.DataContext as QuartiersViewModel; Quartiers ent = dataGrid.SelectedItem as Quartiers; ent.Etat = "SUPPRIMER"; viewM.model.SaveChanges(); viewM.Refresh(); MessageBox.Show("Opération effectuée avec succès", "Quartiers", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Quartiers", MessageBoxButton.OK, MessageBoxImage.Warning); viewM.Refresh(); } } else { MessageBox.Show("Aucune ligne selectionnée dans la liste", "Quartiers", MessageBoxButton.OK, MessageBoxImage.Warning); } } //} }