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
'
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.MainView = Me.viewAD_Users
Me.gridAD_Users.Name = "gridAD_Users"
@ -100,6 +100,7 @@ Partial Class frmADImport_Users
'
'colSELECTED
'
Me.colSELECTED.Caption = "Importieren"
Me.colSELECTED.FieldName = "SELECTED"
Me.colSELECTED.Name = "colSELECTED"
Me.colSELECTED.Visible = True
@ -107,6 +108,7 @@ Partial Class frmADImport_Users
'
'colUSERNAME
'
Me.colUSERNAME.Caption = "Benutzername"
Me.colUSERNAME.FieldName = "USERNAME"
Me.colUSERNAME.Name = "colUSERNAME"
Me.colUSERNAME.OptionsColumn.AllowEdit = False
@ -115,6 +117,7 @@ Partial Class frmADImport_Users
'
'colPRENAME
'
Me.colPRENAME.Caption = "Vorname"
Me.colPRENAME.FieldName = "PRENAME"
Me.colPRENAME.Name = "colPRENAME"
Me.colPRENAME.OptionsColumn.AllowEdit = False
@ -123,6 +126,7 @@ Partial Class frmADImport_Users
'
'colNAME
'
Me.colNAME.Caption = "Name"
Me.colNAME.FieldName = "NAME"
Me.colNAME.Name = "colNAME"
Me.colNAME.OptionsColumn.AllowEdit = False
@ -131,6 +135,7 @@ Partial Class frmADImport_Users
'
'colEMAIL
'
Me.colEMAIL.Caption = "Email"
Me.colEMAIL.FieldName = "EMAIL"
Me.colEMAIL.Name = "colEMAIL"
Me.colEMAIL.OptionsColumn.AllowEdit = False
@ -140,7 +145,7 @@ Partial Class frmADImport_Users
'Panel1
'
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.Name = "Panel1"
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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(873, 464)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.gridAD_Users)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.gridAD_Groups)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmADImport_Users"

View File

@ -2,6 +2,7 @@
Imports System.DirectoryServices.AccountManagement
Imports DDUserManager.UserDataSet
Imports DevExpress.XtraGrid.Views.Grid
Imports DD_LIB_Standards
Public Class frmADImport_Users
@ -10,10 +11,10 @@ Public Class frmADImport_Users
Dim groups = ClassActiveDirectory.GetActiveDirectoryGroups()
gridAD_Groups.DataSource = groups
viewAD_Groups.Columns.Item(0).Caption = "Gruppe"
Catch ex As Exception
MsgBox($"Error while loading initial groups")
End Try
End Sub
Private Sub gridADGroups_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles viewAD_Groups.FocusedRowChanged
@ -42,6 +43,7 @@ Public Class frmADImport_Users
End Sub
Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click
Try
Dim selectedUserHandles As List(Of Integer) = viewAD_Users.GetSelectedRows().ToList()
Dim importedUsers As Integer = 0
@ -55,9 +57,12 @@ Public Class frmADImport_Users
Dim Email As String = IIf(IsDBNull(userRow.EMAIL), Nothing, userRow.EMAIL)
If Not ClassData.UserExists(userRow.USERNAME) Then
ClassData.InsertUser(Username, Prename, Name, Email)
If Not ClassData.UserExists(Username) Then
If ClassData.InsertUser(Username, Prename, Name, Email) Then
importedUsers = importedUsers + 1
Else
Throw New Exception($"Could not insert user {Username} into Database. Check the log.")
End If
End If
Next
@ -66,6 +71,10 @@ Public Class frmADImport_Users
Else
MsgBox($"{importedUsers} Benutzer wurden erfolgreich importiert!", MsgBoxStyle.Information, "UserManager")
End If
Catch ex As Exception
clsLogger.Add($"Error while importing users: {ex.Message}")
MsgBox($"Error while importing users: {ex.Message}", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub viewAD_Users_SelectionChanged(sender As Object, e As DevExpress.Data.SelectionChangedEventArgs) Handles viewAD_Users.SelectionChanged