|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Admin_Users_Default : System.Web.UI.Page
{
static int _currentRecord;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
_currentRecord = 1;
}
else
{
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
MembershipUserCollection allUsersCollection = Membership.GetAllUsers();
ArrayList allUsers = new ArrayList();
foreach(MembershipUser usr in allUsersCollection)
{
allUsers.Add(usr.UserName.ToString());
}
lblTotal.Text = allUsers.Count.ToString();
username.Text = allUsers[_currentRecord - 1].ToString();
String[] allRoles = Roles.GetAllRoles();
userList.DataSource = allUsers;
userList.DataBind();
UserRoles.DataSource = allRoles;
UserRoles.DataBind();
userList.SelectedIndex = _currentRecord - 1;
navlinksettings();
roleboxsettings();
lblCurrent.Text = _currentRecord.ToString();
}
protected void NavigationLink_Click(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "First":
_currentRecord = 1;// _currentPageNumber = 1;
break;
case "Last":
_currentRecord = Int32.Parse(lblTotal.Text);//_currentPageNumber = Int32.Parse(TotalPages.Text);
break;
case "Next":
_currentRecord = Int32.Parse(lblCurrent.Text) + 1;//_currentPageNumber = Int32.Parse(CurrentPage.Text) + 1;
break;
case "Prev":
_currentRecord = Int32.Parse(lblCurrent.Text) - 1;// _currentPageNumber = Int32.Parse(CurrentPage.Text) - 1;
break;
}
}
protected void btnExit_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("~/Login.aspx");
}
protected void btnNew_Click(object sender, EventArgs e)
{
Response.Redirect("Create_User.aspx");
}
private void navlinksettings()
{
if (_currentRecord == 1)
{ btnPrevious.Enabled = false; }
else
{ btnPrevious.Enabled = true; }
if (_currentRecord == Int32.Parse(lblTotal.Text))
{ btnNext.Enabled = false; }
else
{ btnNext.Enabled = true; }
}
protected void btnSave_Click(object sender, EventArgs e)
{
UpdateUserRoles();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
}
protected void btnEdit_Click(object sender, EventArgs e)
{
Membership.DeleteUser(username.Text.ToString(), true); // DC: except during testing, of course!
_currentRecord -= 1;
Response.Redirect("Default.aspx");
}
private void UpdateUserRoles()
{
foreach (ListItem rolebox in UserRoles.Items)
{
if (rolebox.Selected)
{
if (!Roles.IsUserInRole(username.Text, rolebox.Text))
{
Roles.AddUserToRole(username.Text, rolebox.Text);
}
}
else
{
if (Roles.IsUserInRole(username.Text, rolebox.Text))
{
Roles.RemoveUserFromRole(username.Text, rolebox.Text);
}
}
}
}
private void roleboxsettings()
{
foreach (ListItem rolebox in UserRoles.Items)
{
if (Roles.IsUserInRole(username.Text, rolebox.Text))
{
rolebox.Selected = true;
}
else
{
rolebox.Selected = false;
}
}
}
protected void userList_SelectedIndexChanged(object sender, EventArgs e)
{
userList.DataBind();
_currentRecord = userList.SelectedIndex + 1;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I love programming, reading, and meditation. I like to explore management and productivity.