<%@ CodePage="1252" LCID="1046" %> <% Response.Buffer = EW_RESPONSE_BUFFER %> <% Session.Timeout = 20 %> <% Call ew_Header(False, EW_CHARSET) %> <% ' Define page object Dim funcionarios_add Set funcionarios_add = New cfuncionarios_add Set Page = funcionarios_add ' Page init processing Call funcionarios_add.Page_Init() ' Page main processing Call funcionarios_add.Page_Main() %> <% funcionarios_add.ShowPageHeader() %>

<%= Language.Phrase("Add") %> <%= Language.Phrase("TblTypeTABLE") %><%= funcionarios.TableCaption %>

<%= Language.Phrase("GoBack") %>

<% funcionarios_add.ShowMessage %>

<% If funcionarios.NOME.Visible Then ' NOME %> > > > <%= funcionarios.NOME.CustomMsg %> <% End If %> <% If funcionarios.zLOGIN.Visible Then ' LOGIN %> > > > <%= funcionarios.zLOGIN.CustomMsg %> <% End If %> <% If funcionarios.SENHA.Visible Then ' SENHA %> > > > <%= funcionarios.SENHA.CustomMsg %> <% End If %>
<%= funcionarios.NOME.FldCaption %>
<%= funcionarios.zLOGIN.FldCaption %>
<%= funcionarios.SENHA.FldCaption %><%= Language.Phrase("FieldRequiredIndicator") %>

">

<% funcionarios_add.ShowPageFooter() If EW_DEBUG_ENABLED Then Response.Write ew_DebugMsg() %> <% ' Drop page object Set funcionarios_add = Nothing %> <% ' ----------------------------------------------------------------- ' Page Class ' Class cfuncionarios_add ' Page ID Public Property Get PageID() PageID = "add" End Property ' Table Name Public Property Get TableName() TableName = "funcionarios" End Property ' Page Object Name Public Property Get PageObjName() PageObjName = "funcionarios_add" End Property ' Page Name Public Property Get PageName() PageName = ew_CurrentPage() End Property ' Page Url Public Property Get PageUrl() PageUrl = ew_CurrentPage() & "?" If funcionarios.UseTokenInUrl Then PageUrl = PageUrl & "t=" & funcionarios.TableVar & "&" ' add page token End Property ' Message Public Property Get Message() Message = Session(EW_SESSION_MESSAGE) End Property Public Property Let Message(v) Dim msg msg = Session(EW_SESSION_MESSAGE) Call ew_AddMessage(msg, v) Session(EW_SESSION_MESSAGE) = msg End Property Public Property Get FailureMessage() FailureMessage = Session(EW_SESSION_FAILURE_MESSAGE) End Property Public Property Let FailureMessage(v) Dim msg msg = Session(EW_SESSION_FAILURE_MESSAGE) Call ew_AddMessage(msg, v) Session(EW_SESSION_FAILURE_MESSAGE) = msg End Property Public Property Get SuccessMessage() SuccessMessage = Session(EW_SESSION_SUCCESS_MESSAGE) End Property Public Property Let SuccessMessage(v) Dim msg msg = Session(EW_SESSION_SUCCESS_MESSAGE) Call ew_AddMessage(msg, v) Session(EW_SESSION_SUCCESS_MESSAGE) = msg End Property ' Show Message Public Sub ShowMessage() Dim sMessage sMessage = Message Call Message_Showing(sMessage, "") If sMessage <> "" Then Response.Write "

" & sMessage & "

" Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session ' Success message Dim sSuccessMessage sSuccessMessage = SuccessMessage Call Message_Showing(sSuccessMessage, "success") If sSuccessMessage <> "" Then Response.Write "

" & sSuccessMessage & "

" Session(EW_SESSION_SUCCESS_MESSAGE) = "" ' Clear message in Session ' Failure message Dim sErrorMessage sErrorMessage = FailureMessage Call Message_Showing(sErrorMessage, "failure") If sErrorMessage <> "" Then Response.Write "

" & sErrorMessage & "

