上一篇实现的是获取各种版本的数据集。
针对这个方案的特点,用户使用更多的可能只是针对某一版本的数据集,特别是可能只使用最新版本的数据集。
这一篇的代码,已接近界面上的应用。
以下代码在RegionalCodeCenter项目实现。
由于在一开始的方案分析中,分析还是全面、准确、到位、有效的,也通过接口明确了各种范围、各个应用的分工,所以,就算断断续续的来实现这个方案,来写代码,思路还是沿承了下来,没有给弄糊涂。
接口IClientUseServices其实实现的是下面流程图的左边部分。
Namespace [Interface]
Public Interface IClientUseServices
Event ServiceMessage As ServiceMessageHandler
Function IsSameDataDate(ByVal queryDataDate As DateTime, ByVal currentDataDate As String) As Boolean
Function GetAllInformationsTable(ByVal queryDataDate As DateTime) As RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable
Function GetVersionsDataTable() As RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable
Sub Dispose()
End Interface
End Namespace
在实现接口前,先建一个类RegionalCodeService来取各版本的数据集。
RegionalCodeService.vb
Namespace Services
Public Class RegionalCodeService
Inherits RegionalCodeCommon.Services.RegionalCodeServiceBase
Sub New(ByVal connectionString As String)
MyBase.New(New Services.ServerServices(connectionString))
End Sub
End Class
End Namespace
实现接口的类ClientUseServices有两个文件,
ClientUseServices.vb
Namespace Services
Public Class ClientUseServices
Implements RegionalCodeCommon.Interface.IClientUseServices
Public Event ServiceMessage(ByVal sender As Object, ByVal message As String) Implements RegionalCodeCommon.Interface.IClientUseServices.ServiceMessage
'数据服务
Private WithEvents gRegionalCodeService As RegionalCodeCommon.Services.RegionalCodeServiceBase
''' <param name="regionalCodeService">数据服务</param>
Sub New(ByVal regionalCodeService As RegionalCodeCommon.Services.RegionalCodeServiceBase)
Me.gRegionalCodeService = regionalCodeService
End Sub
'版本集
Private gVersionDateTable As New RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable
'当前区划信息
Private gCurrentAllInformationsTable As New RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable
'当前版本
Private gCurrentVersionDate As String = "Empty"
'数据来源
Public Property Source() As RegionalCodeCommon.Services.RegionalCodeServiceBase.DataSource
Get
Return Me.gRegionalCodeService.Source
End Get
Set(ByVal value As RegionalCodeCommon.Services.RegionalCodeServiceBase.DataSource)
Me.gRegionalCodeService.Source = value
End Set
End Property
'存放区划码信息的文件
Public Property RegionalCodeFileName() As String
Get
Return Me.gRegionalCodeService.RegionalCodeFileName
End Get
Set(ByVal value As String)
Me.gRegionalCodeService.RegionalCodeFileName = value
End Set
End Property
'存放服务器当前版本集的文件
Public Property VersionDateFileName() As String
Get
Return Me.gRegionalCodeService.VersionDateFileName
End Get
Set(ByVal value As String)
Me.gRegionalCodeService.VersionDateFileName = value
End Set
End Property
''' <summary>
''' 起用最旧版本
''' </summary>
''' <remarks>如查询日期早于最旧版本日期,使用最旧的版本</remarks>
Public Property UseOldestVersion() As Boolean
Get
Return Me.gRegionalCodeService.UseOldestVersion
End Get
Set(ByVal value As Boolean)
Me.gRegionalCodeService.UseOldestVersion = value
End Set
End Property
Public Function IsSameDataDate(ByVal queryDataDate As Date, ByVal currentDataDate As String) As Boolean Implements RegionalCodeCommon.Interface.IClientUseServices.IsSameDataDate
Return Me.gRegionalCodeService.IsSameDataDate(queryDataDate, currentDataDate)
End Function
Private Sub gRegionalCodeService_ServiceMessage(ByVal sender As Object, ByVal message As String) Handles gRegionalCodeService.ServiceMessage
SendMessage(message)
End Sub
Private Sub SendMessage(ByVal message As String)
RaiseEvent ServiceMessage(Nothing, message)
End Sub
Public Sub Dispose() Implements RegionalCodeCommon.Interface.IClientUseServices.Dispose
End Sub
End Class
End Namespace
ClientUseServices.GetData.vb
Namespace Services
Partial Class ClientUseServices
Public Function GetAllInformationsTable(ByVal queryDataDate As Date) As RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable Implements RegionalCodeCommon.Interface.IClientUseServices.GetAllInformationsTable
'如果查询版本与当前版本相同,则取当前区划信息;否则从gRegionalCodeService数据集中取
If Not IsSameDataDate(queryDataDate, Me.gCurrentVersionDate) Then
gCurrentAllInformationsTable = Me.gRegionalCodeService.GetAllInformationsTable(queryDataDate)
If Me.gCurrentAllInformationsTable IsNot Nothing Then
Me.gCurrentVersionDate = Me.gCurrentAllInformationsTable.TableName
Else
Me.gCurrentVersionDate = "Empty"
End If
End If
Return Me.gCurrentAllInformationsTable
End Function
Public Function GetVersionsDataTable() As RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable Implements RegionalCodeCommon.Interface.IClientUseServices.GetVersionsDataTable
'版本集总向gRegionalCodeService数据集中取
Me.gVersionDateTable = Me.gRegionalCodeService.GetVersionsDataTable
Return Me.gVersionDateTable
End Function
Public ReadOnly Property CurrentVersionDates() As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Get
Dim tmpList As New List(Of String)
For Each row As RegionalCodeCommon.Database.dsRegionalCode.VersionsRow In Me.gVersionDateTable.Rows
tmpList.Add(row.版本日期)
Next
Return New System.Collections.ObjectModel.ReadOnlyCollection(Of String)(tmpList)
End Get
End Property
Public Sub Load()
Me.gRegionalCodeService.Load()
End Sub
Public Sub Save()
Me.gRegionalCodeService.Save()
End Sub
End Class
End Namespace
以上是在命名间Services上的,我再将它提交到根里去,也起名为RegionalCodeService类,
Public Class RegionalCodeService
Inherits Services.ClientUseServices
Sub New(ByVal connectionString As String)
MyBase.New(New Services.RegionalCodeService(connectionString))
End Sub
End Class
这样,RegionalCodeCenter根命名下只有两个服务类,
一是UpdateDatabaseService,含实现更新数据的全部信息,
二是RegionalCodeService,含实现查询数据的全部信息。
我对这两篇实现的功能做了简单测试,效果如下:
到目前的方案代码缓后再上传。
查看本文来源