Exemple #1
0
        private void btnOphalen_Click(object sender, EventArgs e)
        {
            flpOpdrachten.Controls.Clear();
            dataGridView1.AutoGenerateColumns = false;
            int     countOpdracht = 0;
            Decimal totaal        = 0;
            klant   klant         = (klant)cbbKlant.SelectedItem;

            dataGridView1.DataSource = KlantManagement.getOnbetaaldeOpdrachtenVanKlant(klant);

            foreach (opdracht opdracht in KlantManagement.getOnbetaaldeOpdrachtenVanKlant(klant))
            {
                totaal = totaal + Convert.ToDecimal(opdracht.offerte_totaal);

                dataGridView1.Rows[countOpdracht].Cells["ID"].Value         = opdracht.opdracht_id.ToString();
                dataGridView1.Rows[countOpdracht].Cells["Datum"].Value      = opdracht.vanaf_datum.ToString("dd-MM-yyyy");
                dataGridView1.Rows[countOpdracht].Cells["PL"].Value         = opdracht.aantal_personen.ToString();
                dataGridView1.Rows[countOpdracht].Cells["Vertrek"].Value    = OpdrachtManagement.getVertrek(opdracht.opdracht_id).FullAdress;
                dataGridView1.Rows[countOpdracht].Cells["Bestemming"].Value = OpdrachtManagement.getBestemming(opdracht.opdracht_id).FullAdress;
                dataGridView1.Rows[countOpdracht].Cells["Prijs"].Value      = opdracht.offerte_totaal.ToString();

                countOpdracht++;
            }

            txtTotaal.Text = totaal.ToString();
        }
        private void cbbLeverancier_SelectedIndexChanged(object sender, EventArgs e)
        {
            flpOpdrachten.Controls.Clear();
            dataGridView1.AutoGenerateColumns = false;
            int         countOpdracht = 0;
            Decimal     totaal        = 0;
            leverancier leverancier   = (leverancier)cbbLeverancier.SelectedItem;

            dataGridView1.DataSource = LeverancierManagement.getOpdrachtenVanLeverancier(leverancier);

            foreach (opdracht opdracht in LeverancierManagement.getOpdrachtenVanLeverancier(leverancier))
            {
                totaal = totaal + Convert.ToDecimal(opdracht.offerte_totaal);

                dataGridView1.Rows[countOpdracht].Cells["ID"].Value         = opdracht.opdracht_id.ToString();
                dataGridView1.Rows[countOpdracht].Cells["Datum"].Value      = opdracht.vanaf_datum.ToString("dd-MM-yyyy");
                dataGridView1.Rows[countOpdracht].Cells["Vertrek"].Value    = OpdrachtManagement.getVertrek(opdracht.opdracht_id).FullAdress;
                dataGridView1.Rows[countOpdracht].Cells["Bestemming"].Value = OpdrachtManagement.getBestemming(opdracht.opdracht_id).FullAdress;
                dataGridView1.Rows[countOpdracht].Cells["PL"].Value         = opdracht.aantal_personen.ToString();
                dataGridView1.Rows[countOpdracht].Cells["Prijs"].Value      = opdracht.offerte_totaal.ToString();

                countOpdracht++;
            }

            txtTotaal.Text = totaal.ToString();
        }
Exemple #3
0
 private void ucFactuurMini2_Load(object sender, EventArgs e)
 {
     txtID.Text         = miniFactuur.opdracht_id.ToString();
     txtKlant.Text      = miniFactuur.klant.naam;
     dtVertrek.Value    = (DateTime)miniFactuur.vanaf_datum;
     txtBestemming.Text = OpdrachtManagement.getBestemming(miniFactuur.opdracht_id).FullAdress;
 }
