Option Strict On
Public Class Form1
Private Sub radNetwork_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radNetwork.CheckedChanged
End Sub
Private Sub lblTitle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTitle.Click
End Sub
Private Sub btnCalculateCosts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateCosts.Click
Dim objParticipant As Participant
Dim objPreCourse As PreCourse
Dim InputError As Boolean = False
'Is participant ID entered properly
If txtCorporationID.MaskFull = False Then
MsgBox("Enter your Corporation ID in the Corporation ID Box", , _
"Error")
txtCorporationID.Clear()
txtCorporationID.Focus()
InputError = True
'Is Participant First Name entered correctly
ElseIf txtFirst.TextLength < 1 Or _
txtFirst.Text < "A" Then
MsgBox("Enter your first Name in the Participant ID First Name Box", , "Error")
txtFirst.Focus()
txtFirst.Clear()
InputError = True
'Is Last Name entered correctly
ElseIf txtLast.TextLength < 1 Or _
txtLast.Text < "A" Then
MsgBox("Enter your last name in the Participant Last Name Box", , "Error")
txtLast.Clear()
txtLast.Focus()
ElseIf Not IsNumeric(txtNumberOfDays.Text) Then
MsgBox("Enter the days in the Number of Days box", , "Error")
txtNumberOfDays.Clear()
txtNumberOfDays.Focus()
InputError = True
End If
'If No input Error, process the registration costs
If Not InputError Then
If radPreConference.Checked Then
objPreCourse = New PreCourse(txtCorporationID.Text, _
txtFirst.Text, txtLast.Text, txtNumberOfDays)
lblCosts.Visible = True
lblCosts.Text = "Total Conference Costs are: " _
& (objPreCourse.ComputeCosts()).ToString("C2")
Else
objParticipant = New Participant(txtCorporationID.Text, _
txtFirst.Text, txtNumberOfDays.Text, )
lblCosts.Visible = True
lblCosts.Text = "Total Conference Costs are: " _
& (objParticipant.ComputeCosts()).ToString("C2")
End If
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'This event handler is executed when the user clicks the
'Clear Form button. It resets all objects on the user interface.
txtCorporationID.Clear()
txtFirst.Clear()
txtLast.Clear()
radPreConference.Checked = True
radNetwork.Checked = True
End Sub
Private Sub grpCourses_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpCourses.Enter
End Sub
Private Sub radPreConference_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radPreConference.CheckedChanged
End Sub
End Class
Option Strict On
Public Class Participant
'Class Variables
Protected _strCorporationID As String
Protected _strFirst As String
Protected _strLast As String
Protected _intUnits As Integer
Protected _decCost As Decimal
Protected _decCostPerUnit As Decimal = 350D
Dim objParticipantCostFile As ParticipantCostFile
Sub New(ByVal strCorporationID As String, ByVal strFirst As String, _
ByVal strLast As String, ByVal intUnits As String)
'This subprocedure is a constructor for the Participant class. It is called
'when the object is instantiated with the arguments
'The following code assigns the arguments to class variables
_strCorporationID = strCorporationID
_strFirst = strFirst
_strLast = strLast
_intUnits = Convert.ToInt32(intUnits)
End Sub
Overridable Function ComputeCosts() As Decimal
'This function computes the registration costs, writes a record,
'in the participant costs file, and returns the participant costs
'Calculate Costs
_decCost = _intUnits * _decCostPerUnit
'Writes the participant record
objParticipantCostFile = New ParticipantCostFile(_strCorporationID, _
_strFirst, _strLast, _decCost)
objParticipantCostFile.WriteRecord()
'Return the calculated cost
Return _decCost
End Function
End Class
Option Strict On
Public Class PreCourse
Inherits Participant
'Class Variables
Private _Network As Boolean
Private _Conquer As Boolean
Private _Moving As Boolean
Dim objParticipantCostFile As ParticipantCostFile
Sub New(ByVal CorporationID As String, ByVal First As String, _
ByVal Last As String, ByVal Units As String, _
ByVal Network As Boolean, ByVal Conquer As Boolean, _
ByVal Moving As Boolean)
'This subprocedure is a constructor for the Participant Class. It is called when
'instantiated with arguments
MyBase.New(CorporationID, First, Last, Units)
'The follwoing code assigns the arguments to class variables
_Network = Network
_Conquer = Conquer
_Moving = Moving
End Sub
Overrides Function ComputeCosts() As Decimal
'This function computes the registration costs, writes a record
'in the participant costs file, and returns the registration costs
'Define variables
Dim PreCourseCost As Decimal
Const cdecNetworkCourseCost As Decimal = 675D
Const cdecConquerCourseCost As Decimal = 675D
Const cdecMovingCourseCost As Decimal = 675D
'Calculate the cost
If _Network Then
PreCourseCost = cdecNetworkCourseCost
ElseIf _Conquer Then
PreCourseCost = cdecConquerCourseCost
ElseIf _Moving Then
PreCourseCost = cdecMovingCourseCost
End If
_decCost = (_intUnits * _decCostPerUnit) + PreCourseCost
'Write the participant record
objParticipantCostFile = New ParticipantCostFile(_strCorporationID, _
_strFirst, _strLast, _decCost)
objParticipantCostFile.WriteRecord()
'Return the calculated cost
Return _decCost
End Function
End Class
Public Class ParticipantCostFile
Private _strCorporationID As String
Private _strFirst As String
Private _strLast As String
Private _decCost As Decimal
Sub New(ByVal strCorporationID As String, ByVal strFirst As String, ByVal strLast As String, ByVal decCost As Decimal)
' TODO: Complete member initialization
_strCorporationID = strCorporationID
_strFirst = strFirst
_strLast = strLast
_decCost = decCost
End Sub
Sub WriteRecord()
'This subprocedure opens the ParticipantsCost output text file and then
'writes a record in the comma-delimited file
Dim strNameandLocationOfFile As String = "C:\ParticipantCost.txt"
Try
Dim objWriter As IO.StreamWriter = _
IO.File.AppendText(strNameandLocationOfFile)
objWriter.Write(_strCorporationID & ",")
objWriter.Write(_strFirst & ",")
objWriter.Write(_strLast & ",")
objWriter.WriteLine(_decCost)
objWriter.Close()
Catch ex As Exception
MsgBox("No device available - program aborted", , "Error")
Application.Exit()
End Try
End Sub
End Class
This post has been edited by modi123_1: 10 December 2011 - 01:19 PM
Reason for edit:: please use the code tags

New Topic/Question
Reply



MultiQuote







|