Ejemplo n.º 1
0
        private void boutonAjouter_Click(object sender, RoutedEventArgs e)
        {
            if (VerificationFormulaire())
            {
                Adresse adresse = new Adresse();
                int     num;
                Boolean isOk = true;
                if (int.TryParse(this.textBoxAdresseNumero.Text, out num))
                {
                    adresse.Numero = num;
                }
                else
                {
                    isOk = false;
                }

                if (isOk == true)
                {
                    if (this.radioAnnonceur.IsChecked == true)
                    {
                        Annonceur a = new Annonceur();
                        a.RaisonSociale    = this.textBoxRaisonSociale.Text;
                        a.Telephone        = this.textBoxTelephone.Text;
                        a.Email            = this.textBoxEmail.Text;
                        a.NumeroSiret      = this.textBoxSiret.Text;
                        adresse.Rue        = this.textBoxAdresseRue.Text;
                        adresse.CodePostal = this.textBoxAdresseCodePostal.Text;
                        adresse.Ville      = this.textBoxAdresseVille.Text;
                        a.Adresse          = adresse;

                        if (isOk == true)
                        {
                            try
                            {
                                App.dbContext.Societes.Add(a);
                                App.dbContext.SaveChanges();

                                this.parentSocieteControl.Societes.Add(a);
                                this.parentSocieteControl.selectedSociete = a;
                                this.Close();
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                    else if (radioDiffuseur.IsChecked == true)
                    {
                        Diffuseur d = new Diffuseur();
                        d.RaisonSociale    = this.textBoxRaisonSociale.Text;
                        d.Telephone        = this.textBoxTelephone.Text;
                        d.Email            = this.textBoxEmail.Text;
                        d.NumeroSiret      = this.textBoxSiret.Text;
                        adresse.Numero     = num;
                        adresse.Rue        = this.textBoxAdresseRue.Text;
                        adresse.CodePostal = this.textBoxAdresseCodePostal.Text;
                        adresse.Ville      = this.textBoxAdresseVille.Text;
                        d.Adresse          = adresse;

                        if (isOk == true)
                        {
                            try
                            {
                                App.dbContext.Societes.Add(d);
                                App.dbContext.SaveChanges();

                                this.parentSocieteControl.Societes.Add(d);
                                this.parentSocieteControl.selectedSociete = d;
                                this.Close();
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                }
                else
                {
                    this.labelErreurAdresseNumero.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }
        private void boutonEnregistrer_Click(object sender, RoutedEventArgs e)
        {
            if (selectedSociete != null)
            {
                Boolean isOk = true;
                int     num;
                Adresse adresse = selectedSociete.Adresse;
                this.UpdateSources();
                if (VerificationFormulaire())
                {
                    if (int.TryParse(this.textBoxAdresseNumero.Text, out num))
                    {
                        adresse.Numero = num;
                    }
                    else
                    {
                        isOk = false;
                    }

                    if (isOk == true)
                    {
                        if (selectedSociete is Annonceur)
                        {
                            if (radioAnnonceur.IsChecked == true)
                            {
                                try
                                {
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Annonceur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                try
                                {
                                    Diffuseur d = new Diffuseur();
                                    d.RaisonSociale = this.textBoxRaisonSociale.Text;
                                    d.Telephone     = this.textBoxTelephone.Text;
                                    d.Email         = this.textBoxEmail.Text;
                                    d.NumeroSiret   = this.textBoxSiret.Text;
                                    d.Adresse       = adresse;

                                    App.dbContext.Societes.Remove(selectedSociete);
                                    Societes.Remove(selectedSociete);

                                    App.dbContext.Societes.Add(d);
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Diffuseur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);

                                    Societes.Add(d);
                                    listeSociete.SelectedItem = d;
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            if (radioDiffuseur.IsChecked == true)
                            {
                                try
                                {
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Diffuseur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                try
                                {
                                    Annonceur a = new Annonceur();
                                    a.RaisonSociale = this.textBoxRaisonSociale.Text;
                                    a.Telephone     = this.textBoxTelephone.Text;
                                    a.Email         = this.textBoxEmail.Text;
                                    a.NumeroSiret   = this.textBoxSiret.Text;
                                    a.Adresse       = adresse;

                                    App.dbContext.Societes.Remove(selectedSociete);
                                    Societes.Remove(selectedSociete);

                                    App.dbContext.Societes.Add(a);
                                    App.dbContext.SaveChangesAsync();
                                    MessageBox.Show("Annonceur enregistré", "Validation", MessageBoxButton.OK, MessageBoxImage.Information);

                                    Societes.Add(a);
                                    listeSociete.SelectedItem = a;
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    else
                    {
                        this.labelErreurAdresseNumero.Visibility = System.Windows.Visibility.Visible;
                    }
                }
            }
        }