📄 activitiesadd.asp
字号:
Function LoadRow()
Dim rs, sSql, sFilter
sFilter = Activities.SqlKeyFilter
If Not IsNumeric(Activities.Id.CurrentValue) Then
LoadRow = False ' Invalid key, exit
Exit Function
End If
sFilter = Replace(sFilter, "@Id@", ew_AdjustSql(Activities.Id.CurrentValue)) ' Replace key value
' Call Row Selecting event
Call Activities.Row_Selecting(sFilter)
' Load sql based on filter
Activities.CurrentFilter = sFilter
sSql = Activities.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 Activities.Row_Selected(rs)
End If
rs.Close
Set rs = Nothing
End Function
' Load row values from recordset
Sub LoadRowValues(rs)
Activities.Id.DbValue = rs("Id")
Activities.Order_Id.DbValue = rs("Order_Id")
Activities.zDate.DbValue = rs("Date")
Activities.Activity_Type_Id.DbValue = rs("Activity_Type_Id")
Activities.Hours.DbValue = rs("Hours")
Activities.Notes.DbValue = rs("Notes")
Activities.Author_Id.DbValue = rs("Author_Id")
Activities.Creation_Date.DbValue = rs("Creation_Date")
End Sub
%>
<%
' Render row values based on field settings
Sub RenderRow()
' Call Row Rendering event
Call Activities.Row_Rendering()
' Common render codes for all row types
' Order_Id
Activities.Order_Id.CellCssStyle = ""
Activities.Order_Id.CellCssClass = ""
' Date
Activities.zDate.CellCssStyle = ""
Activities.zDate.CellCssClass = ""
' Activity_Type_Id
Activities.Activity_Type_Id.CellCssStyle = ""
Activities.Activity_Type_Id.CellCssClass = ""
' Hours
Activities.Hours.CellCssStyle = ""
Activities.Hours.CellCssClass = ""
' Notes
Activities.Notes.CellCssStyle = ""
Activities.Notes.CellCssClass = ""
' Author_Id
Activities.Author_Id.CellCssStyle = ""
Activities.Author_Id.CellCssClass = ""
' Creation_Date
Activities.Creation_Date.CellCssStyle = ""
Activities.Creation_Date.CellCssClass = ""
If Activities.RowType = EW_ROWTYPE_VIEW Then ' View row
ElseIf Activities.RowType = EW_ROWTYPE_ADD Then ' Add row
' Order_Id
Activities.Order_Id.EditCustomAttributes = "style=""width:400px;"""
If Activities.Order_Id.SessionValue <> "" Then
Activities.Order_Id.CurrentValue = Activities.Order_Id.SessionValue
If Not IsNull(Activities.Order_Id.CurrentValue) And Activities.Order_Id.CurrentValue <> "" Then
sSqlWrk = "SELECT [Code] FROM [Orders] WHERE [Id] = " & ew_AdjustSql(Activities.Order_Id.CurrentValue) & ""
sSqlWrk = sSqlWrk & " ORDER BY [Code] Asc"
Set rswrk = conn.Execute(sSqlWrk)
If Not rswrk.Eof Then
Activities.Order_Id.ViewValue = rswrk("Code")
Else
Activities.Order_Id.ViewValue = Activities.Order_Id.CurrentValue
End If
rswrk.Close
Set rswrk = Nothing
Else
Activities.Order_Id.ViewValue = Null
End If
Activities.Order_Id.CssStyle = ""
Activities.Order_Id.CssClass = ""
Activities.Order_Id.ViewCustomAttributes = ""
Else
sSqlWrk = "SELECT [Id], [Code] FROM [Orders]"
sSqlWrk = sSqlWrk & " ORDER BY [Code] 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"))
Activities.Order_Id.EditValue = arwrk
End If
' Date
Activities.zDate.EditCustomAttributes = "style=""width:400px;"""
Activities.zDate.EditValue = ew_FormatDateTime(Activities.zDate.CurrentValue, 7)
' Activity_Type_Id
Activities.Activity_Type_Id.EditCustomAttributes = "style=""width:400px;"""
sSqlWrk = "SELECT [Id], [Description] FROM [Activity_Types]"
sSqlWrk = sSqlWrk & " ORDER BY [Ordinal_Index] 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"))
Activities.Activity_Type_Id.EditValue = arwrk
' Hours
Activities.Hours.EditCustomAttributes = "style=""width:400px;"""
Activities.Hours.EditValue = ew_HtmlEncode(Activities.Hours.CurrentValue)
' Notes
Activities.Notes.EditCustomAttributes = "style=""width:400px;"""
Activities.Notes.EditValue = ew_HtmlEncode(Activities.Notes.CurrentValue)
ElseIf Activities.RowType = EW_ROWTYPE_EDIT Then ' Edit row
ElseIf Activities.RowType = EW_ROWTYPE_SEARCH Then ' Search row
End If
' Call Row Rendered event
Call Activities.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 = Activities.SqlKeyFilter
If Activities.Id.CurrentValue = "" Or IsNull(Activities.Id.CurrentValue) Then
bCheckKey = False
Else
sFilter = Replace(sFilter, "@Id@", ew_AdjustSql(Activities.Id.CurrentValue)) ' Replace key value
End If
If Not IsNumeric(Activities.Id.CurrentValue) Then
bCheckKey = False
End If
If bCheckKey Then
Set rsChk = Activities.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)"
Activities.CurrentFilter = sFilter
sSql = Activities.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 Order_Id
Call Activities.Order_Id.SetDbValue(Activities.Order_Id.CurrentValue, Null)
rs("Order_Id") = Activities.Order_Id.DbValue
' Field Date
Call Activities.zDate.SetDbValue(ew_UnFormatDateTime(Activities.zDate.CurrentValue, 7), Null)
rs("Date") = Activities.zDate.DbValue
' Field Activity_Type_Id
Call Activities.Activity_Type_Id.SetDbValue(Activities.Activity_Type_Id.CurrentValue, Null)
rs("Activity_Type_Id") = Activities.Activity_Type_Id.DbValue
' Field Hours
Call Activities.Hours.SetDbValue(Activities.Hours.CurrentValue, Null)
rs("Hours") = Activities.Hours.DbValue
' Field Notes
Call Activities.Notes.SetDbValue(Activities.Notes.CurrentValue, Null)
rs("Notes") = Activities.Notes.DbValue
' Field Author_Id
Activities.Author_Id.DbValue = CurrentUserID
rs("Author_Id") = Activities.Author_Id.DbValue
' Field Creation_Date
Activities.Creation_Date.DbValue = ew_CurrentDate
rs("Creation_Date") = Activities.Creation_Date.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 = Activities.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 Activities.CancelMessage <> "" Then
Session(EW_SESSION_MESSAGE) = Activities.CancelMessage
Activities.CancelMessage = ""
Else
Session(EW_SESSION_MESSAGE) = "Insert cancelled"
End If
AddRow = False
End If
rs.Close
Set rs = Nothing
If AddRow Then
Activities.Id.DbValue = rsnew("Id")
' Call Row Inserted event
Call Activities.Row_Inserted(rsnew)
Call WriteAuditTrailOnAdd(rsnew)
End If
If IsObject(rsnew) Then
rsnew.Close
Set rsnew = Nothing
End If
End Function
%>
<%
' Write Audit Trail start/end for grid update
Sub WriteAuditTrailDummy(typ)
On Error Resume Next
Dim table
table = "Activities"
' Write Audit Trail
Dim filePfx, curDate, curTime, id, user, action
Dim i
filePfx = "log"
curDate = ew_ZeroPad(Year(Date), 4) & "/" & ew_ZeroPad(Month(Date), 2) & "/" & ew_ZeroPad(Day(Date), 2)
curTime = ew_ZeroPad(Hour(Time), 2) & ":" & ew_ZeroPad(Minute(Time), 2) & ":" & ew_ZeroPad(Second(Time), 2)
id = Request.ServerVariables("SCRIPT_NAME")
If IsObject(Security) Then user = Security.CurrentUserID
action = typ
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "", "", "", "")
End Sub
%>
<%
' Write Audit Trail (add page)
Sub WriteAuditTrailOnAdd(rs)
On Error Resume Next
Dim table
table = "Activities"
' Get key value
Dim sKey
sKey = ""
If sKey <> "" Then sKey = sKey & EW_COMPOSITE_KEY_SEPARATOR
sKey = sKey & rs.Fields("Id")
' Write Audit Trail
Dim filePfx, curDate, curTime, id, user, action, field, keyvalue, oldvalue
Dim i
filePfx = "log"
curDate = ew_ZeroPad(Year(Date), 4) & "/" & ew_ZeroPad(Month(Date), 2) & "/" & ew_ZeroPad(Day(Date), 2)
curTime = ew_ZeroPad(Hour(Time), 2) & ":" & ew_ZeroPad(Minute(Time), 2) & ":" & ew_ZeroPad(Second(Time), 2)
id = Request.ServerVariables("SCRIPT_NAME")
If IsObject(Security) Then user = Security.CurrentUserID
action = "A"
keyvalue = sKey
oldvalue = ""
' Id Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Id", keyvalue, oldvalue, rs("Id"))
' Order_Id Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Order_Id", keyvalue, oldvalue, rs("Order_Id"))
' Date Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Date", keyvalue, oldvalue, rs("Date"))
' Activity_Type_Id Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Activity_Type_Id", keyvalue, oldvalue, rs("Activity_Type_Id"))
' Hours Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Hours", keyvalue, oldvalue, rs("Hours"))
' Notes Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Notes", keyvalue, oldvalue, "<MEMO>")
' Author_Id Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Author_Id", keyvalue, oldvalue, rs("Author_Id"))
' Creation_Date Field
Call ew_WriteAuditTrail(filePfx, curDate, curTime, id, user, action, table, "Creation_Date", keyvalue, oldvalue, rs("Creation_Date"))
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
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -