%@ LCID = 5129 %>
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"
%>
<%
' Initialize common variables
x_ID = Null: ox_ID = Null: z_ID = Null
x_Group_ID = Null: ox_Group_ID = Null: z_Group_ID = Null
x_Pupil_Name = Null: ox_Pupil_Name = Null: z_Pupil_Name = Null
x_DOB = Null: ox_DOB = Null: z_DOB = Null
x_College = Null: ox_College = Null: z_College = Null
x_Form = Null: ox_Form = Null: z_Form = Null
x_Cell = Null: ox_Cell = Null: z_Cell = Null
x_Dean = Null: ox_Dean = Null: z_Dean = Null
x_Contact1 = Null: ox_Contact1 = Null: z_Contact1 = Null
x_Contact2 = Null: ox_Contact2 = Null: z_Contact2 = Null
x_Address = Null: ox_Address = Null: z_Address = Null
x_Address2 = Null: ox_Address2 = Null: z_Address2 = Null
x_Address3 = Null: ox_Address3 = Null: z_Address3 = Null
x_Subject1 = Null: ox_Subject1 = Null: z_Subject1 = Null
x_Subject2 = Null: ox_Subject2 = Null: z_Subject2 = Null
x_Subject3 = Null: ox_Subject3 = Null: z_Subject3 = Null
x_Subject4 = Null: ox_Subject4 = Null: z_Subject4 = Null
x_Subject5 = Null: ox_Subject5 = Null: z_Subject5 = Null
x_Subject6 = Null: ox_Subject6 = Null: z_Subject6 = Null
x_Subject7 = Null: ox_Subject7 = Null: z_Subject7 = Null
x_Attendance = Null: ox_Attendance = Null: z_Attendance = Null
x_Comments = Null: ox_Comments = Null: z_Comments = Null
x_Date = Null: ox_Date = Null: z_Date = Null
x_AtSchool = Null: ox_AtSchool = Null: z_AtSchool = Null
x_Spare = Null: ox_Spare = Null: z_Spare = Null
%>
<%
Response.Buffer = True
' Load key from QueryString
bCopy = True
x_ID = Request.QueryString("ID")
If x_ID = "" Or IsNull(x_ID) Then
bCopy = False
End If
' Get action
sAction = Request.Form("a_add")
If (sAction = "" Or IsNull(sAction)) Then
If bCopy Then
sAction = "C" ' Copy record
Else
sAction = "I" ' Display blank record
End If
Else
' Get fields from form
x_ID = Request.Form("x_ID")
x_Group_ID = Request.Form("x_Group_ID")
x_Pupil_Name = Request.Form("x_Pupil_Name")
x_DOB = Request.Form("x_DOB")
x_College = Request.Form("x_College")
x_Form = Request.Form("x_Form")
x_Cell = Request.Form("x_Cell")
x_Dean = Request.Form("x_Dean")
x_Contact1 = Request.Form("x_Contact1")
x_Contact2 = Request.Form("x_Contact2")
x_Address = Request.Form("x_Address")
x_Address2 = Request.Form("x_Address2")
x_Address3 = Request.Form("x_Address3")
x_Subject1 = Request.Form("x_Subject1")
x_Subject2 = Request.Form("x_Subject2")
x_Subject3 = Request.Form("x_Subject3")
x_Subject4 = Request.Form("x_Subject4")
x_Subject5 = Request.Form("x_Subject5")
x_Subject6 = Request.Form("x_Subject6")
x_Subject7 = Request.Form("x_Subject7")
x_Attendance = Request.Form("x_Attendance")
x_Comments = Request.Form("x_Comments")
x_Date = Request.Form("x_Date")
x_AtSchool = Request.Form("x_AtSchool")
x_Spare = Request.Form("x_Spare")
End If
' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
Select Case sAction
Case "C": ' Get a record to display
If Not LoadData() Then ' Load Record based on key
Session(ewSessionMessage) = "No records found"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "schoollist.asp"
End If
Case "A": ' Add
If AddData() Then ' Add New Record
Session(ewSessionMessage) = "Add New Record Successful"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "schoollist.asp"
Else
End If
End Select
%>
Add to TABLE: school
Back to List
<%
conn.Close ' Close Connection
Set conn = Nothing
%>
<%
'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables
Function LoadData()
Dim rs, sSql, sFilter
sFilter = ewSqlKeyWhere
sFilter = Replace(sFilter, "@ID", AdjustSql(x_ID)) ' Replace key value
sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSql, conn
If rs.Eof Then
LoadData = False
Else
LoadData = True
rs.MoveFirst
' Get the field contents
x_ID = rs("ID")
x_Group_ID = rs("Group_ID")
x_Pupil_Name = rs("Pupil_Name")
x_DOB = rs("DOB")
x_College = rs("College")
x_Form = rs("Form")
x_Cell = rs("Cell")
x_Dean = rs("Dean")
x_Contact1 = rs("Contact1")
x_Contact2 = rs("Contact2")
x_Address = rs("Address")
x_Address2 = rs("Address2")
x_Address3 = rs("Address3")
x_Subject1 = rs("Subject1")
x_Subject2 = rs("Subject2")
x_Subject3 = rs("Subject3")
x_Subject4 = rs("Subject4")
x_Subject5 = rs("Subject5")
x_Subject6 = rs("Subject6")
x_Subject7 = rs("Subject7")
x_Attendance = rs("Attendance")
x_Comments = rs("Comments")
x_Date = rs("Date")
x_AtSchool = rs("AtSchool")
x_Spare = rs("Spare")
End If
rs.Close
Set rs = Nothing
End Function
%>
<%
'-------------------------------------------------------------------------------
' Function AddData
' - Add Data
' - Variables used: field variables
Function AddData()
Dim rs, sSql, sFilter
Dim bCheckKey, sSqlChk, sWhereChk
sFilter = ewSqlKeyWhere
' Check for duplicate key
bCheckKey = True
If x_ID = "" Or IsNull(x_ID) Then
bCheckKey = False
Else
sFilter = Replace(sFilter, "@ID", AdjustSql(x_ID)) ' Replace key value
End If
If bCheckKey Then
sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
Set rsChk = conn.Execute(sSqlChk)
If Not rsChk.Eof Then
Session(ewSessionMessage) = "Duplicate value for primary key"
rsChk.Close
Set rsChk = Nothing
AddData = False
Exit Function
End If
rsChk.Close
Set rsChk = Nothing
End If
' Add New Record
sFilter = "(0 = 1)"
sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, conn, 1, 2
' Clone new rs object
Dim rsnew
Set rsnew = rs.Clone(1)
rs.AddNew
' Field Group_ID
sTmp = x_Group_ID
If Not IsNumeric(sTmp) Then
sTmp = Null
Else
sTmp = CLng(sTmp)
End If
rs("Group_ID") = sTmp
' Field Pupil_Name
sTmp = Trim(x_Pupil_Name)
If Trim(sTmp) = "" Then sTmp = Null
rs("Pupil_Name") = sTmp
' Field DOB
sTmp = EW_UnFormatDateTime(x_DOB,7)
If IsDate(sTmp) Then
rs("DOB") = CDate(sTmp)
Else
rs("DOB") = Null
End If
' Field College
sTmp = Trim(x_College)
If Trim(sTmp) = "" Then sTmp = Null
rs("College") = sTmp
' Field Form
sTmp = Trim(x_Form)
If Trim(sTmp) = "" Then sTmp = Null
rs("Form") = sTmp
' Field Cell
sTmp = x_Cell
If Not IsNumeric(sTmp) Then
sTmp = Null
Else
sTmp = CLng(sTmp)
End If
rs("Cell") = sTmp
' Field Dean
sTmp = Trim(x_Dean)
If Trim(sTmp) = "" Then sTmp = Null
rs("Dean") = sTmp
' Field Contact1
sTmp = x_Contact1
If Not IsNumeric(sTmp) Then
sTmp = Null
Else
sTmp = CLng(sTmp)
End If
rs("Contact1") = sTmp
' Field Contact2
sTmp = x_Contact2
If Not IsNumeric(sTmp) Then
sTmp = Null
Else
sTmp = CLng(sTmp)
End If
rs("Contact2") = sTmp
' Field Address
sTmp = Trim(x_Address)
If Trim(sTmp) = "" Then sTmp = Null
rs("Address") = sTmp
' Field Address2
sTmp = Trim(x_Address2)
If Trim(sTmp) = "" Then sTmp = Null
rs("Address2") = sTmp
' Field Address3
sTmp = Trim(x_Address3)
If Trim(sTmp) = "" Then sTmp = Null
rs("Address3") = sTmp
' Field Subject1
sTmp = Trim(x_Subject1)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject1") = sTmp
' Field Subject2
sTmp = Trim(x_Subject2)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject2") = sTmp
' Field Subject3
sTmp = Trim(x_Subject3)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject3") = sTmp
' Field Subject4
sTmp = Trim(x_Subject4)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject4") = sTmp
' Field Subject5
sTmp = Trim(x_Subject5)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject5") = sTmp
' Field Subject6
sTmp = Trim(x_Subject6)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject6") = sTmp
' Field Subject7
sTmp = Trim(x_Subject7)
If Trim(sTmp) = "" Then sTmp = Null
rs("Subject7") = sTmp
' Field Attendance
sTmp = Trim(x_Attendance)
If Trim(sTmp) = "" Then sTmp = Null
rs("Attendance") = sTmp
' Field Comments
sTmp = Trim(x_Comments)
If Trim(sTmp) = "" Then sTmp = Null
rs("Comments") = sTmp
' Field Date
sTmp = EW_UnFormatDateTime(x_Date,7)
If IsDate(sTmp) Then
rs("Date") = CDate(sTmp)
Else
rs("Date") = Null
End If
' Field AtSchool
sTmp = x_AtSchool
If sTmp = "Yes" Then
rs("AtSchool") = True
Else
rs("AtSchool") = False
End If
' Field Spare
sTmp = Trim(x_Spare)
If Trim(sTmp) = "" Then sTmp = Null
rs("Spare") = sTmp
' Call recordset inserting event
If Recordset_Inserting(rs) Then
rs.Update
AddData = True
Else
rs.CancelUpdate
AddData = False
End If
rs.Close
Set rs = Nothing
' Call recordset inserted event
If AddData Then
Call Recordset_Inserted(rsnew)
End If
rsnew.Close
Set rsnew = Nothing
End Function
'-------------------------------------------------------------------------------
' Recordset inserting event
Function Recordset_Inserting(rsnew)
On Error Resume Next
' Please enter your customized codes here
Recordset_Inserting = True
End Function
'-------------------------------------------------------------------------------
' Recordset inserted event
Sub Recordset_Inserted(rsnew)
On Error Resume Next
' Get key value
Dim sKey
sKey = ""
If sKey <> "" Then sKey = sKey & ","
sKey = sKey & rsnew.Fields("ID")
x_ID = rsnew.Fields("ID")
End Sub
%>