/// <summary>
        /// Ouvre la facture séléctionnée à l'aide d'une nouvelle fenêtre
        /// </summary>
        public Personne Open()
        {
            if (this._DataGridMain.SelectedItem != null)
            {
                if (this._DataGridMain.SelectedItems.Count == 1)
                {
                    //Affichage du message "modification en cours"
                    ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true;
            ((App)App.Current)._theMainWindow.changementTexteStatusBar("Modification d'un contact en cours ...");

                    //Création de la fenêtre
                    ContactWindow contactWindow = new ContactWindow();

                    //Initialisation du Datacontext en contact et association à la personne sélectionnée
                    contactWindow.DataContext = new Personne();
                    contactWindow.DataContext = (Personne)this._DataGridMain.SelectedItem;

                    //booléen nullable vrai ou faux ou null
                    bool? dialogResult = contactWindow.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 (Personne)contactWindow.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, (Personne)(this._DataGridMain.SelectedItem));
                        //La commande é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 contact annulé : " + this.Contacts.Count() + " / " + this.max);

                        return null;
                    }
                }
                else
                {
                    MessageBox.Show("Vous ne devez sélectionner qu'un seul contact.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return null;
                }
            }
            else
            {
                MessageBox.Show("Vous devez sélectionner un contact.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return null;
            }
        }
        /// <summary>
        /// Ajoute une nouvelle Facture à la liste à l'aide d'une nouvelle fenêtre
        /// </summary>
        public Personne Add()
        {
            //Affichage du message "ajout en cours"
            ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true;
            ((App)App.Current)._theMainWindow.changementTexteStatusBar("Ajout d'un contact en cours ...");

            //Initialisation de la fenêtre
            ContactWindow contactWindow = new ContactWindow();

            //Création de l'objet temporaire
            Personne tmp = new Personne();
            tmp.Contact = new Contact();

            //Mise de l'objet temporaire dans le datacontext
            contactWindow.DataContext = tmp;

            //booléen nullable vrai ou faux ou null
            bool? dialogResult = contactWindow.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 (Personne)contactWindow.DataContext;
            }
            else
            {
                try
                {
                    //On détache le contact
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Detach(((Personne)contactWindow.DataContext).Contact);
                    }
                    catch (Exception) { }
                    ((App)App.Current).mySitaffEntities.Detach((Personne)contactWindow.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 contact annulé : " + this.Contacts.Count() + " / " + this.max);

                return null;
            }
        }
        /// <summary>
        /// Ouvre la facture séléctionnée en lecture seule à l'aide d'une nouvelle fenêtre
        /// </summary>
        public Personne Look(Personne personneToLook)
        {
            if (this._DataGridMain.SelectedItem != null || personneToLook != null)
            {
                if (this._DataGridMain.SelectedItems.Count == 1 || personneToLook != null)
                {
                    //Affichage du message "affichage en cours"
                    ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = true;
            ((App)App.Current)._theMainWindow.changementTexteStatusBar("Affichage d'un contact en cours ...");

                    //Création de la fenêtre
                    ContactWindow contactWindow = new ContactWindow();

                    //Initialisation du Datacontext en Commande_Fournisseur et association à la Commande_Fournisseur sélectionnée
                    contactWindow.DataContext = new Personne();
                    if (personneToLook != null)
                    {
                        contactWindow.DataContext = personneToLook;
                    }
                    else
                    {
                        contactWindow.DataContext = (Personne)this._DataGridMain.SelectedItem;
                    }

                    //Je positionne la lecture seule sur la fenêtre
                    contactWindow.lectureSeule();
                    contactWindow.soloLecture = true;

                    //J'affiche la fenêtre
                    bool? dialogResult = contactWindow.ShowDialog();

                    //Affichage du message "affichage en cours"
                    ((App)App.Current)._theMainWindow.progressBarMainWindow.IsIndeterminate = false;
            ((App)App.Current)._theMainWindow.changementTexteStatusBar("Affichage d'un contact terminé : " + this.Contacts.Count() + " / " + this.max);

                    //Renvoi null
                    return null;
                }
                else
                {
                    MessageBox.Show("Vous ne devez sélectionner qu'un seul contact.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return null;
                }
            }
            else
            {
                MessageBox.Show("Vous devez sélectionner un contact.", "Attention", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return null;
            }
        }
        private void _buttonIntNouveauContact_Click(object sender, RoutedEventArgs e)
        {
            if (this._comboBoxIntEntreprise.SelectedItem != null)
            {
                ContactWindow contactWindow = new ContactWindow();
                Personne tmp = new Personne();

                tmp.Entreprise1 = ((Entreprise)this._comboBoxIntEntreprise.SelectedItem);
                tmp.Contact = new Contact();
                contactWindow.DataContext = tmp;

                //booléen nullable vrai ou faux ou null
                bool? dialogResult = contactWindow.ShowDialog();
                Personne personne = (Personne)contactWindow.DataContext;

                if (dialogResult.HasValue && dialogResult.Value == true)
                {
                    this.listContact.Clear();
                    if (this._comboBoxIntEntreprise.SelectedItem != null)
                    {
                        foreach (Personne pers in ((Entreprise)this._comboBoxIntEntreprise.SelectedItem).Personne)
                        {
                            if (pers.Contact != null)
                            {
                                this.listContact.Add(pers.Contact);
                            }
                        }
                    }
                    this._comboBoxIntContact.SelectedItem = personne.Contact;
                }
                else
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Detach(personne.Contact);
                        ((App)App.Current).mySitaffEntities.Detach(personne);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ((App)App.Current).mySitaffEntities.Contact.DeleteObject(personne.Contact);
                            ((App)App.Current).mySitaffEntities.Personne.DeleteObject(personne);
                        }
                        catch (Exception)
                        {

                        }
                    }
                }
            }
        }
        private void NewContact_Click(object sender, RoutedEventArgs e)
        {
            ContactWindow contactWindow = new ContactWindow();
            Personne tmp = new Personne();

            ObservableCollection<Entreprise> toPutOnComboBox = new ObservableCollection<Entreprise>(((App)App.Current).mySitaffEntities.Entreprise.OrderBy(ent => ent.Libelle));
            if (!toPutOnComboBox.Contains((Entreprise)this._comboBoxClient.SelectedItem))
            {
                toPutOnComboBox.Add((Entreprise)this._comboBoxClient.SelectedItem);
            }
            contactWindow.EntrepriseList = new ObservableCollection<Entreprise>(toPutOnComboBox.OrderBy(ent => ent.Libelle));

            if (this._comboBoxClient.SelectedItem != null)
            {
                tmp.Entreprise1 = (Entreprise)this._comboBoxClient.SelectedItem;
            }
            tmp.Contact = new Contact();
            contactWindow.DataContext = tmp;

            //booléen nullable vrai ou faux ou null
            bool? dialogResult = contactWindow.ShowDialog();
            Personne personne = (Personne)contactWindow.DataContext;

            if (dialogResult.HasValue && dialogResult.Value == true)
            {
                ((App)App.Current).mySitaffEntities.AddToPersonne(personne);
                this.listContact.Clear();
                if (this._comboBoxClient.SelectedItem != null)
                {
                    foreach (Personne pers in ((Entreprise)this._comboBoxClient.SelectedItem).Personne.Where(per => per.Contact != null))
                    {
                        this.listContact.Add(pers.Contact);
                    }
                }
                this._comboBoxContact.SelectedItem = personne.Contact;
                if (this._comboBoxClient.SelectedItem != null)
                {
                    Entreprise E = (Entreprise)this._comboBoxClient.SelectedItem;
                    ObservableCollection<Contact> temp = new ObservableCollection<Contact>();
                    foreach (Personne p in E.Personne)
                    {
                        if (p.Contact != null)
                        {
                            temp.Add(p.Contact);
                        }
                    }
                    this._comboBoxContact.ItemsSource = temp;
                }
            }
            else
            {
                try
                {
                    ((App)App.Current).mySitaffEntities.Detach(personne.Contact);
                    ((App)App.Current).mySitaffEntities.Detach(personne);
                }
                catch (Exception)
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Contact.DeleteObject(personne.Contact);
                        ((App)App.Current).mySitaffEntities.Personne.DeleteObject(personne);
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
        private void _ButtonContactNouveau_Click(object sender, RoutedEventArgs e)
        {
            if (this._TextBoxCoordonnéesNom.Text.Trim() != "")
            {
                ContactWindow contactWindow = new ContactWindow();
                contactWindow.DataContext = new Personne();

                ObservableCollection<Entreprise> toPutOnComboBox = new ObservableCollection<Entreprise>(((App)App.Current).mySitaffEntities.Entreprise.OrderBy(ent => ent.Libelle));
                if (!toPutOnComboBox.Contains((Entreprise)this.DataContext))
                {
                    toPutOnComboBox.Add((Entreprise)this.DataContext);
                }
                contactWindow.EntrepriseList = new ObservableCollection<Entreprise>(toPutOnComboBox.OrderBy(ent => ent.Libelle));

                ((Personne)contactWindow.DataContext).Entreprise1 = (Entreprise)this.DataContext;
                ((Personne)contactWindow.DataContext).Contact = new Contact();
                contactWindow._ComboBoxContactEntreprise.IsEnabled = false;
                bool? dialogResult = contactWindow.ShowDialog();

                if (dialogResult.HasValue && dialogResult.Value == true)
                {
                    ((Entreprise)this.DataContext).Personne.Add((Personne)contactWindow.DataContext);
                    this.ContactsList.Add((Personne)contactWindow.DataContext);
                }
                else
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Detach((Personne)contactWindow.DataContext);
                        ((Entreprise)this.DataContext).Personne.Remove((Personne)contactWindow.DataContext);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ((Entreprise)this.DataContext).Personne.Remove((Personne)contactWindow.DataContext);
                            ((App)App.Current).mySitaffEntities.Detach((Personne)contactWindow.DataContext);
                        }
                        catch (Exception) { }
                    }
                }
                try
                {
                    this._dataGridContact.Items.Refresh();
                }
                catch (Exception) { }
            }
            else
            {
                MessageBox.Show("Veuillez donner un nom à votre entreprise s'il vous plait avant d'ajouter un contact", "pré-requis", MessageBoxButton.OK);
            }
        }
        private void _ButtonContactModifier_Click(object sender, RoutedEventArgs e)
        {
            if (this._dataGridContact.SelectedItems.Count <= 0)
            {
                MessageBox.Show("Vous devez sélectionner un contact à modifier.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
            else if (this._dataGridContact.SelectedItems.Count > 1)
            {
                MessageBox.Show("Vous ne devez sélectionner qu'un contact à modifier.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
            else if (this._dataGridContact.SelectedItem != null)
            {
                ContactWindow contactWindow = new ContactWindow();
                contactWindow.DataContext = (Personne)this._dataGridContact.SelectedItem;
                if (!contactWindow.EntrepriseList.Contains((Entreprise)this.DataContext))
                {
                    contactWindow.EntrepriseList.Add((Entreprise)this.DataContext);
                    contactWindow.EntrepriseList = new ObservableCollection<Entreprise>(contactWindow.EntrepriseList.OrderBy(ent => ent.Libelle));
                }
                contactWindow._ComboBoxContactEntreprise.IsEnabled = false;

                bool? dialogResult = contactWindow.ShowDialog();

                if (dialogResult.HasValue && dialogResult.Value == true)
                {
                    this._dataGridContact.Items.Refresh();
                }
                else
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, (Personne)contactWindow.DataContext);
                        this._dataGridContact.Items.Refresh();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        //Ouvre une fenêtre pour ajouter un nouveau contact
        private void _buttonAjouterNouveauContactGridContact_Click(object sender, RoutedEventArgs e)
        {
            ContactWindow contactWindow = new ContactWindow();
            Contact tmp = new Contact();

            contactWindow.DataContext = tmp;

            //booléen nullable vrai ou faux ou null
            bool? dialogResult = contactWindow.ShowDialog();
            Contact contact = (Contact)contactWindow.DataContext;

            if (dialogResult.HasValue == true && dialogResult.Value == false)
            {
                try
                {
                    ((App)App.Current).mySitaffEntities.Detach(contact);
                }
                catch (Exception)
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Contact.DeleteObject(contact);
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
        private void NewContact_Click(object sender, RoutedEventArgs e)
        {
            ContactWindow contactWindow = new ContactWindow();
            Personne tmp = new Personne();
            if (this._comboBoxFournisseur.SelectedItem != null)
            {
                tmp.Entreprise1 = ((Fournisseur)this._comboBoxFournisseur.SelectedItem).Entreprise;
            }
            tmp.Contact = new Contact();
            contactWindow.DataContext = tmp;

            //booléen nullable vrai ou faux ou null
            bool? dialogResult = contactWindow.ShowDialog();
            Personne personne = (Personne)contactWindow.DataContext;

            if (dialogResult.HasValue && dialogResult.Value == true)
            {
                this.listContacts.Clear();
                if (this._comboBoxFournisseur.SelectedItem != null)
                {
                    foreach (Personne pers in ((Fournisseur)this._comboBoxFournisseur.SelectedItem).Entreprise.Personne.Where(per => per.Contact != null))
                    {
                        this.listContacts.Add(pers.Contact);
                    }
                }
                this._comboBoxContact.SelectedItem = personne.Contact;
                if (this._comboBoxEntLivraison.SelectedItem != null)
                {
                    Entreprise E = (Entreprise)this._comboBoxEntLivraison.SelectedItem;
                    this._comboBoxContact.SelectedItem = personne.Contact;
                    ObservableCollection<Contact> temp = new ObservableCollection<Contact>();
                    foreach (Personne p in E.Personne)
                    {
                        if (p.Contact != null)
                        {
                            temp.Add(p.Contact);
                        }
                    }
                    this._comboBoxContactLivraison.ItemsSource = temp;
                }
            }
            else
            {
                try
                {
                    ((App)App.Current).mySitaffEntities.Detach(personne.Contact);
                    ((App)App.Current).mySitaffEntities.Detach(personne);
                }
                catch (Exception)
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Contact.DeleteObject(personne.Contact);
                        ((App)App.Current).mySitaffEntities.Personne.DeleteObject(personne);
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
        private void NewContact_Click(object sender, RoutedEventArgs e)
        {
            //ListeContactsControl listeContactsControl = new ListeContactsControl();
            //Personne personne = ((App)App.Current)._theMainWindow.AddContacts(listeContactsControl);
            //if (personne != null)
            //{
            //    if (personne.Contact != null)
            //    {
            //        if (devis.Client2 != null)
            //        {
            //            this.Contacts = new ObservableCollection<Contact>(((App)App.Current).mySitaffEntities.Contact.Where(con => con.Personne.Entreprise1.Libelle == devis.Client2.Entreprise.Libelle).OrderBy(con => con.Personne.Nom));
            //        }
            //        else
            //        {
            //            this.Contacts = new ObservableCollection<Contact>(((App)App.Current).mySitaffEntities.Contact.OrderBy(con => con.Personne.Nom));
            //        }
            //        this._ComboBoxDevisChoixContact.SelectedItem = personne.Contact;
            //    }
            //}
            //else
            //{
            //    this._ComboBoxDevisChoixContact.SelectedItem = null;
            //}
            ContactWindow contactWindow = new ContactWindow();
            Personne tmp = new Personne();
            if (this.entreprise != null)
            {
                tmp.Entreprise1 = this.entreprise;
                contactWindow._ComboBoxContactEntreprise.IsEnabled = false;
            }
            tmp.Contact = new Contact();
            contactWindow.DataContext = tmp;

            //booléen nullable vrai ou faux ou null
            bool? dialogResult = contactWindow.ShowDialog();
            Personne personne = (Personne)contactWindow.DataContext;

            if (dialogResult.HasValue && dialogResult.Value == true)
            {
                this.Contacts.Clear();
                this.Contacts = new ObservableCollection<Contact>(((App)App.Current).mySitaffEntities.Contact.Where(con => con.Personne.Entreprise1.Libelle == this.entreprise.Libelle).OrderBy(con => con.Personne.Nom));
                this.Contacts.Add(((Personne)contactWindow.DataContext).Contact);
                this._ComboBoxDevisChoixContact.SelectedItem = personne.Contact;
            }
            else
            {
                try
                {
                    ((App)App.Current).mySitaffEntities.Detach(personne.Contact);
                    ((App)App.Current).mySitaffEntities.Detach(personne);
                }
                catch (Exception)
                {
                    try
                    {
                        ((App)App.Current).mySitaffEntities.Contact.DeleteObject(personne.Contact);
                        ((App)App.Current).mySitaffEntities.Personne.DeleteObject(personne);
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }