public AECInvoiceHistory(DateTime?PeriodeDebut, DateTime?PeriodeFin, bool ClearMode = false)
        {
            this.InitializeComponent();

            this._PeriodeDebut = PeriodeDebut;
            this._PeriodeFin   = PeriodeFin;
            this._ClearMode    = ClearMode;

            if (this._ClearMode)
            {
                this.LabelOperation.Content = "Nettoyage des données !";
            }
            this.ProgressBar.ToolTip = "Nombre de coeurs processeurs utilisés : " + MaximumThreadCount;

            // récupération de la liste des comptes client mappés
            Model.Local.CustomerRepository CustomerRepository = new Model.Local.CustomerRepository();
            List <Model.Local.Customer>    ListCustomer       = CustomerRepository.List();

            // récupération de la liste des comptes Sage existants
            Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
            //List<int> ListSage = F_COMPTETRepository.ListIdTypeSommeil((short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_Type.Client, (short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_Boolean.Non);
            List <Model.Sage.F_COMPTET_Light> ListSage = F_COMPTETRepository.ListLight((short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_Type.Client, (short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_Boolean.Non);

            // filtrage des comptes qui sont centralisés
            ListCustomer = ListCustomer.Where(c => ListSage.Count(s => s.cbMarq == c.Sag_Id) == 1).ToList();

            // filtres clients de l'interface
            if (Core.Global.UILaunch)
            {
                if (!string.IsNullOrWhiteSpace(Core.Temp.ModuleAECInvoiceHistory_Numero))
                {
                    Core.Temp.LoadF_COMPTET_BtoBIfEmpty();
                    ListCustomer = ListCustomer.Where(c => c.Sag_Numero.StartsWith(Core.Temp.ModuleAECInvoiceHistory_Numero)).ToList();
                }
                if (!string.IsNullOrWhiteSpace(Core.Temp.ModuleAECInvoiceHistory_Intitule))
                {
                    Core.Temp.LoadF_COMPTET_BtoBIfEmpty();
                    ListCustomer = ListCustomer.Where(c => c.Sag_Name.ToLower().Contains(Core.Temp.ModuleAECInvoiceHistory_Intitule.ToLower())).ToList();
                }
            }

            this.ListCount = ListCustomer.Count;

            Context = SynchronizationContext.Current;

            this.ParallelOptions.MaxDegreeOfParallelism = MaximumThreadCount;
            this.ReportProgress(0);
            Task.Factory.StartNew(() =>
            {
                Parallel.ForEach(ListCustomer, this.ParallelOptions, Exec);
            });
        }
        // <JG> 06/09/2012 ajout filtre de recherche
        // <JG> 28/02/2013 modification transfert client avec utilisation des paramètre de la fonctionnalité automatique
        private void ButtonSearchSageToPrestashop_Click(object sender, RoutedEventArgs e)
        {
            this.CBClientSage.ItemsSource = new List <Model.Sage.F_COMPTET_Light>();
            // <JG> 04/12/2012 Correction utilisation des champs de recherche
            if (this.CbGroupeClient.SelectedItem != null)
            {
                //this.CBClientSage.Items.Clear();
                this.IsEnabled       = false;
                Mouse.OverrideCursor = Cursors.Wait;
                Model.Sage.F_COMPTETRepository    F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
                List <Model.Sage.F_COMPTET_Light> ListF_COMPTET;
                ListF_COMPTET = F_COMPTETRepository.ListLight(0, 0);

                if (this.TextBoxSageToPrestashopNumero.Text.ToUpper() != "")
                {
                    ListF_COMPTET = ListF_COMPTET.Where(s => s.CT_Num.StartsWith(this.TextBoxSageToPrestashopNumero.Text.ToUpper())).ToList();
                }

                //// <JG> 26/12/2012 ajout filtre catégorie tarifaire
                //Model.Local.GroupRepository GroupRepository = new Model.Local.GroupRepository();
                //if (GroupRepository.ListCatTarifSage().Count > 0)
                //{
                //    List<Model.Sage.F_COMPTET> temp = new List<Model.Sage.F_COMPTET>();
                //    foreach (Int32 CatTarifID in GroupRepository.ListCatTarifSage())
                //    {
                //        temp.AddRange(ListF_COMPTET.Where(c => c.N_CatTarif == CatTarifID));
                //        ListF_COMPTET.RemoveAll(c => c.N_CatTarif == CatTarifID);
                //    }
                //    ListF_COMPTET = temp;

                // <JG> 19/02/2013 correction filtrage des clients sur le groupe sélectionné
                if (((Model.Local.Group) this.CbGroupeClient.SelectedItem).Grp_CatTarifId != null)
                {
                    ListF_COMPTET = ListF_COMPTET.Where(c => c.N_CatTarif == (int)((Model.Local.Group) this.CbGroupeClient.SelectedItem).Grp_CatTarifId).ToList();

                    // <JG> 06/09/2012 ajout filtre sur l'intitulé
                    if (this.TextBoxSageToPrestashopIntitule.Text != null && this.TextBoxSageToPrestashopIntitule.Text.ToUpper().Trim() != "")
                    {
                        ListF_COMPTET = ListF_COMPTET.Where(cpt => cpt.CT_Intitule.ToUpper().Contains(this.TextBoxSageToPrestashopIntitule.Text.ToUpper().Trim())).ToList();
                    }

                    //ListF_COMPTET = ListF_COMPTET.Where(cpt => cpt.CT_EMail != null && cpt.CT_EMail.Trim() != "").ToList();
                    ListF_COMPTET = ListF_COMPTET.Where(cpt => cpt.CT_EMail.Trim() != "" || cpt.F_LIVRAISON_Principale().Count(a => a.LI_EMail != "") > 0).ToList();

                    List <Model.Local.Customer> LocalCustomer = new Model.Local.CustomerRepository().List();
                    ListF_COMPTET = ListF_COMPTET.Where(s => LocalCustomer.Count(l => l.Sag_Id == s.cbMarq) == 0).ToList();

                    if (ListF_COMPTET.Count == 0)
                    {
                        if (sender != this.BtTransfert)
                        {
                            MessageBox.Show("Aucun client dans le résultat de votre recherche !", "", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                    else if (ListF_COMPTET.Count <= 200)
                    {
                        Model.Local.CustomerRepository   CustomerRepository    = new Model.Local.CustomerRepository();
                        Model.Sage.F_LIVRAISONRepository F_LIVRAISONRepository = new Model.Sage.F_LIVRAISONRepository();
                        this.CBClientSage.ItemsSource = ListF_COMPTET;

                        //foreach (Model.Sage.F_COMPTET_Light F_COMPTET in ListF_COMPTET)
                        //    if (CustomerRepository.ExistSage(F_COMPTET.cbMarq) == false) // && F_LIVRAISONRepository.ExistComptetPrincipal(F_COMPTET.CT_Num, 1))
                        //        this.CBClientSage.Items.Add(F_COMPTET.ComboText);
                    }
                    else
                    {
                        MessageBox.Show("Le nombre de résultats de la recherche est trop important, veuillez préciser d'avantage votre recherche !", "", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }


                Mouse.OverrideCursor = Cursors.Arrow;
                this.IsEnabled       = true;
            }
            else
            {
                MessageBox.Show("Veuillez sélectionner un groupe de client !", "Groupe de client", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
        }