<SPC_RE02-01>                                               <----這是第一層
        <Path>                                                       <----這是第二層
            <SpcData Value="" />                            <----這是第三層
        </Path>
        <EnumSetting>
        </EnumSetting>
        <ChartArea1>
            <Times Value="0" />     
            <Series1>          
                <LineStyle Value="0" />                     <-----這是第四層
            </Series1>
        </ChartArea1>
        <ChartArea2>
            <Times Value="0" />
            <Series1>            
                <LineStyle Value="0" />           
            </Series1>
        </ChartArea2>
</SPC_RE02-01>

 

再來 讓我們來看程式碼的部分, 首先建立一個  繼承 System.Configuration.ConfigurationSection 的物件

其實這個就是 第二層分類  主要就是用來做大群組分類。

依照物件畫編輯方式,其實 每一個層 都是一個 Class ,每個Class 都必須繼承 System.Configuration.ConfigurationElement

後面就不再多提

 

 


    ''' <summary>
    ''' 大分類群組
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Sections
        Inherits System.Configuration.ConfigurationSection

        Public Shared SectionName As String      '專屬專案場別  代號

        Sub New()
            SectionName = "SPC_RE02-01"          
        End Sub


        ''' <summary>
        ''' 路徑分類
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("Path")> _
        Public ReadOnly Property Path() As PathGroup
            Get
                Return CType(Me("Path"), PathGroup)
                If My.Computer.Name = "aa" Then

                End If
            End Get
        End Property


        ''' <summary>
        ''' 開放用者修改機台環境變數
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("EnumSetting")> _
        Public ReadOnly Property EnumSetting() As EnumSettingGroup
            Get
                Return CType(Me("EnumSetting"), EnumSettingGroup)
            End Get
        End Property

        ''' <summary>
        ''' 第一個 Chart 用的設定檔
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("ChartArea1")> _
        Public ReadOnly Property Chart1() As ChartGroup
            Get
                Return CType(Me("ChartArea1"), ChartGroup)
            End Get
        End Property

        ''' <summary>
        ''' 第二個 Chart 用的設定檔
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("ChartArea2")> _
        Public ReadOnly Property Chart2() As ChartGroup
            Get
                Return CType(Me("ChartArea2"), ChartGroup)
            End Get
        End Property
    End Class

 

 

上面的 Code 可以看到 都是一個 Group .....也就是自定義的 Class

首先 Property 中的 字串"   "  與 return 中的 "    " 字串必須相同  (不相同  可以自行試試...)

再來是 第三層 與 第四層  用 ChartGroup 來介紹

容我再簡化一次.......


    ''' <summary>
    ''' 路徑群組
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ChartDetail      '
        Inherits System.Configuration.ConfigurationElement

        ''' <summary>
        ''' 分類編號
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("KindNo")> _
        Public ReadOnly Property KindNo As ConfigIntElement
            Get
                Return DirectCast(Me("KindNo"), ConfigIntElement)
            End Get
        End Property

          ''' <summary>
        ''' 折線的種類
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("LineStyle")> _
        Public ReadOnly Property LineStyle As ConfigIntElement
            Get
                Return DirectCast(Me("LineStyle"), ConfigIntElement)
            End Get
        End Property

        ''' <summary>
        ''' 折線的顏色
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("LineColor")> _
        Public ReadOnly Property LineColor As ConfigColorElement
            Get
                Return DirectCast(Me("LineColor"), ConfigColorElement)
            End Get
        End Property

        ''' <summary>
        ''' 折線的粗細
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <Configuration.ConfigurationProperty("BoardWidth")> _
        Public ReadOnly Property BoardWidth As ConfigIntElement
            Get
                Return DirectCast(Me("BoardWidth"), ConfigIntElement)
            End Get
        End Property

    End Class

 

在之前的設定檔 與這個 部分  我們可以看到 一共有 2個 Chart 要設定也就是這樣 才會多一層 用這個再做分類

個別要設定 No, 折線圖種類、線的顏色、線的粗細  (相信很多人對於 Color 要寫設定檔 有點麻煩....這個部分這可以輕鬆幫忙解決)

這兩個 Chart 在設定檔中 各設定一個 Group ,相同的代碼就可以重複使用,對於在特定的時候 真的很好用 (在個人真實使用 高達 12 chart,自己編寫  雖然只是複製貼上 但容易眼花..)

 

 

再來就是最底層 (第四層  也就是 值的輸入),就是下面的部分


    ''' <summary>
    ''' 基本組成元素  Color
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ConfigColorElement
        Inherits System.Configuration.ConfigurationElement

        <Configuration.ConfigurationProperty("Color")> _
        Public Property Color() As Color
            Get
                Return DirectCast(Me("Color"), Color)
            End Get
            Set(ByVal value As Color)
                Me("Color") = value
            End Set
        End Property
    End Class

    ''' <summary>
    ''' 基本組成元素  Boolean
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ConfigBoolElement
        Inherits System.Configuration.ConfigurationElement

        <Configuration.ConfigurationProperty("Switch")> _
        Public Property Switch() As Boolean
            Get
                Return DirectCast(Me("Switch"), Boolean)
            End Get
            Set(ByVal value As Boolean)
                Me("Switch") = value
            End Set
        End Property
    End Class

    ''' <summary>
    ''' 座標基本組成元素
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ConfigCoorElement
        Inherits System.Configuration.ConfigurationElement

        <Configuration.ConfigurationProperty("X")> _
        Public Property X() As Double
            Get
                Return DirectCast(Me("X"), Double)
            End Get
            Set(ByVal value As Double)
                Me("X") = value
            End Set
        End Property

        <Configuration.ConfigurationProperty("Y")> _
        Public Property Y() As Double
            Get
                Return DirectCast(Me("Y"), Double)
            End Get
            Set(ByVal value As Double)
                Me("Y") = value
            End Set
        End Property

        <Configuration.ConfigurationProperty("Z")> _
        Public Property Z() As Double
            Get
                Return DirectCast(Me("Z"), Double)
            End Get
            Set(ByVal value As Double)
                Me("Z") = value
            End Set

        End Property

    End Class

 

在上面這一塊  看到會有些繁雜,但這也是沒有辦法,必須符合 Property 的設定

其實上面的 Group 的組成 也可以 不只是 Readyonly 但就看使用者個需求

這一塊也就是 為何 Color 資料型態 或自定義型態 可以快速寫入設定檔的部分

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Rh 的頭像
    Rh

    程式狂想曲

    Rh 發表在 痞客邦 留言(0) 人氣()