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.
//
using System;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Security.Roles;
using DotNetNuke.Security.Membership;
using System.Collections.Generic;
using DotNetNuke.Entities;
using DotNetNuke.Services.Exceptions;
using System.Collections;
using DotNetNuke.Entities.Users;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace DotNetNuke.Modules
{
    public partial class AjaxUsersC : Entities.Modules.PortalModuleBase
    {
 
        #region Public Properties
 
        public GridViewRowCollection GridViewRows
        {
            get { return GridView2.Rows; }
        }
 
        #endregion
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (DotNetNuke.Framework.AJAX.IsInstalled())
            {
                DotNetNuke.Framework.AJAX.RegisterScriptManager();
            }
        }
 
        #region Form Events
 
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            if (txtUser.Text.Trim().Length != 0)
            {
                ArrayList Users;
                int TotalRecords = 0;
                if (ddlSearchType.SelectedValue == "Email")
                {
                    Users = UserController.GetUsersByEmail(PortalId, false, txtUser.Text + "%", 0, 5, ref TotalRecords);
                }
                else
                {
                    String propertyName = ddlSearchType.SelectedItem.Value;
                    Users = UserController.GetUsersByProfileProperty(PortalId, false, propertyName, txtUser.Text + "%", 0, 5, ref TotalRecords);
                }
 
                if (Users.Count > 0)
                {
                    lblNotFound.Visible = false;
                    GridView1.Visible = true;
 
                    GridView1.DataSource = Users;
                    GridView1.DataBind();
                }
                else
                {
                    lblNotFound.Visible = true;
                    GridView1.Visible = false;
                }
            }
        }
 
        #endregion
 
        #region Private Methods
 
        private void BindGridView(List<tracking_user> tracking_user_list)
        {
            this.GridView2.DataSource = tracking_user_list;
            this.GridView2.DataBind();
        }
 
        private List<tracking_user> GetTrackingUsers()
        {
            tracking_user objtracking_user;
            List<tracking_user> tracking_user_list = new List<tracking_user>();
 
            //Get all the current GridView Items and place in tracking_user_list
            GridViewRowCollection GridViewRowCollection = (GridViewRowCollection)GridView2.Rows;
            int intGridViewRow;
            for (intGridViewRow = 0; (intGridViewRow <= (GridViewRowCollection.Count - 1)); intGridViewRow++)
            {
                GridViewRow GridViewRow = (GridViewRow)GridView2.Rows[intGridViewRow];
                LinkButton LinkButtonUserID = (LinkButton)GridViewRow.FindControl("lnkDelete");
                Label LabelName = (Label)GridViewRow.FindControl("lblname");
                Label LabelEmail = (Label)GridViewRow.FindControl("lblEmail2");
                objtracking_user = new tracking_user(LabelName.Text, LabelEmail.Text, Convert.ToInt16(LinkButtonUserID.CommandArgument));
                tracking_user_list.Add(objtracking_user);
            }
 
            return tracking_user_list;
        }
 
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            tracking_user objtracking_user;
            List<tracking_user> tracking_user_list = GetTrackingUsers();
 
            GridView GridView = (GridView)sender;
            GridViewRow GridViewRowAdd = (GridViewRow)GridView.SelectedRow;
 
            LinkButton LinkButtonAdd = (LinkButton)GridViewRowAdd.FindControl("linkbutton1");
            Label LabelAdd = (Label)GridViewRowAdd.FindControl("lblEmail");
 
            objtracking_user = new tracking_user(LinkButtonAdd.Text, LabelAdd.Text, Convert.ToInt16(LinkButtonAdd.CommandArgument));
 
            tracking_user objSearchtracking_user = tracking_user_list.Find(
                delegate(tracking_user tracking_user)
                { return tracking_user.UserID == objtracking_user.UserID; });
 
            if (objSearchtracking_user == null)
            {
                tracking_user_list.Add(objtracking_user);
            }
 
            BindGridView(tracking_user_list);
 
        }
        
        protected void GridView2_Deleting(object sender, GridViewDeleteEventArgs e)
        {
            List<tracking_user> tracking_user_list = GetTrackingUsers();
 
            GridView GridView = (GridView)sender;
            GridViewRow GridViewRow = (GridViewRow)GridView.Rows[e.RowIndex];
 
            LinkButton LinkButton = (LinkButton)GridViewRow.FindControl("lnkDelete");
 
            tracking_user objSearchtracking_user = tracking_user_list.Find(
                delegate(tracking_user tracking_user)
                { return tracking_user.UserID == Convert.ToInt16(LinkButton.CommandArgument); });
 
            tracking_user_list.Remove(objSearchtracking_user);
 
            BindGridView(tracking_user_list);
        }
 
        #endregion
    }
 
    #region Tracking User
 
    [Serializable]
    public class tracking_user
    {
        public tracking_user() { }
 
        public tracking_user(string username, string useremail, int userID)
        {
            UserName = username; UserEmail = useremail; UserID = userID;
        }
 
        private string username;
        public string UserName
        {
            get { return username; }
            set { username = value; }
        }
 
        private string useremail;
        public string UserEmail
        {
            get { return useremail; }
            set { useremail = value; }
        }
 
        private int userID;
        public int UserID
        {
            get { return userID; }
            set { userID = value; }
        }
 
    }
 
    #endregion
}