'************************************************************************* ' Class: UIsettings ' Author: Ron Savage ' Date: 10/17/2009 ' ' This class holds settings for the UIbuilder. ' ' Modification History ' Date Init Comment ' 10/17/2009 RS Modified Load() to use the class UIFileName, instead of ' sending in the filename as an argument. ' 10/17/2009 RS Created. '************************************************************************* Imports System.IO Public Class UIsettings Dim UIdata As DataSet = Nothing Dim UIFileName As String = "" '************************************************************************* ' Sub: New() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine is called when a new UIsettings() object is created, if filename ' exists we load it, otherwise we create it. '************************************************************************* Sub New(ByVal fileName As String) UIFileName = fileName Dim file As FileInfo = New FileInfo(fileName) ' If the file doesn't exist yet, it's a new one If (Not file.Exists()) Then UIdata = New DataSet("UIData") UIdata.Tables.Add(New DataTable("General")) UIdata.Tables("General").Columns.Add(New DataColumn("Setting")) UIdata.Tables("General").Columns.Add(New DataColumn("Value")) UIdata.Tables.Add(New DataTable("Fields")) UIdata.Tables("Fields").Columns.Add(New DataColumn("FieldName")) UIdata.Tables("Fields").Columns.Add(New DataColumn("Column")) UIdata.Tables("Fields").Columns.Add(New DataColumn("Row")) ' Example of exending with other field data columns 'UIdata.Tables("Fields").Columns.Add(New DataColumn("MinLength")) 'UIdata.Tables("Fields").Columns.Add(New DataColumn("MaxLength")) 'UIdata.Tables("Fields").Columns.Add(New DataColumn("MinValue")) 'UIdata.Tables("Fields").Columns.Add(New DataColumn("MaxValue")) 'UIdata.Tables("Fields").Columns.Add(New DataColumn("MinLength")) 'UIdata.Tables("Fields").Columns.Add(New DataColumn("AllowedRegEx")) Else ' we have a file, so load it. Load() End If End Sub '************************************************************************* ' Sub: Load() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine loads an existing UI configuration file. '************************************************************************* Public Sub Load() UIdata = New DataSet() UIdata.ReadXml(UIFileName) End Sub '************************************************************************* ' Sub: Save() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine saves the file. '************************************************************************* Public Sub Save() UIdata.WriteXml(UIFileName) End Sub '************************************************************************* ' Sub: getFieldValues() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine gets an array of values from the Field settings table. '************************************************************************* Public Function getFieldValues(ByVal fieldName As String) Dim value As String = "" Dim resultRows As DataRow() = Nothing resultRows = UIdata.Tables("Fields").Select("FieldName = '" + fieldName + "'") If (resultRows.Length > 0) Then value = resultRows(0).Item("FieldName") + "," + resultRows(0).Item("Column") + "," + resultRows(0).Item("Row") End If Return (value) End Function '************************************************************************* ' Sub: setFieldValues() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine gets a value from the General settings table. '************************************************************************* Public Sub setFieldValues(ByVal fieldName As String, ByVal column As String, ByVal row As String) Dim resultRows As DataRow() = Nothing resultRows = UIdata.Tables("Fields").Select("fieldName = '" + fieldName + "'") If (resultRows.Length > 0) Then resultRows(0).Item("Column") = column resultRows(0).Item("Row") = row Else Dim newData As String() = {fieldName, column, row} UIdata.Tables("Fields").Rows.Add(newData) End If End Sub '************************************************************************* ' Sub: getGeneralValue() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine gets a value from the General settings table. '************************************************************************* Public Function getGeneralValue(ByVal settingName As String) Dim value As String = "" Dim resultRows As DataRow() = Nothing resultRows = UIdata.Tables("General").Select("Setting = '" + settingName + "'") If (resultRows.Length > 0) Then value = resultRows(0).Item(1).ToString End If Return (value) End Function '************************************************************************* ' Sub: setGeneralValue() ' Author: Ron Savage ' Date: 10/17/2009 ' ' This routine gets a value from the General settings table. '************************************************************************* Public Sub setGeneralValue(ByVal settingName As String, ByVal settingValue As String) Dim resultRows As DataRow() = Nothing resultRows = UIdata.Tables("General").Select("Setting = '" + settingName + "'") If (resultRows.Length > 0) Then resultRows(0).Item("Value") = settingValue Else Dim newData As String() = {settingName, settingValue} UIdata.Tables("General").Rows.Add(newData) End If End Sub End Class