<%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Countrylist" %> <% 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 Countrylist.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 Countrylist.CurrentAction = objForm.GetValue("a_add") ' Get form action Call LoadFormValues() ' Load form values ' Not post back Else If bCopy Then Countrylist.CurrentAction = "C" ' Copy Record Else Countrylist.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 Countrylist.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(Countrylist.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Countrylist.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(Countrylist.KeyUrl(Countrylist.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Countrylist.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>

Add to TABLE: Countrylist

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 %>

> >
countryname

<% ' 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 Countrylist = 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 Countrylist.countryname.FormValue = objForm.GetValue("x_countryname") End Function ' Restore form values Function RestoreFormValues() Countrylist.countryname.CurrentValue = Countrylist.countryname.FormValue End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Countrylist.SqlKeyFilter If Not IsNumeric(Countrylist.ID.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Countrylist.ID.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Countrylist.Row_Selecting(sFilter) ' Load sql based on filter Countrylist.CurrentFilter = sFilter sSql = Countrylist.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 Countrylist.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Countrylist.ID.DbValue = rs("ID") Countrylist.countryname.DbValue = rs("countryname") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Countrylist.Row_Rendering() ' Common render codes for all row types ' countryname Countrylist.countryname.CellCssStyle = "" Countrylist.countryname.CellCssClass = "" If Countrylist.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Countrylist.RowType = EW_ROWTYPE_ADD Then ' Add row ' countryname Countrylist.countryname.EditCustomAttributes = "" Countrylist.countryname.EditValue = ew_HtmlEncode(Countrylist.countryname.CurrentValue) ElseIf Countrylist.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Countrylist.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Countrylist.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 = Countrylist.SqlKeyFilter If Countrylist.ID.CurrentValue = "" Or IsNull(Countrylist.ID.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Countrylist.ID.CurrentValue)) ' Replace key value End If If Not IsNumeric(Countrylist.ID.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Countrylist.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)" Countrylist.CurrentFilter = sFilter sSql = Countrylist.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 countryname Call Countrylist.countryname.SetDbValue(Countrylist.countryname.CurrentValue, Null) rs("countryname") = Countrylist.countryname.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 = Countrylist.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 Countrylist.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Countrylist.CancelMessage Countrylist.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Countrylist.ID.DbValue = rsnew("ID") ' Call Row Inserted event Call Countrylist.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" End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>