Example #1
0
        //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.";
        }