/// <summary> /// Ouvre la commande fournisseur séléctionnée à l'aide d'une nouvelle fenêtre /// </summary> public Bon_Livraison Open() { if (this._DataGridMain.SelectedItem != null) { if (this._DataGridMain.SelectedItems.Count == 1) { if (((Bon_Livraison)this._DataGridMain.SelectedItem).Facture_Fournisseur1 == null) { //Affichage du message "modification en cours" ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true; ((App)App.Current)._theMainWindow.changementTexteStatusBar("Modification d'un bon de livraison en cours ..."); //Création de la fenêtre BonLivraisonWindow bonlivraisonWindow = new BonLivraisonWindow(); //Initialisation du Datacontext en Bon_Livraison et association à la Bon_Livraison sélectionnée bonlivraisonWindow.DataContext = new Bon_Livraison(); bonlivraisonWindow.DataContext = (Bon_Livraison)this._DataGridMain.SelectedItem; //booléen nullable vrai ou faux ou null bool? dialogResult = bonlivraisonWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { //Si j'appuie sur le bouton Ok, je renvoi l'objet DAO se trouvant dans le datacontext de la fenêtre return (Bon_Livraison)bonlivraisonWindow.DataContext; } else { //Je récupère les anciennes données de la base sur les modifications effectuées ((App)App.Current).mySitaffEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, (Bon_Livraison)(this._DataGridMain.SelectedItem)); //Le bl étant un objet "critique" au niveau des associations, je refresh l'edmx et je relance le filtrage s'il y en avait un afin d'avoir les mêmes infos (invisible pour l'user) ((App)App.Current).refreshEDMXSansVidage(); this.filtrage(); //Si j'appuie sur le bouton annuler, je préviens que j'annule ma modification ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = false; this.recalculMax(); ((App)App.Current)._theMainWindow.changementTexteStatusBar("Modification d'un bon de livraison annulée : " + this.listBL.Count() + " / " + this.max); return null; } } else { MessageBox.Show("Vous ne pouvez modifier ce bon de livraison car il est associé à une facture.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop); return null; } } else { MessageBox.Show("Vous ne devez sélectionner qu'un seul bon de livraison.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation); return null; } } else { MessageBox.Show("Vous devez sélectionner un bon de livraison.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation); return null; } }
/// <summary> /// Ouvre la commande fournisseur séléctionnée en lecture seule à l'aide d'une nouvelle fenêtre /// </summary> public Bon_Livraison Look(Bon_Livraison bon_livraison) { if (this._DataGridMain.SelectedItem != null || bon_livraison != null) { if (this._DataGridMain.SelectedItems.Count == 1 || bon_livraison != null) { //Affichage du message "affichage en cours" ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true; ((App)App.Current)._theMainWindow.changementTexteStatusBar("Affichage d'un bon de livraison en cours ..."); //Création de la fenêtre BonLivraisonWindow bonlivraisonWindow = new BonLivraisonWindow(); //Initialisation du Datacontext en Bon_Livraison et association à la Bon_Livraison sélectionnée bonlivraisonWindow.DataContext = new Bon_Livraison(); if (bon_livraison != null) { bonlivraisonWindow.DataContext = bon_livraison; } else { bonlivraisonWindow.DataContext = (Bon_Livraison)this._DataGridMain.SelectedItem; } //Je positionne la lecture seule sur la fenêtre bonlivraisonWindow.lectureSeule(); bonlivraisonWindow.soloLecture = true; //J'affiche la fenêtre bool? dialogResult = bonlivraisonWindow.ShowDialog(); //Affichage du message "affichage en cours" ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = false; ((App)App.Current)._theMainWindow.changementTexteStatusBar("Affichage d'un bon de livraison terminé : " + this.listBL.Count() + " / " + this.max); //Renvoi null return null; } else { MessageBox.Show("Vous ne devez sélectionner qu'un seul bon de livraison.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation); return null; } } else { MessageBox.Show("Vous devez sélectionner une bon de livraison.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation); return null; } }
/// <summary> /// Ajoute une nouvelle Bon_Livraison à la liste à l'aide d'une nouvelle fenêtre /// </summary> public Bon_Livraison Add() { //Affichage du message "ajout en cours" ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true; ((App)App.Current)._theMainWindow.changementTexteStatusBar("Ajout d'un bon de livraison en cours ..."); //Initialisation de la fenêtre BonLivraisonWindow bonlivraisonWindow = new BonLivraisonWindow(); //Création de l'objet temporaire Bon_Livraison tmp = new Bon_Livraison(); //Mise de l'objet temporaire dans le datacontext bonlivraisonWindow.DataContext = tmp; SelectionTypeBL selectionTypeBL = new SelectionTypeBL(); bool? dialogDemandeTypeBL = selectionTypeBL.ShowDialog(); if (dialogDemandeTypeBL.HasValue && dialogDemandeTypeBL.Value == true) { if (selectionTypeBL.affaire == null && selectionTypeBL.commande_fournisseur == null) { //Stock ou Divers ? SelectionStockDiversBLWindow selectionStockDiversBLWindow = new SelectionStockDiversBLWindow(); bool? dialogStockDivers = selectionStockDiversBLWindow.ShowDialog(); if (dialogStockDivers.HasValue && dialogStockDivers.Value == true) { tmp.StockAtelier = selectionStockDiversBLWindow.stock; tmp.Divers = selectionStockDiversBLWindow.divers; } else { return null; } } if (selectionTypeBL.affaire == null && selectionTypeBL.commande_fournisseur != null) { tmp.StockAtelier = selectionTypeBL.commande_fournisseur.Stock; tmp.Divers = selectionTypeBL.commande_fournisseur.Divers; } if (selectionTypeBL.commande_fournisseur != null) { tmp.Fournisseur1 = selectionTypeBL.commande_fournisseur.Fournisseur1; if (selectionTypeBL.commande_fournisseur.Fournisseur1 != null) { bonlivraisonWindow._comboBoxFournisseur.IsEnabled = false; } } tmp.Affaire1 = selectionTypeBL.affaire; tmp.Commande_Fournisseur1 = selectionTypeBL.commande_fournisseur; tmp.Salarie1 = selectionTypeBL.salarie; //booléen nullable vrai ou faux ou null bool? dialogResult = bonlivraisonWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { //Si j'appuie sur le bouton Ok, je renvoi l'objet bon_livraison se trouvant dans le datacontext de la fenêtre return (Bon_Livraison)bonlivraisonWindow.DataContext; } else { try { //On détache tous les élements liés au bl Bon_Livraison_Contenu_Commande_Supplementaire ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire> toRemove = new ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire>(); foreach (Bon_Livraison_Contenu_Commande_Supplementaire item in ((Bon_Livraison)bonlivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire) { toRemove.Add(item); } foreach (Bon_Livraison_Contenu_Commande_Supplementaire item in toRemove) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache tous les élements liés au bl Bon_Livraison_Contenu_Commande ObservableCollection<Bon_Livraison_Contenu_Commande> toRemove1 = new ObservableCollection<Bon_Livraison_Contenu_Commande>(); foreach (Bon_Livraison_Contenu_Commande item in ((Bon_Livraison)bonlivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande) { toRemove1.Add(item); } foreach (Bon_Livraison_Contenu_Commande item in toRemove1) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache le bl ((App)App.Current).mySitaffEntities.Detach((Bon_Livraison)bonlivraisonWindow.DataContext); } catch (Exception) { } //Si j'appuie sur le bouton annuler, je préviens que j'annule mon ajout ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = false; this.recalculMax(); ((App)App.Current)._theMainWindow.changementTexteStatusBar("Ajout d'un bon de livraison annulé : " + this.listBL.Count() + " / " + this.max); return null; } } else { //Si j'appuie sur le bouton annuler, je préviens que j'annule mon ajout ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = false; this.recalculMax(); ((App)App.Current)._theMainWindow.changementTexteStatusBar("Ajout d'un bon de livraison annulé : " + this.listBL.Count() + " / " + this.max); return null; } }
private void _buttonModifierBonLivraison_Click(object sender, RoutedEventArgs e) { if (this._dataGridBonLivraison.SelectedItems.Count <= 0) { MessageBox.Show("Vous devez sélectionner un bon de livraison à modifier.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop); } else if (this._dataGridBonLivraison.SelectedItems.Count > 1) { MessageBox.Show("Vous ne devez sélectionner qu'un bon de livraison à modifier.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop); } else if (this._dataGridBonLivraison.SelectedItem != null) { if (((Bon_Livraison)this._dataGridBonLivraison.SelectedItem).Facture_Fournisseur1 == null) { BonLivraisonWindow bonLivraisonWindow = new BonLivraisonWindow(); bonLivraisonWindow.DataContext = (Bon_Livraison)this._dataGridBonLivraison.SelectedItem; ((Bon_Livraison)bonLivraisonWindow.DataContext).Fournisseur1 = ((Commande_Fournisseur)this.DataContext).Fournisseur1; bool? dialogResult = bonLivraisonWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { this._dataGridBonLivraison.Items.Refresh(); } else { try { ((App)App.Current).mySitaffEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, (Bon_Livraison)bonLivraisonWindow.DataContext); } catch (Exception) { } } } else { MessageBox.Show("Vous ne pouvez modifier ce bon de livraison car il est associé à une facture.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop); } } this.VerrouillerContenu(); }
private void _buttonAjouterBonLivraison_Click(object sender, RoutedEventArgs e) { BonLivraisonWindow bonLivraisonWindow = new BonLivraisonWindow(); bonLivraisonWindow.DataContext = new Bon_Livraison(); ((Bon_Livraison)bonLivraisonWindow.DataContext).Commande_Fournisseur1 = (Commande_Fournisseur)this.DataContext; ((Bon_Livraison)bonLivraisonWindow.DataContext).StockAtelier = ((Commande_Fournisseur)this.DataContext).Stock; ((Bon_Livraison)bonLivraisonWindow.DataContext).Divers = ((Commande_Fournisseur)this.DataContext).Divers; ((Bon_Livraison)bonLivraisonWindow.DataContext).Affaire1 = ((Commande_Fournisseur)this.DataContext).Affaire1; ((Bon_Livraison)bonLivraisonWindow.DataContext).Salarie1 = ((Commande_Fournisseur)this.DataContext).Salarie; ((Bon_Livraison)bonLivraisonWindow.DataContext).Fournisseur1 = ((Commande_Fournisseur)this.DataContext).Fournisseur1; bonLivraisonWindow._comboBoxFournisseur.IsEnabled = false; bool? dialogResult = bonLivraisonWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { } else { // On enlève tous les contenu de commandes associés foreach (Bon_Livraison_Contenu_Commande blcc in ((Bon_Livraison)bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande) { try { ((App)App.Current).mySitaffEntities.Detach(blcc); ((Bon_Livraison)bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande.Remove(blcc); } catch (Exception) { ((Bon_Livraison)bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande.Remove(blcc); ((App)App.Current).mySitaffEntities.Detach(blcc); } } //On enlève tous les contenu supp foreach (Bon_Livraison_Contenu_Commande_Supplementaire blcc in ((Bon_Livraison)bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire) { try { ((App)App.Current).mySitaffEntities.Detach(blcc); ((Bon_Livraison)bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Remove(blcc); } catch (Exception) { ((Bon_Livraison)bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Remove(blcc); ((App)App.Current).mySitaffEntities.Detach(blcc); } } //On détache le BL try { ((App)App.Current).mySitaffEntities.Detach((Bon_Livraison)bonLivraisonWindow.DataContext); ((Commande_Fournisseur)this.DataContext).Bon_Livraison.Remove((Bon_Livraison)bonLivraisonWindow.DataContext); } catch (Exception) { ((Commande_Fournisseur)this.DataContext).Bon_Livraison.Remove((Bon_Livraison)bonLivraisonWindow.DataContext); ((App)App.Current).mySitaffEntities.Detach((Bon_Livraison)bonLivraisonWindow.DataContext); } } this.VerrouillerContenu(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { BonLivraisonWindow bonlivraisonWindow = new BonLivraisonWindow(); //Création de l'objet temporaire Bon_Livraison tmp = new Bon_Livraison(); //Mise de l'objet temporaire dans le datacontext bonlivraisonWindow.DataContext = tmp; SelectionTypeBL selectionTypeBL = new SelectionTypeBL(); bool? dialogDemandeTypeBL = selectionTypeBL.ShowDialog(); if (dialogDemandeTypeBL.HasValue && dialogDemandeTypeBL.Value == true) { if (selectionTypeBL.affaire == null && selectionTypeBL.commande_fournisseur == null) { //Stock ou Divers ? SelectionStockDiversBLWindow selectionStockDiversBLWindow = new SelectionStockDiversBLWindow(); bool? dialogStockDivers = selectionStockDiversBLWindow.ShowDialog(); if (dialogStockDivers.HasValue && dialogStockDivers.Value == true) { tmp.StockAtelier = selectionStockDiversBLWindow.stock; tmp.Divers = selectionStockDiversBLWindow.divers; } else { } } if (selectionTypeBL.affaire == null && selectionTypeBL.commande_fournisseur != null) { tmp.StockAtelier = selectionTypeBL.commande_fournisseur.Stock; tmp.Divers = selectionTypeBL.commande_fournisseur.Divers; } if (selectionTypeBL.commande_fournisseur != null) { tmp.Fournisseur1 = selectionTypeBL.commande_fournisseur.Fournisseur1; if (selectionTypeBL.commande_fournisseur.Fournisseur1 != null) { bonlivraisonWindow._comboBoxFournisseur.IsEnabled = false; } } tmp.Affaire1 = selectionTypeBL.affaire; tmp.Commande_Fournisseur1 = selectionTypeBL.commande_fournisseur; tmp.Salarie1 = selectionTypeBL.salarie; //booléen nullable vrai ou faux ou null bool? dialogResult = bonlivraisonWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { try { ((App)App.Current).mySitaffEntities.AddToBon_Livraison((Bon_Livraison)bonlivraisonWindow.DataContext); } catch (Exception) { } } else { try { //On détache tous les élements liés au bl Bon_Livraison_Contenu_Commande_Supplementaire ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire> toRemove = new ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire>(); foreach (Bon_Livraison_Contenu_Commande_Supplementaire item in ((Bon_Livraison)bonlivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire) { toRemove.Add(item); } foreach (Bon_Livraison_Contenu_Commande_Supplementaire item in toRemove) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache tous les élements liés au bl Bon_Livraison_Contenu_Commande ObservableCollection<Bon_Livraison_Contenu_Commande> toRemove1 = new ObservableCollection<Bon_Livraison_Contenu_Commande>(); foreach (Bon_Livraison_Contenu_Commande item in ((Bon_Livraison)bonlivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande) { toRemove1.Add(item); } foreach (Bon_Livraison_Contenu_Commande item in toRemove1) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache le bl ((App)App.Current).mySitaffEntities.Detach((Bon_Livraison)bonlivraisonWindow.DataContext); } catch (Exception) { } } } else { try { ((App)App.Current).mySitaffEntities.Detach((Bon_Livraison)bonlivraisonWindow.DataContext); } catch (Exception) { } } this.SelectionAutoBL(); }