public SynchronisationLivraison()
        {
            this.InitializeComponent();
            this.LabelInformation.Content = "Recherche des adresses à créer ...";

            this.worker.WorkerReportsProgress = true;
            this.worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                Model.Prestashop.PsAddressRepository    PsAddressRepository = new Model.Prestashop.PsAddressRepository();
                List <Model.Prestashop.PsAddress_Light> ListPsAddress       = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                        ? PsAddressRepository.List()
                        : PsAddressRepository.ListWithOrder();

                // filtrage des adresses par rapport aux clients déjà synchronisés
                List <Model.Local.Customer> listCustomer = new Model.Local.CustomerRepository().List();
                ListPsAddress = ListPsAddress.Where(a => listCustomer.Count(c => c.Pre_Id == a.id_customer) > 0).ToList();

                List <Model.Local.Address> listLocal = new Model.Local.AddressRepository().List();
                ListPsAddress = ListPsAddress.Where(a => listLocal.Count(l => l.Pre_Id == a.id_address) == 0).ToList();

                if (ListPsAddress.Count > 0)
                {
                    this.worker.ReportProgress(-42);
                    Connexion = Core.Global.GetODBC();

                    Core.Temp.ListAddressOnCurrentSync = new List <uint>();
                    foreach (Model.Prestashop.PsAddress_Light PsAddress_Light in ListPsAddress)
                    {
                        if (Connexion != null)
                        {
                            Core.Sync.SynchronisationLivraison SynchronisationLivraison = new Core.Sync.SynchronisationLivraison();
                            SynchronisationLivraison.Exec(Connexion, PsAddress_Light.id_address);
                        }
                        lock (this)
                        {
                            this.CurrentCount += 1;
                        }
                        this.worker.ReportProgress((this.CurrentCount * 100 / ListPsAddress.Count));
                    }
                }
            };

            this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                if (args.ProgressPercentage >= 0)
                {
                    this.ProgressBarLivraison.Value = args.ProgressPercentage;
                    this.LabelInformation.Content   = "Informations : " + args.ProgressPercentage + " %";
                }
                else if (args.ProgressPercentage == -42)
                {
                    this.LabelInformation.Content = "Ouverture connexion ODBC Sage...";
                }
            };

            this.worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (Connexion != null)
                {
                    Connexion.Close_Connexion();
                }
                this.Close();
            };

            // Insérez le code requis pour la création d’objet sous ce point.
            this.worker.RunWorkerAsync();
        }
        public SynchronisationClient()
        {
            this.InitializeComponent();
            this.worker.WorkerReportsProgress = true;
            this.LabelInformation.Content     = "Recherche des clients à créer ...";

            this.worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                if (Core.Global.GetConfig().ConfigBToC)
                {
                    Model.Prestashop.PsCustomerRepository PsCustomerRepository = new Model.Prestashop.PsCustomerRepository();
                    List <Model.Prestashop.idcustomer>    ListCustomer         = (Core.Global.GetConfig().ConfigClientFiltreCommande)
                        ? PsCustomerRepository.ListIDActive(1, Core.Global.CurrentShop.IDShop)
                        : PsCustomerRepository.ListIDActiveWithOrder(1, Core.Global.CurrentShop.IDShop);

                    // <JG> ajout filtre clients déjà mappés
                    List <Model.Local.Customer> listLocal = new Model.Local.CustomerRepository().List();
                    ListCustomer = ListCustomer.Where(c => listLocal.Count(l => l.Pre_Id == c.id_customer) == 0).ToList();
                    this.worker.ReportProgress(0);

                    if (ListCustomer.Count > 0)
                    {
                        this.worker.ReportProgress(-42);
                        Connexion = Core.Global.GetODBC();

                        foreach (Model.Prestashop.idcustomer Customer in ListCustomer)
                        {
                            if (Connexion != null)
                            {
                                Core.Sync.SynchronisationClient SynchronisationClient = new Core.Sync.SynchronisationClient();
                                SynchronisationClient.Exec(Connexion, Customer.id_customer);
                            }
                            lock (this)
                            {
                                this.CurrentCount += 1;
                            }
                            this.worker.ReportProgress((this.CurrentCount * 100 / ListCustomer.Count));
                        }
                    }
                }
            };

            this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                if (args.ProgressPercentage >= 0)
                {
                    this.ProgressBarClient.Value  = args.ProgressPercentage;
                    this.LabelInformation.Content = "Informations : " + args.ProgressPercentage + " %";
                }
                else if (args.ProgressPercentage == -42)
                {
                    this.LabelInformation.Content = "Ouverture connexion ODBC Sage...";
                }
            };

            this.worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (Connexion != null)
                {
                    Connexion.Close_Connexion();
                }
                this.Close();
            };

            // Insérez le code requis pour la création d’objet sous ce point.
            this.worker.RunWorkerAsync();
        }
        public SynchronisationCommande(DateTime?filtre = null)
        {
            this.InitializeComponent();
            this.LabelInformation.Content = "Recherche des commandes à transférer ...";

            this.worker.WorkerReportsProgress = true;
            this.worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                // récupération des commandes PrestaShop (le filtrage par date est appliqué dans la requête SQL)
                Model.Prestashop.PsOrdersRepository PsOrdersRepository = new Model.Prestashop.PsOrdersRepository();
                List <Model.Prestashop.idorder>     ListOrders         = PsOrdersRepository.ListID(Core.Global.CurrentShop.IDShop);

                if (ListOrders.Count > 0)
                {
                    Model.Local.OrderRepository OrderRepository = new Model.Local.OrderRepository();
                    this.ListSync = OrderRepository.ListPrestaShop();

                    // filtrage sur uniquement les commandes non synchronisées et dont le statut demande une création dans Sage
                    Model.Local.ConfigRepository ConfigRepository = new Model.Local.ConfigRepository();
                    Model.Local.Config           ConfigBC         = (ConfigRepository.ExistName(Core.Global.ConfigCommandeStatutCreateBC)) ? ConfigRepository.ReadName(Core.Global.ConfigCommandeStatutCreateBC) : null;
                    Model.Local.Config           ConfigDevis      = (ConfigRepository.ExistName(Core.Global.ConfigCommandeStatutCreateDevis)) ? ConfigRepository.ReadName(Core.Global.ConfigCommandeStatutCreateDevis) : null;
                    List <string> idstate_string = new List <string>();
                    idstate_string.AddRange((ConfigBC != null && !string.IsNullOrEmpty(ConfigBC.Con_Value)) ? ConfigBC.Con_Value.Split('#') : string.Empty.Split('#'));
                    idstate_string.AddRange((ConfigDevis != null && !string.IsNullOrEmpty(ConfigDevis.Con_Value)) ? ConfigDevis.Con_Value.Split('#') : string.Empty.Split('#'));

                    List <Model.Prestashop.idorder> ListNotSync = ListOrders.Where(o => !this.ListSync.Contains((int)o.id_order) && idstate_string.Contains(o.current_state.ToString())).ToList();

                    this.ListCount = ListNotSync.Count;

                    if (ListNotSync.Count > 0)
                    {
                        // ouverture de la connexion ODBC
                        this.worker.ReportProgress(-42);
                        Connexion = Core.Global.GetODBC();

                        Model.Prestashop.PsOrders PsOrders = null;
                        if (Connexion != null)
                        {
                            foreach (Model.Prestashop.idorder Orders in ListNotSync)
                            {
                                try
                                {
                                    PsOrders = PsOrdersRepository.ReadOrder((int)Orders.id_order);
                                    Core.Sync.SynchronisationCommande SynchronisationCommande = new Core.Sync.SynchronisationCommande();
                                    SynchronisationCommande.Exec(Connexion, PsOrders, PsOrdersRepository);
                                }
                                catch (Exception ex)
                                {
                                    Core.Error.SendMailError(ex.ToString());
                                }
                                lock (this)
                                {
                                    this.CurrentCount += 1;
                                }
                                this.worker.ReportProgress((this.CurrentCount * 100 / this.ListCount));
                            }
                        }
                        else
                        {
                            this.CurrentCount += ListNotSync.Count;
                        }
                    }
                }
            };

            this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                if (args.ProgressPercentage >= 0)
                {
                    this.ProgressBarCommande.Value = args.ProgressPercentage;
                    this.LabelInformation.Content  = "Informations : " + args.ProgressPercentage + " %";
                }
                else if (args.ProgressPercentage == -42)
                {
                    this.LabelInformation.Content = "Ouverture connexion ODBC Sage...";
                }
            };

            this.worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (Connexion != null)
                {
                    Connexion.Close_Connexion();
                }
                this.Close();
            };

            // Insérez le code requis pour la création d’objet sous ce point.
            this.worker.RunWorkerAsync();
        }
