Sales/Invoice.cs
author Markus Bröker<broeker.markus@googlemail.com>
Wed, 29 Mar 2017 12:05:27 +0200
changeset 1 80c685d55d63
parent 0 cfa10fbf52b3
child 2 0907765a8b2e
permissions -rwxr-xr-x
Sinnvolles Beispiel für Function-Pointer in C#
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     1
/**
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     2
 * Invoice.cs
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     3
 * 
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     4
 * @author       Markus Bröker<broeker.markus@googlemail.com>
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     5
 * @copyright    Copyright(C) 2017 4Customers UG
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     6
 * 
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     7
 */
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     8
using System;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     9
using System.Collections.Generic;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    10
using System.Linq;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    11
using System.Text;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    12
using System.Threading.Tasks;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    13
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    14
using static Sales.Payment;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    15
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    16
namespace Sales
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    17
{
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    18
    delegate double InvoiceDelegate();
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    19
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    20
    class Invoice
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    21
    {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    22
        private double value = 0;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    23
        private PaymentType till;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    24
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    25
        public Invoice(double value, PaymentType till)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    26
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    27
            this.value = value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    28
            this.till = till;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    29
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    30
            InvoiceDelegate invoiceDelegateReference = this.Rabatt;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    31
            invoiceDelegateReference += this.AddTax;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    32
            invoiceDelegateReference += this.Skonto;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    33
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    34
            invoiceDelegateReference();
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    35
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    36
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    37
        public double getFinalResult()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    38
        {            
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    39
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    40
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    41
1
80c685d55d63 Sinnvolles Beispiel für Function-Pointer in C#
Markus Bröker<broeker.markus@googlemail.com>
parents: 0
diff changeset
    42
        // Rabatt auf den Netto Preis
0
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    43
        private double Rabatt()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    44
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    45
            if (value > 1000.0)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    46
            {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    47
                value *= 0.75;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    48
            }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    49
            else if (value > 500.0)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    50
            {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    51
                value *= 0.85;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    52
            }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    53
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    54
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    55
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    56
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    57
        // Steuern auf den rabattierten Nettopreis
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    58
        private double AddTax()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    59
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    60
            value *= 1.19;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    61
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    62
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    63
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    64
        // Skonto immer zum Schluss
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    65
        private double Skonto()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    66
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    67
            switch (till)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    68
            {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    69
                case PaymentType.NOW:
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    70
                    value *= 0.97;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    71
                    break;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    72
                case PaymentType.WEEK:
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    73
                    value *= 0.98;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    74
                    break;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    75
                case PaymentType.MONTH:
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    76
                    value *= 0.99;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    77
                    break;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    78
            }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    79
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    80
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    81
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    82
    }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    83
}