- Namespace DynamicSoft.Common.Data
- Public Class DbNull
- '**********************************************************************************************************
- '判断数据是否为 Nothing DbNull Empty 返回值如果是返回 True 否则 返回 False
- '**********************************************************************************************************
- Public Shared Function IsNothingDbNullEmpty(ByVal objValue As Object) As Boolean
- If objValue Is Nothing Then
- Return True
- End If
- If IsDBNull(objValue) Then
- Return True
- End If
- If objValue Is String.Empty Then
- Return True
- End If
- Return False
- End Function
- '**********************************************************************************************************
- '判断数据是否为 Nothing DbNull Empty 返回值如果是返回 True 否则 返回 False
- '**********************************************************************************************************
- Public Shared Function GetObjectValue(ByVal objValue As Object, ByVal objReturnValue As Object) As Object
- If objValue Is Nothing Then
- Return objReturnValue
- End If
- If IsDBNull(objValue) Then
- Return objReturnValue
- End If
- Return objValue
- End Function
- #Region "处理变量返回的值"
- '**********************************************************************************************************
- '处理字符串数据类型
- '**********************************************************************************************************
- Public Shared Function GetStringValue(ByVal objValue As Object, Optional ByVal DefaultString As String = "") As String
- If Not IsNothingDbNullEmpty(objValue) Then
- Return objValue
- Else
- Return DefaultString
- End If
- End Function
- '**********************************************************************************************************
- '处理日期数据类型
- '**********************************************************************************************************
- Public Shared Function GetDateValue(ByVal objValue As Object, Optional ByVal DefaultDate As Date = #1/1/1900#) As Date
- Dim MinDate As Date = #1/1/1900#
- If IsDate(objValue) AndAlso objValue > MinDate Then
- Return objValue
- Else
- Return Format(DefaultDate, "yyyy-MM-dd")
- End If
- End Function
- '**********************************************************************************************************
- '处理数字类型
- '**********************************************************************************************************
- Public Shared Function GetNumericValue(ByVal objValue As Object, Optional ByVal DefaultNumeric As Int64 = 0) As Int64
- If IsNumeric(objValue) Then
- Dim MaxValue As String = 0
- Dim MinValue As String = 0
- Select Case objValue.GetType.ToString
- Case Is = "System.Int16"
- MaxValue = Int16.MaxValue : MinValue = Int16.MinValue
- Case Is = "System.Int32"
- MaxValue = Int32.MaxValue : MinValue = Int32.MinValue
- Case Is = "System.Int64"
- MaxValue = Int64.MaxValue : MinValue = Int64.MinValue
- Case Is = "System.Decimal"
- MaxValue = Decimal.MaxValue : MinValue = Decimal.MinValue
- Case Is = "System.Double"
- MaxValue = Double.MaxValue : MinValue = Double.MinValue
- Case Is = "System.Single"
- MaxValue = Single.MaxValue : MinValue = Single.MinValue
- Case Is = "System.Byte"
- MaxValue = Byte.MaxValue : MinValue = Byte.MinValue
- Case Is = "System.SByte"
- MaxValue = SByte.MaxValue : MinValue = SByte.MinValue
- Case Is = "System.String"
- If IsNumeric(objValue) Then
- Return objValue
- End If
- End Select
- If objValue < MaxValue AndAlso objValue > MinValue Then
- Return objValue
- Else
- Return DefaultNumeric
- End If
- Else
- Return DefaultNumeric
- End If
- End Function
- #End Region
- End Class
- End Namespace
调用例子
- '**********************************************************************************************************
- '功 能:获取一条职位内容
- '参 数:JobID - 职位的JobID
- '返回值:Null
- '**********************************************************************************************************
- Public Overrides Function GetJob(ByVal JobID As String) As JobInfo
- Dim dr As DataRow = Common.GetRecordDetails(Table, DetailsReturnField, PrimaryKeyField, JobID)
- Dim jInfo As JobInfo
- jInfo = New JobInfo(DbNull.GetStringValue(dr("JobID")), _
- DbNull.GetStringValue(dr("Job")), _
- DbNull.GetStringValue(dr("Department")), _
- DbNull.GetNumericValue(dr("Number")), _
- DbNull.GetStringValue(dr("City")), _
- DbNull.GetDateValue(dr("ValidityDate")), _
- DbNull.GetStringValue(dr("EmailInbox")), _
- DbNull.GetStringValue(dr("Details")), _
- DbNull.GetNumericValue(dr("Language")), _
- DbNull.GetDateValue(dr("ModifiedDate")))
- Return jInfo
- End Function