Dim mth As String = "February"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
BuildTimesheet()
End Sub
Public Sub BuildTimesheet()
Dim objTbl As Table
Dim objRow As TableRow
Dim objCell As TableCell
Dim objLB As Label
Dim objTB As TextBox
Dim NumDays As Integer
Dim cntr As Integer
NumDays = Day(DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, CDate("01/" & mth & "/" & Date.Today.Year))))
objTbl = Table2
objTbl.CellSpacing = 0
''---------------------------
'' Heading Row for Day number
''---------------------------
objRow = New TableRow()
objTbl.Rows.Add(objRow)
objCell = New TableCell()
objLB = New Label()
objLB.Text = ""
objLB.Width = Unit.Parse("160")
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
For cntr = 1 To NumDays
objLB = New Label()
objLB.Text = cntr.ToString
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
Next
objLB = New Label()
objLB.Text = "Total"
objLB.Font.Bold = True
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
''---------------------------
'' Travel Time Row
''---------------------------
objRow = New TableRow()
objTbl.Rows.Add(objRow)
objCell = New TableCell()
objLB = New Label()
objLB.Text = "Travel Time"
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
For cntr = 1 To NumDays
objTB = New TextBox()
objTB.Width = Unit.Parse("40")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.ID = "TT" & cntr.ToString
objTB.Font.Bold = True
objTB.AutoPostBack = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
AddHandler objTB.TextChanged, AddressOf CalcTotals
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
Next
objTB = New TextBox()
objTB.Width = Unit.Parse("60")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.Font.Bold = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
objTB.ID = "TTTOTAL"
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
''---------------------------
'' Over Time 150% Row
''---------------------------
objRow = New TableRow()
objTbl.Rows.Add(objRow)
objCell = New TableCell()
objLB = New Label()
objLB.Text = "Overtime 150%"
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
For cntr = 1 To NumDays
objTB = New TextBox()
objTB.Width = Unit.Parse("40")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.ID = "OT150" & cntr.ToString
objTB.Font.Bold = True
objTB.AutoPostBack = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
AddHandler objTB.TextChanged, AddressOf CalcTotals
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
Next
objTB = New TextBox()
objTB.Width = Unit.Parse("60")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.Font.Bold = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
objTB.ID = "OT150TOTAL"
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
''---------------------------
'' Over Time 200% Row
''---------------------------
objRow = New TableRow()
objTbl.Rows.Add(objRow)
objCell = New TableCell()
objLB = New Label()
objLB.Text = "Overtime 200%"
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
For cntr = 1 To NumDays
objTB = New TextBox()
objTB.Width = Unit.Parse("40")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.ID = "OT200" & cntr.ToString
objTB.Font.Bold = True
objTB.AutoPostBack = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
AddHandler objTB.TextChanged, AddressOf CalcTotals
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
Next
objTB = New TextBox()
objTB.Width = Unit.Parse("60")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.Font.Bold = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
objTB.ID = "OT200TOTAL"
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
''---------------------------
'' Compensatory Days Row
''---------------------------
objRow = New TableRow()
objTbl.Rows.Add(objRow)
objCell = New TableCell()
objLB = New Label()
objLB.Text = "Compensatory Days"
objCell.Controls.Add(objLB)
objRow.Cells.Add(objCell)
For cntr = 1 To NumDays
objTB = New TextBox()
objTB.Width = Unit.Parse("40")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.ID = "CompDays" & cntr.ToString
objTB.Font.Bold = True
objTB.AutoPostBack = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
AddHandler objTB.TextChanged, AddressOf CalcTotals
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
Next
objTB = New TextBox()
objTB.Width = Unit.Parse("60")
objTB.BorderColor = Color.White
objTB.BorderStyle = BorderStyle.None
objTB.Font.Bold = True
objTB.Attributes("style") = "TEXT-ALIGN: center"
objTB.ID = "CompDaysTotal"
objCell = New TableCell()
objCell.HorizontalAlign = HorizontalAlign.Center
objCell.Controls.Add(objTB)
objRow.Cells.Add(objCell)
End Sub
Public Sub CalcTotals(ByVal objSender As Object, ByVal objArgs As EventArgs)
Dim tb As Table
Dim ttl As Double
Dim txt As TextBox
Dim cntr As Integer
Dim NumDays As Integer
NumDays = Day(DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, CDate("01/" & mth & "/" & Date.Today.Year))))
tb = Table2
For cntr = 1 To NumDays
txt = CType(tb.FindControl("TT" & cntr.ToString), TextBox)
If txt.Text <> "" Then
ttl += Val(txt.Text)
End If
Next
txt = CType(tb.FindControl("TTTOTAL"), TextBox)
txt.Text = ttl.ToString
ttl = 0
For cntr = 1 To NumDays
txt = CType(tb.FindControl("OT150" & cntr.ToString), TextBox)
If txt.Text <> "" Then
ttl += Val(txt.Text)
End If
Next
txt = CType(tb.FindControl("OT150TOTAL"), TextBox)
txt.Text = ttl.ToString
ttl = 0
For cntr = 1 To NumDays
txt = CType(tb.FindControl("OT200" & cntr.ToString), TextBox)
If txt.Text <> "" Then
ttl += Val(txt.Text)
End If
Next
txt = CType(tb.FindControl("OT200TOTAL"), TextBox)
txt.Text = ttl.ToString
ttl = 0
For cntr = 1 To NumDays
txt = CType(tb.FindControl("CompDays" & cntr.ToString), TextBox)
If txt.Text <> "" Then
ttl += Val(txt.Text)
End If
Next
txt = CType(tb.FindControl("CompDaysTOTAL"), TextBox)
txt.Text = ttl.ToString
End Sub