private void ExecDistantLocal(Model.Prestashop.PsSupplier Supplier, Model.Local.Supplier LocalSupplier, Model.Local.SupplierRepository LocalSupplierRepository)
 {
     try
     {
         // Recovery Data From SupplierLang
         Model.Prestashop.PsSupplierLangRepository SupplierLangRepository = new Model.Prestashop.PsSupplierLangRepository();
         Model.Prestashop.PsSupplierLang           SupplierLang           = new Model.Prestashop.PsSupplierLang();
         if (SupplierLangRepository.ExistSupplierLang((Int32)Supplier.IDSupplier, Core.Global.Lang))
         {
             SupplierLang = SupplierLangRepository.ReadSupplierLang((Int32)Supplier.IDSupplier, Core.Global.Lang);
             LocalSupplier.Sup_Description     = SupplierLang.Description;
             LocalSupplier.Sup_MetaTitle       = SupplierLang.MetaTitle;
             LocalSupplier.Sup_MetaKeyword     = SupplierLang.MetaKeywords;
             LocalSupplier.Sup_MetaDescription = SupplierLang.MetaDescription;
         }
         LocalSupplier.Sup_Name   = Supplier.Name;
         LocalSupplier.Sup_Active = Convert.ToBoolean(Supplier.Active);
         LocalSupplier.Sup_Date   = (Supplier.DateUpd != null && Supplier.DateUpd > new DateTime(1753, 1, 2)) ? Supplier.DateUpd : DateTime.Now.Date;
         LocalSupplierRepository.Save();
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
 public void Exec(Int32 F_COMPTETSend)
 {
     try
     {
         Model.Local.SupplierRepository SupplierRepository = new Model.Local.SupplierRepository();
         if (SupplierRepository.ExistSag_Id(F_COMPTETSend) == false)
         {
             Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository();
             Model.Sage.F_COMPTET           F_COMPTET           = F_COMPTETRepository.Read(F_COMPTETSend);
             Model.Local.Supplier           Supplier            = new Model.Local.Supplier()
             {
                 Sup_Active          = true,
                 Sup_Description     = F_COMPTET.CT_Intitule,
                 Sup_MetaDescription = F_COMPTET.CT_Intitule,
                 Sup_MetaKeyword     = F_COMPTET.CT_Intitule,
                 Sup_Name            = F_COMPTET.CT_Intitule,
                 Sup_MetaTitle       = F_COMPTET.CT_Intitule,
                 Sup_Date            = DateTime.Now,
                 Sup_Sync            = true,
                 Sag_Id = F_COMPTET.cbMarq
             };
             SupplierRepository.Add(Supplier);
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
Ejemplo n.º 3
0
        private void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (this.ListBoxFournisseur.SelectedItem != null)
            {
                Model.Local.SupplierRepository SupplierRepository = new Model.Local.SupplierRepository();
                if (SupplierRepository.ExistSag_Id(((Model.Sage.F_COMPTET) this.ListBoxFournisseur.SelectedItem).cbMarq))
                {
                    Model.Local.Supplier Supplier = SupplierRepository.ReadSag_Id(((Model.Sage.F_COMPTET) this.ListBoxFournisseur.SelectedItem).cbMarq);

                    Supplier.Sup_Name            = Core.Global.RemovePurge(this.TextBoxName.Text, 128);
                    Supplier.Sup_Description     = Core.Global.RemovePurge(this.TextBoxDescription.Text, 10000);
                    Supplier.Sup_MetaTitle       = Core.Global.RemovePurge(this.TextBoxTitle.Text, 70);
                    Supplier.Sup_MetaDescription = Core.Global.RemovePurge(this.TextBoxDescription.Text, 160);
                    Supplier.Sup_MetaKeyword     = Core.Global.RemovePurgeMeta(this.TextBoxMetaKeyword.Text, 255);
                    Supplier.Sup_Active          = this.CheckBoxActive.IsChecked.Value;
                    Supplier.Sup_Sync            = this.RadioButtonSync.IsChecked.Value;
                    Supplier.Sup_Date            = DateTime.Now;

                    SupplierRepository.Save();
                    MessageBox.Show("Fournisseur mis à jour avec succès", "Fournisseur", MessageBoxButton.OK);
                }
                else
                {
                    MessageBox.Show("Fournisseur non valide !", "Fournisseur", MessageBoxButton.OK);
                }
            }
        }
        private void ExecLocalDistant(Model.Local.Supplier LocalSupplier, Model.Prestashop.PsSupplier Supplier, Model.Local.SupplierRepository LocalSupplierRepository, Model.Prestashop.PsSupplierRepository SupplierRepository, Boolean isSupplier)
        {
            try
            {
                // Assign data from LocalSupplier to Supplier
                Supplier.Name    = LocalSupplier.Sup_Name;
                Supplier.DateUpd = LocalSupplier.Sup_Date;
                Supplier.Active  = Convert.ToSByte(LocalSupplier.Sup_Active);
                // If the LocalSupplier have not a connection with Prestashop, We need to add Supplier
                if (isSupplier == false)
                {
                    Supplier.DateAdd = Supplier.DateUpd;
                    SupplierRepository.Add(Supplier, Global.CurrentShop.IDShop);
                    // We assign the SupplierId to LocalSupplier
                    LocalSupplier.Pre_Id = (Int32)Supplier.IDSupplier;
                    LocalSupplierRepository.Save();
                }
                // else we need to update Supplier
                else
                {
                    SupplierRepository.Save();
                }

                // We need to update SupplierLang too
                Boolean isSupplierLang = false;
                Model.Prestashop.PsSupplierLangRepository SupplierLangRepository = new Model.Prestashop.PsSupplierLangRepository();
                Model.Prestashop.PsSupplierLang           SupplierLang           = new Model.Prestashop.PsSupplierLang();
                if (SupplierLangRepository.ExistSupplierLang((Int32)Supplier.IDSupplier, Core.Global.Lang))
                {
                    SupplierLang   = SupplierLangRepository.ReadSupplierLang((Int32)Supplier.IDSupplier, Core.Global.Lang);
                    isSupplierLang = true;
                }
                SupplierLang.Description     = LocalSupplier.Sup_Description;
                SupplierLang.MetaTitle       = LocalSupplier.Sup_MetaTitle;
                SupplierLang.MetaDescription = LocalSupplier.Sup_MetaDescription;
                SupplierLang.MetaKeywords    = LocalSupplier.Sup_MetaKeyword;
                // If the SupplierLang doesn't exist, we need to add him
                if (isSupplierLang == false)
                {
                    SupplierLang.IDLang     = (uint)Core.Global.Lang;
                    SupplierLang.IDSupplier = Supplier.IDSupplier;
                    SupplierLangRepository.Add(SupplierLang);
                }
                // else we need to update him
                else
                {
                    SupplierLangRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Ejemplo n.º 5
0
        private void ListBoxFournisseur_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.ListBoxFournisseur.SelectedItem != null)
            {
                if (this.ListBoxFournisseur.SelectedItem is Model.Sage.F_COMPTET)
                {
                    this.isValid = false;
                    Model.Local.SupplierRepository SupplierRepository = new Model.Local.SupplierRepository();
                    Model.Local.Supplier           Supplier           = new Model.Local.Supplier();
                    if (SupplierRepository.ExistSag_Id(((Model.Sage.F_COMPTET) this.ListBoxFournisseur.SelectedItem).cbMarq))
                    {
                        this.groupBoxSupplierDetail.IsEnabled = true;
                        Supplier = SupplierRepository.ReadSag_Id(((Model.Sage.F_COMPTET) this.ListBoxFournisseur.SelectedItem).cbMarq);
                        this.TextBoxName.Text            = Supplier.Sup_Name;
                        this.TextBoxDescription.Text     = Supplier.Sup_Description;
                        this.TextBoxTitle.Text           = Supplier.Sup_MetaTitle;
                        this.TextBoxMetaKeyword.Text     = Supplier.Sup_MetaKeyword;
                        this.TextBoxMetaDescription.Text = Supplier.Sup_MetaDescription;
                        this.CheckBoxActive.IsChecked    = Supplier.Sup_Active;
                        this.RadioButtonSync.IsChecked   = Supplier.Sup_Sync;

                        if (Supplier.Pre_Id != null)
                        {
                            Model.Prestashop.PsSupplierRepository PsSupplierRepository = new Model.Prestashop.PsSupplierRepository();
                            if (PsSupplierRepository.ExistId(Convert.ToInt32(Supplier.Pre_Id)) == false)
                            {
                                MessageBoxResult Result = MessageBox.Show("Le fournisseur Prestashop n'existe plus. Voulez-vous le recréer ?", "Fournisseur", MessageBoxButton.YesNo);
                                if (Result == MessageBoxResult.Yes)
                                {
                                    Supplier.Pre_Id = null;
                                    SupplierRepository.Save();
                                }
                            }
                        }
                    }
                    else
                    {
                        this.LoadComponent();
                        this.groupBoxSupplierDetail.IsEnabled = false;
                    }
                }
                else
                {
                    this.LoadComponent();
                    this.groupBoxSupplierDetail.IsEnabled = false;
                }
            }
            else
            {
                this.LoadComponent();
                this.groupBoxSupplierDetail.IsEnabled = false;
            }
        }
        // Void Exec : Sync Supplier
        public void Exec(Int32 LocalSupplierSend)
        {
            try
            {
                Model.Local.SupplierRepository        LocalSupplierRepository = new Model.Local.SupplierRepository();
                Model.Local.Supplier                  LocalSupplier           = LocalSupplierRepository.ReadId(LocalSupplierSend);
                Model.Prestashop.PsSupplierRepository SupplierRepository      = new Model.Prestashop.PsSupplierRepository();
                Boolean isSupplier = false;
                Model.Prestashop.PsSupplier Supplier = new Model.Prestashop.PsSupplier();

                // If the LocalSupplier have a connection with Prestashop
                if (LocalSupplier.Pre_Id != null)
                {
                    LocalSupplier.Sup_Date = LocalSupplier.Sup_Date.AddMilliseconds(-LocalSupplier.Sup_Date.Millisecond);
                    if (SupplierRepository.ExistId(LocalSupplier.Pre_Id.Value))
                    {
                        Supplier   = SupplierRepository.ReadId(LocalSupplier.Pre_Id.Value);
                        isSupplier = true;
                        if (Supplier.DateUpd.Ticks > LocalSupplier.Sup_Date.Ticks)
                        {
                            this.ExecDistantLocal(Supplier, LocalSupplier, LocalSupplierRepository);
                        }
                        else if (Supplier.DateUpd.Ticks < LocalSupplier.Sup_Date.Ticks)
                        {
                            this.ExecLocalDistant(LocalSupplier, Supplier, LocalSupplierRepository, SupplierRepository, isSupplier);
                        }
                    }
                }
                // We need to sync LocalSupplier with Prestashop
                else
                {
                    this.ExecLocalDistant(LocalSupplier, Supplier, LocalSupplierRepository, SupplierRepository, isSupplier);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Ejemplo n.º 7
0
        private void CreateSupplier(Model.Sage.F_COMPTET F_COMPTET)
        {
            if (F_COMPTET != null && !string.IsNullOrWhiteSpace(F_COMPTET.CT_Intitule))
            {
                Model.Local.SupplierRepository SupplierRepository = new Model.Local.SupplierRepository();
                if (!SupplierRepository.ExistSag_Id(F_COMPTET.cbMarq))
                {
                    Model.Local.Supplier Supplier = new Model.Local.Supplier();
                    //Supplier = SupplierRepository.ReadSag_Id(F_COMPTET.cbMarq);
                    Supplier.Sag_Id              = F_COMPTET.cbMarq;
                    Supplier.Sup_Name            = Core.Global.RemovePurge(F_COMPTET.CT_Intitule, 128);
                    Supplier.Sup_Description     = Supplier.Sup_Name;
                    Supplier.Sup_MetaTitle       = Core.Global.RemovePurge(Supplier.Sup_Name, 70);
                    Supplier.Sup_MetaDescription = Core.Global.RemovePurge(Supplier.Sup_Name, 160);
                    Supplier.Sup_MetaKeyword     = Core.Global.RemovePurgeMeta(Supplier.Sup_Name, 255);
                    Supplier.Sup_Active          = true;
                    Supplier.Sup_Date            = DateTime.Now;
                    Supplier.Sup_Sync            = true;

                    SupplierRepository.Add(Supplier);
                }
            }
        }