//combobox selectie private void ComboBoxOpleiding_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxOpleiding.SelectedIndex == -1) { ClearAll(); //of niets doen } else if (comboBoxOpleiding.SelectedIndex == 0) { ClearAll(); tabControl1.SelectedIndex = 0; } else { ClearAll(); OpleidingsInformatie comboOpl = comboBoxOpleiding.SelectedItem as OpleidingsInformatie; Opleiding = OplLijst.SingleOrDefault(x => x.Id == comboOpl.Id); textBoxOplId.Text = Opleiding.Id.ToString(); textBoxOplInstelling.Text = Opleiding.OpleidingsInstelling; textBoxOpl.Text = Opleiding.Opleiding; textBoxOplContact.Text = Opleiding.Contactpersoon; textBoxOplPlaats.Text = Opleiding.Opleidingsplaats; textBoxOplRef.Text = Opleiding.ReferentieOpledingsPlaats; textBoxOplOE.Text = Opleiding.OeNummer.ToString(); textBoxOplCode.Text = Opleiding.Opleidngscode.ToString(); dateTimePickerOplStart.Value = Opleiding.StartDatum.Date; dateTimePickerOplEind.Value = Opleiding.EindDatum.Date; LaadAlleListbox(); } }
private void ButtonOplUpd_Click(object sender, EventArgs e) { OplTab_Validating(); if (IsValidOpl && textBoxOplId.Text != "") { using (var ctx = new DataContext()) { OpleidingsInformatie oplUpd = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); oplUpd.OpleidingsInstelling = textBoxOplInstelling.Text; oplUpd.Opleiding = textBoxOpl.Text; oplUpd.Contactpersoon = textBoxOplContact.Text; oplUpd.Opleidingsplaats = textBoxOplPlaats.Text; oplUpd.ReferentieOpledingsPlaats = textBoxOplRef.Text; oplUpd.OeNummer = int.Parse(textBoxOplOE.Text); oplUpd.Opleidngscode = int.Parse(textBoxOplCode.Text); oplUpd.StartDatum = dateTimePickerOplStart.Value; oplUpd.EindDatum = dateTimePickerOplEind.Value; ctx.SaveChanges(); OplLijst = ctx.OpleidingsInformatie.ToList(); } Opleiding = OplLijst.Last(); } else { errorProviderOplInfoTab.SetError(buttonOplUpd, "Creeër eerst nieuwe opleiding ipv up te daten."); } }
private void ComboBoxOpl_SelectedIndexChanged(object sender, EventArgs e) { DeleteButtons(); if (comboBoxOpl.SelectedIndex == -1) { // doe niets } else { OpleidingsInformatie comboOpl = comboBoxOpl.SelectedItem as OpleidingsInformatie; Opleiding = OplLijst.SingleOrDefault(x => x.Id == comboOpl.Id); textBoxOplId.Text = Opleiding.Id.ToString(); textBoxOplInstelling.Text = Opleiding.OpleidingsInstelling; textBoxOpl.Text = Opleiding.Opleiding; textBoxOplContact.Text = Opleiding.Contactpersoon; textBoxOplPlaats.Text = Opleiding.Opleidingsplaats; textBoxOplRef.Text = Opleiding.ReferentieOpledingsPlaats; textBoxOplOE.Text = Opleiding.OeNummer.ToString(); textBoxOplCode.Text = Opleiding.Opleidngscode.ToString(); dateTimePickerOplStart.Value = Opleiding.StartDatum.Date; dateTimePickerOplEind.Value = Opleiding.EindDatum.Date; CreateButtons(); } }
// buttons opleidingsinfo tabblad private void ButtonOplCreate_Click(object sender, EventArgs e) { OplTab_Validating(); //check of OE of code al bestaat. Moet enkel in toevoeg, niet in update. foreach (OpleidingsInformatie item in OplLijst) { if (item.OeNummer.ToString() == textBoxOplOE.Text) { errorProviderOplInfoTab.SetError(textBoxOplOE, "OE nummer bestaat al."); IsValidOpl = false; } else { errorProviderOplInfoTab.SetError(textBoxOplOE, string.Empty); } if (item.Opleidngscode.ToString() == textBoxOplCode.Text) { errorProviderOplInfoTab.SetError(textBoxOplOE, "Opleidingscode bestaat al."); IsValidOpl = false; } else { errorProviderOplInfoTab.SetError(textBoxOplOE, string.Empty); } } if (IsValidOpl && textBoxOplId.Text == "")// && ( comboBoxOpleiding.SelectedIndex == 0 || comboBoxOpleiding.SelectedIndex == -1)) //mogelijk nodig { OpleidingsInformatie nieuweOpl = new OpleidingsInformatie { OpleidingsInstelling = textBoxOplInstelling.Text, Opleiding = textBoxOpl.Text, Contactpersoon = textBoxOplContact.Text, Opleidingsplaats = textBoxOplPlaats.Text, ReferentieOpledingsPlaats = textBoxOplRef.Text, OeNummer = int.Parse(textBoxOplOE.Text), Opleidngscode = int.Parse(textBoxOplCode.Text), StartDatum = dateTimePickerOplStart.Value, EindDatum = dateTimePickerOplEind.Value }; using (var ctx = new DataContext()) { ctx.OpleidingsInformatie.Add(nieuweOpl); ctx.SaveChanges(); OplLijst = ctx.OpleidingsInformatie.ToList(); } Opleiding = OplLijst.Last(); textBoxOplId.Text = Opleiding.Id.ToString(); comboBoxOpleiding.Items.Add(Opleiding); OplLijst = OplLijst.OrderBy(x => x.Opleiding).ToList(); } else { errorProviderOplInfoTab.SetError(buttonOplCreate, "Selecteer eerst creeër nieuwe opleiding in menu."); } }
private void ButtonDocentAdd_Click(object sender, EventArgs e) { DocentTab_Validatie(); if (comboBoxOpleiding.SelectedIndex < 1) { errorProviderOplInfoTab.SetError(buttonDocentAdd, "Selecteer of creeër eerst een opleiding om deelnemer aan toe tevoegen."); } else if (IsValidDocent && textBoxDocentId.Text == "") { if (DocentLijst.Any(d => d.Naam.ToLower() == textBoxDocentNaam.Text.ToLower() && d.Bedrijf.ToLower() == textBoxDocentBedrijf.Text.ToLower())) { using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); Docenten docentUpd = ctx.Docenten.SingleOrDefault(x => x.Naam.ToLower() == textBoxDocentNaam.Text.ToLower() && x.Bedrijf.ToLower() == textBoxDocentBedrijf.Text.ToLower()); ctx.DocentenOpleiding.Add(new DocentenOpleiding { Docenten = docentUpd, OpleidingsInformatie = Opleiding }); ctx.SaveChanges(); DocOplLijst = ctx.DocentenOpleiding.Include(x => x.Docenten).Include(x => x.OpleidingsInformatie).ToList(); } } else { Docenten nieuweDoc = new Docenten { Naam = textBoxDocentNaam.Text, Bedrijf = textBoxDocentBedrijf.Text, }; using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); ctx.Docenten.Add(nieuweDoc); ctx.DocentenOpleiding.Add(new DocentenOpleiding { Docenten = nieuweDoc, OpleidingsInformatie = Opleiding }); ctx.SaveChanges(); DocOplLijst = ctx.DocentenOpleiding.Include(x => x.Docenten).Include(x => x.OpleidingsInformatie).ToList(); DocentLijst = ctx.Docenten.ToList(); } textBoxDocentId.Text = DocentLijst.Last().Id.ToString(); } ClearAll(); LaadAlleListbox(); } else { errorProviderOplInfoTab.SetError(buttonDocentAdd, "U probeert te updaten."); } }
private void ButtonVerlofAdd_Click(object sender, EventArgs e) { VerlofTab_validatie(); //is deze datum al toegevoegd? ja -> update ipv toevoegen var verlofLijst = (from v in VerlofLijst where v.OpleidingsInformatie.Id == Opleiding.Id select v); verlofLijst = verlofLijst.OrderBy(v => v.Datum.Date); foreach (NietOpleidingsDagen item in verlofLijst) { if (item.Datum == dateTimePickerVerlof.Value.Date) { errorProviderOplInfoTab.SetError(dateTimePickerVerlof, "Deze dag is al toegevoegd. Probeer update."); IsValidVerlof = false; } } if (comboBoxOpleiding.SelectedIndex < 1) { errorProviderOplInfoTab.SetError(buttonVerlofAdd, "Selecteer of creeër eerst een opleiding om deelnemer aan toe tevoegen."); } else if (IsValidVerlof && textBoxVerlofId.Text == "") { using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); NietOpleidingsDagen nieuweVerlofDag = new NietOpleidingsDagen { Datum = dateTimePickerVerlof.Value.Date, Voormiddag = checkBoxVerlofVoormiddag.Checked, Namiddag = checkBoxVerlofNamiddag.Checked, OpleidingsInformatie = Opleiding }; ctx.NietOpleidingsDagen.Add(nieuweVerlofDag); ctx.SaveChanges(); VerlofLijst = ctx.NietOpleidingsDagen.Include(x => x.OpleidingsInformatie).ToList(); } textBoxVerlofId.Text = VerlofLijst.Last().Id.ToString(); ClearAll(); LaadAlleListbox(); } else if (textBoxVerlofId.Text != "") { errorProviderOplInfoTab.SetError(buttonVerlofAdd, "U probeert te updaten."); } }
private void ButtonOpleidingenRemove_Click(object sender, EventArgs e) { using (var context = new DatabaseContext()) { OpleidingsInformatie opleiding = context.OpleidingsInformatie.FirstOrDefault(f => f.Opleiding == TextboxOpleidingenNaam.Text && f.Opleidingsplaats == TextboxOpleidingenPlaats.Text); if (opleiding != null) { context.OpleidingsInformatie.Remove(opleiding); context.SaveChanges(); } } ReloadOpleidingList(); }
private void OKButton_Click(object sender, EventArgs e) { string selectedItem = ComboboxOpleidingen.SelectedItem.ToString(); var strings = selectedItem.Split(','); string naam = strings[0]; string plaats = strings[1].Substring(2); string startdatum = strings[2].Substring(2); using (var context = new DatabaseContext()) { OpleidingsInformatie opleiding = context.OpleidingsInformatie.FirstOrDefault(f => f.Opleiding == naam && f.Opleidingsplaats == plaats); OnOkEvent?.Invoke(this, opleiding); } ComboboxOpleidingen.Items.Clear(); this.Dispose(); }
private void ListboxOpleidingen_DoubleClick(object sender, EventArgs e) { string selectedItem = ListboxOpleidingen.SelectedItem.ToString(); var strings = selectedItem.Split(','); string naam = strings[0]; string plaats = strings[1].Substring(2); string startdatum = strings[2].Substring(2); using (var context = new DatabaseContext()) { OpleidingsInformatie opleiding = context.OpleidingsInformatie.FirstOrDefault(f => f.Opleiding == naam && f.Opleidingsplaats == plaats); _selectedOpleiding = opleiding; TextboxOpleidingenInstelling.Text = opleiding.Opleidingsinstelling; TextboxOpleidingenNaam.Text = opleiding.Opleiding; TextboxOpleidingenContactPersoon.Text = opleiding.Contactpersoon; TextboxOpleidingenPlaats.Text = opleiding.Opleidingsplaats; TextboxOpleidingenReferentie.Text = opleiding.ReferentieOpleidingsplaats; TextboxOpleidingenOENr.Text = opleiding.OeNummer; TextboxOpleidingenCode.Text = opleiding.Opleidingscode; DateTimePickerOpleidingenVan.Value = opleiding.StartDatum; DateTimePickerOpleidingenTot.Value = opleiding.EindDatum; if (opleiding.Deelnemers != null) { foreach (var item in opleiding.Deelnemers) { ListboxOpleidingenDeelnemers.Items.Add(item); } } if (opleiding.Docentens != null) { foreach (var item in opleiding.Docentens) { ListboxOpleidingenDocenten.Items.Add(item); } } } }
private void ButtonOpleidingenAdd_Click(object sender, EventArgs e) { List <Docenten> docenten = new List <Docenten>(); foreach (var docent in ListboxOpleidingenDocenten.Items) { docenten.Add(docent as Docenten); } List <Deelnemers> deelnemers = new List <Deelnemers>(); foreach (var deelnemer in ListboxOpleidingenDeelnemers.Items) { deelnemers.Add(deelnemer as Deelnemers); } OpleidingsInformatie opleiding = new OpleidingsInformatie() { Opleidingsinstelling = TextboxOpleidingenInstelling.Text, Opleiding = TextboxOpleidingenNaam.Text, Contactpersoon = TextboxOpleidingenContactPersoon.Text, Opleidingsplaats = TextboxOpleidingenPlaats.Text, ReferentieOpleidingsplaats = TextboxOpleidingenReferentie.Text, OeNummer = TextboxOpleidingenOENr.Text, Opleidingscode = TextboxOpleidingenCode.Text, StartDatum = DateTimePickerOpleidingenVan.Value, EindDatum = DateTimePickerOpleidingenTot.Value, Docentens = docenten, Deelnemers = deelnemers }; using (var context = new DatabaseContext()) { context.OpleidingsInformatie.Add(opleiding); context.SaveChanges(); } ReloadOpleidingList(); }
private void DynamicButton_Click(object sender, EventArgs e) { Button button = sender as Button; var deeln = from d in DeelnLijst join dOpl in DeelnOplLijst on d.Id equals dOpl.Deelnemer.Id where dOpl.OpleidingsInformatie.Id == Opleiding.Id select d; Deelnemers deel = new Deelnemers(); using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); deel = ctx.Deelnemers.SingleOrDefault(d => d.Naam == button.Name); ctx.Tijdsregistraties.Add(new Tijdsregistraties { DateTime = DateTime.Now, OpleidingsInformatie = Opleiding, Deelnemers = deel }); ctx.SaveChanges(); TijdLijst = ctx.Tijdsregistraties.Include(x => x.Deelnemers).Include(x => x.OpleidingsInformatie).ToList(); } if (button.Text == "Badge In") { button.Text = "Badge Out"; } else { button.Text = "Badge In"; var tijdPerDeel = from t in TijdLijst join opl in OplLijst on t.OpleidingsInformatie.Id equals opl.Id where t.Deelnemers.Id == deel.Id select t; //List<Tijdsregistraties> tijdPerDeeln = tijdPerDeel as List<Tijdsregistraties>; TimeSpan tijdIn = tijdPerDeel.Last().DateTime - tijdPerDeel.Reverse().Skip(1).First().DateTime; MessageBox.Show($"{deel.Naam} was {tijdIn} aanwezig."); } }
//verwijder opleiding private void ButtonOplDel_Click(object sender, EventArgs e) { int delOpldId = int.Parse(textBoxOplId.Text); using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == delOpldId); ctx.NietOpleidingsDagen.RemoveRange(ctx.NietOpleidingsDagen.Where(x => x.OpleidingsInformatie.Id == delOpldId)); ctx.DeelnemersOpleidingen.RemoveRange(ctx.DeelnemersOpleidingen.Where(x => x.OpleidingsInformatie.Id == delOpldId)); ctx.DocentenOpleiding.RemoveRange(ctx.DocentenOpleiding.Where(x => x.OpleidingsInformatie.Id == delOpldId)); ctx.Tijdsregistraties.RemoveRange(ctx.Tijdsregistraties.Where(x => x.OpleidingsInformatie.Id == delOpldId)); ctx.OpleidingsInformatie.Remove(Opleiding); ctx.SaveChanges(); OplLijst = ctx.OpleidingsInformatie.OrderBy(x => x.Opleiding).ToList(); } comboBoxOpleiding.Items.Clear(); comboBoxOpleiding.Items.Add("Nieuwe opleiding aanmaken"); foreach (var opl in OplLijst) { comboBoxOpleiding.Items.Add(opl); } comboBoxOpleiding.SelectedIndex = 0; }
//buttons deelnemer tabblad private void ButtonDeelnemerCreate_Click(object sender, EventArgs e) { DeelnTab_Validating(); //check of badge nummer al bestaat, moet enkel in toevoegen, niet in updaten. foreach (Deelnemers item in DeelnLijst) { if (item.Badgenummer.ToString() == textBoxDeelnBadge.Text) { errorProviderOplInfoTab.SetError(textBoxOplOE, "Badge nummer bestaat al."); IsValidOpl = false; } else { errorProviderOplInfoTab.SetError(textBoxOplOE, string.Empty); } } if (comboBoxOpleiding.SelectedIndex < 1) { errorProviderOplInfoTab.SetError(buttonDeelnemerCreate, "Selecteer of creeër eerst een opleiding om deelnemer aan toe tevoegen."); } else if (IsValidDeeln && textBoxDeelnId.Text == "") { if (DeelnLijst.Any(d => d.Naam.ToLower() == textBoxDeelnNaam.Text.ToLower() && d.GeboorteDatum.Date == dateTimePickerDeelnGeb.Value.Date)) { using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); Deelnemers deelnUpd = ctx.Deelnemers.SingleOrDefault(x => x.Naam == textBoxDeelnNaam.Text && x.GeboorteDatum == dateTimePickerDeelnGeb.Value.Date); deelnUpd.Woonplaats = textBoxDeelnWoon.Text; deelnUpd.Badgenummer = int.Parse(textBoxDeelnBadge.Text); ctx.DeelnemersOpleidingen.Add(new DeelnemersOpleidingen { Deelnemer = deelnUpd, OpleidingsInformatie = Opleiding }); ctx.SaveChanges(); DeelnLijst = ctx.Deelnemers.ToList(); DeelnOplLijst = ctx.DeelnemersOpleidingen.Include(x => x.Deelnemer).Include(x => x.OpleidingsInformatie).ToList(); } } else { Deelnemers nieuweDeeln = new Deelnemers { Naam = textBoxDeelnNaam.Text, GeboorteDatum = dateTimePickerDeelnGeb.Value.Date, Woonplaats = textBoxDeelnWoon.Text, Badgenummer = int.Parse(textBoxDeelnBadge.Text) }; using (var ctx = new DataContext()) { Opleiding = ctx.OpleidingsInformatie.SingleOrDefault(x => x.Id == Opleiding.Id); ctx.Deelnemers.Add(nieuweDeeln); ctx.DeelnemersOpleidingen.Add(new DeelnemersOpleidingen { Deelnemer = nieuweDeeln, OpleidingsInformatie = Opleiding }); ctx.SaveChanges(); DeelnLijst = ctx.Deelnemers.ToList(); DeelnOplLijst = ctx.DeelnemersOpleidingen.Include(x => x.Deelnemer).Include(x => x.OpleidingsInformatie).ToList(); } textBoxDeelnId.Text = DeelnLijst.Last().Id.ToString(); } ClearAll(); LaadAlleListbox(); } else { errorProviderOplInfoTab.SetError(buttonDeelnemerCreate, "U probeert te updaten."); } }
private void OnAddOpleidingEvent(object sender, OpleidingsInformatie e) { ListboxDocentenOpleidingen.Items.Add(e); }