Exemple #4
0
        private void ucOpdrachtPrijs2_Load(object sender, EventArgs e)
        {
            try
            {
                txtID.Text  = miniopdracht.opdracht_id.ToString();
                dtVan.Value = (DateTime)miniopdracht.vanaf_datum;

                txtBestemming.Text  = OpdrachtManagement.getBestemming(miniopdracht.opdracht_id).FullAdress;
                txtPlaatsen.Text    = miniopdracht.aantal_personen.ToString();
                txtPrijs.Text       = miniopdracht.offerte_totaal.ToString();
                chckBetaald.Checked = (bool)miniopdracht.factuur_betaald;
                txtVertrek.Text     = OpdrachtManagement.getVertrek(miniopdracht.opdracht_id).FullAdress;
            }catch {}
        }
 private void ucLeverancierOpdracht_Load(object sender, EventArgs e)
 {
     txtID.Text           = miniopdracht.opdracht_id.ToString();
     txtPlaatsen.Text     = miniopdracht.aantal_personen.ToString();
     txtKlant.Text        = miniopdracht.klant.naam;
     txtKlantPlaats.Text  = KlantManagement.getAdresVanKlant(miniopdracht.klant.klant_id).plaats;
     dtVan.Value          = (DateTime)miniopdracht.vanaf_datum;
     dtTot.Value          = (DateTime)miniopdracht.tot_datum;
     txtVanUur.Text       = miniopdracht.vanaf_uur;
     txtTotUur.Text       = miniopdracht.tot_uur;
     txtOmschrijving.Text = miniopdracht.ritomschrijving;
     txtVetrekPlaats.Text = OpdrachtManagement.getVertrek(miniopdracht.opdracht_id).FullAdress;
     txtTerugPlaats.Text  = OpdrachtManagement.getBestemming(miniopdracht.opdracht_id).FullAdress;
 }
Exemple #6
0
        private void ucChauffeurRit_Load(object sender, EventArgs e)
        {
            txtID.Text           = miniopdracht.opdracht_id.ToString();
            txtNummerplaat.Text  = "bla";
            txtVoertuigNr.Text   = "bli";
            txtKlant.Text        = miniopdracht.klant.naam;
            txtKlantPlaats.Text  = KlantManagement.getAdresVanKlant(miniopdracht.klant.klant_id).plaats;
            dtVan.Value          = (DateTime)miniopdracht.vanaf_datum;
            dtTot.Value          = (DateTime)miniopdracht.tot_datum;
            txtVanUur.Text       = miniopdracht.vanaf_uur;
            txtTotUur.Text       = miniopdracht.tot_uur;
            txtOmschrijving.Text = miniopdracht.ritomschrijving;

            txtVetrekPlaats.Text = (OpdrachtManagement.getVertrek(miniopdracht.opdracht_id) == null) ? "" : OpdrachtManagement.getVertrek(miniopdracht.opdracht_id).FullAdress;
            txtTerugPlaats.Text  = (OpdrachtManagement.getBestemming(miniopdracht.opdracht_id) == null)? "":OpdrachtManagement.getBestemming(miniopdracht.opdracht_id).FullAdress;
        }
