Offline Modus Verbesserungen, SMB Share für User FIX

This commit is contained in:
ms
2025-03-18 09:03:36 +01:00
parent 130faf71ef
commit d275cf320d
18 changed files with 626 additions and 123 deletions

View File

@@ -4,6 +4,7 @@ Imports System.IO
Public Class Class1
Public Shared offline As Boolean = False
Public sAppPath As String = Application.StartupPath
'Public Shared DBConString As String = "Server=NBMIESENBECK\SPIELWIESE;Initial Catalog=Doku;User ID=sa;Password=verag#3;Connection Timeout=5;"
Public Shared DBConString As String
@@ -12,6 +13,8 @@ Public Class Class1
Public Shared DBAdmin As String = "[SQLGuide01.verag.ost.dmn].ADMIN"
'Public Shared DBDoku As String = "Server=SQLGuide01.verag.ost.dmn\Verag;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;"
Public Shared DBDoku As String = "Server=SQLGuide01.verag.ost.dmn\Verag;Initial Catalog=Doku;User ID=AppUser;Password=yp/THDd?xM+pZ$;Connection Timeout=5;"
Public Shared lokalDBDoku As String = "Server=localhost\SQLExpress;Initial Catalog=Doku;Integrated Security=SSPI;Connection Timeout=5;"
'Public Shared DBDoku As String = "Server=dokusql.verag.ost.dmn\sqlexpress;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;"
Public Shared DBDokuTest As String = "Server=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=Doku;User ID=AppUser;Password=yp/THDd?xM+pZ$;Connection Timeout=5;"
'Public Shared FilePath As String = "\\192.168.0.253\backup\temp_Sebastian\Spielwiese\Doku"
@@ -50,6 +53,8 @@ Public Class Class1
If i > 0 Then
If s = "/d" Or s = "-d" Then
Startparameter = "debug"
ElseIf s = "/offline" Or s = "-offline" Then
Class1.offline = True
Else
End If
End If
@@ -61,6 +66,8 @@ Public Class Class1
Class1.DBConString = DBDokuTest '"Server=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;"
Class1.FilePath = "\\192.168.0.253\backup\temp_Sebastian\DokuTest"
ElseIf offline = True Then
DBConString = lokalDBDoku
Else
Class1.DBConString = DBDoku '"Server=sqlguide01.verag.ost.dmn;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;"
Class1.FilePath = "\\DEVELOPER.verag.ost.dmn\f\EDV-Wartung\Dokumentation"

View File

@@ -115,7 +115,7 @@ Public Class cBerechtigungen
If ds.Tables(0).Rows.Count > 0 Then
Return ds.Tables(0).Rows(0).Item(0).ToString
Else
MsgBox("Keine Berechtigung gefunden")
If Not Class1.offline Then MsgBox("Keine Berechtigung gefunden")
Return "0"
End If
End Function

View File

@@ -71,6 +71,7 @@ Public Class cDomUser
End Function
Public Function getDomUserByID(ID As String)
If Class1.offline Then Exit Function
Dim ds As New DataSet
cSQL.SQL2DS("select " & SelectItems & " from [SQLGuide01.verag.ost.dmn].doku.dbo.tbl_domuser as Doku left join [SQLGuide01.verag.ost.dmn].ADMIN.dbo.tblMitarbeiter on mit_AliasAD_Username = du_sAMAc WHERE du_ID = '" & ID & "'", ds)
@@ -152,6 +153,7 @@ Public Class cDomUser
End If
End Function
Public Function getFromAvisoUser(Optional ByVal AvisoUser As String = "")
If Class1.offline Then Exit Function
If AvisoUser = "" Then
AvisoUser = Me.mit_username
End If
@@ -180,6 +182,7 @@ Public Class cDomUser
End Function
Public Function getFromAvisoUserLIST(AvisoUser As String)
If Class1.offline Then Exit Function
Dim ds As New DataSet
Dim AvisoUserList As New List(Of cDomUser)
cSQL.SQL2DS("select * from ADMIN.dbo.tblMitarbeiter where mit_username = '" & AvisoUser & "'", ds, Class1.DBADMINBuchhaltung)

View File

