This commit is contained in:
Digital Data - Marlon Schreiber
2018-07-13 10:30:32 +02:00
parent 8103f5d055
commit 2d11c3a677
14 changed files with 1303 additions and 1621 deletions

View File

@@ -88,6 +88,7 @@ Public Class frmUserKonfig_AddUsers
Dim group As String = lbGroups.SelectedItem
Dim users As List(Of UserPrincipal) = GetUsersForGroup(group)
DD_ECMAdmin.TBAD_Users.Clear()
Me.Cursor = Cursors.WaitCursor
For Each user In users
Dim newUserRow As DD_ECMAdmin.TBAD_UsersRow
newUserRow = DD_ECMAdmin.TBAD_Users.NewTBAD_UsersRow
@@ -102,90 +103,120 @@ Public Class frmUserKonfig_AddUsers
newUserRow.Username = user.ToString
End Try
Dim email As String = userldap.EmailAddress
newUserRow.Prename = PRENAME
newUserRow.Surname = NAME
newUserRow.Email = email
newUserRow.Prename = IIf((IsDBNull(PRENAME) Or IsNothing(PRENAME)), "", PRENAME)
newUserRow.Surname = IIf((IsDBNull(NAME) Or IsNothing(NAME)), "", NAME)
newUserRow.Email = IIf((IsDBNull(email) Or IsNothing(email)), "", email)
Catch ex As Exception
ClassLogger.Add("Unexpected Error in Read User LDAP-Configurations: " & vbNewLine)
End Try
DD_ECMAdmin.TBAD_Users.Rows.Add(newUserRow)
Next
Me.Cursor = Cursors.Default
End Sub
Private Sub btnAddUsers_Click(sender As Object, e As EventArgs) Handles btnAddUsers.Click
'Dim items As CheckedListBox.CheckedItemCollection = clbUsers.CheckedItems
Dim usersAdded As Integer = 0
Dim _Step
Try
'Dim items As CheckedListBox.CheckedItemCollection = clbUsers.CheckedItems
Dim usersAdded As Integer = 0
Dim usersRefreshed As Integer = 0
'If items.Count = 0 Then
' MsgBox("Keine Benutzer ausgewählt!", MsgBoxStyle.Information)
' Exit Sub
'End If
'If items.Count = 0 Then
' MsgBox("Keine Benutzer ausgewählt!", MsgBoxStyle.Information)
' Exit Sub
'End If
For Each row As DataRow In DD_ECMAdmin.TBAD_Users.Rows
If row.Item(0) = CBool(True) Then
_Step = 1
Dim USERNAME As String
USERNAME = row.Item(1)
_Step = 2
Dim PRENAME As String
Try
PRENAME = row.Item(2)
_Step = 3
Catch ex As Exception
PRENAME = ""
End Try
Dim NAME As String
_Step = 4
Try
NAME = row.Item(3)
'IIf(IsDBNull(row.Item(3)), NAME = "", NAME = row.Item(3))
_Step = 5
Catch ex As Exception
NAME = ""
End Try
For Each row As DataRow In DD_ECMAdmin.TBAD_Users.Rows
If row.Item(0) = CBool(True) Then
Dim USERNAME As String = row.Item(1)
Dim PRENAME As String
Try
PRENAME = row.Item(2)
Catch ex As Exception
PRENAME = ""
End Try
Dim NAME As String = row.Item(3)
Try
NAME = row.Item(3)
Catch ex As Exception
NAME = ""
End Try
Dim email As String
Try
email = row.Item(4)
Catch ex As Exception
email = ""
End Try
Dim SQL
If Not UserExists(USERNAME) Then
SQL = "INSERT INTO TBDD_USER(PRENAME, NAME, USERNAME, EMAIL, MODULE_RECORD_ORG,LANGUAGE, ADDED_WHO) VALUES('" & PRENAME & "', '" & NAME & "', '" & USERNAME & "','" & email & "'," & 1 & ",'" & USER_LANGUAGE & "','" & USER_USERNAME & "')"
If ClassDatabase.Execute_non_Query(SQL, False) = True Then
Dim ID = ClassDatabase.Execute_Scalar("SELECT MAX(GUID) FROM TBDD_USER")
Dim msg = String.Format(">> USER {0}, {1} - {2} ADDED TO CONFIGURATION", NAME, PRENAME, USERNAME)
ClassLogger.Add(msg, False)
ClassHelper.InsertEssential_Log(ID, "USER-ID", msg.Replace(">> ", ""))
usersAdded = usersAdded + 1
End If
Else
SQL = String.Format("UPDATE TBDD_USER SET MODULE_RECORD_ORG = 1,PRENAME = '{0}', NAME = '{1}', EMAIL = '{2}' WHERE UPPER(USERNAME) = UPPER('{3}')", PRENAME, NAME, email, USERNAME)
If ClassDatabase.Execute_non_Query(SQL, False) = True Then
usersAdded = usersAdded + 1
Dim email As String
Try
email = row.Item(4)
' IIf(IsDBNull(row.Item(4)), email = "", email = row.Item(4))
_Step = 6
Catch ex As Exception
email = ""
End Try
Dim SQL
If UserExists(USERNAME) = False Then
_Step = 7
SQL = "INSERT INTO TBDD_USER(PRENAME, NAME, USERNAME, EMAIL, MODULE_RECORD_ORG,LANGUAGE, ADDED_WHO) VALUES('" & PRENAME & "', '" & NAME & "', '" & USERNAME & "','" & email & "'," & 1 & ",'" & USER_LANGUAGE & "','" & USER_USERNAME & "')"
_Step = 8
If ClassDatabase.Execute_non_Query(SQL, False) = True Then
_Step = 9
Dim ID = ClassDatabase.Execute_Scalar("SELECT MAX(GUID) FROM TBDD_USER")
Dim msg = String.Format(">> USER {0}, {1} - {2} ADDED TO CONFIGURATION", NAME, PRENAME, USERNAME)
_Step = 10
ClassLogger.Add(msg, False)
ClassHelper.InsertEssential_Log(ID, "USER-ID", msg.Replace(">> ", ""))
usersAdded += 1
Else
MsgBox("Unexpected Error In Adding User (" & USERNAME & ") : " & "Check the log!", MsgBoxStyle.Exclamation)
End If
Else
_Step = 11
SQL = String.Format("UPDATE TBDD_USER SET MODULE_RECORD_ORG = 1,PRENAME = '{0}', NAME = '{1}', EMAIL = '{2}' WHERE UPPER(USERNAME) = UPPER('{3}')", PRENAME, NAME, email, USERNAME)
_Step = 12
If ClassDatabase.Execute_non_Query(SQL, False) = True Then
usersRefreshed += 1
End If
End If
End If
Next
'For Each item As UserPrincipal In items
' Dim user As UserPrincipal = item
' Dim PRENAME As String = user.GivenName
' Dim NAME As String = user.Surname
' Dim USERNAME As String = user.SamAccountName
' Dim email As String = user.EmailAddress
' Dim SQL
'Next
If USER_LANGUAGE = "de-DE" Then
MsgBox(usersAdded & " Benutzer hinzugefügt." & vbNewLine & usersRefreshed & " Benutzer aktualisiert.", MsgBoxStyle.Information)
Else
MsgBox(usersAdded & " user(s) added." & vbNewLine & usersRefreshed & " user(s) refreshed.", MsgBoxStyle.Information)
End If
Catch ex As Exception
MsgBox("Unexpected Error In Adding User (Step " & _Step.ToString & ") : " & vbNewLine & ex.Message)
End Try
Next
'For Each item As UserPrincipal In items
' Dim user As UserPrincipal = item
' Dim PRENAME As String = user.GivenName
' Dim NAME As String = user.Surname
' Dim USERNAME As String = user.SamAccountName
' Dim email As String = user.EmailAddress
' Dim SQL
'Next
If USER_LANGUAGE = "de-DE" Then
MsgBox(usersAdded & " Benutzer hinzugefügt/upgedatet!", MsgBoxStyle.Information)
Else
MsgBox(usersAdded & " User added/updatet!", MsgBoxStyle.Information)
End If
End Sub
Private Function UserExists(username As String) As Boolean
Try
Dim SQL = "SELECT GUID FROM TBDD_USER WHERE UPPER(USERNAME) = UPPER('" & username & "')"
If ClassDatabase.Execute_Scalar(SQL) = Nothing Then
Return False
Else
Return True
End If
Dim SQL = "SELECT * FROM TBDD_USER WHERE UPPER(USERNAME) = UPPER('" & username & "')"
Dim result As DataTable = ClassDatabase.Return_Datatable(SQL)
Select Case result.Rows.Count
Case 0
Return False
Case 1
Return True
Case Else
MsgBox("Could not check whether user '" & username & "' exists!" & vbNewLine & SQL, MsgBoxStyle.Exclamation)
End Select
Catch ex As Exception
MsgBox("Error in UserExists: " & vbNewLine & ex.Message)
Return False