Создание функций аудита с помощью ASP.NET 2.0
Привет
Вы проделали хорошую работу для примера аудита.
Но он работает только на gridview.
Я хочу того же самого, но работаю в своей единственной форме. ВСТАВИТЬ/ОБНОВИТЬ/DELTE.
Пожалуйста помочь.
С уважением
Маниш
Что я уже пробовал:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web Imports System.Web.Configuration Imports System.Collections.Generic Imports System.Collections.Specialized Public Class CurrentFields 'Private Shared ReadOnly _connectionString As String Private _colName As String Private _colValue As String 'Public Shared Sub New() Public _connectionString As String = WebConfigurationManager.ConnectionStrings("POManagerConnectionString").ConnectionString 'End Sub Public Property CurrColName As String Get Return _colName End Get Set(ByVal value As String) _colName = value End Set End Property Public Property CurrColValue As String Get Return _colValue End Get Set(ByVal value As String) _colValue = value End Set End Property Public Function GetCurrentFields(ByVal WhereField As String, ByVal ID As Integer, ByVal TableName As String) As List(Of CurrentFields) Dim results As List(Of CurrentFields) = New List(Of CurrentFields)() Dim ds As DataSet = New DataSet() Dim dt As DataTable = Nothing Dim dad As SqlDataAdapter = Nothing Dim strSelectSql As String = "SELECT * FROM " & TableName & " where " & WhereField & "=" & ID ' strSelectSql += " WHERE " & WhereField = ID Try Dim conn As SqlConnection = New SqlConnection(_connectionString) dad = New SqlDataAdapter(strSelectSql, conn) dad.Fill(ds) dt = ds.Tables(0) For Each row As DataRow In dt.Rows For Each column As DataColumn In dt.Columns Dim currFlds As CurrentFields = New CurrentFields() currFlds.CurrColName = column.ColumnName currFlds.CurrColValue = row(column).ToString() results.Add(currFlds) Next Next Catch End Try Return results End Function End Class
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web Imports System.Web.Configuration Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Public Class InsertAuditData Public Shared Sub insertAuditChanges(ByVal TableName As String, ByVal Operation As String, ByVal PerformedBy As String, ByVal FieldName As String, ByVal OldValue As String, ByVal NewValue As String) Dim strConn As String = WebConfigurationManager.ConnectionStrings("POManagerConnectionString").ConnectionString Using conn As SqlConnection = New SqlConnection(strConn) Dim strUpdate As String = "INSERT INTO AUDIT_Table (PageName, Operation, OccurredAt, PerformedBy, FieldName, OldValue, NewValue) VALUES " strUpdate += "('" & TableName & "', '" & Operation & "', '" + DateTime.Now & "' ,'" & PerformedBy & "' , '" & FieldName & "', '" & OldValue & "', '" & NewValue & "')" Dim cmd As SqlCommand = New SqlCommand(strUpdate, conn) conn.Open() cmd.ExecuteNonQuery() End Using End Sub End Class
Когда я сохраняю данные, то ставлю этот код, но что-то не так с myDE и e.NewValues, потому что это не gridview ??? Он прекрасно работает с gridview.
' Start Audit ' ---------------------------------------------------------------------------------------- Dim ID As String = txtPOID.Text Dim currFlds As CurrentFields = New CurrentFields() currFieldList = currFlds.GetCurrentFields("POID", ID, "PurchaseOrder") Session("CurrData") = currFieldList currFieldList = CType(Session("CurrData"), List(Of CurrentFields)) 'Dim myDE As DictionaryEntry 'myDE.Value = currFlds.CurrColValue For Each myDE As DictionaryEntry In e.NewValues Dim i As Integer = 0 Dim key As String = myDE.Key.ToString() For Each currFld As CurrentFields In currFieldList If currFld.CurrColName = key Then Exit For End If i += 1 Next If myDE.Value IsNot Nothing Then Dim newVal As String = myDE.Value.ToString() If currFieldList(i).CurrColValue <> newVal Then InsertAuditData.insertAuditChanges("Edit Purchase Order", "UPDATE", Session("Username"), key, currFieldList(i).CurrColValue, newVal) End If Else If currFieldList(i).CurrColValue <> "" Then InsertAuditData.insertAuditChanges("Edit Purchase Order", "UPDATE", Session("Username"), currFieldList(i).CurrColName, currFieldList(i).CurrColValue, "") End If End If Next