181 lines
7.2 KiB
VB.net
181 lines
7.2 KiB
VB.net
Imports System.IO
|
|
Imports System.Xml
|
|
|
|
Module ModuleMySettings
|
|
Dim ConfigPath As String = Path.Combine(Application.UserAppDataPath(), "UserConfig.xml")
|
|
Public MyConnectionString As String = ""
|
|
Public LogErrorsOnly As Boolean = True
|
|
Public GI_withWindream As Boolean = False
|
|
Public vWLaufwerk As String = "W"
|
|
Public Preview As Boolean = True
|
|
Public UniversalViewer As String
|
|
Public FW_started As Boolean = False
|
|
Public Delete_OriginFile As Boolean = False
|
|
|
|
Public Function LoadMyConfig()
|
|
Dim rowresult As String = ""
|
|
Try
|
|
Dim DT As DataTable
|
|
'if file doesn't exist, create the file with its default xml table
|
|
If Not File.Exists(ConfigPath) Then
|
|
DT = CreateConfigTable()
|
|
DT.WriteXml(ConfigPath)
|
|
End If
|
|
DT = GetTablefromXML()
|
|
For Each Row As DataRow In DT.Rows
|
|
rowresult &= Row.Item("ConfigName")
|
|
Select Case Row.Item("ConfigName")
|
|
Case "MyConnectionString"
|
|
Dim connstring As String
|
|
'Den ConnectonString mit verschlüsseltem PW laden
|
|
Dim csb As New SqlClient.SqlConnectionStringBuilder
|
|
csb.ConnectionString = Row.Item("Value")
|
|
If csb.ConnectionString.Contains("Password=") Then
|
|
'SA-Auth
|
|
'Jetzt das Passwort entschlüsseln
|
|
Dim PWplainText As String
|
|
Dim wrapper As New ClassEncryption("!35452didalog=")
|
|
' DecryptData throws if the wrong password is used.
|
|
Try
|
|
PWplainText = wrapper.DecryptData(csb.Password)
|
|
Catch ex As Exception
|
|
ClassLogger.Add("- the Password '" & csb.Password & "' could not be decrypted", False)
|
|
PWplainText = csb.Password
|
|
End Try
|
|
connstring = Row.Item("Value").ToString.Replace(csb.Password, PWplainText)
|
|
Else
|
|
'Win-Auth
|
|
connstring = Row.Item("Value").ToString
|
|
End If
|
|
|
|
MyConnectionString = connstring
|
|
Case "LogErrorsOnly"
|
|
LogErrorsOnly = CBool(Row.Item("Value"))
|
|
Case "Preview"
|
|
Preview = CBool(Row.Item("Value"))
|
|
Case "UniversalViewer"
|
|
UniversalViewer = Row.Item("Value")
|
|
Case "FW_started"
|
|
FW_started = CBool(Row.Item("Value"))
|
|
Case "Delete_OriginFile"
|
|
Delete_OriginFile = CBool(Row.Item("Value"))
|
|
End Select
|
|
|
|
Next
|
|
'update 1.1
|
|
If rowresult.Contains("FW_started") = False Then
|
|
Dim newRow As DataRow = DT.NewRow()
|
|
newRow("ConfigName") = "FW_started"
|
|
newRow("Value") = "False"
|
|
DT.Rows.Add(newRow)
|
|
DT.WriteXml(ConfigPath)
|
|
End If
|
|
'update 1.6
|
|
If rowresult.Contains("Delete_OriginFile") = False Then
|
|
Dim newRow As DataRow = DT.NewRow()
|
|
newRow("ConfigName") = "Delete_OriginFile"
|
|
newRow("Value") = "False"
|
|
DT.Rows.Add(newRow)
|
|
DT.WriteXml(ConfigPath)
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox("Error in MySettings-LoadMyConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
Return True
|
|
|
|
End Function
|
|
Private Function GetTablefromXML()
|
|
Try
|
|
Dim DS As New DataSet
|
|
DS.ReadXml(ConfigPath)
|
|
Return DS.Tables(0)
|
|
Catch ex As Exception
|
|
MsgBox("Error in GetTablefromXML" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
|
|
End Function
|
|
Private Function CreateConfigTable() As DataTable
|
|
Try
|
|
' Create sample Customers table, in order
|
|
' to demonstrate the behavior of the DataTableReader.
|
|
Dim table As New DataTable
|
|
table.TableName = "MyConfig"
|
|
|
|
' Create two columns, ID and Name.
|
|
Dim idColumn As DataColumn = table.Columns.Add("ID", _
|
|
GetType(System.Int32))
|
|
|
|
idColumn.AutoIncrement = True
|
|
idColumn.AutoIncrementSeed = 0
|
|
idColumn.AutoIncrementStep = 1
|
|
table.Columns.Add("ConfigName", GetType(System.String))
|
|
table.Columns.Add("Value", GetType(System.String))
|
|
'Set the ID column as the primary key column.
|
|
table.PrimaryKey = New DataColumn() {idColumn}
|
|
Dim newRow As DataRow = table.NewRow()
|
|
newRow("ConfigName") = "MyConnectionString"
|
|
newRow("Value") = ""
|
|
table.Rows.Add(newRow)
|
|
Dim newRow1 As DataRow = table.NewRow()
|
|
newRow1("ConfigName") = "LogErrorsOnly"
|
|
newRow1("Value") = "True"
|
|
table.Rows.Add(newRow1)
|
|
Dim newRow2 As DataRow = table.NewRow()
|
|
newRow2("ConfigName") = "Preview"
|
|
newRow2("Value") = "True"
|
|
table.Rows.Add(newRow2)
|
|
Dim newRow3 As DataRow = table.NewRow()
|
|
newRow3("ConfigName") = "UniversalViewer"
|
|
newRow3("Value") = ""
|
|
table.Rows.Add(newRow3)
|
|
Dim newRow4 As DataRow = table.NewRow()
|
|
newRow4("ConfigName") = "FW_started"
|
|
newRow4("Value") = "False"
|
|
table.Rows.Add(newRow4)
|
|
table.AcceptChanges()
|
|
Return table
|
|
Catch ex As Exception
|
|
MsgBox("Error in CreateConfigTable" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
Public Function SaveConfigValue(name As String, value As String)
|
|
Try
|
|
Dim DT As DataTable
|
|
DT = GetTablefromXML()
|
|
|
|
For Each Row As DataRow In DT.Rows
|
|
If Row.Item("ConfigName") = name Then
|
|
Row.Item("Value") = value
|
|
End If
|
|
Next
|
|
DT.AcceptChanges()
|
|
DT.WriteXml(ConfigPath)
|
|
Catch ex As Exception
|
|
MsgBox("Error in SaveConfigValue" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
Return True
|
|
|
|
End Function
|
|
Public Function Load_BasicConfig()
|
|
Try
|
|
ClassDatabase.Init()
|
|
Dim sql As String = "select * from tbdd_Modules where NAME = 'Global-Indexer'"
|
|
Dim DT As DataTable = ClassDatabase.Return_Datatable(sql)
|
|
If DT.Rows.Count = 1 Then
|
|
GI_withWindream = DT.Rows(0).Item("BIT1")
|
|
vWLaufwerk = DT.Rows(0).Item("STRING1")
|
|
Else
|
|
Return False
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox("Error in Load_BasicConfig" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return False
|
|
End Try
|
|
Return True
|
|
End Function
|
|
End Module
|