private void btnAdd_Click(object sender, RoutedEventArgs e) { try { viewM = this.Main.DataContext as CommunesViewModel; viewM.SelectedData = new Communes(); InsertData view = new InsertData("AJOUT", viewM.SelectedData, viewM); view.ShowDialog(); if (view.Msg == "OK") { MessageBox.Show("Opération effectuée avec succès", "Communes", MessageBoxButton.OK, MessageBoxImage.Information); viewM.Refresh(); } else if (view.Msg == "Error") { MessageBox.Show(" Echec Opération ", "Communes ", MessageBoxButton.OK, MessageBoxImage.Warning); viewM.Refresh(); } else { viewM.Refresh(); } //} } catch (Exception ex) { MessageBox.Show(ex.Message, "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void btnAnnuler_Click(object sender, RoutedEventArgs e) { CommunesViewModel vehi = this.DataContext as CommunesViewModel; vehi.SelectedData = null; this.Close(); }
//Evenement double clic du RadGridview void OnGridMouseDoubleClick(object sender, MouseButtonEventArgs e) { FrameworkElement originalSender = e.OriginalSource as FrameworkElement; if (originalSender != null) { //var cell = originalSender.ParentOfType<GridViewCell>(); //if (cell != null) //{ // MessageBox.Show("The double-clicked cell is " + cell.Value); //} var row = originalSender.ParentOfType <GridViewRow>(); if (row != null) { try { if (GlobalData.VerificationDroit("CanEditCommunes")) { viewM = this.Main.DataContext as CommunesViewModel; InsertData view = new InsertData("MOD", viewM.SelectedData, viewM); view.ShowDialog(); if (view.Msg == "OK") { MessageBox.Show("Opération effectuée avec succès", "Communes", MessageBoxButton.OK, MessageBoxImage.Information); viewM.Refresh(); } else if (view.Msg == "Error") { MessageBox.Show(" Echec Opération ", "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); viewM.Refresh(); } else { viewM.Refresh(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "Veuillez fermer le formulaire puis recommencer.", "CATEGORIE", MessageBoxButton.OK, MessageBoxImage.Warning); } } } }
public InsertData(string etat, Communes ele, CommunesViewModel 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 { CommunesViewModel vm = this.DataContext as CommunesViewModel; Communes ent = vm.SelectedData; if (Etat == "AJOUT") { try { ent.Etat = "ACTIF"; ent.idHotel = 1; viewVM.model.Communes.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 btnEdit_Click(object sender, RoutedEventArgs e) { if (dataGrid.SelectedItem != null) { try { //if (GlobalData.VerificationDroit("CanAddCommunes")) //{ viewM = this.Main.DataContext as CommunesViewModel; InsertData view = new InsertData("MOD", viewM.SelectedData, viewM); view.ShowDialog(); if (view.Msg == "OK") { MessageBox.Show("Opération effectuée avec succès", "Communes", MessageBoxButton.OK, MessageBoxImage.Information); viewM.Refresh(); } else if (view.Msg == "Error") { MessageBox.Show(" Echec Opération ", "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); viewM.Refresh(); } else { viewM.Refresh(); } //} } catch (Exception ex) { MessageBox.Show(ex.Message, "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("Aucune ligne selectionnée dans la liste", "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { //if (GlobalData.VerificationDroit("CanAddCommunes")) //{ 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 CommunesViewModel; Communes ent = dataGrid.SelectedItem as Communes; ent.Etat = "SUPPRIMER"; viewM.model.SaveChanges(); viewM.Refresh(); MessageBox.Show("Opération effectuée avec succès", "Communes", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); viewM.Refresh(); } } else { MessageBox.Show("Aucune ligne selectionnée dans la liste", "Communes", MessageBoxButton.OK, MessageBoxImage.Warning); } } //} }
private void btnRefresh_Click(object sender, RoutedEventArgs e) { viewM = this.Main.DataContext as CommunesViewModel; viewM.Refresh(); }