jj: Fix user import window, catch errors while importing

This commit is contained in:
Jonathan Jenne 2018-06-19 10:30:17 +02:00
parent 1540389fbb
commit 5843797a52
2 changed files with 37 additions and 23 deletions

View File

@ -68,7 +68,7 @@ Partial Class frmADImport_Users
'gridAD_Users 'gridAD_Users
' '
Me.gridAD_Users.DataSource = Me.TBLOCAL_ADUSERSBindingSource Me.gridAD_Users.DataSource = Me.TBLOCAL_ADUSERSBindingSource
Me.gridAD_Users.Dock = System.Windows.Forms.DockStyle.Top Me.gridAD_Users.Dock = System.Windows.Forms.DockStyle.Fill
Me.gridAD_Users.Location = New System.Drawing.Point(294, 0) Me.gridAD_Users.Location = New System.Drawing.Point(294, 0)
Me.gridAD_Users.MainView = Me.viewAD_Users Me.gridAD_Users.MainView = Me.viewAD_Users
Me.gridAD_Users.Name = "gridAD_Users" Me.gridAD_Users.Name = "gridAD_Users"
@ -100,6 +100,7 @@ Partial Class frmADImport_Users
' '
'colSELECTED 'colSELECTED
' '
Me.colSELECTED.Caption = "Importieren"
Me.colSELECTED.FieldName = "SELECTED" Me.colSELECTED.FieldName = "SELECTED"
Me.colSELECTED.Name = "colSELECTED" Me.colSELECTED.Name = "colSELECTED"
Me.colSELECTED.Visible = True Me.colSELECTED.Visible = True
@ -107,6 +108,7 @@ Partial Class frmADImport_Users
' '
'colUSERNAME 'colUSERNAME
' '
Me.colUSERNAME.Caption = "Benutzername"
Me.colUSERNAME.FieldName = "USERNAME" Me.colUSERNAME.FieldName = "USERNAME"
Me.colUSERNAME.Name = "colUSERNAME" Me.colUSERNAME.Name = "colUSERNAME"
Me.colUSERNAME.OptionsColumn.AllowEdit = False Me.colUSERNAME.OptionsColumn.AllowEdit = False
@ -115,6 +117,7 @@ Partial Class frmADImport_Users
' '
'colPRENAME 'colPRENAME
' '
Me.colPRENAME.Caption = "Vorname"
Me.colPRENAME.FieldName = "PRENAME" Me.colPRENAME.FieldName = "PRENAME"
Me.colPRENAME.Name = "colPRENAME" Me.colPRENAME.Name = "colPRENAME"
Me.colPRENAME.OptionsColumn.AllowEdit = False Me.colPRENAME.OptionsColumn.AllowEdit = False
@ -123,6 +126,7 @@ Partial Class frmADImport_Users
' '
'colNAME 'colNAME
' '
Me.colNAME.Caption = "Name"
Me.colNAME.FieldName = "NAME" Me.colNAME.FieldName = "NAME"
Me.colNAME.Name = "colNAME" Me.colNAME.Name = "colNAME"
Me.colNAME.OptionsColumn.AllowEdit = False Me.colNAME.OptionsColumn.AllowEdit = False
@ -131,6 +135,7 @@ Partial Class frmADImport_Users
' '
'colEMAIL 'colEMAIL
' '
Me.colEMAIL.Caption = "Email"
Me.colEMAIL.FieldName = "EMAIL" Me.colEMAIL.FieldName = "EMAIL"
Me.colEMAIL.Name = "colEMAIL" Me.colEMAIL.Name = "colEMAIL"
Me.colEMAIL.OptionsColumn.AllowEdit = False Me.colEMAIL.OptionsColumn.AllowEdit = False
@ -140,7 +145,7 @@ Partial Class frmADImport_Users
'Panel1 'Panel1
' '
Me.Panel1.Controls.Add(Me.btnImport) Me.Panel1.Controls.Add(Me.btnImport)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom
Me.Panel1.Location = New System.Drawing.Point(294, 409) Me.Panel1.Location = New System.Drawing.Point(294, 409)
Me.Panel1.Name = "Panel1" Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(579, 55) Me.Panel1.Size = New System.Drawing.Size(579, 55)
@ -164,8 +169,8 @@ Partial Class frmADImport_Users
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(873, 464) Me.ClientSize = New System.Drawing.Size(873, 464)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.gridAD_Users) Me.Controls.Add(Me.gridAD_Users)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.gridAD_Groups) Me.Controls.Add(Me.gridAD_Groups)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmADImport_Users" Me.Name = "frmADImport_Users"

