DotNetNukeŽ AJAX Email

'
' DotNetNuke - http:'www.dotnetnuke.com
' Copyright (c) 2002-2007
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'
Imports System
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Security.Roles
Imports DotNetNuke.Security.Membership
Imports System.Collections.Generic
Imports DotNetNuke.Entities
Imports DotNetNuke.Services.Exceptions
Imports System.Collections
Imports DotNetNuke.Entities.Users
Imports System.Web.UI
Imports System.Web.UI.WebControls
 
Namespace DotNetNuke.Modules
 
    Public Class AjaxUsers
        Inherits Entities.Modules.PortalModuleBase
        Private current As tracking_user
 
        Public ReadOnly Property GridViewRows() As GridViewRowCollection
            Get
                Return GridView2.Rows
            End Get
        End Property
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If DotNetNuke.Framework.AJAX.IsInstalled Then
                DotNetNuke.Framework.AJAX.RegisterScriptManager()
            End If
        End Sub
 
        Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As EventArgs)
            If (txtUser.Text.Trim.Length <> 0) Then
                Dim Users As ArrayList
                Dim TotalRecords As Integer = 0
                If (ddlSearchType.SelectedValue = "Email") Then
                    Users = UserController.GetUsersByEmail(PortalId, False, (txtUser.Text + "%"), 0, 5, TotalRecords)
                Else
                    Dim propertyName As String = ddlSearchType.SelectedItem.Value
                    Users = UserController.GetUsersByProfileProperty(PortalId, False, propertyName, (txtUser.Text + "%"), 0, 5, TotalRecords)
                End If
                If (Users.Count > 0) Then
                    lblNotFound.Visible = False
                    GridView1.Visible = True
                    GridView1.DataSource = Users
                    GridView1.DataBind()
                Else
                    lblNotFound.Visible = True
                    GridView1.Visible = False
                End If
            End If
        End Sub
 
        Private Sub BindGridView(ByVal tracking_user_list As List(Of tracking_user))
            Me.GridView2.DataSource = tracking_user_list
            Me.GridView2.DataBind()
        End Sub
 
        Private Function GetTrackingUsers() As List(Of tracking_user)
            Dim objtracking_user As tracking_user
            Dim tracking_user_list As List(Of tracking_user) = New List(Of tracking_user)
            'Get all the current GridView Items and place in tracking_user_list
            Dim GridViewRowCollection As GridViewRowCollection = CType(GridView2.Rows, GridViewRowCollection)
            Dim intGridViewRow As Integer
            intGridViewRow = 0
            Do While (intGridViewRow <= (GridViewRowCollection.Count - 1))
                Dim GridViewRow As GridViewRow = CType(GridView2.Rows(intGridViewRow), GridViewRow)
                Dim LinkButtonUserID As LinkButton = CType(GridViewRow.FindControl("lnkDelete"), LinkButton)
                Dim LabelName As Label = CType(GridViewRow.FindControl("lblname"), Label)
                Dim LabelEmail As Label = CType(GridViewRow.FindControl("lblEmail2"), Label)
                objtracking_user = New tracking_user(LabelName.Text, LabelEmail.Text, Convert.ToInt16(LinkButtonUserID.CommandArgument))
                tracking_user_list.Add(objtracking_user)
                intGridViewRow = (intGridViewRow + 1)
            Loop
            Return tracking_user_list
        End Function
 
        Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim objtracking_user As tracking_user
            Dim tracking_user_list As List(Of tracking_user) = GetTrackingUsers
            Dim GridView As GridView = CType(sender, GridView)
            Dim GridViewRowAdd As GridViewRow = CType(GridView.SelectedRow, GridViewRow)
            Dim LinkButtonAdd As LinkButton = CType(GridViewRowAdd.FindControl("linkbutton1"), LinkButton)
            Dim LabelAdd As Label = CType(GridViewRowAdd.FindControl("lblEmail"), Label)
            objtracking_user = New tracking_user(LinkButtonAdd.Text, LabelAdd.Text, Convert.ToInt16(LinkButtonAdd.CommandArgument))
 
            current = objtracking_user
            Dim objSearchtracking_user As tracking_user = tracking_user_list.Find(AddressOf MatchId)
 
            If (IsNothing(objSearchtracking_user)) Then
                tracking_user_list.Add(objtracking_user)
            End If
 
            BindGridView(tracking_user_list)
        End Sub
 
        Protected Sub GridView2_Deleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
            Dim tracking_user_list As List(Of tracking_user) = GetTrackingUsers()
            Dim GridView As GridView = CType(sender, GridView)
            Dim GridViewRow As GridViewRow = CType(GridView.Rows(e.RowIndex), GridViewRow)
            Dim LinkButton As LinkButton = CType(GridViewRow.FindControl("lnkDelete"), LinkButton)
 
            Dim objtracking_user As New tracking_user()
            objtracking_user.UserID = Convert.ToInt16(LinkButton.CommandArgument)
            current = objtracking_user
 
            Dim objSearchtracking_user As tracking_user = tracking_user_list.Find(AddressOf MatchId)
            tracking_user_list.Remove(objSearchtracking_user)
            BindGridView(tracking_user_list)
        End Sub
 
        Private Function MatchId(ByVal _tracking_user As tracking_user) As Boolean
            Return IIf(current.UserID = _tracking_user.UserID, True, False)
        End Function
 
    End Class
 
 
    Public Class tracking_user
        Private _username As String
        Private _useremail As String
        Private _userID As Integer
 
        Public Sub New()
            MyBase.New()
        End Sub
 
        Public Sub New(ByVal username As String, ByVal useremail As String, ByVal userID As Integer)
            MyBase.New()
            _username = username
            _useremail = useremail
            _userID = userID
        End Sub
 
        Public Property UserName() As String
            Get
                Return _username
            End Get
            Set(ByVal value As String)
                _username = value
            End Set
        End Property
 
        Public Property UserEmail() As String
            Get
                Return _useremail
            End Get
            Set(ByVal value As String)
                _useremail = value
            End Set
        End Property
 
        Public Property UserID() As Integer
            Get
                Return _userID
            End Get
            Set(ByVal value As Integer)
                _userID = value
            End Set
        End Property
    End Class
End Namespace