'Project:     Shedd0406

'Date:        May 22, 2006

'Programmer:  Brad Shedd

'Description: This project displays the summary and earnings of a piece worker, the try catch box is inculded

 

Option Strict On

Public Class workerForm

    Inherits System.Windows.Forms.Form

 

#Region " Windows Form Designer generated code "

 

    Public Sub New()

        MyBase.New()

 

        'This call is required by the Windows Form Designer.

        InitializeComponent()

 

        'Add any initialization after the InitializeComponent() call

 

    End Sub

 

    'Form overrides dispose to clean up the component list.

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing Then

            If Not (components Is Nothing) Then

                components.Dispose()

            End If

        End If

        MyBase.Dispose(disposing)

    End Sub

 

    'Required by the Windows Form Designer

    Private components As System.ComponentModel.IContainer

 

    'NOTE: The following procedure is required by the Windows Form Designer

    'It can be modified using the Windows Form Designer. 

    'Do not modify it using the code editor.

    Friend WithEvents Label1 As System.Windows.Forms.Label

    Friend WithEvents nameTextBox As System.Windows.Forms.TextBox

    Friend WithEvents Label2 As System.Windows.Forms.Label

    Friend WithEvents piecesTextBox As System.Windows.Forms.TextBox

    Friend WithEvents Label3 As System.Windows.Forms.Label

    Friend WithEvents tpLabel As System.Windows.Forms.Label

    Friend WithEvents CalculateButton As System.Windows.Forms.Button

    Friend WithEvents summaryButton As System.Windows.Forms.Button

    Friend WithEvents clearButton As System.Windows.Forms.Button

    Friend WithEvents clearAllButton As System.Windows.Forms.Button

    Friend WithEvents exitButton As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        Me.Label1 = New System.Windows.Forms.Label

        Me.nameTextBox = New System.Windows.Forms.TextBox

        Me.Label2 = New System.Windows.Forms.Label

        Me.piecesTextBox = New System.Windows.Forms.TextBox

        Me.Label3 = New System.Windows.Forms.Label

        Me.tpLabel = New System.Windows.Forms.Label

        Me.CalculateButton = New System.Windows.Forms.Button

        Me.summaryButton = New System.Windows.Forms.Button

        Me.clearButton = New System.Windows.Forms.Button

        Me.clearAllButton = New System.Windows.Forms.Button

        Me.exitButton = New System.Windows.Forms.Button

        Me.SuspendLayout()

        '

        'Label1

        '

        Me.Label1.Location = New System.Drawing.Point(72, 32)

        Me.Label1.Name = "Label1"

        Me.Label1.Size = New System.Drawing.Size(112, 23)

        Me.Label1.TabIndex = 0

        Me.Label1.Text = "Name"

        '

        'nameTextBox

        '

        Me.nameTextBox.Location = New System.Drawing.Point(240, 32)

        Me.nameTextBox.Name = "nameTextBox"

        Me.nameTextBox.Size = New System.Drawing.Size(152, 20)

        Me.nameTextBox.TabIndex = 1

        Me.nameTextBox.Text = ""

        '

        'Label2

        '

        Me.Label2.Location = New System.Drawing.Point(72, 88)

        Me.Label2.Name = "Label2"

        Me.Label2.Size = New System.Drawing.Size(104, 23)

        Me.Label2.TabIndex = 2

        Me.Label2.Text = "Pieces completed"

        '

        'piecesTextBox

        '

        Me.piecesTextBox.Location = New System.Drawing.Point(232, 88)

        Me.piecesTextBox.Name = "piecesTextBox"

        Me.piecesTextBox.Size = New System.Drawing.Size(128, 20)

        Me.piecesTextBox.TabIndex = 3

        Me.piecesTextBox.Text = ""

        '

        'Label3

        '

        Me.Label3.Location = New System.Drawing.Point(72, 144)

        Me.Label3.Name = "Label3"

        Me.Label3.Size = New System.Drawing.Size(112, 23)

        Me.Label3.TabIndex = 4

        Me.Label3.Text = "Amount earned"

        '

        'tpLabel

        '

        Me.tpLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

        Me.tpLabel.Location = New System.Drawing.Point(224, 144)

        Me.tpLabel.Name = "tpLabel"

        Me.tpLabel.Size = New System.Drawing.Size(144, 23)

        Me.tpLabel.TabIndex = 5

        Me.tpLabel.TextAlign = System.Drawing.ContentAlignment.TopRight

        '

        'CalculateButton

        '

        Me.CalculateButton.Location = New System.Drawing.Point(32, 256)

        Me.CalculateButton.Name = "CalculateButton"

        Me.CalculateButton.Size = New System.Drawing.Size(128, 32)

        Me.CalculateButton.TabIndex = 6

        Me.CalculateButton.Text = "&Calculate"

        '

        'summaryButton

        '

        Me.summaryButton.Location = New System.Drawing.Point(192, 256)

        Me.summaryButton.Name = "summaryButton"

        Me.summaryButton.Size = New System.Drawing.Size(136, 32)

        Me.summaryButton.TabIndex = 7

        Me.summaryButton.Text = "Summary"

        '

        'clearButton

        '

        Me.clearButton.DialogResult = System.Windows.Forms.DialogResult.Cancel

        Me.clearButton.Location = New System.Drawing.Point(360, 256)

        Me.clearButton.Name = "clearButton"

        Me.clearButton.Size = New System.Drawing.Size(136, 32)

        Me.clearButton.TabIndex = 8

        Me.clearButton.Text = "C&lear"

        '

        'clearAllButton

        '

        Me.clearAllButton.Location = New System.Drawing.Point(32, 328)

        Me.clearAllButton.Name = "clearAllButton"

        Me.clearAllButton.Size = New System.Drawing.Size(120, 32)

        Me.clearAllButton.TabIndex = 9

        Me.clearAllButton.Text = "Clear All"

        '

        'exitButton

        '

        Me.exitButton.Location = New System.Drawing.Point(216, 328)

        Me.exitButton.Name = "exitButton"

        Me.exitButton.Size = New System.Drawing.Size(136, 32)

        Me.exitButton.TabIndex = 10

        Me.exitButton.Text = "E&xit"

        '

        'workerForm

        '

        Me.AcceptButton = Me.CalculateButton

        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

        Me.CancelButton = Me.clearButton

        Me.ClientSize = New System.Drawing.Size(544, 461)

        Me.Controls.Add(Me.exitButton)

        Me.Controls.Add(Me.clearAllButton)

        Me.Controls.Add(Me.clearButton)

        Me.Controls.Add(Me.summaryButton)

        Me.Controls.Add(Me.CalculateButton)

        Me.Controls.Add(Me.tpLabel)

        Me.Controls.Add(Me.Label3)

        Me.Controls.Add(Me.piecesTextBox)

        Me.Controls.Add(Me.Label2)

        Me.Controls.Add(Me.nameTextBox)

        Me.Controls.Add(Me.Label1)

        Me.Name = "workerForm"

        Me.Text = "Piece Worker Summary"

        Me.ResumeLayout(False)

 

    End Sub

 

