Beispiel #1
0
        private void b_Click(object sender, RoutedEventArgs e)
        {
            if (C3.SelectedDate == null)
            {
                MessageBoxResult result = MessageBox.Show("Error : Aucune date sélectionnée");
            }
            else if (StringCheck(C1.Text) && StringCheck(C2.Text))
            {
                MessageBoxResult result = MessageBox.Show("Error : Aucun Titre sélectionné");
            }
            else
            {
                //lier les eux objets
                using (var db = new BBD_projetEntities())
                {
                    BO.Competence  t     = (BO.Competence)list2.SelectedItem;
                    DAL.Competence objet = null;
                    test2.Content = Actif.ToString();
                    var objet2 = new DAL.IntituleCompetence();

                    if (list2.SelectedItem != null)
                    {
                        objet = new DAL.Competence()
                        {
                            Actuel = this.Actuel,
                            Id_CompetenceActuel = t.Id_CompetenceActuel,
                            Annee = C3.SelectedDate.ToString(),
                            Actif = this.Actif
                        };
                    }
                    else
                    {
                        objet = new DAL.Competence()
                        {
                            Actuel = this.Actuel,
                            Id_CompetenceActuel = null,
                            Annee = C3.SelectedDate.ToString(),
                            Actif = this.Actif
                        };
                    }
                    if (list.SelectedItem == null)
                    {
                        objet2 = new DAL.IntituleCompetence()
                        {
                            intitule    = C1.Text,
                            Description = C2.Text,
                            Id_Langue   = 3,
                            Competence  = objet
                        };
                    }
                    else
                    {
                        objet2 = new DAL.IntituleCompetence()
                        {
                            intitule    = C1.Text,
                            Description = C2.Text,
                            Id_Langue   = ((int)list.SelectedValue),
                            Competence  = objet
                        };
                    }

                    objet.IntituleCompetences.Add(objet2);
                    db.Competences.Add(objet);
                    db.SaveChanges();
                    ListViewCompetence l = new ListViewCompetence();
                    this.NavigationService.Navigate(new Uri("ListViewCompetence.xaml", UriKind.Relative));
                }
            }
        }
        private void b_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new BBD_projetEntities())
            {
                BO.Competence  t      = (BO.Competence)list2.SelectedItem;
                DAL.Competence objet  = null;
                var            objet2 = new DAL.IntituleCompetence();
                test2.Content = Actif.ToString();

                IEnumerable <IntituleCompetence> req = null;
                if (((int?)list.SelectedValue) != null)
                {
                    req = (from c in db.IntituleCompetences
                           where c.Id_Competence == Competence.Id_Competence && c.Id_Langue == ((int)list.SelectedValue)
                           select new
                    {
                        Competence = c.Competence,
                        Id_Langue = c.Id_Langue,
                        Id_Competence = c.Id_Competence,
                        Description = c.Description,
                        intitule = c.intitule,
                        Langue = c.Langue
                    }).ToList().Select(c => new DAL.IntituleCompetence
                    {
                        Competence    = c.Competence,
                        Id_Langue     = c.Id_Langue,
                        Id_Competence = c.Id_Competence,
                        Description   = c.Description,
                        intitule      = c.intitule,
                        Langue        = c.Langue
                    });
                }
                if (!(req == null) || (req != null && req.ToList().Count > 0))
                {
                    var o       = new BO.IntituleCompetence(req.ToList()[0]);
                    var IcObjet = db.IntituleCompetences.Find(o.Id_Competence, o.Id_Langue);
                    IcObjet.intitule    = C1.Text;
                    IcObjet.Description = C2.Text;
                    if (list.SelectedItem == null)
                    {
                        IcObjet.Id_Langue = db.LangueParDefaut();
                    }
                    else
                    {
                        IcObjet.Id_Langue = ((int)list.SelectedValue);
                    }
                }
                else
                {
                    if (list.SelectedItem == null)
                    {
                        var LangueParDef = db.LangueParDefaut();
                        if ((from c in db.IntituleCompetences
                             where c.Id_Competence == Competence.Id_Competence && c.Id_Langue == LangueParDef
                             select new { }).Count() > 1)
                        {
                            objet2 = new DAL.IntituleCompetence()
                            {
                                intitule      = C1.Text,
                                Description   = C2.Text,
                                Id_Langue     = db.LangueParDefaut(),
                                Id_Competence = Competence.Id_Competence,
                                Competence    = db.Competences.Find(Competence.Id_Competence),
                                Langue        = db.Langues.Find(db.LangueParDefaut())
                            };
                            System.Diagnostics.Debug.WriteLine(objet2.intitule);
                            System.Diagnostics.Debug.WriteLine(objet2.Description);
                            System.Diagnostics.Debug.WriteLine(objet2.Id_Langue);
                            System.Diagnostics.Debug.WriteLine(objet2.Id_Competence);

                            db.IntituleCompetences.Add(objet2);
                        }
                        else
                        {
                            //work
                            var IcObjet = db.IntituleCompetences.Find(Competence.Id_Competence, db.LangueParDefaut());
                            IcObjet.intitule    = C1.Text;
                            IcObjet.Description = C2.Text;
                        }
                    }
                    else
                    {
                        objet2 = new DAL.IntituleCompetence()
                        {
                            intitule      = C1.Text,
                            Description   = C2.Text,
                            Id_Langue     = ((int)list.SelectedValue),
                            Id_Competence = Competence.Id_Competence
                        };

                        db.IntituleCompetences.Add(objet2);
                    }
                }
                var DALCompetence = db.Competences.Find(Competence.Id_Competence);
                if (list2.SelectedValue != null)
                {
                    DALCompetence.Id_CompetenceActuel = t.Id_Competence;
                }

                /* System.Diagnostics.Debug.WriteLine(C3.SelectedDate == null);
                 * System.Diagnostics.Debug.WriteLine(C3.SelectedDate != null);
                 * System.Diagnostics.Debug.WriteLine(!(C3.SelectedDate == null));*/
                if (C3.SelectedDate != null)
                {
                    DALCompetence.Annee = C3.SelectedDate.ToString();
                }
                if (DALCompetence.Actif == this.Actif)
                {
                    DALCompetence.Actif = this.Actif;
                }


                System.Diagnostics.Debug.WriteLine(C3.SelectedDate.ToString());
                System.Diagnostics.Debug.WriteLine(DALCompetence.Annee);
                System.Diagnostics.Debug.WriteLine(!(C3.SelectedDate == null));
                db.SaveChanges();
                ListViewCompetence l = new ListViewCompetence();
                this.NavigationService.Navigate(new Uri("ListViewCompetence.xaml", UriKind.Relative));
            }
        }