@@ -3,7 +3,7 @@ Imports Chilkat
Public Class cPascom
Dim API_USER_AUTHORIZATION = "bW9ieTpnWlhTSVprTnhmaUQxOEU="
Dim API_USER_AUTHORIZATION = ""
Property Arbeitsplatz As String = ""
Property Username As String = ""
Dim TelUrl As String = ""
@@ -14,9 +14,18 @@ Public Class cPascom
If ds.Tables(0).Rows.Count > 0 Then
TelUrl = ds.Tables(0).Rows(0).Item(0).ToString
End If
ds.Clear()
cSQL.SQL2DS("SELECT Parameter FROM [Doku].[dbo].[TbL_Dienste] where name = 'PascomAPICred'", ds)
If ds.Tables(0).Rows.Count > 0 Then
API_USER_AUTHORIZATION = ds.Tables(0).Rows(0).Item(0).ToString
End If
End Sub
Public Function Anmelden() As Boolean
If Arbeitsplatz.Length > 0 And Username.Length > 0 Then
Try
@@ -129,7 +138,7 @@ Public Class cPascom
End If
rest.AddHeader("Content-Type", "application/json")
rest.SetAuthBasic("moby", "XgDsFmMSutaMLA1")
rest.SetAuthBasic("qYAnX6SpQ62SK4ZZfi8IMRIHJ", "10vO6fO2CMVfL1P0hFuqWzvvh")
Dim json As New Chilkat.JsonObject
@@ -171,7 +180,7 @@ Public Class cPascom
Dim Resp_errorCode = jsonResp.StringOf("errorCode")
Target = jsonResp.StringOf("target")
' MsgBox("Hier!!!")
'MsgBox("Hier!!!")
Return True

View File

