有没有简单的方法来跟踪lightswitch
应用屏幕上的更改内容?
我有一个表单,显示有关客户的信息(listdetail
)。当我保存它时,我想写一个历史表,改变了什么。
答案 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