Home

Example Application:
Payroll Processing

 

Payroll Information

Introduction

This sample application demonstrates various features of the text box. It reviews the textual sides of the control. It takes advantages of its different properties such as its string and the text alignment.

New in the .NET Framework 2.0, the string of a text box could come from a preset list of items, whether from the file system or from the history list of URLs from the browser. This features is implemented through the AutoCompleteCustomSource, the AutoCompleteSource, the CustomSource, and the AutoCompleteMode properties.

 

Practical LearningPractical Learning: Creating the Application

  1. To start a new application, on the main menu, click File -> New -> Project (or File -> New Project)
  2. In the Templates list, click Windows Application and set the name to PayrollProcessing1
  3. Click OK
  4. Design the form as follows:
     
    Payroll Processing
    Control Name Text Other Properties
    GroupBox GroupBox   Employee Identification  
    Label Label   &Employee Name:  
    TextBox TextBox txtEmployeeName    
    Label Label   Hourly &Salary:  
    TextBox TextBox txtHourlySalary    
    GroupBox GroupBox   Time Values  
    Label Label   Monday  
    Label Label   Tuesday  
    Label Label   Wednesday  
    Label Label   Thursday  
    Label Label   Friday  
    Label Label   Saturday  
    Label Label   Sunday  
    Label Label   First Week:  
    TextBox TextBox txtMonday1 0.00 TextAlign: Right
    TextBox TextBox txtTuesday1 0.00 TextAlign: Right
    TextBox TextBox txtWednesday1 0.00 TextAlign: Right
    TextBox TextBox txtThursday1 0.00 TextAlign: Right
    TextBox TextBox txtFriday1 0.00 TextAlign: Right
    TextBox TextBox txtSaturday1 0.00 TextAlign: Right
    TextBox TextBox txtSunday1 0.00 TextAlign: Right
    Label Label   Second Week:  
    TextBox TextBox txtMonday2 0.00 TextAlign: Right
    TextBox TextBox txtTuesday2 0.00 TextAlign: Right
    TextBox TextBox txtWednesday2 0.00 TextAlign: Right
    TextBox TextBox txtThursday2 0.00 TextAlign: Right
    TextBox TextBox txtFriday2 0.00 TextAlign: Right
    TextBox TextBox txtSaturday2 0.00 TextAlign: Right
    TextBox TextBox txtSunday2 0.00 TextAlign: Right
    GroupBox GroupBox   Payroll Processing  
    Label Label   Hours  
    Label Label   Amount  
    Button Button btnCalculate Calculate  
    Label Label   Regular  
    TextBox TextBox txtRegularTime 0.00 TextAlign: Right
    TextBox TextBox txtRegularAmount 0.00 TextAlign: Right
    Label Label   Net Pay:  
    TextBox TextBox txtNetPay 0.00 TextAlign: Right
    Label Label   Overtime  
    TextBox TextBox txtOvertime 0.00 TextAlign: Right
    TextBox TextBox txtOvertimeAmount 0.00 TextAlign: Right
    Button Button btnClose    
  5. Double-click the Close button and implement its Click event as follows:
     
    Private Sub btnCloseClick(ByVal sender As System.Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnClose.Click
            End
    End Sub
  6. On the form, click the text box at the intersection of Time and Regular
  7. In the Properties window, double-click ReadOnly to change its value to True
  8. Do the same for the following text boxes: txtRegularAmount, txtNetPay, txtOvertime, and txtOvertimeAmount
  9. On the form, click the txtEmployeeName text box
  10. In the Properties window, click AutoCompleteCustomSource and click its ellipsis button
  11. In the String Collection Editor, enter the following names:
    Micheline Hammond
    Paul Bertrand Yamaguchi
    Gertrude Monay
    Ernestine Ngaleu
    Andy Barang
    Christophe Yuen
    Jean Michel Kankan
  12. Click OK
  13. Click AutoCompleteSource, then click the arrow of its combo box and select CustomSource
  14. Click AutoCompleteMode, then click the arrow of its combo box and select Accept
  15. On the form, double-click the Calculate button and implement its event as follows:
     
    Private Sub btnCalculateClick(ByVal sender As Object, 
                                       ByVal e As System.EventArgs) 
                                       Handles btnCalculate.Click
            Dim Monday1 As Double, Tuesday1 As Double
            Dim Wednesday1 As Double, Thursday1 As Double
            Dim Friday1 As Double, Saturday1 As Double, Sunday1 As Double
            Dim Monday2 As Double, Tuesday2 As Double
            Dim Wednesday2 As Double, Thursday2 As Double
            Dim Friday2 As Double, Saturday2 As Double
            Dim Sunday2 As Double, TotalHoursWeek1 As Double
            Dim TotalHoursWeek2 As Double
    
            Dim regHours1 As Double, regHours2 As Double
            Dim ovtHours1 As Double, ovtHours2 As Double
            Dim regAmount1 As Double, regAmount2 As Double
            Dim ovtAmount1 As Double, ovtAmount2 As Double
            Dim RegularHours As Double, OvertimeHours As Double
            Dim RegularAmount As Double, OvertimeAmount As Double
            Dim TotalEarnings As Double, HourlySalary As Double
    
            ' Retrieve the hourly salary
            Try
                hourlySalary = CDbl(txtHourlySalary.Text)
            Catch
                MsgBox("The value you typed for the salary is invalid" & 
                       vbCrLf & "Please try again")
                txtHourlySalary.Focus()
            End Try
    
            ' Retrieve the value of each day worked
            Try
                monday1 = CDbl(txtMonday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                         "Please try again")
                txtMonday1.Focus()
            End Try
    
            Try
                tuesday1 = CDbl(txtTuesday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtTuesday1.Focus()
            End Try
    
            Try
                wednesday1 = CDbl(txtWednesday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtWednesday1.Focus()
            End Try
    
            Try
                thursday1 = CDbl(txtThursday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtThursday1.Focus()
            End Try
    
            Try
                friday1 = CDbl(txtFriday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtFriday1.Focus()
            End Try
    
            Try
                saturday1 = CDbl(txtSaturday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtSaturday1.Focus()
            End Try
    
            Try
                sunday1 = CDbl(txtSunday1.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtSunday1.Focus()
            End Try
    
            Try
                monday2 = CDbl(txtMonday2.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtMonday2.Focus()
            End Try
    
            Try
                tuesday2 = CDbl(txtTuesday2.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtTuesday2.Focus()
            End Try
    
            Try
                wednesday2 = CDbl(txtWednesday2.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtWednesday2.Focus()
            End Try
    
            Try
                thursday2 = CDbl(txtThursday2.Text)
            Catch
    
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtThursday2.Focus()
            End Try
    
            Try
                friday2 = CDbl(txtFriday2.Text)
            Catch
    
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtFriday2.Focus()
            End Try
    
            Try
                saturday2 = CDbl(txtSaturday2.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtSaturday2.Focus()
            End Try
    
            Try
                sunday2 = CDbl(txtSunday2.Text)
            Catch
                MsgBox("You typed an invalid value" & vbCrLf & 
                    "Please try again")
                txtSunday2.Focus()
            End Try
    
            ' Calculate the total number of hours for each week
            totalHoursWeek1 = monday1 + tuesday1 + wednesday1 + 
                              thursday1 + friday1 + saturday1 + sunday1
            totalHoursWeek2 = monday2 + tuesday2 + wednesday2 + 
                              thursday2 + friday2 + saturday2 + sunday2
    
            ' The overtime is paid time and half
            Dim ovtSalary As Double = HourlySalary * 1.5
    
            ' If the employee worked under 40 hours, there is no overtime
            If TotalHoursWeek1 < 40 Then
    
                regHours1 = TotalHoursWeek1
                regAmount1 = HourlySalary * regHours1
                ovtHours1 = 0.0
                ovtAmount1 = 0.0
                ' If the employee worked over 40 hours, calculate the overtime
            ElseIf TotalHoursWeek1 >= 4 Then
                regHours1 = 40
                regAmount1 = HourlySalary * 40
                ovtHours1 = TotalHoursWeek1 - 40
                ovtAmount1 = ovtHours1 * ovtSalary
            End If
    
            If TotalHoursWeek2 < 40 Then
                regHours2 = TotalHoursWeek2
                regAmount2 = HourlySalary * regHours2
                ovtHours2 = 0.0
                ovtAmount2 = 0.0
            ElseIf TotalHoursWeek2 >= 40 Then
                regHours2 = 40
                regAmount2 = HourlySalary * 40
                ovtHours2 = TotalHoursWeek2 - 40
                ovtAmount2 = ovtHours2 * ovtSalary
            End If
    
            RegularHours = regHours1 + regHours2
            OvertimeHours = ovtHours1 + ovtHours2
            RegularAmount = regAmount1 + regAmount2
            OvertimeAmount = ovtAmount1 + ovtAmount2
            TotalEarnings = RegularAmount + OvertimeAmount
    
            txtRegularTime.Text = RegularHours.ToString("F")
            txtOvertime.Text = OvertimeHours.ToString("F")
            txtRegularAmount.Text = RegularAmount.ToString("F")
            txtOvertimeAmount.Text = OvertimeAmount.ToString("F")
    
            txtNetPay.Text = TotalEarnings.ToString("F")
    End Sub
  16. Execute the application to see the result
     
    Payroll Information
  17. Close the form and return to your programming environment

Download

 

Home Copyright © 2008-2012 FunctionX