View File

@ -2,6 +2,7 @@
Imports System.DirectoryServices.AccountManagement Imports System.DirectoryServices.AccountManagement
Imports DDUserManager.UserDataSet Imports DDUserManager.UserDataSet
Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid
Imports DD_LIB_Standards
Public Class frmADImport_Users Public Class frmADImport_Users
@ -10,10 +11,10 @@ Public Class frmADImport_Users
Dim groups = ClassActiveDirectory.GetActiveDirectoryGroups() Dim groups = ClassActiveDirectory.GetActiveDirectoryGroups()
gridAD_Groups.DataSource = groups gridAD_Groups.DataSource = groups
viewAD_Groups.Columns.Item(0).Caption = "Gruppe"
Catch ex As Exception Catch ex As Exception
MsgBox($"Error while loading initial groups") MsgBox($"Error while loading initial groups")
End Try End Try
End Sub End Sub
Private Sub gridADGroups_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles viewAD_Groups.FocusedRowChanged Private Sub gridADGroups_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles viewAD_Groups.FocusedRowChanged
@ -42,30 +43,38 @@ Public Class frmADImport_Users
End Sub End Sub
Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click
Dim selectedUserHandles As List(Of Integer) = viewAD_Users.GetSelectedRows().ToList() Try
Dim importedUsers As Integer = 0 Dim selectedUserHandles As List(Of Integer) = viewAD_Users.GetSelectedRows().ToList()
Dim importedUsers As Integer = 0
For Each rowHandle In selectedUserHandles For Each rowHandle In selectedUserHandles
Dim rowView As DataRowView = viewAD_Users.GetRow(rowHandle) Dim rowView As DataRowView = viewAD_Users.GetRow(rowHandle)
Dim userRow As TBLOCAL_ADUSERSRow = rowView.Row Dim userRow As TBLOCAL_ADUSERSRow = rowView.Row
Dim Username As String = userRow.USERNAME Dim Username As String = userRow.USERNAME
Dim Prename As String = IIf(IsDBNull(userRow.PRENAME), Nothing, userRow.PRENAME) Dim Prename As String = IIf(IsDBNull(userRow.PRENAME), Nothing, userRow.PRENAME)
Dim Name As String = IIf(IsDBNull(userRow.NAME), Nothing, userRow.NAME) Dim Name As String = IIf(IsDBNull(userRow.NAME), Nothing, userRow.NAME)
Dim Email As String = IIf(IsDBNull(userRow.EMAIL), Nothing, userRow.EMAIL) Dim Email As String = IIf(IsDBNull(userRow.EMAIL), Nothing, userRow.EMAIL)
If Not ClassData.UserExists(userRow.USERNAME) Then If Not ClassData.UserExists(Username) Then
ClassData.InsertUser(Username, Prename, Name, Email) If ClassData.InsertUser(Username, Prename, Name, Email) Then
importedUsers = importedUsers + 1 importedUsers = importedUsers + 1
Else
Throw New Exception($"Could not insert user {Username} into Database. Check the log.")
End If
End If
Next
If importedUsers = 0 Then
MsgBox($"Es wurden keine neuen Benutzer importiert, da alle ausgewählten Benutzer bereits in der Benutzerverwaltung vorhanden sind.", MsgBoxStyle.Exclamation, "UserManager")
Else
MsgBox($"{importedUsers} Benutzer wurden erfolgreich importiert!", MsgBoxStyle.Information, "UserManager")
End If End If
Next Catch ex As Exception
clsLogger.Add($"Error while importing users: {ex.Message}")
If importedUsers = 0 Then MsgBox($"Error while importing users: {ex.Message}", MsgBoxStyle.Critical)
MsgBox($"Es wurden keine neuen Benutzer importiert, da alle ausgewählten Benutzer bereits in der Benutzerverwaltung vorhanden sind.", MsgBoxStyle.Exclamation, "UserManager") End Try
Else
MsgBox($"{importedUsers} Benutzer wurden erfolgreich importiert!", MsgBoxStyle.Information, "UserManager")
End If
End Sub End Sub
Private Sub viewAD_Users_SelectionChanged(sender As Object, e As DevExpress.Data.SelectionChangedEventArgs) Handles viewAD_Users.SelectionChanged Private Sub viewAD_Users_SelectionChanged(sender As Object, e As DevExpress.Data.SelectionChangedEventArgs) Handles viewAD_Users.SelectionChanged