Here is a quick example I put together for you. You need a form (Form1), a CheckedListBox (CheckedListBox1) and a Button (Button1).
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim discounts As New List(Of Discount)
discounts.Add(New Discount("Discount 1", Discount.DiscountTypes.Percentage, 0.1D, 0D)) '10% discount - no min purchase
discounts.Add(New Discount("Discount 2", Discount.DiscountTypes.DollarAmount, 5D, 5D)) '$5.00 discount, min $5 purchase
discounts.Add(New Discount("Discount 3", Discount.DiscountTypes.DollarOffPerXPurchased, 25D, 50D)) '$25.00 discount with min purchase of $50.00
CheckedListBox1.CheckOnClick = True
CheckedListBox1.Items.AddRange(discounts.ToArray)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim totalPurchased As Decimal = 99.03D
Dim totalDiscount As Decimal = CalculateDiscounts(totalPurchased)
MessageBox.Show(String.Format("Total purchase: {0}{3}Total discount: {1}{3}Net Due: {2}", _
totalPurchased.ToString("C"), totalDiscount.ToString("C"), _
(totalPurchased - totalDiscount).ToString("C"), Environment.NewLine))
End Sub
Public Function CalculateDiscounts(ByVal purchaseAmount As Decimal) As Decimal
'You should have your own rules on how to calculate multiple discounts, i.e discount type precedence,
'should the discount amount be taken off the purchase amount before applying the next discount...
'In this example, I just do a simple discount by applying all discounts in whatever order theuy come in
Dim discountAmount As Decimal = 0D
Dim discountValue As Decimal = 0D
Dim requiredAmt As Decimal = 0D
For Each itm As Discount In CheckedListBox1.CheckedItems
discountValue = itm.DiscountValue
requiredAmt = itm.RequiredPurchaseAmount
Select Case itm.DiscountType
Case Discount.DiscountTypes.DollarAmount
If purchaseAmount >= discountAmount Then
discountAmount += discountValue
purchaseAmount -= discountValue
Else
discountAmount += purchaseAmount
purchaseAmount = 0D
End If
Case Discount.DiscountTypes.DollarOffPerXPurchased
If purchaseAmount >= requiredAmt Then
discountAmount += discountValue
purchaseAmount -= discountValue
End If
Case Discount.DiscountTypes.Percentage
discountAmount += purchaseAmount * discountValue
purchaseAmount -= purchaseAmount * discountValue
Case Discount.DiscountTypes.PercentOffPerXPurchased
If purchaseAmount >= requiredAmt Then
discountAmount += purchaseAmount * discountValue
purchaseAmount -= purchaseAmount * discountValue
End If
End Select
Next
Return discountAmount
End Function
Public Class Discount
Public Enum DiscountTypes
Percentage 'percent off the total purchase.
PercentOffPerXPurchased 'percent off applied only when min purchase of X dollars reached.
DollarAmount 'fixed dollar amount off the entire purchase
DollarOffPerXPurchased 'fixed dollar amount off applied only when min purchase of X dollars reached
'And so on....
End Enum
Public Property DiscountName() As String
Public Property DiscountValue() As Decimal
Public Property DiscountType As Discount.DiscountTypes
Public Property RequiredPurchaseAmount As Decimal
Public Sub New(ByVal txt As String, ByVal discntType As Discount.DiscountTypes, ByVal discount As Decimal, ByVal minPurchase As Decimal)
Me.DiscountName = txt
Me.DiscountType = discntType
Me.DiscountValue = discount
Me.RequiredPurchaseAmount = minPurchase
End Sub
Public Overrides Function ToString() As String
Return String.Format("{0} - {1}: {2}", Me.DiscountName, Me.DiscountType.ToString, Me.DiscountValue.ToString("N2"))
End Function
End Class
End Class