private void Button3_Click(object sender, EventArgs e) //VERWIJDEREN
        {
            using (var context = new AanwezigheidslijstContext())
            {
                if (comboBox1.SelectedItem != null && listBox1.SelectedItem != null)
                {
                    var b = listBox1.SelectedItem as DocentenOpleidingen;
                    DocentenOpleidingen docentenOpleidingen = context.DocentenOpleidingen.FirstOrDefault(a => a.Docenten.Id == b.Docenten.Id);
                    context.DocentenOpleidingen.Remove(docentenOpleidingen);
                    MessageBox.Show("docent is uitgeschreven");
                    context.SaveChanges();

                    listBox1.Items.Clear();

                    var c     = comboBox1.SelectedItem as Opleidingsinformatie;
                    var query = from dco in context.DocentenOpleidingen
                                join opli in context.Opleidingsinformatie on dco.Opleidingsinformatie.Id equals opli.Id
                                where dco.Opleidingsinformatie.Id == c.Id
                                select dco;
                    foreach (var item in query.Include(x => x.Opleidingsinformatie).Include(x => x.Docenten))
                    {
                        listBox1.Items.Add(item);
                    }
                }
                else
                {
                    MessageBox.Show("Kies eerst de opleiding");
                }
            }
        }
Esempio n. 2
0
        private void Button3_Click(object sender, EventArgs e) //DELETE
        {
            using (var context = new AanwezigheidslijstContext())
            {
                var      b      = listBox1.SelectedItem as Docenten;
                Docenten docent = context.Docenten.FirstOrDefault(a => a.Naam == b.Naam);
                context.Docenten.Remove(docent);

                DocentenOpleidingen opl = context.DocentenOpleidingen.FirstOrDefault(a => a.Docenten.Id == docent.Id);
                if (opl != null)
                {
                    context.DocentenOpleidingen.Remove(opl);
                }
                context.SaveChanges();
                MessageBox.Show("Docent verwijdert");
            }
            listBox1.Items.Clear();
            using (var ctx = new AanwezigheidslijstContext())
            {
                foreach (var item in ctx.Docenten)
                {
                    listBox1.Items.Add(item);
                }
            }
        }
        private void Button4_Click(object sender, EventArgs e)
        {
            using (var context = new AanwezigheidslijstContext())
            {
                var b = listBox1.SelectedItem as DocentenOpleidingen;
                DocentenOpleidingen deelnemersOpl = context.DocentenOpleidingen.FirstOrDefault(a => a.Docenten.Id == b.Docenten.Id);

                var      checkbox2 = comboBox2.SelectedItem as Docenten;
                Docenten dln       = context.Docenten.FirstOrDefault(a => a.Id == checkbox2.Id);
                deelnemersOpl.Docenten = dln;

                var checkbox             = comboBox1.SelectedItem as Opleidingsinformatie;
                Opleidingsinformatie opl = context.Opleidingsinformatie.FirstOrDefault(a => a.Id == checkbox.Id);
                deelnemersOpl.Opleidingsinformatie = opl;
                context.SaveChanges();
                MessageBox.Show("Aangepast");

                listBox1.Items.Clear();

                var c     = comboBox1.SelectedItem as Opleidingsinformatie;
                var query = from dco in context.DocentenOpleidingen
                            join opli in context.Opleidingsinformatie on dco.Opleidingsinformatie.Id equals opli.Id
                            where dco.Opleidingsinformatie.Id == c.Id
                            select dco;
                foreach (var item in query.Include(x => x.Opleidingsinformatie).Include(x => x.Docenten))
                {
                    listBox1.Items.Add(item);
                }
            }
        }
        private void Button1_Click(object sender, EventArgs e) //TOEVOEGEN
        {
            listBox1.Items.Clear();

            if (comboBox1 != null && comboBox2 != null)
            {
                using (var context = new AanwezigheidslijstContext())
                {
                    var docentOpl = new DocentenOpleidingen();

                    var checkbox = comboBox2.SelectedItem as Docenten;
                    var docent   = context.Docenten.SingleOrDefault(a => a.Id == checkbox.Id);
                    docentOpl.Docenten = docent;

                    //docentOpl.Docenten = comboBox2.SelectedItem as Docenten;

                    var checkbox2 = comboBox1.SelectedItem as Opleidingsinformatie;
                    var opl       = context.Opleidingsinformatie.SingleOrDefault(a => a.Id == checkbox2.Id);
                    docentOpl.Opleidingsinformatie = opl;

                    context.DocentenOpleidingen.Add(docentOpl);
                    context.SaveChanges();
                    MessageBox.Show("Docent aan opleiding toegevoegd");

                    var b     = comboBox1.SelectedItem as Opleidingsinformatie;
                    var query = from dco in context.DocentenOpleidingen
                                join opli in context.Opleidingsinformatie on dco.Opleidingsinformatie.Id equals opli.Id
                                where dco.Opleidingsinformatie.Id == b.Id
                                select dco;
                    foreach (var item in query.Include(x => x.Opleidingsinformatie).Include(x => x.Docenten))
                    {
                        listBox1.Items.Add(item);
                    }
                }
                //using (var ctx = new AanwezigheidslijstContext())
                //{
                //    foreach (var item in ctx.DocentenOpleidingen)
                //    {
                //        listBox1.Items.Add(item);
                //    }
                //}
            }
            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);
                }
            }
        }