csetcninfo.vb

来自「The Management Information System of Lib」· VB 代码 · 共 57 行

VB
57
字号
'将数据服务器信息序列化为xml文件的类
Imports System.Xml.Serialization
Imports System.IO
Imports System.Collections
Public Class CsetCnInfo
    Structure CnInfo
        Public server As String
        Public database As String
        Public uid As String
        Public password As String
    End Structure
    Private mCC(4) As String
    Public Function setCnTofile()
        Dim mcn As CnInfo
        mcn.server = mCC(0)
        mcn.database = mCC(1)
        mcn.uid = mCC(2)
        mcn.password = mCC(3)
        Dim xmlS As New XmlSerializer(GetType(CnInfo))
        Dim txtwt As TextWriter = New StreamWriter("cninfo.xml")
        xmlS.Serialize(txtwt, mCn)
        txtwt.Close()
    End Function
    Public Function GetCnFromfile() As String
        Dim mcn As CnInfo
        Dim xmls As New XmlSerializer(GetType(CnInfo))
        Dim txtwt As TextReader = New StreamReader("cninfo.xml")
        Try
            mcn = xmls.Deserialize(txtwt)
            mCC(0) = mcn.server
            mCC(1) = mcn.database
            mCC(2) = mcn.uid
            mCC(3) = mcn.password
        Catch ex As Exception
            Throw ex
        Finally
            txtwt.Close()
        End Try
        Return returnCnstr()
    End Function
    Public Function returnCnstr() As String
        Return "server=" + mCC(0) + ";database=" _
        + mCC(1) + ";uid=" + mCC(2) + ";pwd=" + mCC(3)
    End Function
    Public Property cnstr() As String()
        Get
            Return mCC
        End Get
        Set(ByVal Value As String())
            Value.CopyTo(mCC, 0)
        End Set
    End Property
    Public Sub New()

    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?