179 lines
6.6 KiB
VB.net
179 lines
6.6 KiB
VB.net
Imports System.Data.SqlClient
|
|
Public Class NetzwerkAdmin
|
|
Private con As New SqlConnection
|
|
Private cmd As New SqlCommand
|
|
Private Sub NetzwerkAdmin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
LstStandortLoad()
|
|
LstNetzwerkLoad()
|
|
End Sub
|
|
Public Function dbload()
|
|
con.ConnectionString = Class1.DBConString
|
|
cmd.Connection = con
|
|
End Function
|
|
Public Function LstStandortLoad()
|
|
Dim ds As New DataSet()
|
|
Dim dt As New DataTable()
|
|
Main.dbload()
|
|
Dim dataadapter As New SqlDataAdapter("SELECT NWSTANDORT from TbL_Netzwerke where main='True'", Main.con)
|
|
LstStandort.Items.Clear()
|
|
|
|
Try
|
|
Main.con.Open()
|
|
dataadapter.Fill(ds)
|
|
|
|
'DgVMain.DataSource = ds.Tables(0)
|
|
|
|
For Each dr As DataRow In ds.Tables(0).Rows
|
|
LstStandort.Items.Add(dr.Item(0))
|
|
Next
|
|
Catch ex As Exception
|
|
MsgBox("DataadapterFill LstStandOrtLoad(): " & ex.Message)
|
|
End Try
|
|
|
|
Main.con.Close()
|
|
End Function
|
|
Public Function LstNetzwerkLoad()
|
|
Dim ds As New DataSet()
|
|
Dim dt As New DataTable()
|
|
Dim Standort As String = LstStandort.SelectedItem
|
|
Main.dbload()
|
|
Dim dataadapter As New SqlDataAdapter("select NETNAME from TbL_Netzwerke where NWSTANDORT='" & Standort & "'", Main.con)
|
|
LstNetzwerk.Items.Clear()
|
|
Try
|
|
Main.con.Open()
|
|
dataadapter.Fill(ds)
|
|
|
|
'DgVMain.DataSource = ds.Tables(0)
|
|
|
|
For Each dr As DataRow In ds.Tables(0).Rows
|
|
LstNetzwerk.Items.Add(dr.Item(0))
|
|
Next
|
|
|
|
Catch ex As Exception
|
|
MsgBox("DataadapterFill LstNwerkload(): " & ex.Message)
|
|
End Try
|
|
Main.con.Close()
|
|
|
|
Try
|
|
LstNetzwerk.SetSelected(0, True)
|
|
|
|
Catch ex As Exception
|
|
' MsgBox("LstNetzwerkLoad SetSelected: " & ex.Message)
|
|
End Try
|
|
|
|
End Function
|
|
|
|
Public Function NWDelete()
|
|
Dim ds As New DataSet()
|
|
Dim dt As New DataTable()
|
|
dbload()
|
|
Dim netzwerkname As String = LstStandort.SelectedItem & "_" & LstNetzwerk.SelectedItem
|
|
|
|
If LstNetzwerk.SelectedItem = "Intern" Then
|
|
MsgBox("Standardnetzwerk 'Intern' kann nicht gelöscht werden.")
|
|
Else
|
|
If MsgBox("Netzwerk " & netzwerkname & " wirklich löschen?", vbOKCancel) = MsgBoxResult.Cancel Then
|
|
Exit Function
|
|
Else
|
|
con.Open()
|
|
Dim result As Integer = MsgBox("NetzwerkHosts ebenfalls aus Datenbank löschen?", vbYesNoCancel)
|
|
If result = MsgBoxResult.Cancel Then
|
|
Exit Function
|
|
ElseIf result = MsgBoxResult.Yes Then
|
|
Try
|
|
cmd.CommandText = "DELETE FROM tbl_netzwerkclients WHERE NETNAME = '" & LstNetzwerk.SelectedItem & "' AND NWSTANDORT = '" & LstStandort.SelectedItem & "'"
|
|
cmd.ExecuteNonQuery()
|
|
cmd.CommandText = "DELETE FROM tbl_netzwerke WHERE Netzwerkname = '" & netzwerkname & "'"
|
|
cmd.ExecuteNonQuery()
|
|
'MsgBox("Yes")
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
ElseIf result = MsgBoxResult.No Then
|
|
Try
|
|
cmd.CommandText = "DELETE FROM tbl_netzwerke WHERE Netzwerkname = '" & netzwerkname & "'"
|
|
cmd.ExecuteNonQuery()
|
|
'MsgBox("Yes")
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
'MsgBox("No")
|
|
End If
|
|
End If
|
|
con.Close()
|
|
End If
|
|
LstStandortLoad()
|
|
LstNetzwerkLoad()
|
|
End Function
|
|
|
|
Public Function StandOrtDelete()
|
|
Dim ds As New DataSet()
|
|
Dim dt As New DataTable()
|
|
dbload()
|
|
Dim netzwerkname As String = LstStandort.SelectedItem & "_" & LstNetzwerk.SelectedItem
|
|
|
|
|
|
If MsgBox("Den kompletten Standort " & LstStandort.SelectedItem & " wirklich löschen?", vbOKCancel) = MsgBoxResult.Cancel Then
|
|
Exit Function
|
|
Else
|
|
con.Open()
|
|
Dim result As Integer = MsgBox("Wirklich zu 100% Ernte???", vbYesNoCancel)
|
|
If result = MsgBoxResult.Cancel Then
|
|
Exit Function
|
|
ElseIf result = MsgBoxResult.Yes Then
|
|
Try
|
|
cmd.CommandText = "DELETE FROM tbl_netzwerkclients WHERE NWSTANDORT = '" & LstStandort.SelectedItem & "'"
|
|
cmd.ExecuteNonQuery()
|
|
cmd.CommandText = "DELETE FROM tbl_netzwerke WHERE NWStandort = '" & LstStandort.SelectedItem & "'"
|
|
cmd.ExecuteNonQuery()
|
|
'MsgBox("Yes")
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
ElseIf result = MsgBoxResult.No Then
|
|
Exit Function
|
|
End If
|
|
End If
|
|
con.Close()
|
|
LstStandortLoad()
|
|
LstNetzwerkLoad()
|
|
End Function
|
|
|
|
Private Sub LstStandort_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LstStandort.SelectedIndexChanged
|
|
LstNetzwerkLoad()
|
|
End Sub
|
|
|
|
Private Sub LstNetzwerk_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LstNetzwerk.SelectedIndexChanged
|
|
|
|
End Sub
|
|
|
|
Private Sub CmdStandortAdd_Click(sender As Object, e As EventArgs) Handles CmdStandortAdd.Click
|
|
Standorthinzu.Show()
|
|
End Sub
|
|
|
|
Private Sub ChkDelete_CheckedChanged(sender As Object, e As EventArgs) Handles ChkDelete.CheckedChanged
|
|
If ChkDelete.Checked Then
|
|
CmdNetWDelete.Enabled = True
|
|
CmdStandortDelete.Enabled = True
|
|
Else
|
|
CmdNetWDelete.Enabled = False
|
|
CmdStandortDelete.Enabled = False
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CmdNetWDelete_Click(sender As Object, e As EventArgs) Handles CmdNetWDelete.Click
|
|
NWDelete()
|
|
End Sub
|
|
|
|
Private Sub CmdStandortDelete_Click(sender As Object, e As EventArgs) Handles CmdStandortDelete.Click
|
|
StandOrtDelete()
|
|
End Sub
|
|
|
|
Private Sub CmdNetzwerkAdd_Click(sender As Object, e As EventArgs) Handles CmdNetzwerkAdd.Click
|
|
NetzwerkHinzu.Show()
|
|
End Sub
|
|
Private Sub Closing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
|
|
Main.LstStandortLoad()
|
|
Main.allesladen()
|
|
End Sub
|
|
End Class |