Imports System.IO Imports System.Data.Sql Imports System.Data.SqlClient Imports System.Security.Principal Public Class DB Public dsDaten As New DataSet Public dsdaten1 As New DataSet Public dadaten1 As New SqlDataAdapter Public dadaten As SqlDataAdapter Dim sql As String Public Sub Get_Funktionsgruppe() Try dsDaten.Clear() sql = " SELECT funktionsgruppenr, bezeichnung from funktionsgruppe" dadaten = New SqlDataAdapter(sql, Globals.sConnectionstring) dadaten.Fill(dsDaten, "Funktionsgruppe") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Sub Get_Dokumenttyp_Funktionsgruppe(dokumenttypnr As Integer) dsdaten1.Clear() sql = " SELECT * from dokumentaufhebung where aktiv=1 and dokumenttypnr=" + dokumenttypnr.ToString dadaten1 = New SqlDataAdapter(sql, Globals.sConnectionstring) dadaten1.Fill(dsdaten1, "DokumenttypFunktionsgruppe") End Sub Sub Update_Daten() 'Try ' Dim cb As New SqlCommandBuilder(dadatendocm) ' dadatendocm.Update(dsdatendocm, dsdatendocm.Tables(0).TableName) ' MsgBox("Änderungen wurden gespeichert") 'Catch ex As Exception ' MsgBox("Felher: " + ex.Message) 'End Try End Sub End Class Public Class DB_Connection ''' ''' Liest sämtlcihe CFG-Dateien mit dem Namen "Vertragsverwaltung...". Sind meherere Dateien vorhanden, ''' wird ein Auswahldialog zur Datenbank-Selektion angezeigt. ''' Standardmässig wird Vertragsverwaltung.cfg als CFG-Datei benutzt. ''' ''' Die CFG-Datei ist verschlüsselt und wird über die Crypto-Funktionen entschlüsselt. ''' ''' Shared Sub New() Dim path As String = "" Dim fc As Integer = 0 Dim ofile As System.IO.File Dim oread As System.IO.StreamReader '25062018 If Globals.ConnectionFilename.Length = 0 And Globals.Connection_Overwritten = False Then If fc < 2 Then Globals.ConnectionFilename = "edokaconn.cfg" Globals.ConnectionFilename = ApplicationPath() + "\" + Globals.ConnectionFilename End If oread = ofile.OpenText(Globals.ConnectionFilename) sConnectionstring = oread.ReadLine sConnectionstring = Crypto.DecryptText(sConnectionstring, "HutterundMueller") sConnectionstring = Left(sConnectionstring, Len(sConnectionstring) - 1) Globals.sConnectionstring = sConnectionstring oread.Close() '20180625 Globals.conn.sConnectionString = Globals.sConnectionstring If Globals.Connection_Overwritten = False Then Check_DBConn_Overwrite() Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("Select beschreibung from pluginparameter where pluginparamnr=1", connection) Dim CB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet() Try connection.ConnectionString = Globals.sConnectionstring connection.Open() da.Fill(ds, "params") path = ds.Tables(0).Rows(0).Item(0) Catch ex As Exception path = "" CB = Nothing End Try ds = Nothing da = Nothing connection.Close() connection = Nothing Globals.ConnectionFilename = "edokaconn.cfg" oread = ofile.OpenText(path + "\" + Globals.ConnectionFilename) sConnectionstring = oread.ReadLine sConnectionstring = Crypto.DecryptText(sConnectionstring, "HutterundMueller") sConnectionstring = Left(sConnectionstring, Len(sConnectionstring) - 1) Globals.sConnectionstring = sConnectionstring oread.Close() Globals.conn.sConnectionString = Globals.sConnectionstring End Sub Shared Sub Check_DBConn_Overwrite() Dim ConnectionFile As String ConnectionFile = Check_Connectionchange(Get_Username) If ConnectionFile <> "" Then Globals.ConnectionFilename = ConnectionFile Dim ofile As System.IO.File Dim oread As System.IO.StreamReader oread = ofile.OpenText(Globals.ConnectionFilename) sConnectionstring = oread.ReadLine sConnectionstring = Crypto.DecryptText(sConnectionstring, "HutterundMueller") sConnectionstring = Left(sConnectionstring, Len(sConnectionstring) - 1) Globals.sConnectionstring = sConnectionstring Globals.conn.sConnectionString = Globals.sConnectionstring oread.Close() Globals.Connection_Overwritten = True End If End Sub Shared Function Check_Connectionchange(ByVal tgnummer As String) As String Dim scmCmdToExecute As SqlCommand = New SqlCommand() Dim i As Integer Dim connopen As Boolean = False scmCmdToExecute.CommandText = "dbo.[sp_check_Connectionchange]" scmCmdToExecute.CommandType = CommandType.StoredProcedure scmCmdToExecute.Connection = conn.scoDBConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@tgnummer", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, tgnummer)) scmCmdToExecute.Parameters.Add(New SqlParameter("@Resultat", SqlDbType.VarChar, 1024, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, 0)) Try scmCmdToExecute.Connection.Open() Catch ex As Exception 'MsgBox(ex.Message) End Try scmCmdToExecute.ExecuteNonQuery() Return scmCmdToExecute.Parameters("@Resultat").Value Catch ex As Exception MsgBox(ex.Message) Finally scmCmdToExecute.Connection.Close() scmCmdToExecute.Dispose() End Try End Function Shared Function Get_Username() As String Dim ouser As New WindowsPrincipal(WindowsIdentity.GetCurrent) With ouser.Identity.Name Return (.Substring(.IndexOf("\") + 1)) End With End Function End Class