private void cbbChauffeur_SelectedIndexChanged(object sender, EventArgs e) { flpOpdrachten.Controls.Clear(); dataGridView1.AutoGenerateColumns = false; int countOpdracht = 0; chauffeur chauffeur = (chauffeur)cbbChauffeur.SelectedItem; dataGridView1.DataSource = ChauffeurManagement.getOngeredenOpdrachtanVanChauffeur(chauffeur); foreach (opdracht opdracht in ChauffeurManagement.getOngeredenOpdrachtanVanChauffeur(chauffeur)) { dataGridView1.Rows[countOpdracht].Cells["ID"].Value = opdracht.opdracht_id.ToString(); dataGridView1.Rows[countOpdracht].Cells["Voertuig"].Value = ""; dataGridView1.Rows[countOpdracht].Cells["Klant"].Value = opdracht.klant.naam; locatie vertrek = OpdrachtManagement.getVertrek(opdracht.opdracht_id); if (vertrek != null) { dataGridView1.Rows[countOpdracht].Cells["Datum"].Value = opdracht.vanaf_datum.ToString("dd-MM-yyyy"); } dataGridView1.Rows[countOpdracht].Cells["Uur"].Value = opdracht.vanaf_uur; dataGridView1.Rows[countOpdracht].Cells["Omschrijving"].Value = opdracht.ritomschrijving; dataGridView1.Rows[countOpdracht].Cells["Plaats"].Value = (OpdrachtManagement.getVertrek(opdracht.opdracht_id) == null) ? "" : OpdrachtManagement.getVertrek(opdracht.opdracht_id).FullAdress; countOpdracht++; } }
private void refreshCBBAdressen() { locatie templocatie = (locatie)cbbVertrek.SelectedItem; cbbVertrek.DataSource = LocatieManagement.getLocaties(); cbbVertrek.DisplayMember = "FullAdress"; cbbVertrek.ValueMember = "locatie_id"; cbbVertrek.SelectedItem = templocatie; templocatie = (locatie)cbbBestemming.SelectedItem; cbbBestemming.DataSource = LocatieManagement.getLocaties(); cbbBestemming.DisplayMember = "FullAdress"; cbbBestemming.ValueMember = "locatie_id"; cbbBestemming.SelectedItem = templocatie; templocatie = (locatie)cbbOpstap_1.SelectedItem; cbbOpstap_1.DataSource = LocatieManagement.getLocaties(); cbbOpstap_1.DisplayMember = "FullAdress"; cbbOpstap_1.ValueMember = "locatie_id"; cbbOpstap_1.SelectedItem = templocatie; templocatie = (locatie)cbbOpstap_2.SelectedItem; cbbOpstap_2.DataSource = LocatieManagement.getLocaties(); cbbOpstap_2.DisplayMember = "FullAdress"; cbbOpstap_2.ValueMember = "locatie_id"; cbbOpstap_2.SelectedItem = templocatie; }
private void btnOphalen_Click(object sender, EventArgs e) { dataGridView1.AutoGenerateColumns = false; int countOpdracht = 0; klant klant = (klant)cbbKlant.SelectedItem; dataGridView1.DataSource = KlantManagement.getOpdrachtenVanKlant(klant); foreach (opdracht opdracht in KlantManagement.getOpdrachtenVanKlant(klant)) { dataGridView1.Rows[countOpdracht].Cells["ID"].Value = opdracht.opdracht_id.ToString(); dataGridView1.Rows[countOpdracht].Cells["Omschrijving"].Value = opdracht.ritomschrijving; dataGridView1.Rows[countOpdracht].Cells["PL"].Value = opdracht.aantal_personen.ToString(); locatie vertrek = OpdrachtManagement.getVertrek(opdracht.opdracht_id); if (vertrek != null) { dataGridView1.Rows[countOpdracht].Cells["Vertrekplaats"].Value = vertrek.FullAdress; } dataGridView1.Rows[countOpdracht].Cells["Vertrekdatum"].Value = opdracht.vanaf_datum.ToString("dd-MM-yyyy"); dataGridView1.Rows[countOpdracht].Cells["VanUur"].Value = opdracht.vanaf_uur; dataGridView1.Rows[countOpdracht].Cells["TotUur"].Value = opdracht.tot_uur; dataGridView1.Rows[countOpdracht].Cells["Prijs"].Value = opdracht.offerte_totaal.ToString(); countOpdracht++; } }
private void btnOphalen_Click(object sender, EventArgs e) { flpOpdrachten.Controls.Clear(); dataGridView1.AutoGenerateColumns = false; int countOpdracht = 0; chauffeur chauffeur = (chauffeur)cbbChauffeur.SelectedItem; dataGridView1.DataSource = ChauffeurManagement.getOngeredenOpdrachtanVanChauffeur(chauffeur); //dataGridView1.DataSource = ChauffeurManagement.getOngeredenOpdrachtanVanChauffeurPrint(chauffeur); foreach (opdracht opdracht in ChauffeurManagement.getOngeredenOpdrachtanVanChauffeur(chauffeur)) { dataGridView1.Rows[countOpdracht].Cells["ID"].Value = opdracht.opdracht_id.ToString(); dataGridView1.Rows[countOpdracht].Cells["Voertuig"].Value = ""; dataGridView1.Rows[countOpdracht].Cells["Klant"].Value = opdracht.klant.naam; locatie vertrek = OpdrachtManagement.getVertrek(opdracht.opdracht_id); if (vertrek != null) { dataGridView1.Rows[countOpdracht].Cells["Datum"].Value = opdracht.vanaf_datum.ToString("dd-MM-yyyy"); } dataGridView1.Rows[countOpdracht].Cells["Uur"].Value = opdracht.vanaf_uur; dataGridView1.Rows[countOpdracht].Cells["Omschrijving"].Value = opdracht.ritomschrijving; dataGridView1.Rows[countOpdracht].Cells["Plaats"].Value = (OpdrachtManagement.getVertrek(opdracht.opdracht_id) == null) ? "" : OpdrachtManagement.getVertrek(opdracht.opdracht_id).FullAdress; countOpdracht++; } //dataGridView1.Columns.Clear(); //dataGridView1.AutoGenerateColumns = false; //dataGridView1.DataSource = ChauffeurManagement.getOngeredenOpdrachtanVanChauffeur(chauffeur); ////Kolommen opvullen ////ID kolom //DataGridViewTextBoxColumn id = new DataGridViewTextBoxColumn(); //id.Name = "ID"; //id.DataPropertyName = "opdracht_id"; ////voertuig kolom //DataGridViewTextBoxColumn opstap = new DataGridViewTextBoxColumn(); //opstap.Name = "Opstap"; //opstap.DataPropertyName = "opstap"; ////Vertrek datum kolom //DataGridViewTextBoxColumn klant = new DataGridViewTextBoxColumn(); //klant.Name = "Klant"; //klant.DataPropertyName = "klantnaam"; //this.dataGridView1.Columns.Add(id); //this.dataGridView1.Columns.Add(opstap); //this.dataGridView1.Columns.Add(klant); }
private void ucOpdrachtMini_Load(object sender, EventArgs e) { txtID.Text = miniopdracht.opdracht_id.ToString(); txtPlaatsen.Text = miniopdracht.aantal_personen.ToString(); txtOmschrijving.Text = miniopdracht.ritomschrijving; locatie vertrek = OpdrachtManagement.getVertrek(miniopdracht.opdracht_id); if (vertrek != null) { txtVertrekPlaats.Text = vertrek.FullAdress; } dtVan.Value = (DateTime)miniopdracht.vanaf_datum; txtVanUur.Text = miniopdracht.vanaf_uur; txtTotUur.Text = miniopdracht.tot_uur; txtPrijs.Text = miniopdracht.offerte_totaal.ToString(); }
private void cbbID_SelectedIndexChanged(object sender, EventArgs e) { txtStraat.Text = string.Empty; txtPlaats.Text = string.Empty; txtNr.Text = string.Empty; txtPostcode.Text = string.Empty; cbbLand.SelectedIndex = -1; txtOmschrijving.Text = string.Empty; locatie locatie = (locatie)cbbID.SelectedItem; txtStraat.Text = locatie.straat; txtNr.Text = locatie.nr.ToString(); txtPlaats.Text = locatie.plaats; txtPostcode.Text = locatie.postcode.ToString(); txtOmschrijving.Text = locatie.omschrijving; cbbLand.SelectedItem = locatie.land; btnSave.Enabled = true; }
private void BTNInsert_Click(object sender, EventArgs e) { if (Validation.hasValidationErrors(this.Controls)) { return; } if (selectedAddressID == 0) { string postcode; if (txtPostcode.Equals("____")) { postcode = string.Empty; } else { postcode = txtPostcode.Text; } LocatieManagement.addLocatie(txtStraat.Text, txtNr.Text, postcode, txtPlaats.Text, cbbLand.SelectedText, txtOmschrijving.Text); MainForm.updateStatus = "De locatie is succesvol aangemaakt."; } else { locatie nieuwAdres = LocatieManagement.getLocatie(selectedAddressID); LocatieManagement.updateLocatie(nieuwAdres.locatie_id, txtStraat.Text, txtNr.Text, txtPostcode.Text, txtPlaats.Text, cbbLand.Text, txtOmschrijving.Text); MainForm.updateStatus = "De locatie is succesvol aangepast."; } selectedAddressID = 0; RefreshGridview(); emptyFields(); }
private void btnPrint_Click(object sender, EventArgs e) { String opdrachtenInhoud = ""; decimal totalAmount = 0; foreach (DataGridViewRow row in facturenGridView.Rows) { if ((Boolean)row.Cells[0].Value != false) { int opdrachtID = 0; if (!int.TryParse(row.Cells[1].Value.ToString(), out opdrachtID)) { continue; } opdracht op = OpdrachtManagement.getOpdracht(opdrachtID); opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(op); foreach (opdracht_factuur_detail ofd in FactuurManagement.getFactuurDetails(of)) { opdrachtenInhoud += of.opdracht_id + "\t"; opdrachtenInhoud += ofd.omschrijving + "\t"; opdrachtenInhoud += ofd.bedrag_basis + "\t"; opdrachtenInhoud += ofd.btw_percent + "\t"; opdrachtenInhoud += ofd.btw_bedrag + "\t"; opdrachtenInhoud += ofd.bedrag_inclusief + "\t"; opdrachtenInhoud += System.Environment.NewLine; totalAmount += ofd.bedrag_inclusief.Value; FactuurNummering nummer = new FactuurNummering(); nummer.bedrijf = opdracht.FactuurNummering.bedrijf; nummer.FactuurNr = opdracht.FactuurNummering.FactuurNr; nummer.FactuurJaar = opdracht.FactuurNummering.FactuurJaar; op.FactuurNummering = nummer; Backend.DataContext.dc.SubmitChanges(); } //opdrachtenInhoud += row.Cells[1].Value + "\t" + row.Cells[2].Value + "\t" + row.Cells[4].Value + "\t" + row.Cells[5].Value + "\t€" + row.Cells[6].Value + System.Environment.NewLine; //totalAmount += Convert.ToDouble(row.Cells[6].Value.ToString()); } } if (totalAmount > 0) { locatie adres = KlantManagement.getAdresVanKlant(opdracht.klant.klant_id); //Convert date to acceptable format for use in file name String datum = DateTime.Today.ToString("yyyy-MM-dd"); //missing oject to use with various word commands object missing = System.Reflection.Missing.Value; //the template file you will be using object fileToOpen = (object)@"R:\CarGo\opdracht_template.docx"; //Where the new file will be saved to. object fileToSave = (object)@"R:\CarGo\opdrachten\opdracht_" + opdracht.klant.naam + "_" + datum + ".docx"; //Create new instance of word and create a new document Word.Application wordApp = new Word.Application(); Word.Document doc = null; //Properties for the new word document object readOnly = false; object isVisible = false; //Settings the application to invisible, so the user doesn't notice that anything is going on wordApp.Visible = false; try { try { File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true); } catch { MessageBox.Show("Loading the template file failed.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } readOnly = false; doc = wordApp.Documents.Open(ref fileToSave, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); } catch { } PrintManagement.findAndReplace(doc, "factuurdatum", datum); PrintManagement.findAndReplace(doc, "factuurnummer", opdracht.FactuurNummering.FactuurNr + " " + opdracht.FactuurNummering.FactuurJaar); PrintManagement.findAndReplace(doc, "startOfDocument", opdrachtenInhoud); PrintManagement.findAndReplace(doc, "totaal", "Totaal: €" + totalAmount); Console.WriteLine(opdrachtenInhoud); doc.Save(); doc.Activate(); //Making word visible to be able to show the print preview. wordApp.Visible = true; wordApp.Activate(); //doc.PrintPreview(); } else { MessageBox.Show("Onvoldoende gegevens om factuur op te stellen. Kijk Detail Facturatie na", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }
private void btnOpslaan_Click(object sender, EventArgs e) { //Validatie if (Validation.hasValidationErrors(this.Controls)) { return; } //als validatie geslaagd is //if (btnOpslaan.Name == "btnAanmaken") if (cbbID.Visible == false) { opdracht nieuwContract = ContractManagement.addContract((klant)cbbKlant.SelectedItem, dtVan.Value, dtTot.Value, Byte.Parse(txtPlaatsen.Text), txtOmschrijving.Text, txtGezelschap.Text, txtMemo.Text, Decimal.Parse(txtDagprijs.Text), true); //Vertreklocatie toevoegen aan opdracht locatie vertrek = (locatie)cbbVertrek.SelectedItem; ContractManagement.addLocatie(nieuwContract, vertrek, "vertrek"); //Bestemming locatie toevoegen aan opdracht locatie bestemming = (locatie)cbbBestemming.SelectedItem; ContractManagement.addLocatie(nieuwContract, bestemming, "bestemming"); //opstap_1 locatie toevoegen aan opdracht locatie opstap_1 = (locatie)cbbOpstap_1.SelectedItem; ContractManagement.addLocatie(nieuwContract, opstap_1, "opstap_1"); //opstap_2 locatie toevoegen aan opdracht locatie opstap_2 = (locatie)cbbOpstap_2.SelectedItem; ContractManagement.addLocatie(nieuwContract, opstap_2, "opstap_2"); foreach (ucRit ucRit in flpRitten.Controls) { contract_rit rit = new contract_rit(); rit.dag = ucRit.dag; rit.rit1_terug = ucRit.terug_1; rit.rit2_terug = ucRit.terug_2; rit.rit1_vertrek = ucRit.vertrek_1; rit.rit2_vertrek = ucRit.vertrek_2; opdracht_contract_rit ocr = new opdracht_contract_rit(); ocr.contract_rit = rit; ocr.opdracht = nieuwContract; ContractManagement.addRitBijContract(ocr); } //Voor elke usercontrol ucChauffeurkiezer in flpChauffeurs een nieuwe chauffeur link toevoegen aan de veel op veel tussentabel foreach (ucChauffeurKiezer cha in flpChauffeurs.Controls) { opdracht_chauffeur oc = new opdracht_chauffeur(); oc.opdracht = nieuwContract; oc.chauffeur = cha.chauffeur; ContractManagement.addChauffeurBijContract(oc); } //Voor elke usercontrol ucVoertuigKiezer in flpVoertuigen een nieuwe voertuig link toevoegen aan de veel op veel tussentabel foreach (ucVoertuigKiezer voe in flpVoertuigen.Controls) { opdracht_voertuig ov = new opdracht_voertuig(); ov.opdracht = nieuwContract; ov.voertuig = voe.voertuig; ContractManagement.addVoertuigBijOpdracht(ov); } cbbID.DataSource = ContractManagement.getContracten(); //cbbID.SelectedIndex = cbbID.Items.Count - 1; cbbID.SelectedItem = nieuwContract; cbbID.Visible = true; MainForm.updateStatus = "Het contract met ID: " + nieuwContract.opdracht_id + ", is succesvol aangemaakt."; } //else if (btnOpslaan.Name == "btnOpslaan") else if (cbbID.Visible == true) { opdracht oudContract = (opdracht)cbbID.SelectedItem; opdracht updateContract = ContractManagement.updateContract(oudContract.opdracht_id, (klant)cbbKlant.SelectedItem, dtVan.Value, dtTot.Value, Byte.Parse(txtPlaatsen.Text), txtOmschrijving.Text, txtGezelschap.Text, txtMemo.Text, Decimal.Parse(txtDagprijs.Text), true); //Vertreklocatie toevoegen aan opdracht locatie vertrek = (locatie)cbbVertrek.SelectedItem; ContractManagement.addLocatie(updateContract, vertrek, "vertrek"); //Bestemming locatie toevoegen aan opdracht locatie bestemming = (locatie)cbbBestemming.SelectedItem; ContractManagement.addLocatie(updateContract, bestemming, "bestemming"); //opstap_1 locatie toevoegen aan opdracht locatie opstap_1 = (locatie)cbbOpstap_1.SelectedItem; ContractManagement.addLocatie(updateContract, opstap_1, "opstap_1"); //opstap_2 locatie toevoegen aan opdracht locatie opstap_2 = (locatie)cbbOpstap_2.SelectedItem; ContractManagement.addLocatie(updateContract, opstap_2, "opstap_2"); foreach (contract_rit rit in ContractManagement.getRitten(updateContract.opdracht_id)) { Boolean bestaat = false; foreach (ucRit ucRit in flpRitten.Controls) { contract_rit schermrit = new contract_rit(); schermrit.dag = ucRit.dag; schermrit.rit1_terug = ucRit.terug_1; schermrit.rit2_terug = ucRit.terug_2; schermrit.rit1_vertrek = ucRit.vertrek_1; schermrit.rit2_vertrek = ucRit.vertrek_2; if (rit.dag == schermrit.dag && rit.rit1_terug == schermrit.rit1_terug && rit.rit1_vertrek == schermrit.rit1_vertrek && rit.rit2_terug == schermrit.rit2_terug && rit.rit2_vertrek == schermrit.rit2_vertrek) { bestaat = true; break; } } if (bestaat == false) { ContractManagement.deleteRit(updateContract, rit); } } foreach (ucRit ucRit in flpRitten.Controls) { contract_rit rit = new contract_rit(); rit.dag = ucRit.dag; rit.rit1_terug = ucRit.terug_1; rit.rit2_terug = ucRit.terug_2; rit.rit1_vertrek = ucRit.vertrek_1; rit.rit2_vertrek = ucRit.vertrek_2; if (ContractManagement.bestaatRit(updateContract, rit) == false) { opdracht_contract_rit ocr = new opdracht_contract_rit(); ocr.contract_rit = rit; ocr.opdracht = updateContract; ContractManagement.addRitBijContract(ocr); } else { } } //Voor elke usercontrol ucChauffeurkiezer in flpChauffeurs een nieuwe chauffeur link toevoegen aan de veel op veel tussentabel foreach (ucChauffeurKiezer cha in flpChauffeurs.Controls) { opdracht_chauffeur oc = new opdracht_chauffeur(); oc.opdracht = updateContract; oc.chauffeur = cha.chauffeur; ContractManagement.addChauffeurBijContract(oc); } //Voor elke usercontrol ucVoertuigKiezer in flpVoertuigen een nieuwe voertuig link toevoegen aan de veel op veel tussentabel foreach (ucVoertuigKiezer voe in flpVoertuigen.Controls) { opdracht_voertuig ov = new opdracht_voertuig(); ov.opdracht = updateContract; ov.voertuig = voe.voertuig; ContractManagement.addVoertuigBijOpdracht(ov); } MainForm.updateStatus = "Het contract met ID: " + updateContract.opdracht_id + ", is succesvol aangepast."; } }
private void btnPrint_Click(object sender, EventArgs e) { //opdracht ophalen opdracht opdracht = (opdracht)cbbID.SelectedItem; if (opdracht == null) { MainForm.updateStatus = "Er is geen factuur geselecteerd, selecteer een opdracht en probeer dan opnieuw."; } else { //adres ophalen van klant locatie adres = KlantManagement.getAdresVanKlant(opdracht.klant.klant_id); //Convert date to acceptable format for use in file name DateTime begindatum = (DateTime)dtPeriodeBegin2.Value; String datum1 = begindatum.ToString("yyyy-MM-dd"); DateTime einddatum = (DateTime)dtPeriodeEinde2.Value; String datum2 = einddatum.ToString("yyyy-MM-dd"); //missing oject to use with various word commands object missing = System.Reflection.Missing.Value; //the template file you will be using object fileToOpen = (object)@"R:\CarGo\factuur_contract_template.docx"; //Where the new file will be saved to. object fileToSave = (object)@"R:\CarGo\contractfacturen\factuur_" + opdracht.klant.naam + "_" + datum1 + "-" + datum2 + ".docx"; //Create new instance of word and create a new document Word.Application wordApp = new Word.Application(); Word.Document doc = null; //Properties for the new word document object readOnly = false; object isVisible = false; //Settings the application to invisible, so the user doesn't notice that anything is going on wordApp.Visible = false; try { File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true); } catch { MainForm.updateStatus = "Kan nieuw document niet opslaan"; return; } doc = wordApp.Documents.Open(ref fileToSave, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); //Search for bookmarks and replace them with the text you want PrintManagement.findAndReplace(doc, "naam_bedrijf", opdracht.klant.naam); PrintManagement.findAndReplace(doc, "straat_bedrijf", adres.straat); PrintManagement.findAndReplace(doc, "huisnummer_bedrijf", adres.nr); PrintManagement.findAndReplace(doc, "postcode_bedrijf", adres.postcode); PrintManagement.findAndReplace(doc, "gemeente_bedrijf", adres.plaats); PrintManagement.findAndReplace(doc, "id", opdracht.factuur_id_full); PrintManagement.findAndReplace(doc, "telefoon_klant", opdracht.klant.telefoon); PrintManagement.findAndReplace(doc, "fax_klant", opdracht.klant.fax); PrintManagement.findAndReplace(doc, "contractnummer", opdracht.contract_id_full); PrintManagement.findAndReplace(doc, "periode_begin1", datum1); PrintManagement.findAndReplace(doc, "periode_tot1", datum2); PrintManagement.findAndReplace(doc, "omschrijving", opdracht.ritomschrijving); PrintManagement.findAndReplace(doc, "vertrek", cbbVertrek.Text.ToString()); PrintManagement.findAndReplace(doc, "bestemming", cbbBestemming.Text.ToString()); PrintManagement.findAndReplace(doc, "aantal_plaatsen", opdracht.aantal_personen); PrintManagement.findAndReplace(doc, "opstap1", ContractManagement.getLocatie(opdracht.opdracht_id, "opstap_1").FullAdress); PrintManagement.findAndReplace(doc, "opstap2", ContractManagement.getLocatie(opdracht.opdracht_id, "opstap_1").FullAdress); PrintManagement.findAndReplace(doc, "dagprijs", opdracht.contract_dagprijs.ToString()); PrintManagement.findAndReplace(doc, "saldo", txtPrijs.Text); ////Tabel invullen, lukte mij niet //Word.Tables tables = doc.Tables; //if (tables.Count > 0) //{ // //Eerste tabel eruit halen // Word.Table table = tables[2]; // int rowsCount = table.Rows.Count; // int coulmnsCount = table.Columns.Count; // foreach (contract_rit rit in ContractManagement.getRitten(opdracht.opdracht_id)) // { // Word.Row row = table.Rows.Add(ref missing); // for (int j = 1; j <= coulmnsCount; j++) // { // row.Cells[j].Range.Text = string.Format("{0} : {1}", ofd.omschrijving, ofd.bedrag_inclusief.ToString()); // row.Cells[j].WordWrap = true; // row.Cells[j].Range.Underline = Word.WdUnderline.wdUnderlineNone; // row.Cells[j].Range.Bold = 0; // } // } //} //rest aan te vullen... doc.Save(); doc.Activate(); //Making word visible to be able to show the print preview. wordApp.Visible = true; //Close the document and the application (otherwise the process will keep running) /*doc.Close(ref missing, ref missing, ref missing); * wordApp.Quit(ref missing, ref missing, ref missing);*/ } }
public static void addLocatie(locatie nieuweLocatie) { dc.locaties.InsertOnSubmit(nieuweLocatie); dc.SubmitChanges(); }
//Factuur updaten private void btnOpslaan_Click(object sender, EventArgs e) { //Validatie check if (Validation.hasValidationErrors(this.Controls)) { return; } //Huidige opdracht (factuur) selecteren in combbox (voor id uit te halen) opdracht oudeOpdracht = (opdracht)cbbID.SelectedItem; //dtVan.Value, dtTot.Value //De oude opdracht (factuur) updaten en de geupdate opdracht (factuur) terugsturen int voorschot; if (!int.TryParse(txtVoorschot.Text, out voorschot)) { voorschot = 0; } opdracht nieuweOpdracht = FactuurManagement.updateFactuur(oudeOpdracht.opdracht_id, (klant)cbbKlant.SelectedItem, dtVan.Value.ToShortDateString(), dtTot.Value.ToShortDateString(), txtVan_uur.Text, txtTot_uur.Text, decimal.Parse(txtSaldo.Text), voorschot, cbBetaald.Checked, txtBetalingMemo.Text, dtBetaald.Value, cbBetaaldvoorschot.Checked, txtBetalingMemovoorschot.Text, dtBetaaldvoorschot.Value); //Vertreklocatie toevoegen aan opdracht (factuur) locatie vertrek = (locatie)cbbVertrek.SelectedItem; OfferteManagement.addLocatieBijOfferte(vertrek, nieuweOpdracht, "vertrek"); //Bestemming locatie toevoegen aan opdracht (factuur) locatie bestemming = (locatie)cbbBestemming.SelectedItem; OfferteManagement.addLocatieBijOfferte(bestemming, nieuweOpdracht, "bestemming"); //Factuur info opslaan #region gegevensophaal decimal?bedrag_basis; if (txtBedrag_basis.Text == string.Empty) { bedrag_basis = null; } else { bedrag_basis = decimal.Parse(txtBedrag_basis.Text); } decimal?btw_bedrag; if (txtBtw_bedrag.Text == string.Empty) { btw_bedrag = null; } else { btw_bedrag = decimal.Parse(txtBtw_bedrag.Text); } decimal?bedrag_inclusief; if (txtBedrag_inclusief.Text == string.Empty) { bedrag_inclusief = null; } else { bedrag_inclusief = decimal.Parse(txtBedrag_inclusief.Text); } decimal?credit_voorschot; if (txtCreditvoorschot.Text == string.Empty) { credit_voorschot = null; } else { credit_voorschot = decimal.Parse(txtCreditvoorschot.Text); } decimal?totaal_reis; if (txtTotaal_reis.Text == string.Empty) { totaal_reis = null; } else { totaal_reis = decimal.Parse(txtTotaal_reis.Text); } decimal?btw_percent; if (cbbBTW.Text == string.Empty) { btw_percent = null; } else { btw_percent = decimal.Parse(cbbBTW.Text); } #endregion opdracht_factuur updatedFactuur = new opdracht_factuur(); if (FactuurManagement.hasFactuur(nieuweOpdracht) == true) { //updaten updatedFactuur = FactuurManagement.updateFactuurVanOpdracht(nieuweOpdracht, totaal_reis, credit_voorschot, bedrag_basis, btw_bedrag, btw_percent, bedrag_inclusief, txtOmschrijving.Text); } else { //aanmaken opdracht_factuur of = new opdracht_factuur(); of.totaal_reis = totaal_reis; of.voorschot = credit_voorschot; of.credit_basis = bedrag_basis; of.credit_btwbedrag = btw_bedrag; of.credit_btwpercent = btw_percent; of.credit_inc = bedrag_inclusief; of.credit_omschrijving = txtOmschrijving.Text; of.opdracht = nieuweOpdracht; updatedFactuur = FactuurManagement.addFactuurVanOpdracht(of); } //Factuur detail FactuurManagement.deleteDetailsVanFactuur(updatedFactuur); foreach (ucDetailFactuur uc in flpDetail.Controls) { opdracht_factuur_detail ofd = new opdracht_factuur_detail(); ofd.bedrag_basis = uc.bedrag_basis; ofd.omschrijving = uc.omschrijving; ofd.btw_percent = uc.btw_percent; ofd.btw_bedrag = uc.btw_bedrag; ofd.bedrag_inclusief = uc.bedrag_inclusief; ofd.opdracht_factuur_id = updatedFactuur.opdracht_factuur_id; FactuurManagement.updateDetailsVanFactuur(ofd); } cbbID_SelectedIndexChanged(); //frmMain statusbalk updaten MainForm.updateStatus = "De factuur met ID: " + oudeOpdracht.opdracht_id + ", is succesvol opgeslaan."; }
private void btnPrintCredit_Click(object sender, EventArgs e) { String opdrachtenInhoud = ""; decimal totalAmount = 0; if (cbbID.SelectedItem == null) { return; } opdracht op = (opdracht)cbbID.SelectedItem; if (op.FactuurNummering1 == null) { return; } if (op.FactuurNummering1.FactuurJaar == null || op.FactuurNummering1.FactuurNr == null) { return; } opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(op); opdrachtenInhoud += of.opdracht_id + "\t"; opdrachtenInhoud += of.credit_omschrijving + "\t"; opdrachtenInhoud += of.credit_basis + "\t"; opdrachtenInhoud += of.credit_btwpercent + "\t"; opdrachtenInhoud += of.credit_btwbedrag + "\t"; opdrachtenInhoud += of.credit_inc + "\t"; opdrachtenInhoud += System.Environment.NewLine; totalAmount += of.credit_inc.Value; //opdrachtenInhoud += row.Cells[1].Value + "\t" + row.Cells[2].Value + "\t" + row.Cells[4].Value + "\t" + row.Cells[5].Value + "\t€" + row.Cells[6].Value + System.Environment.NewLine; //totalAmount += Convert.ToDouble(row.Cells[6].Value.ToString()); if (totalAmount > 0) { locatie adres = KlantManagement.getAdresVanKlant(opdracht.klant.klant_id); //Convert date to acceptable format for use in file name String datum = DateTime.Today.ToString("yyyy-MM-dd"); //missing oject to use with various word commands object missing = System.Reflection.Missing.Value; //the template file you will be using //object fileToOpen = (object)@"R:\CarGo\CreditNota_template.docx"; object fileToOpen = (object)@"R:\CarGo\opdracht_template.docx"; //Where the new file will be saved to. object fileToSave = (object)@"R:\CarGo\opdrachten\Credit_" + opdracht.klant.naam + "_" + datum + ".docx"; //Create new instance of word and create a new document Word.Application wordApp = new Word.Application(); Word.Document doc = null; //Properties for the new word document object readOnly = false; object isVisible = false; //Settings the application to invisible, so the user doesn't notice that anything is going on wordApp.Visible = false; try { try { File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true); } catch { MessageBox.Show("Loading the template file failed.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } readOnly = false; doc = wordApp.Documents.Open(ref fileToSave, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); } catch { } PrintManagement.findAndReplace(doc, "factuurdatum", datum); PrintManagement.findAndReplace(doc, "factuurnummer", opdracht.FactuurNummering1.FactuurNr + " " + opdracht.FactuurNummering1.FactuurJaar); PrintManagement.findAndReplace(doc, "startOfDocument", opdrachtenInhoud); PrintManagement.findAndReplace(doc, "totaal", "Totaal: €" + totalAmount); Console.WriteLine(opdrachtenInhoud); doc.Save(); doc.Activate(); //Making word visible to be able to show the print preview. wordApp.Visible = true; wordApp.Activate(); //doc.PrintPreview(); } else { MessageBox.Show("Credit bedrag moet groter dan 0 zijn.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }
//Methode voor het opslaan / aanmaken van een klant private void btnOpslaan_Click(object sender, EventArgs e) { //Validatie if (Validation.hasValidationErrors(this.Controls)) { return; } //als validatie geslaagd is /*Voor de knop opslaan heb je 2 mogelijkheden, of je gaat een bestaande chauffeur updaten * (btnOpslaan) en of je gaat een nieuwe aanmaken (btnAanmaken), passende methoden oproepen * bij de verschillende namen */ if (btnOpslaan.Name == "btnOpslaan") { //nieuwe klant aanmaken klant updateKlant = new klant(); //Oude klant opahlen klant oudeKlant = (klant)cbbID.SelectedItem; //deze "nieuwe" klant opvullen met gegevens op basis van de te updaten klant updateKlant.klant_id = oudeKlant.klant_id; updateKlant.naam = txtNaam.Text; //titel mag leeg zijn updateKlant.titel = cbbTitel.Text; updateKlant.activiteit = cbbActiviteit.Text; updateKlant.verantwoordelijke = txtVerantwoordelijke.Text; updateKlant.telefoon = txtTelefoon.Text; updateKlant.gsm = txtGsm.Text; updateKlant.fax = txtFax.Text; updateKlant.email = txtEmail.Text; updateKlant.btw_nummer = txtBTW.Text; int korting; if (txtKorting.Text == "") { korting = 0; } else { korting = Convert.ToInt32(txtKorting.Text); } updateKlant.korting = korting; updateKlant.vervaldagen_offerte = txtVervaldagenOfferte.Text; updateKlant.vervaldagen_factuur = txtVervalDagenFactuur.Text; updateKlant.aantal_facturen = txtAantalFacturen.Text; updateKlant.memo = txtMemo.Text; //Adres updaten //Eerst oude relatie verwijderen en dan nieuwe maken, gedaan in methode updateAdresVanKlant(); locatie Adres = (locatie)cbbAdres.SelectedItem; KlantManagement.updateAdresVanKlant(oudeKlant.klant_id, Adres.locatie_id, "Adres"); KlantManagement.updateKlant(updateKlant); //Eerste alle opstapplaatsen verwijderen OpstapplaatsManagement.deleteOpstapplaatsen(updateKlant.klant_id); //Opstapplaatsen updaten foreach (ComboBox cbbOpstap in flpOpstapplaats.Controls) { //Dan nieuwe toevoegen locatie opstapLocatie = (locatie)cbbOpstap.SelectedItem; locatie_klant opstapLocatie_nieuw = new locatie_klant(); opstapLocatie_nieuw.klant_id = updateKlant.klant_id; opstapLocatie_nieuw.locatie = opstapLocatie; opstapLocatie_nieuw.type = "Opstapplaats"; OpstapplaatsManagement.addOpstapplaats(opstapLocatie_nieuw); } MainForm.updateStatus = "Klant: " + updateKlant.naam + ", is succesvol geupdate."; } else if (btnOpslaan.Name == "btnAanmaken") { if (KlantManagement.bestaatKlant(txtNaam.Text, (locatie)cbbAdres.SelectedItem) == true) { MainForm.updateStatus = "De klant: " + txtNaam.Text + " bestaat reeds."; } else { //Nieuw klant object aanmaken klant nieuweKlant = new klant(); //Algemene gegevens invullen in het nieuweKlant object nieuweKlant.naam = txtNaam.Text; //titel mag leeg zijn nieuweKlant.titel = cbbTitel.Text; //Activiteit mag leg zijn nieuweKlant.activiteit = cbbActiviteit.Text; nieuweKlant.verantwoordelijke = txtVerantwoordelijke.Text; nieuweKlant.telefoon = txtTelefoon.Text; nieuweKlant.gsm = txtGsm.Text; nieuweKlant.fax = txtFax.Text; nieuweKlant.email = txtEmail.Text; nieuweKlant.btw_nummer = txtBTW.Text; int korting; if (txtKorting.Text == "") { korting = 0; } else { korting = Convert.ToInt32(txtKorting.Text); } nieuweKlant.korting = korting; nieuweKlant.vervaldagen_offerte = txtVervaldagenOfferte.Text; nieuweKlant.vervaldagen_factuur = txtVervalDagenFactuur.Text; nieuweKlant.aantal_facturen = txtAantalFacturen.Text; nieuweKlant.memo = txtMemo.Text; //klant toevoegen aan de database KlantManagement.addKlant(nieuweKlant); //Adres toevoegen aan de klant locatie adresVanKlant = (locatie)cbbAdres.SelectedItem; locatie_klant adresLink = new locatie_klant(); adresLink.klant = nieuweKlant; adresLink.locatie = adresVanKlant; adresLink.type = "Adres"; KlantManagement.addAdresBijKlant(adresLink); //Opstapplaatsen toevoegen aan de klant foreach (ComboBox cbbOpstap in flpOpstapplaats.Controls) { locatie opstapLocatie = (locatie)cbbOpstap.SelectedItem; locatie_klant opstapLocatieLink = new locatie_klant(); opstapLocatieLink.klant = nieuweKlant; opstapLocatieLink.locatie = opstapLocatie; opstapLocatieLink.type = "Opstapplaats"; OpstapplaatsManagement.addOpstapplaats(opstapLocatieLink); } MainForm.updateStatus = "Klant: " + nieuweKlant.naam + ", is succesvol aangemaakt."; } } //combobox opnieuw vullen cbbID.Items.Clear(); cbbID.Items.AddRange(KlantManagement.getKlanten().ToArray()); cbbID.DisplayMember = "naam"; cbbID.ValueMember = "klant_id"; //knoppen goedzetten cbbID.Visible = true; btnNieuw.Enabled = true; btnVerwijder.Enabled = true; emptyFields(); disablefields(); }
private void btnSave_Click(object sender, EventArgs e) { //Validatie if (Validation.hasValidationErrors(this.Controls)) { return; } //na Validatie if (btnSave.Text == "Aanmaken") { string postcode; if (txtPostcode.Equals("____")) { postcode = string.Empty; } else { postcode = txtPostcode.Text; } locatie locatie = LocatieManagement.addLocatie(txtStraat.Text, txtNr.Text, postcode, txtPlaats.Text, cbbLand.SelectedText, txtOmschrijving.Text); cbbID.DataSource = LocatieManagement.getLocaties(); cbbID.DisplayMember = "adres_id"; cbbID.ValueMember = "locatie_id"; cbbID.SelectedItem = locatie; btnSave.Text = "Opslaan"; btnDelete.Text = "Verwijderen"; btnNew.Enabled = true; cbbID.Visible = true; btnFirst.Enabled = true; btnPrevious.Enabled = true; btnNext.Enabled = true; btnLast.Enabled = true; lblStatus.Text = "De locatie is succesvol aangemaakt."; } else if (btnSave.Text == "Opslaan") { string selectedland; if (cbbLand.SelectedItem == null) { selectedland = ""; } else { selectedland = cbbLand.SelectedItem.ToString(); } LocatieManagement.updateLocatie(Int32.Parse(cbbID.SelectedValue.ToString()), txtStraat.Text, txtNr.Text, txtPostcode.Text, txtPlaats.Text, selectedland, txtOmschrijving.Text); object currentSelection = cbbID.SelectedItem; cbbID.DataSource = LocatieManagement.getLocaties(); cbbID.DisplayMember = "adres_id"; cbbID.ValueMember = "locatie_id"; cbbID.SelectedItem = currentSelection; lblStatus.Text = "De locatie is succesvol aangepast."; } }