#End Region

    'Declare Contants

    Const RATE1_TO_199_Decimal As Decimal = 0.5D

    Const RATE200_TO_399_Decimal As Decimal = 0.55D

    Const RATE400_TO_599_Decimal As Decimal = 0.6D

    Const RATE600_PLUS_Decimal As Decimal = 0.65D

    Private workerCountInteger, totalPiecesInteger As Integer

    Private totalPayDecimal As Decimal

 

    Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click

        'Calculate amount earned.

        Dim messageString, nameString As String

        Dim quantityInteger As Integer

        Dim payRateDecimal, amountEarnedDecimal As Decimal

 

        ' Calculate Pay

        If nameTextBox.Text <> "" Then 'Person has entered Name

            Try

                'Convert the quantity.

                quantityInteger = Integer.Parse(piecesTextBox.Text)

 

                'Number of peices must be greater than 0.

                If quantityInteger > 0 Then

                    'Determine Pay Rate.

                    Select Case quantityInteger

                        Case 1 To 199

                            payRateDecimal = RATE1_TO_199_Decimal

                        Case 200 To 399

                            payRateDecimal = RATE200_TO_399_Decimal

                        Case 400 To 599

                            payRateDecimal = RATE400_TO_599_Decimal

                        Case Is > 599

                            payRateDecimal = RATE600_PLUS_Decimal

                    End Select

 

                    'Perform Calculations and accululate totals.

                    amountEarnedDecimal = quantityInteger * payRateDecimal

                    totalPiecesInteger += quantityInteger

                    totalPayDecimal += amountEarnedDecimal

                    workerCountInteger += 1

 

                    'Display Pay

                    tpLabel.Text = amountEarnedDecimal.ToString("C")

 

                Else

                    'Nothing was entered

                    messageString = "Please enter a number greater than 0."

                    MessageBox.Show(messageString, "Data Entry Error", _

                    MessageBoxButtons.OK, MessageBoxIcon.Information)

                    With piecesTextBox

                        .Focus()

                        .SelectAll()

                    End With

                End If

            Catch err As Exception

                MessageBox.Show("Error: " & err.Message)

                'No Name in text box.

                messageString = "Enter Name"

                MessageBox.Show(messageString, "No Data", _

                MessageBoxButtons.OK, MessageBoxIcon.Error)

                nameTextBox.Focus()

            End Try

        End If

    End Sub

 

    Private Sub summaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles summaryButton.Click

        'Calculate average pay and display totals.

        Dim averagePayDecimal As Decimal

        Dim messageString As String

 

        If workerCountInteger > 0 Then

            'Clear textBoxes and Labels.

            clearButton_Click(sender, e)

 

            'Calculate average pay.

            averagePayDecimal = totalPayDecimal / workerCountInteger

 

            'Concatenate the message string.

            messageString = "Total Pieces: " & totalPiecesInteger.ToString _

            & ControlChars.NewLine & ControlChars.NewLine _

            & "TotalPay: " & totalPayDecimal.ToString("C") _

            & ControlChars.NewLine & ControlChars.NewLine _

            & "Average Amount Earned: " & averagePayDecimal.ToString("C") _

            & ControlChars.NewLine & ControlChars.NewLine _

            & "Number of Workers: " & workerCountInteger.ToString

 

            MessageBox.Show(messageString, "Piecework Pay Summary", _

            MessageBoxButtons.OK, MessageBoxIcon.Information)

 

        Else

            messageString = "No Data to Summarize."

            MessageBox.Show(messageString, "Piecework Pay Sjummary", MessageBoxButtons.OK, _

            MessageBoxIcon.Information)

            nameTextBox.Focus()

 

        End If

    End Sub

 

    Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click

        tpLabel.Text = ""

        piecesTextBox.Clear()

        With nameTextBox

            .Clear()

            .Focus()

        End With

    End Sub

 

    Private Sub clearAllButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearAllButton.Click

        'Clear all information.

        Dim returnDialogResult As DialogResult

        Dim messageString As String

 

        'Confirm clear

        messageString = "Clear all information?"

        returnDialogResult = MessageBox.Show(messageString, "Reset", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

        If returnDialogResult = DialogResult.Yes Then ' User clicked yes.

            clearButton_Click(sender, e)              'Clear all fields.

            'Clear Summary.

            workerCountInteger = 0

            totalPiecesInteger = 0

            totalPayDecimal = 0

        End If

 

    End Sub

 

 

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click

        'Exit the program.

 

        Me.Close()

 

    End Sub

End Class

 

 

Homepage