Author:水如烟
总目录:行政区划数据方案设计
上一篇,行政区划程序的设计(十)
这篇是 IServerServices的实现,比较简单。
在C/S模式中(是叫C/S模式吗),这个接口的实现是在服务端,“宿主机”提供。
这里我放在RegionalCodeCenter项目。
ServerServices.vb
Namespace
Services
Public Class ServerServices
Implements RegionalCodeCommon.Interface.IServerServices
Public Event ServiceMessage( ByVal sender As Object , ByVal message As String ) Implements RegionalCodeCommon.Interface.IServerServices.ServiceMessage
Public Event UpdateDatabaseCurrentPercent( ByVal sender As Object , ByVal currentPercent As Integer ) Implements RegionalCodeCommon.Interface.IServerServices.UpdateDatabaseCurrentPercent
Private WithEvents gRegionalCodeServerServices As RegionalCodeLibrary.DatabaseServices
Sub New ( ByVal connectionString As String )
gRegionalCodeServerServices = New RegionalCodeLibrary.DatabaseServices(connectionString)
End Sub
Private Sub gRegionalCodeServerServices_ServiceMessage( ByVal sender As Object , ByVal message As String ) Handles gRegionalCodeServerServices.ServiceMessage
SendMessage(sender, message)
End Sub
Private Sub gRegionalCodeServerServices_UpdateDatabaseCurrentPercent( ByVal sender As Object , ByVal currentPercent As Integer ) Handles gRegionalCodeServerServices.UpdateDatabaseCurrentPercent
ShowCurrentPercent(currentPercent)
End Sub
Private Sub SendMessage( ByVal message As String )
SendMessage( Nothing , message)
End Sub
Private Sub SendMessage( ByVal sender As Object , ByVal message As String )
RaiseEvent ServiceMessage(sender, message)
End Sub
Private Sub ShowCurrentPercent( ByVal currentPercent As Integer )
RaiseEvent UpdateDatabaseCurrentPercent( Nothing , currentPercent)
End Sub
End Class
End Namespace
Public Class ServerServices
Implements RegionalCodeCommon.Interface.IServerServices
Public Event ServiceMessage( ByVal sender As Object , ByVal message As String ) Implements RegionalCodeCommon.Interface.IServerServices.ServiceMessage
Public Event UpdateDatabaseCurrentPercent( ByVal sender As Object , ByVal currentPercent As Integer ) Implements RegionalCodeCommon.Interface.IServerServices.UpdateDatabaseCurrentPercent
Private WithEvents gRegionalCodeServerServices As RegionalCodeLibrary.DatabaseServices
Sub New ( ByVal connectionString As String )
gRegionalCodeServerServices = New RegionalCodeLibrary.DatabaseServices(connectionString)
End Sub
Private Sub gRegionalCodeServerServices_ServiceMessage( ByVal sender As Object , ByVal message As String ) Handles gRegionalCodeServerServices.ServiceMessage
SendMessage(sender, message)
End Sub
Private Sub gRegionalCodeServerServices_UpdateDatabaseCurrentPercent( ByVal sender As Object , ByVal currentPercent As Integer ) Handles gRegionalCodeServerServices.UpdateDatabaseCurrentPercent
ShowCurrentPercent(currentPercent)
End Sub
Private Sub SendMessage( ByVal message As String )
SendMessage( Nothing , message)
End Sub
Private Sub SendMessage( ByVal sender As Object , ByVal message As String )
RaiseEvent ServiceMessage(sender, message)
End Sub
Private Sub ShowCurrentPercent( ByVal currentPercent As Integer )
RaiseEvent UpdateDatabaseCurrentPercent( Nothing , currentPercent)
End Sub
End Class
End Namespace
ServerServices.GetAllInformationsTable.vb
Namespace
Services
Partial Class ServerServices
Private Const ALLINFORMATIONS_EMPTY As String = " Empty "
Public Function GetAllInformationsTable( ByVal regionalcodeDate As String ) As RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable Implements RegionalCodeCommon.Interface.IServerServices.GetAllInformationsTable
Dim mResult As New RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable
mResult.TableName = ALLINFORMATIONS_EMPTY ' 版本日期初始化为Empty
Dim tmpTable As DataTable = gRegionalCodeServerServices.AllInformationsTable(regionalcodeDate)
If tmpTable.TableName = ALLINFORMATIONS_EMPTY Then
SendMessage( String .Format( " 查询不到日期为{0}的数据。数据库若无数据请更新;若有数据,请考虑使用最早版本的数据。 " , regionalcodeDate))
Else
With mResult
.Load(tmpTable.CreateDataReader)
.TableName = tmpTable.TableName ' 取版本日期
.AcceptChanges()
End With
End If
Return mResult
End Function
End Class
End Namespace
Partial Class ServerServices
Private Const ALLINFORMATIONS_EMPTY As String = " Empty "
Public Function GetAllInformationsTable( ByVal regionalcodeDate As String ) As RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable Implements RegionalCodeCommon.Interface.IServerServices.GetAllInformationsTable
Dim mResult As New RegionalCodeCommon.Database.dsRegionalCode.AllInformationsDataTable
mResult.TableName = ALLINFORMATIONS_EMPTY ' 版本日期初始化为Empty
Dim tmpTable As DataTable = gRegionalCodeServerServices.AllInformationsTable(regionalcodeDate)
If tmpTable.TableName = ALLINFORMATIONS_EMPTY Then
SendMessage( String .Format( " 查询不到日期为{0}的数据。数据库若无数据请更新;若有数据,请考虑使用最早版本的数据。 " , regionalcodeDate))
Else
With mResult
.Load(tmpTable.CreateDataReader)
.TableName = tmpTable.TableName ' 取版本日期
.AcceptChanges()
End With
End If
Return mResult
End Function
End Class
End Namespace
ServerServices.GetDataVersionTable.vb
Namespace
Services
Partial Class ServerServices
Private Const VERSIONDATE_TABLENAME As String = " VersionDate "
Public Function GetDataVersionTable() As RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable Implements RegionalCodeCommon.Interface.IServerServices.GetDataVersionTable
Dim mResult As New RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable
mResult.TableName = VERSIONDATE_TABLENAME
Dim tmpTable As DataTable = gRegionalCodeServerServices.DataVersionTable
If tmpTable.Rows.Count = 0 Then
SendMessage( " 数据库无数据。请从网上下载数据。如本地有数据,也可以本地数据来更新 " )
Else
mResult.Load(tmpTable.CreateDataReader)
mResult.AcceptChanges()
End If
Return mResult
End Function
End Class
End Namespace
Partial Class ServerServices
Private Const VERSIONDATE_TABLENAME As String = " VersionDate "
Public Function GetDataVersionTable() As RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable Implements RegionalCodeCommon.Interface.IServerServices.GetDataVersionTable
Dim mResult As New RegionalCodeCommon.Database.dsRegionalCode.VersionsDataTable
mResult.TableName = VERSIONDATE_TABLENAME
Dim tmpTable As DataTable = gRegionalCodeServerServices.DataVersionTable
If tmpTable.Rows.Count = 0 Then
SendMessage( " 数据库无数据。请从网上下载数据。如本地有数据,也可以本地数据来更新 " )
Else
mResult.Load(tmpTable.CreateDataReader)
mResult.AcceptChanges()
End If
Return mResult
End Function
End Class
End Namespace
ServerServices.UpdateDatabase.vb
Namespace
Services
Partial Class ServerServices
Public Sub UpdateDatabase( ByVal tableCollection As RegionalCodeCommon.Database.UpdateDatabaseDataSet) Implements RegionalCodeCommon.Interface.IServerServices.UpdateDatabase
gRegionalCodeServerServices.UpdateDatabase(tableCollection.DataSet)
End Sub
End Class
End Namespace
Partial Class ServerServices
Public Sub UpdateDatabase( ByVal tableCollection As RegionalCodeCommon.Database.UpdateDatabaseDataSet) Implements RegionalCodeCommon.Interface.IServerServices.UpdateDatabase
gRegionalCodeServerServices.UpdateDatabase(tableCollection.DataSet)
End Sub
End Class
End Namespace
那些提示信息,可以考虑放在项目资源里面。在这里这样写,是为了方便读代码。
下一篇完成后,我提供代码下载,写到这里,需要调试了。
下一篇,行政区划程序的设计(十二),RegionalCodeCenter项目的编码,IClientProvideServices的实现。