%@ CodePage=65001 %> <% Const EW_PAGE_ID = "delete" 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 Dim sKey, bSingleDelete, arRecKeys, nKeySelected Dim sKeyFld, arKeyFlds Dim i Dim sFilter Dim nRecCount ' Load Key Parameters sKey = "" bSingleDelete = True ' Initialize as single delete nKeySelected = 0 ' Initialize selected key count If Request.QueryString("ID").Count > 0 Then Clubs.ID.QueryStringValue = Request.QueryString("ID") If Not IsNumeric(Clubs.ID.QueryStringValue) Then Call Page_Terminate(Clubs.ReturnUrl) ' Prevent sql injection, exit End If sKey = sKey & Clubs.ID.QueryStringValue Else bSingleDelete = False End If If bSingleDelete Then nKeySelected = 1 ' Set up key selected count Redim arRecKeys(0) ' Set up key arRecKeys(0) = sKey Else If Request.Form("key_m").Count > 0 Then ' Key in form nKeySelected = Request.Form("key_m").Count ' Set up key selected count Redim arRecKeys(nKeySelected-1) For i = 1 to nKeySelected ' Set up keys arRecKeys(i-1) = Request.Form("key_m")(i) Next End If End If If nKeySelected <= 0 Then Call Page_Terminate(Clubs.ReturnUrl) ' No key specified, exit ' Build filter For i = 0 to nKeySelected - 1 sKey = Trim(arRecKeys(i)) sFilter = sFilter & "(" ' Set up key field sKeyFld = sKey If Not IsNumeric(sKeyFld) Then Call Page_Terminate(Clubs.ReturnUrl) ' Prevent sql injection, exit End If sFilter = sFilter & "[ID]=" & ew_AdjustSql(sKeyFld) & " AND " If Right(sFilter, 5) = " AND " Then sFilter = Left(sFilter, Len(sFilter)-5) & ") OR " Next If Right(sFilter, 4) = " OR " Then sFilter = Left(sFilter, Len(sFilter)-4) ' Set up filter (Sql Where Clause) and get Return Sql ' Sql constructor in Clubs class, Clubsinfo.asp Clubs.CurrentFilter = sFilter ' Get action If Request.Form("a_delete").Count > 0 Then Clubs.CurrentAction = Request.Form("a_delete") Else Clubs.CurrentAction = "D" ' Delete record directly End If Select Case Clubs.CurrentAction Case "D" ' Delete Clubs.SendEmail = True ' Send email on delete success If DeleteRows() Then ' delete rows Session(EW_SESSION_MESSAGE) = "Delete Successful" ' Set up success message Call Page_Terminate(Clubs.ReturnUrl) ' Return to caller End If End Select ' Load records for display Dim rs, nTotalRecs Set rs = LoadRecordset() nTotalRecs = rs.RecordCount ' Get record count If nTotalRecs <= 0 Then ' No record found, exit rs.Close Set rs = Nothing Call Page_Terminate(Clubs.ReturnUrl) ' Return to caller End If %>
Delete from TABLE: Clubs
Go Back
<%= Session(EW_SESSION_MESSAGE) %>
<% Session(EW_SESSION_MESSAGE) = "" ' Clear message End If %> <% ' 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) ' ---------------------------------------- %> <% ' ------------------------------------------------ ' Function DeleteRows ' - Delete Records based on current filter ' Function DeleteRows() On Error Resume Next Dim sKey, sThisKey, sKeyFld, arKeyFlds Dim rs, sSql, sWrkFilter Dim rsold DeleteRows = True sWrkFilter = Clubs.CurrentFilter ' Set up filter (Sql Where Clause) and get Return Sql ' Sql constructor in Clubs class, Clubsinfo.asp Clubs.CurrentFilter = sWrkFilter sSql = Clubs.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing DeleteRows = False Exit Function ElseIf rs.Eof Then Session(EW_SESSION_MESSAGE) = "No records found" ' No record found rs.Close Set rs = Nothing DeleteRows = False Exit Function End If conn.BeginTrans ' Clone old rs object Set rsold = ew_CloneRs(rs) ' Call recordset deleting event If DeleteRows Then DeleteRows = Clubs.Recordset_Deleting(rs) If DeleteRows Then sKey = "" If Not rs.Eof Then rs.MoveFirst Do While Not rs.Eof sThisKey = "" If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR sThisKey = sThisKey & rs("ID") rs.Delete If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description ' Set up error message DeleteRows = False Exit Do End If If sKey <> "" Then sKey = sKey & ", " sKey = sKey & sThisKey rs.MoveNext Loop Else ' Set up error message If Clubs.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Clubs.CancelMessage Clubs.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Delete cancelled" End If End If If DeleteRows Then conn.CommitTrans ' Commit the changes If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description DeleteRows = False ' Delet failed Else End If Else conn.RollbackTrans ' Rollback changes End If rs.Close Set rs = Nothing ' Call recordset deleted event If DeleteRows Then Call Clubs.Recordset_Deleted(rsold) rsold.Close Set rsold = Nothing End Function %> <% ' Load recordset Function LoadRecordset() ' Call Recordset Selecting event Call Clubs.Recordset_Selecting(Clubs.CurrentFilter) ' Load list page sql Dim sSql sSql = Clubs.ListSQL ' Response.Write sSql ' Uncomment to show SQL for debugging ' Load recordset Dim rs Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 ' Call Recordset Selected event Call Clubs.Recordset_Selected(rs) Set LoadRecordset = rs 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 ' ID Clubs.ID.CellCssStyle = "" Clubs.ID.CellCssClass = "" ' Name Clubs.Name.CellCssStyle = "" Clubs.Name.CellCssClass = "" ' City Clubs.City.CellCssStyle = "" Clubs.City.CellCssClass = "" ' Email Clubs.Email.CellCssStyle = "" Clubs.Email.CellCssClass = "" ' Contact_Person Clubs.Contact_Person.CellCssStyle = "" Clubs.Contact_Person.CellCssClass = "" If Clubs.RowType = EW_ROWTYPE_VIEW Then ' View row ' ID Clubs.ID.ViewValue = Clubs.ID.CurrentValue Clubs.ID.CssStyle = "" Clubs.ID.CssClass = "" Clubs.ID.ViewCustomAttributes = "" ' Name Clubs.Name.ViewValue = Clubs.Name.CurrentValue Clubs.Name.CssStyle = "" Clubs.Name.CssClass = "" Clubs.Name.ViewCustomAttributes = "" ' City Clubs.City.ViewValue = Clubs.City.CurrentValue Clubs.City.CssStyle = "" Clubs.City.CssClass = "" Clubs.City.ViewCustomAttributes = "" ' Email Clubs.Email.ViewValue = Clubs.Email.CurrentValue Clubs.Email.CssStyle = "" Clubs.Email.CssClass = "" Clubs.Email.ViewCustomAttributes = "" ' Contact_Person Clubs.Contact_Person.ViewValue = Clubs.Contact_Person.CurrentValue Clubs.Contact_Person.CssStyle = "" Clubs.Contact_Person.CssClass = "" Clubs.Contact_Person.ViewCustomAttributes = "" ' ID ' *** view refer script Clubs.ID.HrefValue = "" ' Name ' *** view refer script Clubs.Name.HrefValue = "" ' City ' *** view refer script Clubs.City.HrefValue = "" ' Email ' *** view refer script Clubs.Email.HrefValue = "" ' Contact_Person ' *** view refer script Clubs.Contact_Person.HrefValue = "" ElseIf Clubs.RowType = EW_ROWTYPE_ADD Then ' Add row 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 %> <% ' Page Load event Sub Page_Load() '***Response.Write "Page Load" End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>