public BoekScherm(Overzicht_groot submain, Boek boek, bool is_edit = false) { InitializeComponent(); this.submain = submain; this.is_edit = is_edit; this.boek = boek; if (is_edit) { foreach (Control c in this.Controls) { if (c.GetType().FullName != "System.Windows.Forms.Label") { c.Visible = true; } else { if (c.Name.Substring(0, 6) == "lblGeg") { c.Visible = false; } } } boekvoorraad.boek_isbn_nummer = boek.isbn_nummer; boekvoorraad = BoekvoorraadDb.ophalen(boekvoorraad.boek_isbn_nummer); txtVoorraad.Text = Convert.ToString(boekvoorraad.aantal); txtIsbnNummer.Text = boek.isbn_nummer.ToString(); txtTitel.Text = boek.titel.ToString(); txtAuteur.Text = boek.auteur.ToString(); txtGenre.Text = boek.genre.ToString(); txtBeschrijving.Text = boek.beschrijving.ToString(); txtPrijs.Text = boek.prijs.ToString(); btnKlaar.Visible = true; btnKlaar.Text = "Wijzigen"; } else { foreach (Control c in this.Controls) { if (c.GetType().FullName == "System.Windows.Forms.Label" && c.Name != "lblError") { c.Visible = true; } } txtBeschrijving.Visible = true; lblGegIsbnNummer.Text = boek.isbn_nummer.ToString(); lblGegTitel.Text = boek.titel.ToString(); lblGegAuteur.Text = boek.auteur.ToString(); lblGegGenre.Text = boek.genre.ToString(); lblGegPrijs.Text = "€ " + boek.prijs.ToString(); lblGegVoorraad.Text = BoekvoorraadDb.ophalen(boek.isbn_nummer).aantal.ToString(); txtBeschrijving.Text = boek.beschrijving.ToString(); txtBeschrijving.ReadOnly = true; btnKlaar.Visible = false; } }
//methode om bestelling aan te maken : private void bestellen() { Cursor.Current = Cursors.WaitCursor; bestelling.besteldatum = datum; bestelling.klant_id = klant.id; string strDatum = ""; string omschrijving = ""; string aantal = ""; string prijs = ""; string totaalPrijs = ""; foreach (DataGridViewRow row in dgvBoeken.Rows) { DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dgvBoeken.Rows[row.Index].Cells[1]; if ((bool)checkbox.EditedFormattedValue) { strDatum += datum.AddDays(3).ToString("dd/MM/yyyy") + "\v"; omschrijving += row.Cells[4].Value + "\v"; aantal += row.Cells[0].Value + "\v"; totaalPrijs += row.Cells[2].Value + "\v"; prijs += "€" + row.Cells[7].Value + "\v"; } } BestellingDb.aanmaken(bestelling); bestelling.id = BestellingDb.GetLaatsteBestelling(); Factuur factuur = new Factuur(); bestelling.factuur = factuur.aanmaken(klant, BedrijfsinformatieDb.ophalen(), bestelling, strDatum, omschrijving, aantal, prijs, totaalPrijs, lblPrijs.Text); BestellingDb.wijzigen(bestelling); foreach (DataGridViewRow row in dgvBoeken.Rows) { DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dgvBoeken.Rows[row.Index].Cells[1]; if ((bool)checkbox.EditedFormattedValue) { bestellingregel.bestelling_id = bestelling.id; bestellingregel.boek_isbn_nummer = Convert.ToString(row.Cells[3].Value); bestellingregel.aantal = Convert.ToInt32(row.Cells[0].Value); BestellingregelDB.aanmaken(bestellingregel); Boekvoorraad voorraad = new Boekvoorraad(); voorraad.boek_isbn_nummer = bestellingregel.boek_isbn_nummer; if (bestellingregel.aantal > Convert.ToInt32(row.Cells[6].Value)) { voorraad.aantal = 0; } else { voorraad.aantal = Convert.ToInt32(row.Cells[6].Value) - bestellingregel.aantal; } BoekvoorraadDb.wijzigen(voorraad); } } Mail mail = new Mail(); mail.mailAanmaken(klant, bestelling, bestelling.factuur); submain.vulDgOverzicht(); submain.dgvOverzicht.Rows[0].Selected = true; submain.dgvOverzichtClick(); Logging logging = new Logging(); logging.onderwerp = "Bestelling"; logging.handeling = "Aangemaakt"; logging.datum = DateTime.Now; logging.medewerker_id = Account.getMedewerker().id; logging.bestelling_id = bestelling.id; logging.boek_isbn_nummer = ""; LoggingDb.aanmaken(logging); }