private void LoadOrdersAndCustomers()
        {
            PRESTACONNECT.Commande.ReadCommandePrestashop(DataGridCommande, 20);

            Core.Temp.ListLocalCustomer  = new Model.Local.CustomerRepository().List();
            Core.Temp.ListF_COMPTET_BtoB = new Model.Sage.F_COMPTETRepository().ListBtoB((short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_Type.Client);

            Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
            this.DataGridClient.ItemsSource = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                ? PsCustomerRepository.ListTopActiveOrderByDateAdd(20, 1, Core.Global.CurrentShop.IDShop)
                : PsCustomerRepository.ListTopActiveOrderByDateAddWithOrder(20, 1, Global.CurrentShop.IDShop);
        }
        private void LoadComponent()
        {
            // <JG> 26/12/2012
            this.CbGroupeClient.ItemsSource = new Model.Local.GroupRepository().ListGroupesLies();

            this.ButtonOustanding.IsEnabled = Core.Global.GetConfig().ModuleAECCustomerOutstandingActif;

            if (Core.Global.GetConfig().ConfigBToB)
            {
                this.TabItemClientBToB.IsEnabled  = true;
                this.TabItemClientBToC.IsEnabled  = false;
                this.TabItemClientBToB.IsSelected = true;

                this.GroupBoxSageCustomer.Header = (Core.Global.GetConfig().ConfigClientMultiMappageBtoB) ? "Client(s) Sage" : "Client(s) Sage non mappé(s)";

                this.LoadBTOBCustomer();
            }
            else if (Core.Global.GetConfig().ConfigBToC)
            {
                this.TabItemClientBToC.IsEnabled  = true;
                this.TabItemClientBToB.IsEnabled  = false;
                this.TabItemClientBToC.IsSelected = true;

                Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();

                this.DataGridClient.ItemsSource = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                            ? PsCustomerRepository.ListTopActiveOrderByDateAdd(60, 1, Core.Global.CurrentShop.IDShop)
                            : PsCustomerRepository.ListTopActiveOrderByDateAddWithOrder(60, 1, Core.Global.CurrentShop.IDShop);
                this.TabItemClientBToB.IsEnabled = false;

                #region centralisation clients
                Model.Local.Config Config = new Model.Local.Config();

                Model.Local.ConfigRepository ConfigRepository = new Model.Local.ConfigRepository();
                if (ConfigRepository.ExistName(Core.Global.ConfigClientTypeLien) &&
                    ConfigRepository.ReadName(Core.Global.ConfigClientTypeLien).Con_Value == Core.Global.ConfigClientTypeLienEnum.CompteCentralisateur.ToString())
                {
                    if (ConfigRepository.ExistName(Core.Global.ConfigClientCompteCentralisateur))
                    {
                        Config = ConfigRepository.ReadName(Core.Global.ConfigClientCompteCentralisateur);
                        if (Core.Global.IsInteger(Config.Con_Value))
                        {
                            Int32 cbMarqCentralisateur = Int32.Parse(Config.Con_Value);
                            Model.Sage.F_COMPTETRepository F_COMPTETRepositoryCentralisateur = new Model.Sage.F_COMPTETRepository();
                            Model.Sage.F_COMPTET           F_COMPTETCentralisateur;
                            if (F_COMPTETRepositoryCentralisateur.ExistId(cbMarqCentralisateur))
                            {
                                F_COMPTETCentralisateur = F_COMPTETRepositoryCentralisateur.Read(cbMarqCentralisateur);

                                this.LabelClientCentralisateur.Content = "Commandes et adresses des clients Prestashop centralisées vers le compte Sage " + F_COMPTETCentralisateur.CT_Num + " " + F_COMPTETCentralisateur.CT_Intitule;
                            }
                        }
                    }
                }
                #endregion
            }
            else
            {
                this.BtTransfert.IsEnabled = false;
            }

            LoadModules();
        }
        private void ButtonSync_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PRESTACONNECT.Loading Loading = new PRESTACONNECT.Loading();
                Loading.Show();


                DateTime?filtre = null, old_config = Core.Global.GetConfig().ConfigCommandeFiltreDate;
                if (DataContext.SyncDay)
                {
                    filtre = DateTime.Now.Date;
                }
                else if (DataContext.SyncWeek)
                {
                    filtre = DateTime.Now.Date.AddDays(-7);
                }
                else if (DataContext.SyncMonth)
                {
                    filtre = DateTime.Now.Date.AddMonths(-1);
                }

                if (filtre != null)
                {
                    Core.Global.GetConfig().UpdateConfigCommandeFiltreDate(filtre, true);
                }


                if (Core.Global.GetConfig().ConfigBToC)
                {
                    PRESTACONNECT.SynchronisationClient SynchronisationClient = new SynchronisationClient();
                    SynchronisationClient.ShowDialog();
                }

                PRESTACONNECT.SynchronisationLivraison SynchronisationLivraison = new SynchronisationLivraison();
                SynchronisationLivraison.ShowDialog();


                if (filtre != null)
                {
                    Core.Global.GetConfig().UpdateConfigCommandeFiltreDate(old_config, true);
                }

                Loading.Close();

                if (this.TabItemClientBToC.IsEnabled)
                {
                    Core.Temp.ListLocalCustomer  = new Model.Local.CustomerRepository().List();
                    Core.Temp.ListF_COMPTET_BtoB = new Model.Sage.F_COMPTETRepository().ListBtoB((short)ABSTRACTION_SAGE.F_COMPTET.Obj._Enum_CT_Type.Client);

                    Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();

                    this.DataGridClient.ItemsSource = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                                ? PsCustomerRepository.ListTopActiveOrderByDateAdd(60, 1, Core.Global.CurrentShop.IDShop)
                                : PsCustomerRepository.ListTopActiveOrderByDateAddWithOrder(60, 1, Core.Global.CurrentShop.IDShop);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }