Imports System.Runtime.InteropServices
<ComVisible(True), InterfaceType(ComInterfaceType.InterfaceIsDual), GuidAttribute("D5447A7B-FDD0-4869-8B12-69EB1A56E6E0")> _
Public Interface IEWarootUfl
Function NumberThai(ByVal strPass As String) As String 'แปลงตัวเลขอารบิคเป็นตัวเลขไทย เช่น 123 --> ๑๒๓
Function StringDate(ByVal pDate As DateTime, ByVal Date_Format As String, Optional ByVal Era_Type As String = "en_US") As String 'Support era ไทย/คริสศักราช/so on.
Function BahtText(ByVal dblPass As Double) As String 'คำตัวเลขเป็นคำอ่านภาษาไทย เช่น 12.25 --> สิบสองบาทยี่สิบห้าสตางค์
End Interface
Imports System.Runtime.InteropServices
Imports System.Globalization
<ComVisible(True), ClassInterface(ClassInterfaceType.None), GuidAttribute("F2AFEC0E-B776-41a7-A4CD-CF7F09386AE5")> _
Public Class CRUFLWaroot : Implements IEWarootUfl
'
'แปลงตัวเลขอารบิค เป็นตัวเลขไทย เช่น 123 เป็น ๑๒๓ เป็นต้น
'
Public Function NumberThai(ByVal strPass As String) As String Implements IEWarootUfl.NumberThai
If String.IsNullOrEmpty(strPass) = True OrElse strPass.Trim.Length = 0 Then Return String.Empty
For iSub As Byte = 0 To 9 'Byte 1-255
strPass = strPass.Replace(iSub.ToString, Chr(iSub + 240)) 'อักษรตัวอื่นคงไว้ที่เดิม
Next
Return strPass
End Function
'
'แปลงตัวเลขเป็นคำอ่านภาษาไทย เช่น 101 -> หนึ่งร้อยหนึ่งบาทค้วย
'
Function BahtText(ByVal dblPass As Double) As String Implements IEWarootUfl.BahtText
Return "หนึ่งสองสามสี่"
End Function
''' <summary>
''' Fixed Bug Crystal Report Datetime And Gobal Culture
''' Calll StringDate(DateTime.Now, "dd/yyyy/MM", "th-TH")
''' </summary>
''' <param name="pDate"></param>
''' <param name="Date_Format">dd/MM/yyyy, MM/dd/yyyy, etc...</param>
''' <param name="Era_Type">th-TH, en-US, en-GB</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function StringDate(pDate As Date, Date_Format As String, Optional Era_Type As String = "en_US") As String Implements IEWarootUfl.StringDate
Return pDate.ToString(Date_Format, New CultureInfo(Era_Type))
End Function
End Class
Public Class StringConverter
Public Shared Function [CDec](input As String) As String
Return String.Join(" ", (From c In input.ToCharArray() Select Convert.ToString(AscW(CChar(c)))).ToArray)
End Function
Public Shared Function CHex(input As String) As String
Return String.Join(" ", (From c In input.ToCharArray() Select Convert.ToString(AscW(CChar(c)), 16)).ToArray).ToUpper()
End Function
Public Shared Function CBin(input As String) As String
Return String.Join(" ", (From c As String In input.ToCharArray() Select Convert.ToString(AscW(CChar(c)), 2).PadLeft(8, "0")).ToArray)
End Function
Public Shared Function COct(input As String) As String
Return String.Join(" ", (From c In input.ToCharArray() Select Convert.ToString(AscW(CChar(c)), 8)).ToArray)
End Function
End Class