private void DataGridBTOBCustomerButtonDelete_Click(object sender, RoutedEventArgs e) { Model.Local.Customer Customer = this.DataGridCustomerBTOB.SelectedItem as Model.Local.Customer; Model.Local.CustomerRepository CustomerRepository = new Model.Local.CustomerRepository(); bool delete = false; if (CustomerRepository.ExistPrestashopSage(Customer.Pre_Id, Customer.Sag_Id)) { Model.Sage.F_COMPTETRepository F_COMPTETRepository = new Model.Sage.F_COMPTETRepository(); if (F_COMPTETRepository.ExistId(Customer.Sag_Id) == false) { delete = true; } else if (MessageBox.Show("Êtes-vous sûr de vouloir supprimer le mappage entre le compte PrestaShop : " + Customer.Pre_Name + "\n" + "et le compte Sage : " + Customer.Sag_Name + " ?", "Suppression mappage", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { delete = true; } //else //{ // MessageBox.Show("Votre client Prestashop a déjà été synchronisé. \n Pour pouvoir le supprimer, il faut préalablement supprimer le compte Sage associé : " + Customer.Sag_Name, "Client", MessageBoxButton.OK, MessageBoxImage.Exclamation); //} if (delete) { Model.Local.Customer CustomerDelete = CustomerRepository.ReadPrestashopSage(Customer.Pre_Id, Customer.Sag_Id); CustomerRepository.Delete(CustomerDelete); // suppression mappage adresse Model.Sage.F_LIVRAISONRepository F_LIVRAISONRepository = new Model.Sage.F_LIVRAISONRepository(); Model.Local.AddressRepository AddressRepository = new Model.Local.AddressRepository(); foreach (Model.Sage.F_LIVRAISON F_LIVRAISON in F_LIVRAISONRepository.ListComptet(Customer.Sag_Numero)) { if (AddressRepository.ExistSage(F_LIVRAISON.cbMarq)) { AddressRepository.Delete(AddressRepository.ReadSage(F_LIVRAISON.cbMarq)); } } this.RefreshBtoB(); } } }
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(); }