背景
机房收费系统里面有个基本数据设定的功能,我有个想法,就是如果我没有修改基本数据然后点击更新,希望系统能识别出来,并且告诉我。
基本思路
在外观层,用一个实体类对象保存从数据库查询出来的当前基本数据,然后U层的数据也组装成一个实体类保存U层的基本数据设定。然后比较这两个实体类的属性是不是完全相同。
关键代码
Public Sub UpdateBasicData(enBasicData As Entity.BasicDataEntity)
Dim i As Integer
Dim oldValue As String
Dim newValue As String
Dim pi As System.Reflection.PropertyInfo
Dim mpi() As System.Reflection.PropertyInfo
mpi = GetType(Entity.BasicDataEntity).GetProperties()
For i = 0 To mpi.Length - 3
pi = mpi(i)
oldValue = pi.GetValue(NewBasicDataEntity, Nothing).ToString()
newValue = pi.GetValue(enBasicData, Nothing).ToString()
If oldValue <> newValue Then
Exit For
End If
Next
If i = mpi.Length - 2 Then
Throw New BasicDataNotEdit
End If
BasicDataBLL.EditBasicData(enBasicData)
End Sub
参考资料
<img src="https://img-blog.csdn.net/20150517220906917?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3hsMDkyMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />