Example #1
0
        private void Button3_Click(object sender, EventArgs e) //VERWIJDEREN
        {
            using (var context = new AanwezigheidslijstContext())
            {
                var b = listBox1.SelectedItem as NietOpleidingsDagen;
                NietOpleidingsDagen nietOpl = context.NietOpleidingsDagen.FirstOrDefault(a => a.Id == b.Id);
                context.NietOpleidingsDagen.Remove(nietOpl);
                MessageBox.Show("Vakantiedag verwijdert");
                context.SaveChanges();

                listBox1.Items.Clear();
                var c = comboBox1.SelectedItem as Opleidingsinformatie;
                //var deelnemers = context.Deelnemers.Select(deelnem => new { })
                var query = from nto in context.NietOpleidingsDagen
                            join opli in context.Opleidingsinformatie on nto.Opleidingsinformatie.Id equals opli.Id
                            where nto.Opleidingsinformatie.Id == c.Id
                            select nto;
                foreach (var item in query.Include(x => x.Opleidingsinformatie))
                {
                    listBox1.Items.Add(item);
                }
            }

            //listBox1.Items.Clear();
            //using (var ctx = new AanwezigheidslijstContext())
            //{
            //    foreach (var item in ctx.NietOpleidingsDagen.Include(x => x.Opleidingsinformatie))
            //    {
            //        listBox1.Items.Add(item);
            //    }
            //}
        }
Example #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (dateTimePicker2.Value > DateTime.Now && checkBox1.Checked == true || checkBox2.Checked == true)
            {
                listBox1.Items.Clear();

                using (var context = new AanwezigheidslijstContext())
                {
                    var nietopleidingsDagen = new NietOpleidingsDagen();
                    nietopleidingsDagen.Datum      = dateTimePicker2.Value;
                    nietopleidingsDagen.Voormiddag = checkBox1.Checked;
                    nietopleidingsDagen.Namiddag   = checkBox2.Checked;

                    var checkbox   = comboBox1.SelectedItem as Opleidingsinformatie;
                    var nietOplDag = context.Opleidingsinformatie.SingleOrDefault(a => a.Opleiding == checkbox.Opleiding);

                    nietopleidingsDagen.Opleidingsinformatie = nietOplDag;


                    context.NietOpleidingsDagen.Add(nietopleidingsDagen);
                    context.SaveChanges();
                    MessageBox.Show("Niet opleidingsdag toegevoegd");

                    var b = comboBox1.SelectedItem as Opleidingsinformatie;
                    //var deelnemers = context.Deelnemers.Select(deelnem => new { })
                    var query = from nto in context.NietOpleidingsDagen
                                join opli in context.Opleidingsinformatie on nto.Opleidingsinformatie.Id equals opli.Id
                                where nto.Opleidingsinformatie.Id == b.Id
                                select nto;
                    foreach (var item in query.Include(x => x.Opleidingsinformatie))
                    {
                        listBox1.Items.Add(item);
                    }
                    //foreach (var item in context.NietOpleidingsDagen.Include(x=>x.Opleidingsinformatie))
                    //{
                    //    listBox1.Items.Add(item);
                    //}
                }
                //using (var ctx = new AanwezigheidslijstContext())
                //{

                //}
            }
            else
            {
                MessageBox.Show("Gelieve de gegevens correct in te vullen");
            }
        }
        private void Button3_Click(object sender, EventArgs e)  //DELETE
        {
            using (var context = new AanwezigheidslijstContext())
            {
                //OPLEIDING VERWIJDEREN
                var b = listBox1.SelectedItem as Opleidingsinformatie;
                Opleidingsinformatie opleiding = context.Opleidingsinformatie.FirstOrDefault(a => a.Opleiding == b.Opleiding);
                context.Opleidingsinformatie.Remove(opleiding);
                //*

                //DEELNEMEROPLEIDING VERWIJDEREN
                var opl = from deeln in context.DeelnemersOpleidingen
                          join opl1 in context.Opleidingsinformatie on deeln.Opleidingsinformatie.Opleiding equals opl1.Opleiding
                          where deeln.Opleidingsinformatie.Opleiding == b.Opleiding
                          select deeln;

                foreach (var item in opl)
                {
                    context.DeelnemersOpleidingen.Remove(item);
                }
                //*

                //TIJDSREGISTRATIES VERWIJDEREN
                var verwijdertijd = from tijdr in context.Tijdsregistraties
                                    join opl1 in context.Opleidingsinformatie on tijdr.Opleidingsinformatie.Opleiding equals opl1.Opleiding
                                    where tijdr.Opleidingsinformatie.Opleiding == b.Opleiding
                                    select tijdr;

                foreach (var item in verwijdertijd)
                {
                    context.Tijdsregistraties.Remove(item);
                }
                //*

                //DOCENT VERWIJDEREN
                DocentenOpleidingen doc = context.DocentenOpleidingen.FirstOrDefault(a => a.Opleidingsinformatie.Id == opleiding.Id);
                if (doc != null)
                {
                    context.DocentenOpleidingen.Remove(doc);
                }
                //*

                //NIETOPLEIDINGSDAG VERWIJDEREN
                NietOpleidingsDagen niet = context.NietOpleidingsDagen.FirstOrDefault(a => a.Opleidingsinformatie.Id == opleiding.Id);
                if (niet != null)
                {
                    context.NietOpleidingsDagen.Remove(niet);
                }
                //*

                context.SaveChanges();
                MessageBox.Show("Opleiding verwijdert");
            }
            listBox1.Items.Clear();
            using (var context = new AanwezigheidslijstContext())
            {
                foreach (var item in context.Opleidingsinformatie)
                {
                    listBox1.Items.Add(item);
                }
            }
        }