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(); }
/// <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; } }
/// <summary> /// Ajoute une nouvelle Facture à la liste à l'aide d'une nouvelle fenêtre /// </summary> public Facture_Proforma Add() { //Affichage du message "ajout en cours" ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true; ((App)App.Current)._theMainWindow.changementTexteStatusBar("Ajout d'une facture proforma en cours ..."); //Initialisation de la fenêtre FactureProformaWindow factureproformaWindow = new FactureProformaWindow(); //Création de l'objet temporaire Facture_Proforma tmp = new Facture_Proforma(); //Mise de l'objet temporaire dans le datacontext factureproformaWindow.DataContext = tmp; MessageBoxResult resultatDemande = MessageBox.Show("Une commande est-elle associée à votre facture proforma ?", "Association commande ?", MessageBoxButton.YesNo, MessageBoxImage.Question); if (resultatDemande == MessageBoxResult.Yes) { SelectionTypeBL selectionTypeBL = new SelectionTypeBL(); selectionTypeBL.Title = "Sélection commande"; selectionTypeBL.testSupp = true; selectionTypeBL._comboBoxAffaire.Visibility = Visibility.Collapsed; selectionTypeBL._comboBoxDonneurOrdre.Visibility = Visibility.Collapsed; selectionTypeBL._textBlockAffaire.Visibility = Visibility.Collapsed; selectionTypeBL._textBlockDonneurOrdre.Visibility = Visibility.Collapsed; bool? dialogDemandeTypeBL = selectionTypeBL.ShowDialog(); if (dialogDemandeTypeBL.HasValue && dialogDemandeTypeBL.Value == true) { ((Facture_Proforma)factureproformaWindow.DataContext).Commande_Fournisseur1 = selectionTypeBL.commande_fournisseur; if (selectionTypeBL.commande_fournisseur.Affaire1 != null) { ((Facture_Proforma)factureproformaWindow.DataContext).Affaire1 = selectionTypeBL.commande_fournisseur.Affaire1; } ((Facture_Proforma)factureproformaWindow.DataContext).Fournisseur1 = selectionTypeBL.commande_fournisseur.Fournisseur1; } 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'une facture proforma annulé : " + this.listFactureProforma.Count() + " / " + this.max); return null; } } else if (resultatDemande == MessageBoxResult.No) { ChoixTypeCommandeWindow choixTypeCommandeWindows = new ChoixTypeCommandeWindow(); choixTypeCommandeWindows.Title = "Sélection type facture proforma"; bool? dialogChoix = choixTypeCommandeWindows.ShowDialog(); if (dialogChoix.HasValue && dialogChoix.Value == true) { if (choixTypeCommandeWindows.affaire != null) { ((Facture_Proforma)factureproformaWindow.DataContext).Affaire1 = choixTypeCommandeWindows.affaire; } if (choixTypeCommandeWindows.stock == true) { ((Facture_Proforma)factureproformaWindow.DataContext).Stock = true; } if (choixTypeCommandeWindows.divers == true) { ((Facture_Proforma)factureproformaWindow.DataContext).Divers = true; } ((Facture_Proforma)factureproformaWindow.DataContext).Entreprise_Mere1 = choixTypeCommandeWindows.entreprise_mere; } 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'une facture proforma annulé : " + this.listFactureProforma.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'une facture proforma annulé : " + this.listFactureProforma.Count() + " / " + this.max); return null; } //booléen nullable vrai ou faux ou null bool? dialogResult = factureproformaWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { //Si j'appuie sur le bouton Ok, je renvoi l'objet facture se trouvant dans le datacontext de la fenêtre return (Facture_Proforma)factureproformaWindow.DataContext; } else { try { //On détache la facture proforma ((App)App.Current).mySitaffEntities.Detach((Facture_Proforma)factureproformaWindow.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'une facture proforma annulé : " + this.listFactureProforma.Count() + " / " + this.max); return null; } }