Class Cls_IniSixt


Imports System.IO
Imports System
Imports System.Collections
Imports System.Xml

Public Class Cls_IniSixt

    Private Info As ccyt.com.Information.CfgType

    Public Function CreateNewXml(ByVal FileName As String) As String

        If File.Exists(FileName) Then
        Else
            Dim sr As StreamWriter
            sr = New StreamWriter(FileName, False)
            sr.WriteLine("<?xml version='1.0' encoding='utf-8' ?>")
            sr.WriteLine("<" & Info.NOR_AuditSoftWareInfo & ">")
            sr.WriteLine("</" & Info.NOR_AuditSoftWareInfo & ">")
            sr.Close()
        End If

        Dim xmldoc As New XmlDocument
        xmldoc.Load(FileName)
        Dim root As XmlNode = xmldoc.SelectSingleNode(Info.NOR_AuditSoftWareInfo)
        root.RemoveAll()
        '添加一级
        Dim xe1 As XmlElement = xmldoc.CreateElement(Info.NOR_ConfigInfo)
        xe1.SetAttribute("databaselx", "1")

        root.AppendChild(xe1)

        xmldoc.Save(FileName)

    End Function

    Public Function WriteXml(ByVal FileName As String)

        Dim myXmlTextWriter As New System.Xml.XmlTextWriter(FileName, Nothing)

        myXmlTextWriter.Formatting = System.Xml.Formatting.Indented
        myXmlTextWriter.WriteStartDocument(False)
        myXmlTextWriter.WriteComment("2005-9-15 ccyt config.xml") '''注释
        myXmlTextWriter.WriteComment(Info.NOR_AuditSoftWareInfo)  '''注释

        myXmlTextWriter.WriteStartElement(Info.NOR_ConfigInfo)   '''表名

        myXmlTextWriter.WriteStartElement("appConfig", Nothing)

        myXmlTextWriter.WriteAttributeString("mc", "pub_odbcSys")
        myXmlTextWriter.WriteAttributeString("bz", "system")
        myXmlTextWriter.WriteAttributeString("sm", "system")
        myXmlTextWriter.WriteAttributeString("xz", "system")
        myXmlTextWriter.WriteAttributeString("jm", "system")
        myXmlTextWriter.WriteAttributeString("xm", "system")
        myXmlTextWriter.WriteAttributeString("yh", "system")

        myXmlTextWriter.WriteEndElement()

        myXmlTextWriter.WriteStartElement("appConfig", Nothing)
        myXmlTextWriter.WriteAttributeString("mc", "pub_odbcdw")
        myXmlTextWriter.WriteAttributeString("bz", "uid=sa;pwd=;driver={SQL Server};server=CCYT01;database=CCYT_AUDIT;")
        myXmlTextWriter.WriteAttributeString("sm", "system")
        myXmlTextWriter.WriteAttributeString("xz", "system")
        myXmlTextWriter.WriteAttributeString("jm", "system")
        myXmlTextWriter.WriteAttributeString("xm", "system")
        myXmlTextWriter.WriteAttributeString("yh", "system")
        myXmlTextWriter.WriteEndElement()

        myXmlTextWriter.Flush()
        myXmlTextWriter.Close()
    End Function

    Public Function DatatableToXml(ByVal FileName As String) As Boolean
        Dim Ds As DataSet
        Ds = New DataSet(Info.NOR_AuditSoftWareInfo)
        Dim Dt As New DataTable(Info.NOR_ConfigInfo)
        Ds.Tables.Add(Dt)
        Dim Dc_mc As New DataColumn("mc")
        Dim Dc_bz As New DataColumn("bz")
        Dim Dc_sm As New DataColumn("sm")
        Dim Dc_xz As New DataColumn("xz")
        Dim Dc_jm As New DataColumn("jm")
        Dim Dc_xm As New DataColumn("xm")
        Dim Dc_yh As New DataColumn("yh")

        Dt.Columns.Add(Dc_mc)
        Dt.Columns.Add(Dc_bz)
        Dt.Columns.Add(Dc_sm)
        Dt.Columns.Add(Dc_xz)
        Dt.Columns.Add(Dc_jm)
        Dt.Columns.Add(Dc_xm)
        Dt.Columns.Add(Dc_yh)

        Dc_mc.MaxLength = 200
        Dc_bz.MaxLength = 200
        Dc_sm.MaxLength = 200
        Dc_xz.MaxLength = 200
        Dc_jm.MaxLength = 200
        Dc_xm.MaxLength = 200
        Dc_yh.MaxLength = 200

        Dim Dr As DataRow = Dt.NewRow
        Dr.Item(0) = Info.NOR_DbType
        Dr.Item(1) = "1"
        Dr.Item(2) = "111"
        Dr.Item(3) = "111"
        Dr.Item(4) = "111"
        Dr.Item(5) = "111"
        Dr.Item(6) = "111"
        Dt.Rows.Add(Dr)

        Dr = Dt.NewRow
        Dr.Item(0) = Info.NOR_SysSource
        Dr.Item(1) = "system"
        Dr.Item(2) = "222"
        Dr.Item(3) = "222"
        Dr.Item(4) = "222"
        Dr.Item(5) = "222"
        Dr.Item(6) = "222"
        Dt.Rows.Add(Dr)

        Dr = Dt.NewRow
        Dr.Item(0) = Info.NOR_UnitSource
        Dr.Item(1) = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=CCYT_AUDIT;Data Source=ccyt01;"
        Dr.Item(2) = "333"
        Dr.Item(3) = "333"
        Dr.Item(4) = "333"
        Dr.Item(5) = "333"
        Dr.Item(6) = "333"
        Dt.Rows.Add(Dr)

        Dr = Dt.NewRow
        Dr.Item(0) = Info.NOR_ConnectMode
        Dr.Item(1) = "1"
        Dr.Item(2) = "444"
        Dr.Item(3) = "444"
        Dr.Item(4) = "444"
        Dr.Item(5) = "444"
        Dr.Item(6) = "444"
        Dt.Rows.Add(Dr)

        Dr = Dt.NewRow
        Dr.Item(0) = Info.NOR_VersionInfo
        Dr.Item(1) = "1.0.0.1"
        Dr.Item(2) = "555"
        Dr.Item(3) = "555"
        Dr.Item(4) = "555"
        Dr.Item(5) = "555"
        Dr.Item(6) = "555"
        Dt.Rows.Add(Dr)

        Dr = Dt.NewRow
        Dr.Item(0) = "OleConnString"
        Dr.Item(1) = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=CCYT_AUDIT;Data Source=ccyt01;"
        Dr.Item(2) = "555"
        Dr.Item(3) = "555"
        Dr.Item(4) = "555"
        Dr.Item(5) = "555"
        Dr.Item(6) = "555"
        Dt.Rows.Add(Dr)

        Ds.WriteXml(FileName)
        Ds.Dispose()
        'Dt.Select(mc = "")

    End Function

    Public Function ReadDataFromXml(ByVal filename As String) As Str_Sjxtini

        Dim R_ini As Str_Sjxtini
        If File.Exists(filename) Then
            Dim Ds As New DataSet(Info.NOR_AuditSoftWareInfo)
            Ds.ReadXml(filename)
            Dim Dr As DataRow()

            Dr = Ds.Tables(0).Select("mc='" & Info.NOR_DbType & "'")
            Dim str_bz As String
            str_bz = CType(Dr(0).Item(1), String)

            Dr = Ds.Tables(0).Select("mc='" & Info.NOR_SysSource & "'")
            Dim str_bz1 As String
            str_bz1 = CType(Dr(0).Item(1), String)

            Dr = Ds.Tables(0).Select("mc='" & Info.NOR_UnitSource & "'")
            Dim str_bz2 As String
            str_bz2 = CType(Dr(0).Item(1), String)

            Dr = Ds.Tables(0).Select("mc='" & Info.NOR_ConnectMode & "'")
            Dim str_bz3 As String
            str_bz3 = CType(Dr(0).Item(1), String)

            Dr = Ds.Tables(0).Select("mc='" & Info.NOR_VersionInfo & "'")
            Dim str_bz4 As String
            str_bz4 = CType(Dr(0).Item(1), String)

            Dr = Ds.Tables(0).Select("mc='OleConnString'")
            Dim str_bz5 As String
            str_bz5 = CType(Dr(0).Item(1), String)

            R_ini.Dblx = str_bz
            R_ini.OdbcSys = str_bz1
            R_ini.OdbcDw = str_bz2
            R_ini.Fs = str_bz3
            R_ini.Bbxx = str_bz4
            R_ini.OleConn = str_bz5

            ReadDataFromXml = R_ini
            Ds.Dispose()
        Else
            DatatableToXml(filename)
            ReadDataFromXml(filename)
        End If

    End Function

End Class

Public Structure Str_Sjxtini
    Public Dblx As String
    Public OdbcDw As String
    Public OdbcSys As String
    Public Fs As String
    Public Bbxx As String
    Public OleConn As String
End Structure

 

你可能感兴趣的:(Class)