Exemple #7
0
        private void cbbID_SelectedIndexChanged(object sender, EventArgs e)
        {
            opdracht opdracht = (opdracht)cbbID.SelectedItem;

            if (opdracht == null)
            {
            }
            else
            {
                //De opslaan knop op enabled zetten, zodat de gebruiker kan opslaan
                btnOpslaan.Enabled = true;

                opdracht selectedOpdracht = (opdracht)cbbID.SelectedItem;

                //velden moeten eerst leeggemaakt worden, anders gaan er waarden instaan die er niet mogen instaan (van vorige geselecteerde factuur)
                emptyFields();

                //Velden ook enabled zetten
                enableFields();

                //Kijken of gefactureerd is of niet
                if (ContractManagement.getFacturenVanContract(opdracht) == null)
                {
                    lblGefactureerd.Text      = "Niet gefactureerd";
                    lblGefactureerd.ForeColor = Color.Red;
                }
                else
                {
                    lblGefactureerd.Text      = "Gefactureerd";
                    lblGefactureerd.ForeColor = Color.Green;
                }

                cbbKlant.SelectedItem = selectedOpdracht.klant;
                dtVan.Value           = selectedOpdracht.vanaf_datum;
                dtTot.Value           = selectedOpdracht.tot_datum;

                cbbVertrek.SelectedItem    = OpdrachtManagement.getVertrek(selectedOpdracht.opdracht_id);
                cbbBestemming.SelectedItem = OpdrachtManagement.getBestemming(selectedOpdracht.opdracht_id);

                decimal prijs;
                if (selectedOpdracht.voorschot != null)
                {
                    prijs = (decimal)selectedOpdracht.offerte_totaal - (decimal)selectedOpdracht.voorschot;
                }
                else
                {
                    if (selectedOpdracht.offerte_totaal != null)
                    {
                        prijs = (decimal)selectedOpdracht.offerte_totaal;
                    }
                }

                if (selectedOpdracht.FactuurNummering != null)
                {
                    if (selectedOpdracht.FactuurNummering.FactuurJaar != null)
                    {
                        _factuurjaar = selectedOpdracht.FactuurNummering.FactuurJaar.Value;
                    }
                    if (selectedOpdracht.FactuurNummering.FactuurNr != null)
                    {
                        _factuurnr = selectedOpdracht.FactuurNummering.FactuurNr.Value;
                    }
                    if (selectedOpdracht.FactuurNummering.bedrijf != null)
                    {
                        txt_eigenaarFactuur.Text = selectedOpdracht.FactuurNummering.bedrijf.naam;
                    }
                }



                txt_FactuurNr.Enabled   = false;
                txt_factuurjaar.Enabled = false;
                cbBetaald.Checked       = Convert.ToBoolean(selectedOpdracht.factuur_betaald);

                //Statusbar updaten
                MainForm.updateStatus = "De factuur met ID: " + opdracht.opdracht_id + ", is succesvol geladen.";

                //Alle facturen van bepaalde contract ophalen
                cbbFactuurID.DataSource    = ContractManagement.getFacturenVanContract(selectedOpdracht);
                cbbFactuurID.DisplayMember = "FullDate";
                cbbFactuurID.ValueMember   = "contract_factuur_id";

                if (ContractManagement.getFacturenVanContract(selectedOpdracht).Any() == true)
                {
                    contract_factuur laatste_factuur = ContractManagement.getFacturenVanContract(selectedOpdracht).Last();
                    dtPeriodeBegin.MinDate = laatste_factuur.periode_einde;
                    dtPeriodeBegin.MaxDate = selectedOpdracht.tot_datum;
                    dtPeriodeEinde.MinDate = laatste_factuur.periode_einde;
                    dtPeriodeEinde.MaxDate = selectedOpdracht.tot_datum;

                    dtPeriodeBegin.Value = laatste_factuur.periode_einde;

                    //Als het contract korter is dan 1 maand, kunnen er geen facturen gemaakt worden voor 1 maand, dus factuur van begindatum tot einddatum.
                    if (laatste_factuur.periode_einde.AddMonths(1) > selectedOpdracht.tot_datum)
                    {
                        dtPeriodeEinde.Value = selectedOpdracht.tot_datum;
                    }
                    else
                    {
                        dtPeriodeEinde.Value = laatste_factuur.periode_einde.AddMonths(1);
                    }
                }
                else
                {
                    dtPeriodeBegin.MinDate = selectedOpdracht.vanaf_datum;
                    dtPeriodeBegin.MaxDate = selectedOpdracht.tot_datum;
                    dtPeriodeEinde.MinDate = selectedOpdracht.vanaf_datum;
                    dtPeriodeEinde.MaxDate = selectedOpdracht.tot_datum;

                    dtPeriodeBegin.Value = selectedOpdracht.vanaf_datum;


                    //Als het contract korter is dan 1 maand, kunnen er geen facturen gemaakt worden voor 1 maand, dus factuur van begindatum tot einddatum.
                    if (selectedOpdracht.vanaf_datum.AddMonths(1) > selectedOpdracht.tot_datum)
                    {
                        dtPeriodeEinde.Value = selectedOpdracht.tot_datum;
                    }
                    else
                    {
                        dtPeriodeEinde.Value = selectedOpdracht.vanaf_datum.AddMonths(1);
                    }
                }
            }
        }
