Hi,
I want to add a user to a roll when a checkbox is checked. I dont know what i'm missin in my code? could any1 have a quick at it
code :
Dim Company As String
Dim cSQL As String
Dim cb As CheckBox
Dim dgi As DataGridItem
Dim idList As String = ""
Dim DataRow As Object
Dim DataSet As Object
Dim Algemeen As String
Dim rowindex As Integer
Dim columnindex As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim userInfo As UserInfo
userInfo = UserController.GetCurrentUserInfo()
If userInfo.UserID = -1 Then
End If
Company = userInfo.Profile.GetPropertyValue("Company")
Dim strSQLconnection As String = ("Data Source=.\SQLExpress;Initial Catalog=dnn2;User ID=vb1;Password=Klompsrv1")
cSQL = "SELECT Users.UserID, Users.Username, UserProfile.PropertyValue FROM ProfilePropertyDefinition INNER JOIN UserProfile ON ProfilePropertyDefinition.PropertyDefinitionID = UserProfile.PropertyDefinitionID INNER JOIN Users ON UserProfile.UserID = Users.UserID WHERE (ProfilePropertyDefinition.PropertyName = 'Company') AND (UserProfile.PropertyValue = '" + Company + "')"
Dim sqlConnection As New SqlConnection(strSQLconnection)
Dim sqlCommand As New SqlCommand(cSQL, sqlConnection)
Dim SqlAdapter As New SqlDataAdapter(sqlCommand)
Dim DataSet As New DataSet()
SqlAdapter.Fill(DataSet)
If sqlConnection.State = ConnectionState.Closed Then
sqlConnection.Open()
End If
WebDataGrid1.DataSource = DataSet
WebDataGrid1.DataBind()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEditPermissions.Click
For i As Integer = 0 To WebDataGrid1.Rows.Count - 1
For x As Integer = 0 To WebDataGrid1.Columns.Count - 1
If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Algemeen"), CheckBox).Checked() Then
Dim rc As New DotNetNuke.Security.Roles.RoleController()
Dim groupName As String = "Algemeen"
Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)
Dim CurUser As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetUser(PortalId, UserId, False)
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, CurUser)
End If
If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Financieel"), CheckBox).Checked() Then
Dim rc As New DotNetNuke.Security.Roles.RoleController()
Dim groupName As String = "Financieel"
Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)
End If
If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Licentie"), CheckBox).Checked() Then
Dim rc As New DotNetNuke.Security.Roles.RoleController()
Dim groupName As String = "Licentie"
Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)
End If
If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Applicatie"), CheckBox).Checked() Then
Dim rc As New DotNetNuke.Security.Roles.RoleController()
Dim groupName As String = "Applicatie"
Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)
End If
If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("UitDienst"), CheckBox).Checked() Then
Dim rc As New DotNetNuke.Security.Roles.RoleController()
Dim groupName As String = "UitDienst"
Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)
End If
Next
Next
End Sub
|