" Session(EW_SESSION_FAILURE_MESSAGE) = "" ' Clear message in Session End Sub Dim PageHeader Dim PageFooter ' Show Page Header Public Sub ShowPageHeader() Dim sHeader sHeader = PageHeader Call Page_DataRendering(sHeader) If sHeader <> "" Then ' Header exists, display Response.Write "

" & sHeader & "

" End If End Sub ' Show Page Footer Public Sub ShowPageFooter() Dim sFooter sFooter = PageFooter Call Page_DataRendered(sFooter) If sFooter <> "" Then ' Footer exists, display Response.Write "

" & sFooter & "

" End If End Sub ' ----------------------- ' Validate Page request ' Public Function IsPageRequest() If funcionarios.UseTokenInUrl Then IsPageRequest = False If Not (ObjForm Is Nothing) Then IsPageRequest = (funcionarios.TableVar = ObjForm.GetValue("t")) End If If Request.QueryString("t").Count > 0 Then IsPageRequest = (funcionarios.TableVar = Request.QueryString("t")) End If Else IsPageRequest = True End If End Function ' ----------------------------------------------------------------- ' Class initialize ' - init objects ' - open ADO connection ' Private Sub Class_Initialize() If IsEmpty(StartTimer) Then StartTimer = Timer ' Init start time ' Initialize language object If IsEmpty(Language) Then Set Language = New cLanguage Call Language.LoadPhrases() End If ' Initialize table object If IsEmpty(funcionarios) Then Set funcionarios = New cfuncionarios Set Table = funcionarios ' Initialize urls ' Initialize form object Set ObjForm = Nothing ' Intialize page id (for backward compatibility) EW_PAGE_ID = "add" ' Initialize table name (for backward compatibility) EW_TABLE_NAME = "funcionarios" ' Open connection to the database If IsEmpty(Conn) Then Call ew_Connect() End Sub ' ----------------------------------------------------------------- ' Subroutine Page_Init ' - called before page main ' - check Security ' - set up response header ' - call page load events ' Sub Page_Init() ' Create form object Set ObjForm = New cFormObj ' Global page loading event (in userfn7.asp) Call Page_Loading() ' Page load event, used in current page Call Page_Load() End Sub ' ----------------------------------------------------------------- ' Class terminate ' - clean up page object ' Private Sub Class_Terminate() Call Page_Terminate("") End Sub ' ----------------------------------------------------------------- ' Subroutine Page_Terminate ' - called when exit page ' - clean up ADO connection and objects ' - if url specified, redirect to url ' Sub Page_Terminate(url) ' Page unload event, used in current page Call Page_Unload() ' Global page unloaded event (in userfn60.asp) Call Page_Unloaded() Dim sRedirectUrl sReDirectUrl = url Call Page_Redirecting(sReDirectUrl) If Not (Conn Is Nothing) Then Conn.Close ' Close Connection Set Conn = Nothing Set funcionarios = Nothing Set ObjForm = Nothing ' Go to url if specified If sReDirectUrl <> "" Then If Response.Buffer Then Response.Clear Response.Redirect sReDirectUrl End If End Sub ' ' Subroutine Page_Terminate (End) ' ---------------------------------------- Dim DbMasterFilter, DbDetailFilter Dim Priv Dim OldRecordset Dim CopyRecord ' ----------------------------------------------------------------- ' Page main processing ' Sub Page_Main() ' Process form if post back If ObjForm.GetValue("a_add")&"" <> "" Then funcionarios.CurrentAction = ObjForm.GetValue("a_add") ' Get form action CopyRecord = LoadOldRecord() ' Load old recordset Call LoadFormValues() ' Load form values ' Validate Form If Not ValidateForm() Then funcionarios.CurrentAction = "I" ' Form error, reset action funcionarios.EventCancelled = True ' Event cancelled Call RestoreFormValues() ' Restore form values FailureMessage = gsFormError End If ' Not post back Else ' Load key values from QueryString CopyRecord = True If Request.QueryString("ID").Count > 0 Then funcionarios.ID.QueryStringValue = Request.QueryString("ID") Call funcionarios.SetKey("ID", funcionarios.ID.CurrentValue) ' Set up key Else Call funcionarios.SetKey("ID", "") ' Clear key CopyRecord = False End If If CopyRecord Then funcionarios.CurrentAction = "C" ' Copy Record Else funcionarios.CurrentAction = "I" ' Display Blank Record Call LoadDefaultValues() ' Load default values End If End If ' Perform action based on action code Select Case funcionarios.CurrentAction Case "I" ' Blank record, no action required Case "C" ' Copy an existing record If Not LoadRow() Then ' Load record based on key FailureMessage = Language.Phrase("NoRecord") ' No record found Call Page_Terminate("funcionarioslist.asp") ' No matching record, return to list End If Case "A" ' Add new record funcionarios.SendEmail = True ' Send email on add success If AddRow(OldRecordset) Then ' Add successful SuccessMessage = Language.Phrase("AddSuccess") ' Set up success message Dim sReturnUrl sReturnUrl = funcionarios.ReturnUrl If ew_GetPageName(sReturnUrl) = "funcionariosview.asp" Then sReturnUrl = funcionarios.ViewUrl ' View paging, return to view page with keyurl directly Call Page_Terminate(sReturnUrl) ' Clean up and return Else funcionarios.EventCancelled = True ' Event cancelled Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type funcionarios.RowType = EW_ROWTYPE_ADD ' Render add type ' Render row Call funcionarios.ResetAttrs() Call RenderRow() End Sub ' ----------------------------------------------------------------- ' Function Get upload files ' Function GetUploadFiles() ' Get upload data Dim index, confirmPage index = ObjForm.Index ' Save form index ObjForm.Index = 0 confirmPage = (ObjForm.GetValue("a_confirm") & "" <> "") ObjForm.Index = index ' Restore form index End Function ' ----------------------------------------------------------------- ' Load default values ' Function LoadDefaultValues() funcionarios.NOME.CurrentValue = Null funcionarios.NOME.OldValue = funcionarios.NOME.CurrentValue funcionarios.zLOGIN.CurrentValue = Null funcionarios.zLOGIN.OldValue = funcionarios.zLOGIN.CurrentValue funcionarios.SENHA.CurrentValue = Null funcionarios.SENHA.OldValue = funcionarios.SENHA.CurrentValue End Function ' ----------------------------------------------------------------- ' Load form values ' Function LoadFormValues() ' Load values from form If Not funcionarios.NOME.FldIsDetailKey Then funcionarios.NOME.FormValue = ObjForm.GetValue("x_NOME") If Not funcionarios.zLOGIN.FldIsDetailKey Then funcionarios.zLOGIN.FormValue = ObjForm.GetValue("x_zLOGIN") If Not funcionarios.SENHA.FldIsDetailKey Then funcionarios.SENHA.FormValue = ObjForm.GetValue("x_SENHA") End Function ' ----------------------------------------------------------------- ' Restore form values ' Function RestoreFormValues() Call LoadOldRecord() funcionarios.NOME.CurrentValue = funcionarios.NOME.FormValue funcionarios.zLOGIN.CurrentValue = funcionarios.zLOGIN.FormValue funcionarios.SENHA.CurrentValue = funcionarios.SENHA.FormValue End Function ' ----------------------------------------------------------------- ' Load row based on key values ' Function LoadRow() Dim RsRow, sSql, sFilter sFilter = funcionarios.KeyFilter ' Call Row Selecting event Call funcionarios.Row_Selecting(sFilter) ' Load sql based on filter funcionarios.CurrentFilter = sFilter sSql = funcionarios.SQL Call ew_SetDebugMsg("LoadRow: " & sSql) ' Show SQL for debugging Set RsRow = ew_LoadRow(sSql) If RsRow.Eof Then LoadRow = False Else LoadRow = True RsRow.MoveFirst Call LoadRowValues(RsRow) ' Load row values End If RsRow.Close Set RsRow = Nothing End Function ' ----------------------------------------------------------------- ' Load row values from recordset ' Sub LoadRowValues(RsRow) Dim sDetailFilter If RsRow.Eof Then Exit Sub ' Call Row Selected event Call funcionarios.Row_Selected(RsRow) funcionarios.ID.DbValue = RsRow("ID") funcionarios.NOME.DbValue = RsRow("NOME") funcionarios.zLOGIN.DbValue = RsRow("LOGIN") funcionarios.SENHA.DbValue = RsRow("SENHA") End Sub ' Load old record Function LoadOldRecord() ' Load key values from Session Dim bValidKey bValidKey = True If funcionarios.GetKey("ID")&"" <> "" Then funcionarios.ID.CurrentValue = funcionarios.GetKey("ID") ' ID Else bValidKey = False End If ' Load old recordset If bValidKey Then funcionarios.CurrentFilter = funcionarios.KeyFilter Dim sSql sSql = funcionarios.SQL Set OldRecordset = ew_LoadRecordset(sSql) Call LoadRowValues(OldRecordset) ' Load row values Else OldRecordset = Null End If LoadOldRecord = bValidKey End Function ' ----------------------------------------------------------------- ' Render row values based on field settings ' Sub RenderRow() ' Initialize urls ' Call Row Rendering event Call funcionarios.Row_Rendering() ' --------------------------------------- ' Common render codes for all row types ' --------------------------------------- ' ID ' NOME ' LOGIN ' SENHA ' ----------- ' View Row ' ----------- If funcionarios.RowType = EW_ROWTYPE_VIEW Then ' View row ' ID funcionarios.ID.ViewValue = funcionarios.ID.CurrentValue funcionarios.ID.CssStyle = "text-align:center;" funcionarios.ID.ViewCustomAttributes = "" ' NOME funcionarios.NOME.ViewValue = funcionarios.NOME.CurrentValue funcionarios.NOME.CssStyle = "text-align:center;" funcionarios.NOME.ViewCustomAttributes = "" ' LOGIN funcionarios.zLOGIN.ViewValue = funcionarios.zLOGIN.CurrentValue funcionarios.zLOGIN.CssStyle = "text-align:center;" funcionarios.zLOGIN.ViewCustomAttributes = "" ' SENHA funcionarios.SENHA.ViewValue = funcionarios.SENHA.CurrentValue funcionarios.SENHA.CssStyle = "text-align:center;" funcionarios.SENHA.ViewCustomAttributes = "" ' View refer script ' NOME funcionarios.NOME.LinkCustomAttributes = "" funcionarios.NOME.HrefValue = "" funcionarios.NOME.TooltipValue = "" ' LOGIN funcionarios.zLOGIN.LinkCustomAttributes = "" funcionarios.zLOGIN.HrefValue = "" funcionarios.zLOGIN.TooltipValue = "" ' SENHA funcionarios.SENHA.LinkCustomAttributes = "" funcionarios.SENHA.HrefValue = "" funcionarios.SENHA.TooltipValue = "" ' --------- ' Add Row ' --------- ElseIf funcionarios.RowType = EW_ROWTYPE_ADD Then ' Add row ' NOME funcionarios.NOME.EditCustomAttributes = "" funcionarios.NOME.EditValue = ew_HtmlEncode(funcionarios.NOME.CurrentValue) ' LOGIN funcionarios.zLOGIN.EditCustomAttributes = "" funcionarios.zLOGIN.EditValue = ew_HtmlEncode(funcionarios.zLOGIN.CurrentValue) ' SENHA funcionarios.SENHA.EditCustomAttributes = "" funcionarios.SENHA.EditValue = ew_HtmlEncode(funcionarios.SENHA.CurrentValue) ' Edit refer script ' NOME funcionarios.NOME.HrefValue = "" ' LOGIN funcionarios.zLOGIN.HrefValue = "" ' SENHA funcionarios.SENHA.HrefValue = "" End If If funcionarios.RowType = EW_ROWTYPE_ADD Or funcionarios.RowType = EW_ROWTYPE_EDIT Or funcionarios.RowType = EW_ROWTYPE_SEARCH Then ' Add / Edit / Search row Call funcionarios.SetupFieldTitles() End If ' Call Row Rendered event If funcionarios.RowType <> EW_ROWTYPE_AGGREGATEINIT Then Call funcionarios.Row_Rendered() End If End Sub ' ----------------------------------------------------------------- ' Validate form ' Function ValidateForm() ' Initialize gsFormError = "" ' Check if validation required If Not EW_SERVER_VALIDATE Then ValidateForm = (gsFormError = "") Exit Function End If If Not IsNull(funcionarios.SENHA.FormValue) And funcionarios.SENHA.FormValue&"" = "" Then Call ew_AddMessage(gsFormError, Language.Phrase("EnterRequiredField") & " - " & funcionarios.SENHA.FldCaption) End If If Not ew_CheckInteger(funcionarios.SENHA.FormValue) Then Call ew_AddMessage(gsFormError, funcionarios.SENHA.FldErrMsg) End If ' Return validate result ValidateForm = (gsFormError = "") ' Call Form Custom Validate event Dim sFormCustomError sFormCustomError = "" ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError) If sFormCustomError <> "" Then Call ew_AddMessage(gsFormError, sFormCustomError) End If End Function ' ----------------------------------------------------------------- ' Add record ' Function AddRow(RsOld) If Not EW_DEBUG_ENABLED Then On Error Resume Next Dim Rs, sSql, sFilter Dim RsNew Dim bInsertRow Dim RsChk Dim sIdxErrMsg ' Clear any previous errors Err.Clear ' Add new record sFilter = "(0 = 1)" funcionarios.CurrentFilter = sFilter sSql = funcionarios.SQL Set Rs = Server.CreateObject("ADODB.Recordset") Rs.CursorLocation = EW_CURSORLOCATION Rs.Open sSql, Conn, 1, EW_RECORDSET_LOCKTYPE Rs.AddNew If Err.Number <> 0 Then Message = Err.Description Rs.Close Set Rs = Nothing AddRow = False Exit Function End If ' Field NOME Call funcionarios.NOME.SetDbValue(Rs, funcionarios.NOME.CurrentValue, Null, False) ' Field LOGIN Call funcionarios.zLOGIN.SetDbValue(Rs, funcionarios.zLOGIN.CurrentValue, Null, False) ' Field SENHA If Not EW_CASE_SENSITIVE_PASSWORD And Not IsNull(funcionarios.SENHA.CurrentValue) Then funcionarios.SENHA.CurrentValue = LCase(funcionarios.SENHA.CurrentValue) If EW_ENCRYPTED_PASSWORD And Not IsNull(funcionarios.SENHA.CurrentValue) Then funcionarios.SENHA.CurrentValue = MD5(funcionarios.SENHA.CurrentValue) Call funcionarios.SENHA.SetDbValue(Rs, funcionarios.SENHA.CurrentValue, Null, False) ' Check recordset update error If Err.Number <> 0 Then FailureMessage = Err.Description Rs.Close Set Rs = Nothing AddRow = False Exit Function End If ' Call Row Inserting event bInsertRow = funcionarios.Row_Inserting(RsOld, Rs) If bInsertRow Then ' Clone new recordset object Set RsNew = ew_CloneRs(Rs) Rs.Update If Err.Number <> 0 Then FailureMessage = Err.Description AddRow = False Else AddRow = True End If Else Rs.CancelUpdate If funcionarios.CancelMessage <> "" Then FailureMessage = funcionarios.CancelMessage funcionarios.CancelMessage = "" Else FailureMessage = Language.Phrase("InsertCancelled") End If AddRow = False End If Rs.Close Set Rs = Nothing If AddRow Then funcionarios.ID.DbValue = RsNew("ID") End If If AddRow Then ' Call Row Inserted event Call funcionarios.Row_Inserted(RsOld, 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 ' Page Redirecting event Sub Page_Redirecting(url) 'url = newurl End Sub ' Message Showing event ' typ = ""|"success"|"failure" Sub Message_Showing(msg, typ) ' Example: 'If typ = "success" Then msg = "your success message" End Sub ' Page Data Rendering event Sub Page_DataRendering(header) ' Example: 'header = "your header" End Sub ' Page Data Rendered event Sub Page_DataRendered(footer) ' Example: 'footer = "your footer" End Sub ' Form Custom Validate event Function Form_CustomValidate(CustomError) 'Return error message in CustomError Form_CustomValidate = True End Function End Class %>