Exemple #8
0
        private void cbbID_SelectedIndexChanged()
        {
            opdracht opdracht = (opdracht)cbbID.SelectedItem;

            if (opdracht == null)
            {
                MainForm.updateStatus = "Er is geen factuur gekozen.";
            }
            else
            {
                //De opslaan knop op enabled zetten, zodat de gebruiker kan opslaan
                btnOpslaan.Enabled = true;
                enableFields();

                //velden moeten eerst leeggemaakt worden, anders gaan er waarden instaan die er niet mogen instaan (van vorige geselecteerde factuur)
                emptyFields();

                opdracht selectedOpdracht = (opdracht)cbbID.SelectedItem;

                //Kijken of gefactureerd is of niet
                if (selectedOpdracht.factuur_datum == null)
                {
                    lblGefactureerd.Text      = "Niet gefactureerd";
                    lblGefactureerd.ForeColor = Color.Red;
                }
                else
                {
                    lblGefactureerd.Text      = "Gefactureerd";
                    lblGefactureerd.ForeColor = Color.Green;
                }

                cbbKlant.SelectedItem = selectedOpdracht.klant;
                dtVan.Value           = selectedOpdracht.vanaf_datum;
                dtTot.Value           = selectedOpdracht.tot_datum;

                TimeSpan aantaldagen = dtTot.Value - dtVan.Value;
                int      dagen       = aantaldagen.Days + 1;
                txtAantalDagen.Text = dagen.ToString();

                txtVan_uur.Text            = selectedOpdracht.vanaf_uur;
                txtTot_uur.Text            = selectedOpdracht.tot_uur;
                cbbVertrek.SelectedItem    = OpdrachtManagement.getVertrek(selectedOpdracht.opdracht_id);
                cbbBestemming.SelectedItem = OpdrachtManagement.getBestemming(selectedOpdracht.opdracht_id);
                txtTotaalprijs.Text        = selectedOpdracht.offerte_totaal.ToString();

                decimal prijs;
                if (selectedOpdracht.voorschot != null)
                {
                    prijs = (decimal)selectedOpdracht.offerte_totaal - (decimal)selectedOpdracht.voorschot;
                }
                else
                {
                    prijs = (decimal)selectedOpdracht.offerte_totaal;
                }

                txtSaldo.Text     = prijs.ToString();
                txtVoorschot.Text = selectedOpdracht.voorschot.ToString();

                cbBetaald.Checked          = Convert.ToBoolean(selectedOpdracht.factuur_betaald);
                cbBetaaldvoorschot.Checked = Convert.ToBoolean(selectedOpdracht.factuur_betaald_voorschot);
                try
                {
                    dtBetaald.Value = selectedOpdracht.factuur_betalingsdatum.Value;
                }
                catch { } try
                {
                    dtBetaaldvoorschot.Value = selectedOpdracht.factuur_betalingsdatum_voorschot.Value;
                }
                catch { }

                txtBetalingMemo.Text          = selectedOpdracht.factuur_betalingmemo;
                txtBetalingMemovoorschot.Text = selectedOpdracht.factuur_betalingmemo_voorschot;

                Factuurbetaald();
                Voorschotbetaald();

                ////Alle reservaties ophalen en toevoegen aan flpReservaties
                //foreach (reservatie res in OpdrachtManagement.getReservaties(selectedOpdracht.opdracht_id))
                //{
                //    ucReservatie ucReservatie = new ucReservatie();
                //    ucReservatie.Prijs = res.prijs;
                //    ucReservatie.Leverancier = res.leverancier;
                //    ucReservatie.Omschrijving = res.omschrijving;

                //    flpReservaties.Controls.Add(ucReservatie);
                //}

                //factuur informatie ophalen
                opdracht_factuur of = FactuurManagement.getFactuurVanOpdracht(selectedOpdracht);

                if (of == null)
                {
                }
                else
                {
                    txtBedrag_basis.Text     = of.credit_basis.ToString();
                    txtOmschrijving.Text     = of.credit_omschrijving;
                    txtBtw_bedrag.Text       = of.credit_btwbedrag.ToString();
                    cbbBTW.Text              = of.credit_btwpercent.ToString();
                    txtBedrag_inclusief.Text = of.credit_inc.ToString();
                    txtCreditvoorschot.Text  = of.voorschot.ToString();
                    txtTotaal_reis.Text      = of.totaal_reis.ToString();

                    //factuur detail informatie ophalen
                    foreach (opdracht_factuur_detail ofd in FactuurManagement.getFactuurDetails(of))
                    {
                        ucDetailFactuur uc = new ucDetailFactuur();
                        uc.bedrag_basis     = ofd.bedrag_basis;
                        uc.omschrijving     = ofd.omschrijving;
                        uc.bedrag_inclusief = ofd.bedrag_inclusief;
                        uc.btw_bedrag       = ofd.btw_bedrag;
                        uc.btw_percent      = ofd.btw_percent;

                        flpDetail.Controls.Add(uc);
                    }
                }

                if (selectedOpdracht.FactuurNummering != null)
                {
                    if (selectedOpdracht.FactuurNummering.FactuurJaar != null)
                    {
                        _factuurjaar = selectedOpdracht.FactuurNummering.FactuurJaar.Value;
                    }
                    if (selectedOpdracht.FactuurNummering.FactuurNr != null)
                    {
                        _factuurnr = selectedOpdracht.FactuurNummering.FactuurNr.Value;
                    }
                    if (selectedOpdracht.FactuurNummering.bedrijf != null)
                    {
                        txt_eigenaarFactuur.Text = selectedOpdracht.FactuurNummering.bedrijf.naam;
                    }
                }

                if (selectedOpdracht.FactuurNummering1 != null)
                {
                    if (selectedOpdracht.FactuurNummering1.FactuurJaar != null)
                    {
                        _factuurjaarCredit = selectedOpdracht.FactuurNummering1.FactuurJaar.Value;
                    }
                    if (selectedOpdracht.FactuurNummering1.FactuurNr != null)
                    {
                        _factuurnrCredit = selectedOpdracht.FactuurNummering1.FactuurNr.Value;
                    }
                }

                txt_FactuurNr.Enabled         = false;
                txt_factuurjaar.Enabled       = false;
                txt_FactuurNrCredit.Enabled   = false;
                txt_factuurjaarCredit.Enabled = false;

                //Statusbar updaten
                MainForm.updateStatus = "De factuur met ID: " + opdracht.opdracht_id + ", is succesvol geladen.";
            }
        }
        //EditTim: Printen van alle ritten van de gekozen chauffeur op de gekozen datum
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime date = dateTimePicker1.Value.Date;

            //alle informatie van contracten ophalen
            IEnumerable <rit_instantie> ritten = ContractManagement.getRitten(date);

            foreach (rit_instantie ri in ritten)
            {
                opdracht od = ContractManagement.getContract(ri.contract_rit);
                if (date.ToString("dddd", new CultureInfo("en-US")) == (ri.contract_rit.dag))
                {
                    var idfull    = od.contract_id_full;
                    var ritnummer = od.ritomschrijving;
                    var rit1vertr = ri.contract_rit.rit1_vertrek;
                    var rit2vertr = ri.contract_rit.rit2_vertrek;
                    var rit1terug = ri.contract_rit.rit1_terug;
                    var rit2terug = ri.contract_rit.rit2_terug;

                    if (ContractManagement.hasRitInfo(ri))
                    {
                        rit_info info = ContractManagement.getRitInfo(ri);
                        chauffeurnaam = info.chauffeur.naam;
                        voertuignaam1 = info.voertuig.identificatie;
                        voertuignaam2 = info.voertuig1.identificatie;
                    }
                    var vertrek    = OpdrachtManagement.getVertrek(od.opdracht_id);
                    var bestemming = OpdrachtManagement.getBestemming(od.opdracht_id);

                    if (chauffeurnaam.ToString() == cbxChauffeurs.SelectedItem.ToString())
                    {
                        //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\ritblad_chauffeur_CONTRACT.docx";
                        //object fileToOpen = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritblad_template.docx";

                        //Where the new file will be saved to.
                        object fileToSave = (object)@"R:\CarGo\printouts\ritblad_chauffeur_CONTRACT" + "" + DateTime.Now.Second + DateTime.Now.Millisecond + ".docx";
                        //object fileToSave = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritbladen\ritblad_" + opdracht.opdracht_id_full + "_" + OpdrachtManagement.getChauffeursVanOpdracht(opdracht).First().naam + ".docx";

                        //Create new instance of word and create a new document
                        Word.Application wordApp = new Word.Application();
                        Word.Document    doc     = null;

                        //MessageBox.Show(System.IO.Path.GetTempPath(), "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        //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;

                        //Open and activate the chosen template
                        doc = wordApp.Documents.Open(ref fileToOpen, 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);

                        try
                        {
                            File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true);
                        }
                        catch
                        {
                            MainForm.updateStatus = "Kan nieuw document niet opslaan";
                            return;
                        }

                        //Search for bookmarks and replace them with the text you want
                        PrintManagement.findAndReplace(doc, "Datum", date.ToString("dddd dd MMMM yyyy"));
                        PrintManagement.findAndReplace(doc, "Van1", rit1vertr);
                        PrintManagement.findAndReplace(doc, "Tot1", rit1terug);
                        PrintManagement.findAndReplace(doc, "Van2", rit2vertr);
                        PrintManagement.findAndReplace(doc, "Tot2", rit2terug);
                        PrintManagement.findAndReplace(doc, "Naam", chauffeurnaam);
                        PrintManagement.findAndReplace(doc, "Ritnummer1", ritnummer);
                        PrintManagement.findAndReplace(doc, "Ritnummer", ritnummer);
                        PrintManagement.findAndReplace(doc, "Bestemming1", vertrek.FullAdress);
                        PrintManagement.findAndReplace(doc, "Bestemming2", vertrek.FullAdress);
                        PrintManagement.findAndReplace(doc, "Vertrekplaats1", bestemming.FullAdress);
                        PrintManagement.findAndReplace(doc, "Vertrekplaats2", bestemming.FullAdress);
                        PrintManagement.findAndReplace(doc, "Voertuignummer1", voertuignaam1);
                        PrintManagement.findAndReplace(doc, "Voertuignummer2", voertuignaam2);
                        //doc = wordApp.Documents.Open(fileToSave, ReadOnly: false, Visible: true);

                        doc.Save();
                        doc.Activate();

                        //Making word visible to be able to show the print preview.
                        wordApp.Visible = true;
                    }
                }
            }

            foreach (opdracht o in OpdrachtManagement.getOpdrachten(date))
            {
                rit_info info = ContractManagement.getRitInfo(null);

                int       counter     = 0;
                chauffeur firstChauff = null;
                chauffeur secChauff   = null;

                var idfull    = o.contract_id_full;
                var ritnummer = o.ritomschrijving;
                var rit1vertr = o.vanaf_uur;
                var rit1terug = o.tot_uur;

                foreach (opdracht_chauffeur cha in OpdrachtManagement.getChauffeursVanOpdract(o))
                {
                    if (counter == 0)
                    {
                        firstChauff = cha.chauffeur;
                    }
                    else if (counter == 1)
                    {
                        secChauff = cha.chauffeur;
                    }
                    counter++;
                }
                var vertrek    = OpdrachtManagement.getVertrek(o.opdracht_id);
                var bestemming = OpdrachtManagement.getBestemming(o.opdracht_id);
                IEnumerable <opdracht_voertuig> voertuigen = OpdrachtManagement.getVoertuigenVanOpdracht(o);
                var voertuignaam3 = voertuigen.First().voertuig.identificatie;

                if (firstChauff.naam.ToString() == cbxChauffeurs.SelectedItem.ToString())
                {
                    //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\ritblad_chauffeur_CONTRACT.docx";
                    //object fileToOpen = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritblad_template.docx";

                    //Where the new file will be saved to.
                    object fileToSave = (object)@"R:\CarGo\printouts\ritblad_chauffeur_CONTRACT" + "" + DateTime.Now.Second + DateTime.Now.Millisecond + ".docx";
                    //object fileToSave = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritbladen\ritblad_" + opdracht.opdracht_id_full + "_" + OpdrachtManagement.getChauffeursVanOpdracht(opdracht).First().naam + ".docx";

                    //Create new instance of word and create a new document
                    Word.Application wordApp = new Word.Application();
                    Word.Document    doc     = null;

                    //MessageBox.Show(System.IO.Path.GetTempPath(), "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    //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;

                    //Open and activate the chosen template
                    doc = wordApp.Documents.Open(ref fileToOpen, 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);

                    try
                    {
                        File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true);
                    }
                    catch
                    {
                        MainForm.updateStatus = "Kan nieuw document niet opslaan";
                        return;
                    }

                    //Search for bookmarks and replace them with the text you want
                    PrintManagement.findAndReplace(doc, "Datum", date.ToString("dddd dd MMMM yyyy"));
                    PrintManagement.findAndReplace(doc, "Van1", rit1vertr);
                    PrintManagement.findAndReplace(doc, "Tot1", rit1terug);
                    PrintManagement.findAndReplace(doc, "Van2", "");
                    PrintManagement.findAndReplace(doc, "Tot2", "");
                    PrintManagement.findAndReplace(doc, "Naam", firstChauff.naam.ToString());
                    PrintManagement.findAndReplace(doc, "Ritnummer1", ritnummer);
                    PrintManagement.findAndReplace(doc, "Ritnummer", "");
                    PrintManagement.findAndReplace(doc, "Bestemming1", vertrek.FullAdress);
                    PrintManagement.findAndReplace(doc, "Bestemming2", "");
                    PrintManagement.findAndReplace(doc, "Vertrekplaats1", bestemming.FullAdress);
                    PrintManagement.findAndReplace(doc, "Vertrekplaats2", "");
                    PrintManagement.findAndReplace(doc, "Voertuignummer1", voertuignaam3);
                    PrintManagement.findAndReplace(doc, "Voertuignummer2", "");
                    //doc = wordApp.Documents.Open(fileToSave, ReadOnly: false, Visible: true);

                    doc.Save();
                    doc.Activate();

                    //Making word visible to be able to show the print preview.
                    wordApp.Visible = true;
                }
            }
        }