%@ LANGUAGE="VBSCRIPT" TRANSACTION=REQUIRED %>
<% Option Explicit %>
<%
Dim m_strFirstName, m_strLastName, m_strMiddleName, m_strKnownAs, m_strSSN, _
m_intGender, m_datBirthdate, m_strAddress1, _
m_strAddress2, m_strCity, m_strState, m_strPostCode, m_strCountry, m_strHomePhone, _
m_strBusinessPhone, m_strFax, m_strEmail, _
m_lngExemptions, m_lngEmployeeGeoAreaId, m_intEmployeeStatus, m_strMainPrompt, _
m_strNTUserName, m_UpdateMessage
'
' This block determines whether to display the page, or Update the
' database and then redirect.
'
m_UpdateMessage = ""
If Request.Form("SubmitProfile") <> "" Then
GetValuesFromForm
If UpdateDatabase = 0 Then ' database update occurred successfully
If Request.Form("SubmitProfile") = "Add Dependent" Then
Response.Redirect("DependentAdd.asp")
Response.End
Else
m_UpdateMessage = " Language=JavaScript " & _
"onLoad=" & Chr(34) & "{ alert ('Your Employee Record was updated.');}" & Chr(34)
End If
End If
Else
GetValuesFromDatabase
If Request.QueryString("DepAddSuccess") = 1 Then
m_UpdateMessage = " Language=JavaScript " & _
"onLoad=" & Chr(34) & "{ alert ('Your Employee Record was updated.');}" & Chr(34)
End If
End If
m_strMainPrompt = "To make changes, fill out the form below. " & _
"The items listed in bold and marked by a blue dot are required. " & _
"Click Save or Add Dependent when you are finished."
%>
<%
'
' Begin server side helper functions
'
'
' Create Select list of Genders
'
Sub BuildGenderList
Dim BenefitList, rstGenderList
Set BenefitList = Server.CreateObject("Benefit.BenefitList")
Set rstGenderList = BenefitList.GenderList(Application("DSNBenefits"))
Response.Write "" & Chr(13)
End Sub
'
' Set page level variables to values retrieved from database
'
Sub GetValuesFromDatabase()
Dim Employee, rstEmployee
Set Employee = Server.CreateObject("Benefit.Employee")
rstEmployee = Employee.GetForID(Application("DSNBenefits"), Session("EmployeeID"))
' This is the employee's own dependent id
Session("DependentId") = rstEmployee("DependentId")
m_strNTUserName = rstEmployee("NTUserName")
m_strFirstName = rstEmployee("FirstName")
m_strLastName = rstEmployee("LastName")
m_strMiddleName = rstEmployee("MiddleName")
m_strKnownAs = rstEmployee("KnownAs")
m_strSSN = rstEmployee("DependentSSN")
m_intGender = rstEmployee("DependentGenderId")
m_datBirthdate = rstEmployee("DependentBirthdate")
m_strAddress1 = rstEmployee("Address1")
m_strAddress2 = rstEmployee("Address2")
m_strCity = rstEmployee("City")
m_strState = rstEmployee("State")
m_strPostCode = rstEmployee("PostCode")
m_strCountry = rstEmployee("Country")
m_strHomePhone = rstEmployee("HomePhone")
m_strBusinessPhone = rstEmployee("BusinessPhone")
m_strFax = rstEmployee("Fax")
m_strEmail = rstEmployee("Email")
m_lngExemptions = rstEmployee("Exemptions")
End Sub
'
' Generate the rows for a table consisting of the Dependent info for this Employee
'
Sub ListDependents
Dim Employee, rstDependents
Set Employee = Server.CreateObject("Benefit.Employee")
Set rstDependents = Employee.GetDependents(Application("DSNBenefits"), Session("EmployeeId"))
If rstDependents.EOF Then
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Response.Write "
" & Chr(13)
Else
Do Until rstDependents.EOF
Response.Write "
" & Chr(13)
rstDependents.MoveNext
Loop
End If
End Sub
'
' Create Select list of Dependent Genders
'
Sub BuildDepGenderList (ByVal DependentGenderId)
Dim BenefitList, rstGenderList
Set BenefitList = Server.CreateObject("Benefit.BenefitList")
Set rstGenderList = BenefitList.GenderList(Application("DSNBenefits"))
Response.Write "" & Chr(13)
End Sub
'
' Take values from the submitted form and assign to page level variables.
' These variables will in turn be passed to the database. If the database
' update fails, the form will be displayed again with these values filled
' into the correct fields.
'
Sub GetValuesFromForm
m_strFirstName = Trim(Request.Form("FirstName"))
m_strLastName = Trim(Request.Form("LastName"))
m_strMiddleName = Trim(Request.Form("MiddleName"))
m_strKnownAs = Trim(Request.Form("KnownAs"))
m_strSSN = Trim(Request.Form("SSN"))
m_intGender = Trim(Request.Form("Gender"))
m_datBirthdate = Trim(Request.Form("Birthdate"))
If Not IsDate(m_datBirthdate) Then
m_datBirthdate = Now()
End If
m_strAddress1 = Trim(Request.Form("Address1"))
m_strAddress2 = Trim(Request.Form("Address2"))
m_strCity = Trim(Request.Form("City"))
m_strState = Trim(Request.Form("State"))
m_strPostCode = Trim(Request.Form("PostCode"))
m_strCountry = Trim(Request.Form("Country"))
m_strHomePhone = Trim(Request.Form("HomePhone"))
m_strBusinessPhone = Trim(Request.Form("BusinessPhone"))
m_strFax = Trim(Request.Form("Fax"))
m_strEmail = Trim(Request.Form("Email"))
m_lngExemptions = Trim(Request.Form("Exemptions"))
If Not IsNumeric(m_lngExemptions) Then
m_lngExemptions = 1
End If
End Sub
'
' Update the database. Return 0 if successful or 1 if an error is encountered.
'
Function UpdateDatabase
On Error Resume Next
Dim Employee, i
Set Employee = Server.CreateObject("Benefit.Employee")
Employee.Update Application("DSNBenefits"), Session("EmployeeId"), Session("DependentId"), _
m_strFirstName, m_strLastName, _
m_strMiddleName, m_strKnownAs, m_strSSN, _
m_intGender, m_datBirthdate, m_strAddress1, m_strAddress2, _
m_strCity, m_strState, m_strPostCode, m_strCountry, m_strHomePhone, _
m_strBusinessPhone, m_strFax, m_strEmail, m_lngExemptions
' Save Dependent records
For i = 1 to Request.Form("DependentId").Count
Employee.UpdateDependent Application("DSNBenefits"), Request.Form("DependentId")(i), _
Request.Form("DependentSSN")(i), Request.Form("DependentGender")(i), _
Request.Form("DependentBirthdate")(i)
Next
' Process any Dependents marked for Removal (Change status to 2 for inactive )
For i = 1 to Request.Form("RemoveDep").Count
Employee.RemoveDependent Application("DSNBenefits"), Session("EmployeeId"), _
Request.Form("RemoveDep")(i)
Next
If Err.Number = 0 Then
UpdateDatabase = 0
Else
ContextObject.SetAbort
UpdateDatabase = 1
End If
End Function
Sub OnTransactionCommit
End Sub
Sub OnTransactionAbort
m_strMainPrompt = "A problem occurred while trying to update the database. Please try again later. "
End Sub
%>