%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Wall_Papers" %> <% 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 Wall_Papers.ID.QueryStringValue = Request.QueryString("ID") Else bCopy = False End If ' Create form object Dim objForm Set objForm = ew_GetUploadObj() ' Process form if post back If objForm.GetValue("a_add")&"" <> "" Then Wall_Papers.CurrentAction = objForm.GetValue("a_add") ' Get form action Call GetUploadFiles() ' Get upload files Call LoadFormValues() ' Load form values ' Not post back Else If bCopy Then Wall_Papers.CurrentAction = "C" ' Copy Record Else Wall_Papers.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 Wall_Papers.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(Wall_Papers.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Wall_Papers.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(Wall_Papers.KeyUrl(Wall_Papers.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Wall_Papers.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>
Add to TABLE: Wall Papers
Go Back
<%= Session(EW_SESSION_MESSAGE) %>
<% Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session 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 Wall_Papers = 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 Get upload files Function GetUploadFiles() ' Get upload data If Wall_Papers.Wall_Paper_Thumb.Upload.UploadFile() Then ' No action required Else Response.Write Wall_Papers.Wall_Paper_Thumb.Upload.Message Response.End End If If Wall_Papers.Wall_Paper_Image.Upload.UploadFile() Then ' No action required Else Response.Write Wall_Papers.Wall_Paper_Image.Upload.Message Response.End End If End Function %> <% ' Load default values Function LoadDefaultValues() End Function %> <% ' Load form values Function LoadFormValues() ' Load from form Wall_Papers.Wall_Paper_Name.FormValue = objForm.GetValue("x_Wall_Paper_Name") End Function ' Restore form values Function RestoreFormValues() Wall_Papers.Wall_Paper_Name.CurrentValue = Wall_Papers.Wall_Paper_Name.FormValue End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Wall_Papers.SqlKeyFilter If Not IsNumeric(Wall_Papers.ID.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Wall_Papers.ID.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Wall_Papers.Row_Selecting(sFilter) ' Load sql based on filter Wall_Papers.CurrentFilter = sFilter sSql = Wall_Papers.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 Wall_Papers.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Wall_Papers.ID.DbValue = rs("ID") Wall_Papers.Wall_Paper_Name.DbValue = rs("Wall_Paper_Name") Wall_Papers.Wall_Paper_Thumb.Upload.DbValue = rs("Wall_Paper_Thumb") Wall_Papers.Wall_Paper_Image.Upload.DbValue = rs("Wall_Paper_Image") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Wall_Papers.Row_Rendering() ' Common render codes for all row types ' Wall_Paper_Name Wall_Papers.Wall_Paper_Name.CellCssStyle = "" Wall_Papers.Wall_Paper_Name.CellCssClass = "" ' Wall_Paper_Thumb Wall_Papers.Wall_Paper_Thumb.CellCssStyle = "" Wall_Papers.Wall_Paper_Thumb.CellCssClass = "" ' Wall_Paper_Image Wall_Papers.Wall_Paper_Image.CellCssStyle = "" Wall_Papers.Wall_Paper_Image.CellCssClass = "" If Wall_Papers.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Wall_Papers.RowType = EW_ROWTYPE_ADD Then ' Add row ' Wall_Paper_Name Wall_Papers.Wall_Paper_Name.EditCustomAttributes = "" Wall_Papers.Wall_Paper_Name.EditValue = ew_HtmlEncode(Wall_Papers.Wall_Paper_Name.CurrentValue) ' Wall_Paper_Thumb Wall_Papers.Wall_Paper_Thumb.EditCustomAttributes = "" If Not IsNull(Wall_Papers.Wall_Paper_Thumb.Upload.DbValue) Then Wall_Papers.Wall_Paper_Thumb.EditValue = Wall_Papers.Wall_Paper_Thumb.Upload.DbValue Wall_Papers.Wall_Paper_Thumb.ImageAlt = "" Else Wall_Papers.Wall_Paper_Thumb.EditValue = "" End If ' Wall_Paper_Image Wall_Papers.Wall_Paper_Image.EditCustomAttributes = "" If Not IsNull(Wall_Papers.Wall_Paper_Image.Upload.DbValue) Then Wall_Papers.Wall_Paper_Image.EditValue = Wall_Papers.Wall_Paper_Image.Upload.DbValue Wall_Papers.Wall_Paper_Image.ImageAlt = "" Else Wall_Papers.Wall_Paper_Image.EditValue = "" End If ElseIf Wall_Papers.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Wall_Papers.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Wall_Papers.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 = Wall_Papers.SqlKeyFilter If Wall_Papers.ID.CurrentValue = "" Or IsNull(Wall_Papers.ID.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Wall_Papers.ID.CurrentValue)) ' Replace key value End If If Not IsNumeric(Wall_Papers.ID.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Wall_Papers.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)" Wall_Papers.CurrentFilter = sFilter sSql = Wall_Papers.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 Wall_Paper_Name Call Wall_Papers.Wall_Paper_Name.SetDbValue(Wall_Papers.Wall_Paper_Name.CurrentValue, Null) rs("Wall_Paper_Name") = Wall_Papers.Wall_Paper_Name.DbValue ' Field Wall_Paper_Thumb Call Wall_Papers.Wall_Paper_Thumb.Upload.SaveToSession() ' Save file value to Session Wall_Papers.Wall_Paper_Thumb.Upload.DbValue = rs("Wall_Paper_Thumb") ' Get original value If IsNull(Wall_Papers.Wall_Paper_Thumb.Upload.Value) Then rs("Wall_Paper_Thumb") = Null Else rs("Wall_Paper_Thumb") = ew_UploadFileNameEx(ew_UploadPathEx(True, "pedro/wallpaper/thumb/"), Wall_Papers.Wall_Paper_Thumb.Upload.FileName) End If ' Field Wall_Paper_Image Call Wall_Papers.Wall_Paper_Image.Upload.SaveToSession() ' Save file value to Session Wall_Papers.Wall_Paper_Image.Upload.DbValue = rs("Wall_Paper_Image") ' Get original value If IsNull(Wall_Papers.Wall_Paper_Image.Upload.Value) Then rs("Wall_Paper_Image") = Null Else rs("Wall_Paper_Image") = ew_UploadFileNameEx(ew_UploadPathEx(True, "pedro/wallpaper/image/"), Wall_Papers.Wall_Paper_Image.Upload.FileName) End If ' 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 = Wall_Papers.Row_Inserting(rs) If bInsertRow Then ' Field Wall_Paper_Thumb If Not IsNull(Wall_Papers.Wall_Paper_Thumb.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "pedro/wallpaper/thumb/"), rs("Wall_Paper_Thumb"), Wall_Papers.Wall_Paper_Thumb.Upload.Value) If Wall_Papers.Wall_Paper_Thumb.Upload.Action = "2" Or Wall_Papers.Wall_Paper_Thumb.Upload.Action = "3" Then ' Update/Remove If Wall_Papers.Wall_Paper_Thumb.Upload.DbValue <> "" Then ew_DeleteFile ew_UploadPathEx(True, "pedro/wallpaper/thumb/") & Wall_Papers.Wall_Paper_Thumb.Upload.DbValue End If ' Field Wall_Paper_Image If Not IsNull(Wall_Papers.Wall_Paper_Image.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "pedro/wallpaper/image/"), rs("Wall_Paper_Image"), Wall_Papers.Wall_Paper_Image.Upload.Value) If Wall_Papers.Wall_Paper_Image.Upload.Action = "2" Or Wall_Papers.Wall_Paper_Image.Upload.Action = "3" Then ' Update/Remove If Wall_Papers.Wall_Paper_Image.Upload.DbValue <> "" Then ew_DeleteFile ew_UploadPathEx(True, "pedro/wallpaper/image/") & Wall_Papers.Wall_Paper_Image.Upload.DbValue End If ' 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 Wall_Papers.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Wall_Papers.CancelMessage Wall_Papers.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Wall_Papers.ID.DbValue = rsnew("ID") ' Call Row Inserted event Call Wall_Papers.Row_Inserted(rsnew) End If ' Field Wall_Paper_Thumb Call Wall_Papers.Wall_Paper_Thumb.Upload.RemoveFromSession() ' Remove file value from Session ' Field Wall_Paper_Image Call Wall_Papers.Wall_Paper_Image.Upload.RemoveFromSession() ' Remove file value from Session 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 End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>