Exemplo n.º 4
0
        public SynchronisationPaiement()
        {
            this.InitializeComponent();
            this.LabelInformation.Content = "Recherche des paiements à copier ...";

            this.worker.WorkerReportsProgress = true;
            this.worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                if (Core.Global.GetConfig().SyncReglementActif)
                {
                    this.worker.ReportProgress(-42);
                    Connexion = Core.Global.GetODBC();

                    if (Connexion != null)
                    {
                        Model.Prestashop.PsOrdersRepository       PsOrdersRepository       = new Model.Prestashop.PsOrdersRepository();
                        Model.Prestashop.PsOrderPaymentRepository PsOrderPaymentRepository = new Model.Prestashop.PsOrderPaymentRepository();

                        Model.Local.OrderRepository        OrderRepository        = new Model.Local.OrderRepository();
                        Model.Local.OrderPaymentRepository OrderPaymentRepository = new Model.Local.OrderPaymentRepository();

                        Model.Sage.F_DOCENTETERepository F_DOCENTETERepository = new Model.Sage.F_DOCENTETERepository();

                        List <Model.Prestashop.order_payment> list_order = PsOrdersRepository.ListIDPayment(Core.Global.CurrentShop.IDShop);

                        foreach (Model.Prestashop.order_payment order in list_order)
                        {
                            try
                            {
                                // comparaison nombre de paiements PrestaShop avec ceux déjà transférés
                                if (OrderRepository.ExistPrestashop((int)order.id_order) &&
                                    F_DOCENTETERepository.ExistWeb(order.id_order.ToString()) &&
                                    PsOrderPaymentRepository.CountOrderReference(order.reference) > OrderPaymentRepository.CountOrder((int)order.id_order))
                                // pour ne pas prendre en compte les articles non suivi en stock
                                {
                                    // récupération du dernier document Sage
                                    Model.Sage.F_DOCENTETE F_DOCENTETE = F_DOCENTETERepository.ListWeb(order.id_order.ToString()).FirstOrDefault();

                                    ABSTRACTION_SAGE.F_DOCENTETE.Obj ObjF_DOCENTETE = new ABSTRACTION_SAGE.F_DOCENTETE.Obj()
                                    {
                                        DO_Domaine = (ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Domaine)F_DOCENTETE.DO_Domaine,
                                        DO_Type    = (ABSTRACTION_SAGE.F_DOCENTETE.Obj._Enum_DO_Type)F_DOCENTETE.DO_Type,
                                        DO_Piece   = F_DOCENTETE.DO_Piece
                                    };

                                    ObjF_DOCENTETE.ReadDO_Domaine_DO_Type_DO_Piece(Connexion, false);
                                    if (ObjF_DOCENTETE != null)
                                    {
                                        Model.Prestashop.PsOrders         PsOrders = PsOrdersRepository.ReadOrder((int)order.id_order);
                                        Core.Sync.SynchronisationCommande form     = new Core.Sync.SynchronisationCommande();
                                        bool exist_payment;
                                        form.ExecReglement(PsOrders, Connexion, ObjF_DOCENTETE, out exist_payment);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Core.Error.SendMailError("[SYNCHRONISATION REGLEMENTS]" + ex.ToString());
                            }
                            lock (this)
                            {
                                this.CurrentCount += 1;
                            }
                            this.worker.ReportProgress((this.CurrentCount * 100 / list_order.Count));
                        }
                    }
                }
            };

            this.worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                if (args.ProgressPercentage >= 0)
                {
                    this.ProgressBar.Value        = args.ProgressPercentage;
                    this.LabelInformation.Content = "Informations : " + args.ProgressPercentage + " %";
                }
                else if (args.ProgressPercentage == -42)
                {
                    this.LabelInformation.Content = "Ouverture connexion ODBC Sage...";
                }
            };

            this.worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (Connexion != null)
                {
                    Connexion.Close_Connexion();
                }
                this.Close();
            };

            // Insérez le code requis pour la création d’objet sous ce point.
            this.worker.RunWorkerAsync();
        }