/// <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; } }
/// <summary> /// Ajoute une nouvelle Commande_Fournisseur à la liste à l'aide d'une nouvelle fenêtre /// </summary> public Commande_Fournisseur Add() { //Affichage du message "ajout en cours" ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true; ((App)App.Current)._theMainWindow.changementTexteStatusBar("Ajout d'une commande fournisseur en cours ..."); //Initialisation de la fenêtre ChoixTypeCommandeWindow choixTypeCommandeWindows = new ChoixTypeCommandeWindow(); CommandeWindow commandeWindow = new CommandeWindow(); //Création de l'objet temporaire Commande_Fournisseur tmp = new Commande_Fournisseur(); tmp.Utilisateur1 = ((App)App.Current)._connectedUser; //Mise de l'objet temporaire dans le datacontext commandeWindow.DataContext = tmp; //Définition du type de commande bool? dialogChoix = choixTypeCommandeWindows.ShowDialog(); if (dialogChoix.HasValue && dialogChoix.Value == true) { if (choixTypeCommandeWindows.affaire != null) { ((Commande_Fournisseur)commandeWindow.DataContext).Affaire1 = choixTypeCommandeWindows.affaire; } if (choixTypeCommandeWindows.stock == true) { ((Commande_Fournisseur)commandeWindow.DataContext).Stock = true; } if (choixTypeCommandeWindows.divers == true) { ((Commande_Fournisseur)commandeWindow.DataContext).Divers = true; } ((Commande_Fournisseur)commandeWindow.DataContext).Entreprise_Mere1 = choixTypeCommandeWindows.entreprise_mere; //booléen nullable vrai ou faux ou null bool? dialogResult = commandeWindow.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value == true) { //Si j'appuie sur le bouton Ok, je renvoi l'objet commande se trouvant dans le datacontext de la fenêtre return (Commande_Fournisseur)commandeWindow.DataContext; } else { try { //On détache tous les élements liés à la commande Commande_Fournisseur_Condition_Reglement ObservableCollection<Commande_Fournisseur_Condition_Reglement> toRemove = new ObservableCollection<Commande_Fournisseur_Condition_Reglement>(); foreach (Commande_Fournisseur_Condition_Reglement item in ((Commande_Fournisseur)commandeWindow.DataContext).Commande_Fournisseur_Condition_Reglement) { toRemove.Add(item); } foreach (Commande_Fournisseur_Condition_Reglement item in toRemove) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache tous les élements liés à la commande Contenu_Commande_Fournisseur ObservableCollection<Contenu_Commande_Fournisseur> toRemove1 = new ObservableCollection<Contenu_Commande_Fournisseur>(); foreach (Contenu_Commande_Fournisseur item in ((Commande_Fournisseur)commandeWindow.DataContext).Contenu_Commande_Fournisseur) { toRemove1.Add(item); } foreach (Contenu_Commande_Fournisseur item in toRemove1) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache tous les élements liés à la commande Bon_Livraison ObservableCollection<Bon_Livraison> toRemove2 = new ObservableCollection<Bon_Livraison>(); foreach (Bon_Livraison item in ((Commande_Fournisseur)commandeWindow.DataContext).Bon_Livraison) { toRemove2.Add(item); } foreach (Bon_Livraison item in toRemove2) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache tous les élements liés à la commande Facture_Proforma ObservableCollection<Facture_Proforma> toRemove3 = new ObservableCollection<Facture_Proforma>(); foreach (Facture_Proforma item in ((Commande_Fournisseur)commandeWindow.DataContext).Facture_Proforma) { toRemove3.Add(item); } foreach (Facture_Proforma item in toRemove3) { ((App)App.Current).mySitaffEntities.Detach(item); } //On détache la commande ((App)App.Current).mySitaffEntities.Detach((Commande_Fournisseur)commandeWindow.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 commande fournisseur annulé : " + this.listCommandes.Count() + " / " + this.max); return null; } } else { try { ((App)App.Current).mySitaffEntities.Detach((Commande_Fournisseur)commandeWindow.DataContext); //Pas besoin de détacher le reste car ici l'utilisateur annule avant qu'il n'ait pu insérer quoi que ce soit } 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 commande fournisseur annulé : " + this.listCommandes.Count() + " / " + this.max); return null; } }