Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Referencing USERID as global variable
Message
 
À
20/04/2004 14:00:16
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00896598
Message ID:
00896730
Vues:
8
>Using the MM framework and inheriting mmUserLoginForm, how can I put the userid to a global variable when authenticated so I can use it in all my forms. I have to several maintenance form and I wanted to track the user who change a record for that form and store the userid in fields like mytable.changeby field.

Aldrin, there may be better ways to do this, but this is what I did for this after consulting with Kevin privately and getting his input:

1) I override MM.NET's main business object with my own application's business object and declare a public variable that will be set to the current user:
Public Class CerelogicBusinessObject
    Inherits ABusinessObject
    Public CurrentUser As String
2) In the business object above, I utilize the HookPreSave method as follows:
Protected Overrides Function HookPreSave(ByVal table As DataTable) As Boolean

        Dim Result As Boolean = True
        Dim dr As DataRow

        For Each dr In table.Rows
            If dr.RowState = DataRowState.Modified Then
                dr("AuditLastAction") = "Modified"
                dr("AuditLastUser") = CurrentUser
                dr("AuditLastDateTime") = DateTime.UtcNow
            End If
            If dr.RowState = DataRowState.Added Then
                dr("AuditLastAction") = "Created"
                dr("AuditLastUser") = CurrentUser
                dr("AuditLastDateTime") = DateTime.UtcNow
            End If

        Next dr

        Return Result
    End Function 'HookPreSave 
3) Now in each web page UI where the user does editing to a record, I do something like this (in this case I'm using IntersoftPT's WebGrid 3.5 Enterprise to update a record):
    Private Sub WebGrid1_UpdateRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs) Handles WebGrid1.UpdateRow
        
        Dim ds As DataSet = CType(WebGrid1.DataSource, DataSet)

        ' update the changed row using proper dataadapter for each datatable.

        oMyBizObj.CurrentUser = CStr(Me.SecurityUserPk)
        Dim result As mmSaveDataResult = Me.oMyBizObj.SaveDataSet(ds)
    End Sub
A possible drawback to this approach is that the user id in your audit field is set to the PK value of the user logged in. You are not saving the actual user id or name. To get that, you would have to roll your own code to retrieve that from MM.NET's security tables. I believe Kevin plans to introduce some additional properties in MM.NET that will simplify this.

Regards,
Carl.
Carl Olson, Jr.
CEO, Founder
Cerelogic, Inc.

www.cerelogic.com

"Applying rocket science to business."
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform