<%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Clubs" %> <% Session.Timeout = 100 %> <% Response.Expires = 0 Response.ExpiresAbsolute = Now() - 1 Response.AddHeader "pragma", "no-cache" Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate" %> <% ' Open connection to the database Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.Open EW_DB_CONNECTION_STRING %> <% Dim Security Set Security = New cAdvancedSecurity %> <% If Not Security.IsLoggedIn() Then Call Security.AutoLogin() If Not Security.IsLoggedIn() Then Call Security.SaveLastUrl() Call Page_Terminate("login.asp") End If %> <% ' Common page loading event (in userfn60.asp) Call Page_Loading() %> <% ' Page load event, used in current page Call Page_Load() %> <% Response.Buffer = True ' Load key values from QueryString Dim bCopy bCopy = True If Request.QueryString("ID").Count > 0 Then Clubs.ID.QueryStringValue = Request.QueryString("ID") Else bCopy = False End If ' Create form object Dim objForm Set objForm = New cFormObj ' Process form if post back If objForm.GetValue("a_add")&"" <> "" Then Clubs.CurrentAction = objForm.GetValue("a_add") ' Get form action Call LoadFormValues() ' Load form values ' Not post back Else If bCopy Then Clubs.CurrentAction = "C" ' Copy Record Else Clubs.CurrentAction = "I" ' Display Blank Record Call LoadDefaultValues() ' Load default values End If End If ' Close form object Set objForm = Nothing ' Perform action based on action code Select Case Clubs.CurrentAction Case "I" ' Blank record, no action required Case "C" ' Copy an existing record If Not LoadRow() Then ' Load record based on key Session(EW_SESSION_MESSAGE) = "No records found" ' No record found Call Page_Terminate(Clubs.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Clubs.SendEmail = True ' Send email on add success If AddRow() Then ' Add successful Session(EW_SESSION_MESSAGE) = "Add New Record Successful" ' Set up success message Call Page_Terminate(Clubs.KeyUrl(Clubs.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Clubs.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>

Add to TABLE: Clubs

Go Back

<% If Session(EW_SESSION_MESSAGE) <> "" Then ' Mesasge in Session, display %>

<%= Session(EW_SESSION_MESSAGE) %>

<% Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session End If %>

> > > > > > > > > > > > > > > >
Name *
City
Country
Email
Contact Person
Telephone
Mobile
Address
Fax

<% ' If control is passed here, simply terminate the page without redirect Call Page_Terminate("") ' ----------------------------------------------------------------- ' Subroutine Page_Terminate ' - called when exit page ' - clean up ADO connection and objects ' - if url specified, redirect to url, otherwise end response ' Sub Page_Terminate(url) ' Page unload event, used in current page Call Page_Unload() ' Global page unloaded event (in userfn60.asp) Call Page_Unloaded() conn.Close ' Close Connection Set conn = Nothing Set Security = Nothing Set Clubs = Nothing ' Go to url if specified If url <> "" Then Response.Clear Response.Redirect url End If ' Terminate response Response.End End Sub ' ' Subroutine Page_Terminate (End) ' ---------------------------------------- %> <% ' Load default values Function LoadDefaultValues() End Function %> <% ' Load form values Function LoadFormValues() ' Load from form Clubs.Name.FormValue = objForm.GetValue("x_Name") Clubs.City.FormValue = objForm.GetValue("x_City") Clubs.Country.FormValue = objForm.GetValue("x_Country") Clubs.Email.FormValue = objForm.GetValue("x_Email") Clubs.Contact_Person.FormValue = objForm.GetValue("x_Contact_Person") Clubs.Telephone.FormValue = objForm.GetValue("x_Telephone") Clubs.Mobile.FormValue = objForm.GetValue("x_Mobile") Clubs.Address.FormValue = objForm.GetValue("x_Address") Clubs.Fax.FormValue = objForm.GetValue("x_Fax") End Function ' Restore form values Function RestoreFormValues() Clubs.Name.CurrentValue = Clubs.Name.FormValue Clubs.City.CurrentValue = Clubs.City.FormValue Clubs.Country.CurrentValue = Clubs.Country.FormValue Clubs.Email.CurrentValue = Clubs.Email.FormValue Clubs.Contact_Person.CurrentValue = Clubs.Contact_Person.FormValue Clubs.Telephone.CurrentValue = Clubs.Telephone.FormValue Clubs.Mobile.CurrentValue = Clubs.Mobile.FormValue Clubs.Address.CurrentValue = Clubs.Address.FormValue Clubs.Fax.CurrentValue = Clubs.Fax.FormValue End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Clubs.SqlKeyFilter If Not IsNumeric(Clubs.ID.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Clubs.ID.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Clubs.Row_Selecting(sFilter) ' Load sql based on filter Clubs.CurrentFilter = sFilter sSql = Clubs.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadRow = False Else LoadRow = True rs.MoveFirst Call LoadRowValues(rs) ' Load row values ' Call Row Selected event Call Clubs.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Clubs.ID.DbValue = rs("ID") Clubs.Name.DbValue = rs("Name") Clubs.City.DbValue = rs("City") Clubs.Country.DbValue = rs("Country") Clubs.Email.DbValue = rs("Email") Clubs.Contact_Person.DbValue = rs("Contact_Person") Clubs.Telephone.DbValue = rs("Telephone") Clubs.Mobile.DbValue = rs("Mobile") Clubs.Address.DbValue = rs("Address") Clubs.Fax.DbValue = rs("Fax") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Clubs.Row_Rendering() ' Common render codes for all row types ' Name Clubs.Name.CellCssStyle = "" Clubs.Name.CellCssClass = "" ' City Clubs.City.CellCssStyle = "" Clubs.City.CellCssClass = "" ' Country Clubs.Country.CellCssStyle = "" Clubs.Country.CellCssClass = "" ' Email Clubs.Email.CellCssStyle = "" Clubs.Email.CellCssClass = "" ' Contact_Person Clubs.Contact_Person.CellCssStyle = "" Clubs.Contact_Person.CellCssClass = "" ' Telephone Clubs.Telephone.CellCssStyle = "" Clubs.Telephone.CellCssClass = "" ' Mobile Clubs.Mobile.CellCssStyle = "" Clubs.Mobile.CellCssClass = "" ' Address Clubs.Address.CellCssStyle = "" Clubs.Address.CellCssClass = "" ' Fax Clubs.Fax.CellCssStyle = "" Clubs.Fax.CellCssClass = "" If Clubs.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Clubs.RowType = EW_ROWTYPE_ADD Then ' Add row ' Name Clubs.Name.EditCustomAttributes = "" Clubs.Name.EditValue = ew_HtmlEncode(Clubs.Name.CurrentValue) ' City Clubs.City.EditCustomAttributes = "" Clubs.City.EditValue = ew_HtmlEncode(Clubs.City.CurrentValue) ' Country Clubs.Country.EditCustomAttributes = "" sSqlWrk = "SELECT [ID], [countryname] FROM [Countrylist]" sSqlWrk = sSqlWrk & " ORDER BY [countryname] Asc" Set rswrk = Server.CreateObject("ADODB.Recordset") rswrk.Open sSqlWrk, conn If Not rswrk.Eof Then arwrk = rswrk.GetRows Else arwrk = "" End If rswrk.Close Set rswrk = Nothing arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Clubs.Country.EditValue = arwrk ' Email Clubs.Email.EditCustomAttributes = "" Clubs.Email.EditValue = ew_HtmlEncode(Clubs.Email.CurrentValue) ' Contact_Person Clubs.Contact_Person.EditCustomAttributes = "" Clubs.Contact_Person.EditValue = ew_HtmlEncode(Clubs.Contact_Person.CurrentValue) ' Telephone Clubs.Telephone.EditCustomAttributes = "" Clubs.Telephone.EditValue = ew_HtmlEncode(Clubs.Telephone.CurrentValue) ' Mobile Clubs.Mobile.EditCustomAttributes = "" Clubs.Mobile.EditValue = ew_HtmlEncode(Clubs.Mobile.CurrentValue) ' Address Clubs.Address.EditCustomAttributes = "" Clubs.Address.EditValue = Clubs.Address.CurrentValue ' Fax Clubs.Fax.EditCustomAttributes = "" Clubs.Fax.EditValue = ew_HtmlEncode(Clubs.Fax.CurrentValue) ElseIf Clubs.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Clubs.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Clubs.Row_Rendered() End Sub %> <% ' Add record Function AddRow() On Error Resume Next Dim rs, sSql, sFilter Dim rsnew Dim bCheckKey, sSqlChk, sWhereChk, rsChk Dim bInsertRow ' Check for duplicate key bCheckKey = True sFilter = Clubs.SqlKeyFilter If Clubs.ID.CurrentValue = "" Or IsNull(Clubs.ID.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Clubs.ID.CurrentValue)) ' Replace key value End If If Not IsNumeric(Clubs.ID.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Clubs.LoadRs(sFilter) If Not (rsChk Is Nothing) Then Session(EW_SESSION_MESSAGE) = "Duplicate value for primary key" rsChk.Close Set rsChk = Nothing AddRow = False Exit Function End If End If ' Add new record sFilter = "(0 = 1)" Clubs.CurrentFilter = sFilter sSql = Clubs.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 rs.AddNew If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing AddRow = False Exit Function End If ' Field Name Call Clubs.Name.SetDbValue(Clubs.Name.CurrentValue, Null) rs("Name") = Clubs.Name.DbValue ' Field City Call Clubs.City.SetDbValue(Clubs.City.CurrentValue, Null) rs("City") = Clubs.City.DbValue ' Field Country Call Clubs.Country.SetDbValue(Clubs.Country.CurrentValue, Null) rs("Country") = Clubs.Country.DbValue ' Field Email Call Clubs.Email.SetDbValue(Clubs.Email.CurrentValue, Null) rs("Email") = Clubs.Email.DbValue ' Field Contact_Person Call Clubs.Contact_Person.SetDbValue(Clubs.Contact_Person.CurrentValue, Null) rs("Contact_Person") = Clubs.Contact_Person.DbValue ' Field Telephone Call Clubs.Telephone.SetDbValue(Clubs.Telephone.CurrentValue, Null) rs("Telephone") = Clubs.Telephone.DbValue ' Field Mobile Call Clubs.Mobile.SetDbValue(Clubs.Mobile.CurrentValue, Null) rs("Mobile") = Clubs.Mobile.DbValue ' Field Address Call Clubs.Address.SetDbValue(Clubs.Address.CurrentValue, Null) rs("Address") = Clubs.Address.DbValue ' Field Fax Call Clubs.Fax.SetDbValue(Clubs.Fax.CurrentValue, Null) rs("Fax") = Clubs.Fax.DbValue ' Check recordset update error If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing AddRow = False Exit Function End If ' Call Row Inserting event bInsertRow = Clubs.Row_Inserting(rs) If bInsertRow Then ' Clone new rs object Set rsnew = ew_CloneRs(rs) rs.Update If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description AddRow = False Else AddRow = True End If Else rs.CancelUpdate If Clubs.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Clubs.CancelMessage Clubs.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Clubs.ID.DbValue = rsnew("ID") ' Call Row Inserted event Call Clubs.Row_Inserted(rsnew) End If If IsObject(rsnew) Then rsnew.Close Set rsnew = Nothing End If End Function %> <% ' Page Load event Sub Page_Load() '***Response.Write "Page Load" Server.ScriptTimeout=1000 Server.ScriptTimeout = 500 End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>