Files
Doku/Dokumentation/HostVerschieben.vb
2018-11-22 16:52:25 +01:00

90 lines
3.3 KiB
VB.net

Imports System.Data.SqlClient
Public Class HostVerschieben
Dim AlteIP As String
Dim NeueIP As String
Public con As New SqlConnection
Public cmd As New SqlCommand
Public Linked As Boolean = False
Private Sub NetzwerkÄndern_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dbload()
AlteIP = HostBearbeiten.TxtIP.Text
Linked = HostBearbeiten.ChkLinked.Checked
TxtIPAlt.Text = AlteIP
End Sub
Public Function dbload()
con.ConnectionString = Class1.DBConString
cmd.Connection = con
End Function
Private Sub CmdSave_Click(sender As Object, e As EventArgs) Handles CmdSave.Click
Dim ZielNWName As String
Dim ZielStandort As String
Dim QuellNWName As String
Dim QuellStandort As String
Dim QuellNW, ZielNW As String
NeueIP = TxtIPNeu.Text
Dim FQDN, Type As String
Class1.GetFQDNandType(NeueIP, FQDN, Type)
If FQDN = "" And Type = "" Then
If MsgBox("IP Adresse von " & AlteIP & " auf " & NeueIP & " ändern?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Class1.ip2netname(NeueIP, ZielStandort, ZielNWName)
Class1.ip2netname(AlteIP, QuellStandort, QuellNWName)
Class1.Name2Netzwerk(QuellStandort, QuellNWName, QuellNW)
Class1.Name2Netzwerk(ZielStandort, ZielNWName, ZielNW)
Dim NeuerHost As String = Class1.IP2Host(NeueIP)
Dim AlterHost As String = Class1.IP2Host(AlteIP)
If FolderMove(QuellStandort & "_" & QuellNWName, AlterHost, ZielStandort & "_" & ZielNWName, NeuerHost) = "Fehler" Then
Exit Sub
End If
con.Open()
cmd.CommandText = "DELETE Tbl_Netzwerkclients WHERE IPAdresse = '" & NeueIP & "'"
cmd.ExecuteNonQuery()
cmd.CommandText = "UPDATE Tbl_Netzwerkclients SET IPAdresse = '" & NeueIP & "', NWSTANDORT = '" & ZielStandort & "', NETNAME = '" & ZielNWName & "', HOST = '" & NeuerHost & "' WHERE IPAdresse = '" & AlteIP & "'"
cmd.ExecuteNonQuery()
con.Close()
Class1.RefillNW(QuellNW)
HostBearbeiten.importiere(ZielStandort, ZielNWName, NeuerHost)
HostBearbeiten.StandA = ZielStandort
HostBearbeiten.NetA = ZielNWName
HostBearbeiten.HostA = NeuerHost
Me.Close()
Else
Exit Sub
End If
Else
MsgBox("Eintrag " & FQDN & " an ZielIP bereits vorhanden.")
Exit Sub
End If
End Sub
Private Function FolderMove(oldID As String, oldHost As String, newID As String, NewHost As String)
Dim PathOld As String
Dim PathNew As String
'MsgBox(oldID & newID)
If Linked = True Then
Exit Function
Else
PathOld = Class1.FilePath & "\" & oldID & "\" & oldHost
PathNew = Class1.FilePath & "\" & newID & "\" & NewHost
If IO.Directory.Exists(PathNew) Then
MsgBox("Zielordner existiert bereits! Abbruch.")
Return "Fehler"
End If
If IO.Directory.Exists(PathNew) Then
IO.Directory.Move(PathOld, PathNew)
End If
End If
End Function
End Class