//Methode om voertuig aan te passen / toe te voegen, a.d.h.v. button naam private void btnOpslaan_Click(object sender, EventArgs e) { //Validatie if (Validation.hasValidationErrors(this.Controls)) { return; } //na Validatie //if (btnOpslaan.Name == "btnAanmaken") if (cbbID.Visible == false) { //Gegevens uit textboxen, comboboxen halen in voertuig met aanmaken voertuig nieuwVoertuig = new voertuig(); nieuwVoertuig.bedrijf = (bedrijf)cbbbedrijf.SelectedItem; nieuwVoertuig.identificatie = txtIdentificatie.Text; nieuwVoertuig.nummerplaat = txtNummerplaat.Text; nieuwVoertuig.voertuigsoort = cbbSoort.Text; nieuwVoertuig.merk = cbbMerk.Text; nieuwVoertuig.type = txtType.Text; nieuwVoertuig.onderstel_nr = txtOnderstel.Text; nieuwVoertuig.motormerk = txtMotorMerk.Text; nieuwVoertuig.motortype = txtMotortype.Text; nieuwVoertuig.bouwjaar = txtBouwjaar.Text; nieuwVoertuig.ingebruikname = txtIngebruikname.Text; //aankoopprijs int?aankoopprijs; if (String.IsNullOrEmpty(txtAankoopprijs.Text)) { aankoopprijs = null; } else { aankoopprijs = Convert.ToInt32(txtAankoopprijs.Text); } nieuwVoertuig.aankoopprijs = aankoopprijs; //zitplaatsen int?zitplaatsen; if (String.IsNullOrEmpty(txtZitplaatsen.Text)) { zitplaatsen = null; } else { zitplaatsen = Convert.ToInt32(txtZitplaatsen.Text); } nieuwVoertuig.zitplaatsen = zitplaatsen; //staanplaatsen int?staanplaatsen; if (String.IsNullOrEmpty(txtStaanplaatsen.Text)) { staanplaatsen = null; } else { staanplaatsen = Convert.ToInt32(txtStaanplaatsen.Text); } nieuwVoertuig.staanplaatsen = staanplaatsen; //Sterren int sterren = cbbSterren.SelectedIndex; nieuwVoertuig.sterren = sterren; nieuwVoertuig.memo = txtMemo.Text; nieuwVoertuig.leverancier = (leverancier)cbbLeverancier.SelectedItem; //Accommodaties toevoegen aan voertuig + voertuig toevoegen foreach (ComboBox cbbAccommodatie in flpAccomodaties.Controls) { accommodatie accommodatie = (accommodatie)cbbAccommodatie.SelectedItem; voertuig_accomodatie va = new voertuig_accomodatie(); va.accommodatie = accommodatie; va.voertuig = nieuwVoertuig; VoertuigManagement.addAccommodatieBijVoertuig(va); } VoertuigManagement.addVoertuig(nieuwVoertuig); //VoertuigManagement.addVoertuig(txtNummerplaat.Text, cbbSoort.SelectedItem.ToString(), cbbMerk.SelectedItem.ToString(), // txtType.Text, txtOnderstel.Text, txtMotorMerk.Text, txtMotortype.Text, txtBouwjaar.Text, txtIngebruikname.Text, // Decimal.Parse(txtAankoopprijs.Text), Int32.Parse(txtZitplaatsen.Text), Int32.Parse(txtStaanplaatsen.Text), // Int32.Parse(cbbSterren.SelectedItem.ToString()), txtMemo.Text, (leverancier)cbbLeverancier.SelectedItem); //Buttons en dergelijke terug goedzetten btnNieuwVoertuig.Visible = true; btnDelete.Visible = true; cbbID.Visible = true; btnOpslaan.Name = "btnOpslaan"; MainForm.updateStatus = "Voertuig: " + nieuwVoertuig.identificatie + ", is succesvol aangemaakt."; //Combobox datasource opnieuw laden, zodat deze nu tussen de lijst staat. cbbID.DataSource = VoertuigManagement.getVoertuigen(); cbbID.SelectedItem = nieuwVoertuig; } //else if (btnOpslaan.Name == "btnOpslaan") else if (cbbID.Visible == true) { voertuig updateVoertuig = (voertuig)cbbID.SelectedItem; int sterren = cbbSterren.SelectedIndex; //Gegevens uit textboxen, comboboxen halen en database methode oproepen om voertuig aan te passen VoertuigManagement.updateVoertuig(updateVoertuig.voertuig_id, txtIdentificatie.Text, txtNummerplaat.Text, cbbSoort.Text, cbbMerk.Text, txtType.Text, txtOnderstel.Text, txtMotorMerk.Text, txtMotortype.Text, txtBouwjaar.Text, txtIngebruikname.Text, txtAankoopprijs.Text, txtZitplaatsen.Text, txtStaanplaatsen.Text, sterren, txtMemo.Text, (leverancier)cbbLeverancier.SelectedItem, (bedrijf)cbbbedrijf.SelectedItem); //Eerste alle accommodaties verwijderen VoertuigManagement.deleteAccommodaties(updateVoertuig.voertuig_id); //Accommodaties updaten foreach (ComboBox cbbAccommodaties in flpAccomodaties.Controls) { //Dan nieuwe toevoegen accommodatie am = (accommodatie)cbbAccommodaties.SelectedItem; voertuig_accomodatie va = new voertuig_accomodatie(); va.voertuig_id = updateVoertuig.voertuig_id; va.accommodatie = am; VoertuigManagement.addAccommodatieBijVoertuig(va); } MainForm.updateStatus = "Voertuig: " + txtNummerplaat.Text + ", is succesvol aangepast."; } }
//Accommodatie toevoegen aan voertuig (tussentabel opvullen dus) public static void addAccommodatieBijVoertuig(voertuig_accomodatie va) { dc.voertuig_accomodaties.InsertOnSubmit(va); dc.SubmitChanges(); }