@@ -15,6 +15,95 @@ Public Class cSQL
con.Close()
End Sub
Sub UpdateDatenbankStruktur()
Dim conn As New SqlConnection(Class1.DBDoku)
Dim cmd As New SqlCommand("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'", conn)
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
Dim tableName As String = reader("TABLE_NAME").ToString()
Console.WriteLine("CREATE TABLE " & tableName)
' Hier kannst du dann den CREATE TABLE Befehl generieren
UpdateOrCreateTable(Class1.DBDoku, Class1.lokalDBDoku, tableName)
SyncDatenbank(tableName)
End While
conn.Close()
End Sub
Sub SyncDatenbank(tabelle As String)
Dim conn As New SqlConnection(Class1.lokalDBDoku)
Dim cmd As New SqlCommand($"
DELETE FROM {tabelle};
INSERT INTO {tabelle}
SELECT * FROM [sqlcluster.verag.ost.dmn].doku.dbo.{tabelle};", conn)
Try
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Console.WriteLine("Datenbank erfolgreich synchronisiert!")
Catch ex As Exception
Console.WriteLine("Fehler bei der Synchronisation: " & ex.Message)
End Try
End Sub
Sub UpdateOrCreateTable(sqlServerConnectionString As String, localSqlServerConnectionString As String, tableName As String)
' SQL Server-Abfrage für die Spalteninformationen
Dim query As String = $"SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{tableName}'"
Dim columnDefinitions As New List(Of String)
' Abfrage für die Spaltenstruktur der Remote-Tabelle
Using con As New SqlConnection(sqlServerConnectionString)
con.Open()
Using cmd As New SqlCommand(query, con)
Using reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
Dim columnName As String = reader("COLUMN_NAME").ToString()
Dim dataType As String = reader("DATA_TYPE").ToString()
If reader("CHARACTER_MAXIMUM_LENGTH") IsNot DBNull.Value Then
dataType &= $"({reader("CHARACTER_MAXIMUM_LENGTH").ToString()})"
If dataType = "varchar(-1)" Then dataType = "varchar(max)"
End If
Dim isNullable As String = If(reader("IS_NULLABLE").ToString() = "YES", "NULL", "NOT NULL")
columnDefinitions.Add($"{columnName} {dataType} {isNullable}")
End While
End Using
End Using
End Using
' Die lokale SQL Server-Datenbank, in der die Tabelle erstellt wird
Using localSqlCon As New SqlConnection(localSqlServerConnectionString)
localSqlCon.Open()
' Prüfen, ob die Tabelle bereits existiert
Dim tableExistsQuery As String = $"SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{tableName}'"
Using cmd As New SqlCommand(tableExistsQuery, localSqlCon)
Dim exists As Object = cmd.ExecuteScalar()
If exists Is Nothing Then
' Erstelle die Tabelle, wenn sie nicht existiert
Dim createTableSQL As String = $"CREATE TABLE {tableName} ({String.Join(", ", columnDefinitions)});"
Using createCmd As New SqlCommand(createTableSQL, localSqlCon)
createCmd.ExecuteNonQuery()
End Using
Else
' Falls die Tabelle bereits existiert, überprüfe und füge neue Spalten hinzu
For Each columnDef In columnDefinitions
Dim columnName As String = columnDef.Split(" ")(0)
Dim addColumnSQL As String = $"ALTER TABLE {tableName} ADD COLUMN {columnDef};"
Try
Using alterCmd As New SqlCommand(addColumnSQL, localSqlCon)
alterCmd.ExecuteNonQuery()
End Using
Catch ex As Exception
' Falls die Spalte bereits existiert, wird die Exception ignoriert
End Try
Next
End If
End Using
End Using
End Sub
Public Shared Sub UpdateSQL(ByRef table As String, ByRef values As String, ByRef where As String, Optional ByRef DBConnect As String = "")
If DBConnect = "" Then DBConnect = Class1.DBConString
Dim con As New SqlConnection

View File

@@ -0,0 +1,128 @@
Imports System.Data.SqlClient
Imports System.Data.SQLite
Public Class cSQL2SQLLite
Function Main(tableName As String)
Dim sqlServerConString = Class1.DBDoku
Dim sqliteFile As String = "C:\verag\offline_db.sqlite"
Dim sqliteConnString As String = $"Data Source={sqliteFile};Version=3;"
UpdateOrCreateTable(sqlServerConString, sqliteConnString, tableName)
CopyDataIncrementally(sqlServerConString, sqliteConnString, tableName)
End Function
Sub UpdateOrCreateTable(sqlServerConnectionString As String, localSqlServerConnectionString As String, tableName As String)
' SQL Server-Abfrage für die Spalteninformationen
Dim query As String = $"SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{tableName}'"
Dim columnDefinitions As New List(Of String)
' Abfrage für die Spaltenstruktur der Remote-Tabelle
Using con As New SqlConnection(sqlServerConnectionString)
con.Open()
Using cmd As New SqlCommand(query, con)
Using reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
Dim columnName As String = reader("COLUMN_NAME").ToString()
Dim dataType As String = reader("DATA_TYPE").ToString()
If reader("CHARACTER_MAXIMUM_LENGTH") IsNot DBNull.Value Then
dataType &= $"({reader("CHARACTER_MAXIMUM_LENGTH").ToString()})"
End If
Dim isNullable As String = If(reader("IS_NULLABLE").ToString() = "YES", "NULL", "NOT NULL")
columnDefinitions.Add($"{columnName} {dataType} {isNullable}")
End While
End Using
End Using
End Using
' Die lokale SQL Server-Datenbank, in der die Tabelle erstellt wird
Using localSqlCon As New SqlConnection(localSqlServerConnectionString)
localSqlCon.Open()
' Prüfen, ob die Tabelle bereits existiert
Dim tableExistsQuery As String = $"SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{tableName}'"
Using cmd As New SqlCommand(tableExistsQuery, localSqlCon)
Dim exists As Object = cmd.ExecuteScalar()
If exists Is Nothing Then
' Erstelle die Tabelle, wenn sie nicht existiert
Dim createTableSQL As String = $"CREATE TABLE {tableName} ({String.Join(", ", columnDefinitions)});"
Using createCmd As New SqlCommand(createTableSQL, localSqlCon)
createCmd.ExecuteNonQuery()
End Using
Else
' Falls die Tabelle bereits existiert, überprüfe und füge neue Spalten hinzu
For Each columnDef In columnDefinitions
Dim columnName As String = columnDef.Split(" ")(0)
Dim addColumnSQL As String = $"ALTER TABLE {tableName} ADD COLUMN {columnDef};"
Try
Using alterCmd As New SqlCommand(addColumnSQL, localSqlCon)
alterCmd.ExecuteNonQuery()
End Using
Catch ex As Exception
' Falls die Spalte bereits existiert, wird die Exception ignoriert
End Try
Next
End If
End Using
End Using
End Sub
Sub CopyDataIncrementally(sqlServerConnectionString As String, sqliteConnectionString As String, tableName As String)
Dim query As String = $"SELECT * FROM {tableName}"
Using sqlCon As New SqlConnection(sqlServerConnectionString)
sqlCon.Open()
Using cmd As New SqlCommand(query, sqlCon)
Using reader As SqlDataReader = cmd.ExecuteReader()
Using sqliteCon As New SQLiteConnection(sqliteConnectionString)
sqliteCon.Open()
While reader.Read()
Dim columns As New List(Of String)
Dim values As New List(Of String)
Dim parameters As New List(Of SQLiteParameter)
For i As Integer = 0 To reader.FieldCount - 1
Dim columnName As String = reader.GetName(i)
columns.Add(columnName)
values.Add($"@{columnName}")
parameters.Add(New SQLiteParameter($"@{columnName}", reader.GetValue(i)))
Next
Dim insertSQL As String = $"INSERT OR IGNORE INTO {tableName} ({String.Join(", ", columns)}) VALUES ({String.Join(", ", values)})"
Using insertCmd As New SQLiteCommand(insertSQL, sqliteCon)
insertCmd.Parameters.AddRange(parameters.ToArray())
insertCmd.ExecuteNonQuery()
End Using
End While
End Using
End Using
End Using
End Using
End Sub
Function MapSQLServerToSQLiteType(sqlType As String, length As Object) As String
Select Case sqlType.ToLower()
Case "int", "bigint", "smallint", "tinyint"
Return "INTEGER"
Case "bit"
Return "BOOLEAN"
Case "decimal", "numeric", "money", "smallmoney", "float", "real"
Return "REAL"
Case "char", "nchar", "varchar", "nvarchar", "text", "ntext"
Return "TEXT"
Case "datetime", "smalldatetime", "date", "time", "datetime2"
Return "TEXT"
Case Else
Return "TEXT"
End Select
End Function
End Class

View File

@@ -0,0 +1,127 @@
Imports System.Data.SqlClient
Imports System.Data.SQLite
Imports System.IO
Public Class cSQLSync
Dim sqlConnString As String = Class1.DBDoku
Dim sqliteFile As String = "C:\verag\offline_db.sqlite"
Dim sqliteConnString As String = $"Data Source={sqliteFile};Version=3;"
Property TbL As String
Sub Main()
' Falls die lokale Datenbank nicht existiert, erstelle sie
If Not File.Exists(sqliteFile) Then
SQLiteConnection.CreateFile(sqliteFile)
End If
' Daten synchronisieren
'CreateLocalTables()
SyncDatabase()
End Sub
' Erstellt Tabellen in der lokalen SQLite-Datenbank
Sub CreateLocalTables()
Using sqliteConn As New SQLiteConnection(sqliteConnString)
Dim convert As New cSQL2SQLLite
sqliteConn.Open()
Dim sql As String = convert.Main(TbL)
Using cmd As New SQLiteCommand(sql, sqliteConn)
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
' Synchronisiert Daten von SQL Server zu SQLite
Sub SyncDatabase()
Using sqlConn As New SqlConnection(sqlConnString)
sqlConn.Open()
' TbL_Netzwerkclients-Daten abrufen
Dim sqlQuery As String = "SELECT * FROM TbL_Netzwerkclients"
Using sqlCmd As New SqlCommand(sqlQuery, sqlConn)
Using reader As SqlDataReader = sqlCmd.ExecuteReader()
Using sqliteConn As New SQLiteConnection(sqliteConnString)
sqliteConn.Open()
' Einfügen oder Aktualisieren (Upsert)
While reader.Read()
Dim upsertQuery As String = "INSERT INTO TbL_Netzwerkclients (
IPAdresse, FQDN, QINFO, NETNAME, Seriennummer, MAC, Benutzer, Passwort, LINK, INFO, TYPE, HOST, NWSTANDORT, Modell,
Linked, LinkedWith, AddIP, Standort, DHCP, Netzwerk, Firewall, TeamviewerID, TeamviewerKennwort, SSHPort, AnydeskID, AnydeskPassword
) VALUES (
@IP, @FQDN, @QINFO, @NETNAME, @Seriennummer, @MAC, @Benutzer, @Passwort, @LINK, @INFO, @TYPE, @HOST, @NWSTANDORT, @Modell,
@Linked, @LinkedWith, @AddIP, @Standort, @DHCP, @Netzwerk, @Firewall, @TeamviewerID, @TeamviewerKennwort, @SSHPort, @AnydeskID, @AnydeskPassword
)
ON CONFLICT(IPAdresse) DO UPDATE SET
FQDN = excluded.FQDN,
QINFO = excluded.QINFO,
NETNAME = excluded.NETNAME,
Seriennummer = excluded.Seriennummer,
MAC = excluded.MAC,
Benutzer = excluded.Benutzer,
Passwort = excluded.Passwort,
LINK = excluded.LINK,
INFO = excluded.INFO,
TYPE = excluded.TYPE,
HOST = excluded.HOST,
NWSTANDORT = excluded.NWSTANDORT,
Modell = excluded.Modell,
Linked = excluded.Linked,
LinkedWith = excluded.LinkedWith,
AddIP = excluded.AddIP,
Standort = excluded.Standort,
DHCP = excluded.DHCP,
Netzwerk = excluded.Netzwerk,
Firewall = excluded.Firewall,
TeamviewerID = excluded.TeamviewerID,
TeamviewerKennwort = excluded.TeamviewerKennwort,
SSHPort = excluded.SSHPort,
AnydeskID = excluded.AnydeskID,
AnydeskPassword = excluded.AnydeskPassword;"
Using upsertCmd As New SQLiteCommand(upsertQuery, sqliteConn)
upsertCmd.Parameters.AddWithValue("@IP", reader("IPAdresse"))
upsertCmd.Parameters.AddWithValue("@FQDN", reader("FQDN"))
upsertCmd.Parameters.AddWithValue("@QINFO", reader("QINFO"))
upsertCmd.Parameters.AddWithValue("@NETNAME", reader("NETNAME"))
upsertCmd.Parameters.AddWithValue("@Seriennummer", reader("Seriennummer"))
upsertCmd.Parameters.AddWithValue("@MAC", reader("MAC"))
upsertCmd.Parameters.AddWithValue("@Benutzer", reader("Benutzer"))
upsertCmd.Parameters.AddWithValue("@Passwort", reader("Passwort"))
upsertCmd.Parameters.AddWithValue("@LINK", reader("LINK"))
upsertCmd.Parameters.AddWithValue("@INFO", reader("INFO"))
upsertCmd.Parameters.AddWithValue("@TYPE", reader("TYPE"))
upsertCmd.Parameters.AddWithValue("@HOST", reader("HOST"))
upsertCmd.Parameters.AddWithValue("@NWSTANDORT", reader("NWSTANDORT"))
upsertCmd.Parameters.AddWithValue("@Modell", reader("Modell"))
upsertCmd.Parameters.AddWithValue("@Linked", reader("Linked"))
upsertCmd.Parameters.AddWithValue("@LinkedWith", reader("LinkedWith"))
upsertCmd.Parameters.AddWithValue("@AddIP", reader("AddIP"))
upsertCmd.Parameters.AddWithValue("@Standort", reader("Standort"))
upsertCmd.Parameters.AddWithValue("@DHCP", reader("DHCP"))
upsertCmd.Parameters.AddWithValue("@Netzwerk", reader("Netzwerk"))
upsertCmd.Parameters.AddWithValue("@Firewall", reader("Firewall"))
upsertCmd.Parameters.AddWithValue("@TeamviewerID", reader("TeamviewerID"))
upsertCmd.Parameters.AddWithValue("@TeamviewerKennwort", reader("TeamviewerKennwort"))
upsertCmd.Parameters.AddWithValue("@SSHPort", reader("SSHPort"))
upsertCmd.Parameters.AddWithValue("@AnydeskID", reader("AnydeskID"))
upsertCmd.Parameters.AddWithValue("@AnydeskPassword", reader("AnydeskPassword"))
upsertCmd.ExecuteNonQuery()
End Using
End While
End Using
End Using
End Using
End Using
Console.WriteLine("Synchronisation abgeschlossen!")
End Sub
End Class