在lightswitch应用程序中保存屏幕更改历史记录

时间:2011-10-02 18:54:06

标签: visual-studio c#-3.0 visual-studio-lightswitch

有没有简单的方法来跟踪lightswitch应用屏幕上的更改内容?

我有一个表单,显示有关客户的信息(listdetail)。当我保存它时,我想写一个历史表,改变了什么。

1 个答案:

答案 0 :(得分:3)

找到了答案here

只需在控件的_updating_inserting事件中使用以下代码。

    Private Sub Employees_Updating(entity As Employee)
       Dim change = entity.EmployeeChanges.AddNew()
       change.ChangeType = "Updated" change.Employee = entity
       change.Updated = Now()
       change.ChangedBy = Me.Application.User.FullName

       Dim newvals = "New Values:"    
       Dim oldvals = "Original Values:"    

       For Each prop In entity.Details.Properties.All().
            OfType(Of Microsoft.LightSwitch.Details.IEntityStorageProperty)()

           If prop.Name <> "Id" Then             

                If Not Object.Equals(prop.Value, prop.OriginalValue) Then                 
                    oldvals += String.Format("{0}{1}: {2}", vbCrLf, prop.Name, prop.OriginalValue)
                    newvals += String.Format("{0}{1}: {2}", vbCrLf, prop.Name, prop.Value)
                End If         
           End If    

       Next   

      change.OriginalValues = oldvals
      change.NewValues = newvals

End Sub