protected void Page_Load(object sender, EventArgs e) { AdminTableAdapter adapter = new AdminTableAdapter(); DollarSaverDB.AdminDataTable admins = adapter.GetByRole(StationId, CurrentUser.AdminRoleId); if (admins.Count > 0) { itemGrid.DataSource = admins.Rows; itemGrid.DataBind(); } if (ReadOnly) { newLink.Visible = false; itemGrid.Columns[0].Visible = false; itemGrid.Columns[1].Visible = true; } else { newLink.Visible = true; itemGrid.Columns[0].Visible = true; itemGrid.Columns[1].Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { saveButton.Click += new EventHandler(saveButton_Click); cancelButton.Click += new EventHandler(cancelButton_Click); deleteButton.Click += new EventHandler(deleteButton_Click); deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');"; adminId = GetIdFromQueryString(); if (!Page.IsPostBack) { if (adminId > 0) { createEditLabel.Text = "Edit"; updateHolder.Visible = true; AdminTableAdapter adminAdapter = new AdminTableAdapter(); DollarSaverDB.AdminDataTable admins = adminAdapter.GetAdmin(adminId); if (admins.Rows.Count == 1) { DollarSaverDB.AdminRow admin = admins[0]; if (admin.Role != AdminRole.Root || !admin.IsStationIdNull()) { RedirectToUserList(); } usernameBox.Text = admin.Username; if (!admin.IsEmailAddressNull()) { emailBox.Text = admin.EmailAddress; } isActiveBox.Checked = admin.IsActive; if (adminId == CurrentUser.AdminId) { deleteButton.Visible = false; } } else { RedirectToUserList(); } } else { updateHolder.Visible = false; deleteButton.Visible = false; saveButton.Text = "Create"; createEditLabel.Text = "Create"; } } }
protected void Page_Load(object sender, EventArgs e) { AdminTableAdapter adapter = new AdminTableAdapter(); DollarSaverDB.AdminDataTable admins = adapter.GetRootUsers(); if (admins.Count > 0) { userHolder.Visible = true; noUserHolder.Visible = false; itemGrid.DataSource = admins.Rows; itemGrid.DataBind(); } else { userHolder.Visible = false; noUserHolder.Visible = true; } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); Page.Response.Buffer = true; int adminId = Convert.ToInt32(Context.User.Identity.Name); AdminTableAdapter adminAdapter = new AdminTableAdapter(); DollarSaverDB.AdminDataTable adminTable = adminAdapter.GetAdmin(adminId); if (adminTable.Count != 1) { FormsAuthentication.RedirectToLoginPage(); } _currentUser = adminTable[0]; }
void saveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { String username = usernameBox.Text.Trim().ToLower(); String emailAddress = emailBox.Text.Trim(); String password = passwordBox.Text; String confirmPassword = confirmPasswordBox.Text; bool isActive = isActiveBox.Checked; if (username == String.Empty) { ErrorMessage = "Username is required"; return; } if (emailAddress != String.Empty && !Regex.IsMatch(emailAddress, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")) { ErrorMessage = "E-mail address is not valid"; return; } if (emailAddress == String.Empty) { emailAddress = null; } if (password != confirmPassword) { ErrorMessage = "Password and Confirmation must be the same."; return; } if (password != String.Empty && password.Length < 6) { ErrorMessage = "Password must be at least 6 characters long"; return; } if (!Regex.IsMatch(username, @"^\w+$")) { ErrorMessage = "Username can only contain numbers, letters or underscores"; return; } AdminTableAdapter adminAdapter = new AdminTableAdapter(); DollarSaverDB.AdminDataTable checkAdmins = adminAdapter.GetByUsername(0, username); if (checkAdmins.Count == 1 && checkAdmins[0].AdminId != adminId) { ErrorMessage = "Username is already in use"; return; } if (adminId > 0) { DollarSaverDB.AdminRow admin = adminAdapter.GetAdmin(adminId)[0]; admin.Username = username; admin.IsActive = isActive; if (emailAddress != null) { admin.EmailAddress = emailAddress; } else { admin.SetEmailAddressNull(); } if (password != String.Empty) { admin.Password = password; } adminAdapter.Update(admin); InfoMessage = "Root User updated"; } else { if (password == String.Empty) { ErrorMessage = "Password is required"; return; } adminAdapter.Insert(null, (int)AdminRole.Root, username, password, emailAddress, DateTime.Now, null, isActive, false); InfoMessage = "Root User created"; } RedirectToUserList(); } }
protected void Page_Load(object sender, EventArgs e) { saveButton.Click += new EventHandler(saveButton_Click); cancelButton.Click += new EventHandler(cancelButton_Click); deleteButton.Click += new EventHandler(deleteButton_Click); deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');"; adminId = GetIdFromQueryString(); if (!Page.IsPostBack) { foreach (AdminRole role in Enum.GetValues(typeof(AdminRole))) { if (((int)role) >= CurrentUser.AdminRoleId && role != AdminRole.Root) { roleList.Items.Add(new ListItem(role.ToString(), ((int)role).ToString())); } } if (adminId > 0) { createEditLabel.Text = "Edit"; AdminTableAdapter adminAdapter = new AdminTableAdapter(); DollarSaverDB.AdminDataTable admins = adminAdapter.GetAdmin(adminId); if (admins.Rows.Count == 1) { DollarSaverDB.AdminRow admin = admins[0]; if (admin.AdminRoleId < CurrentUser.AdminRoleId) { Response.Redirect("~/admin/AdminList.aspx"); } if (admin.StationId == StationId) { roleList.SelectedValue = ((int)admin.AdminRoleId).ToString(); usernameBox.Text = admin.Username; if (!admin.IsEmailAddressNull()) { emailBox.Text = admin.EmailAddress; } isActiveBox.Checked = admin.IsActive; isOrderContactBox.Checked = admin.IsOrderContact; if (adminId == CurrentUser.AdminId) { deleteButton.Visible = false; } } else { Response.Redirect("~/admin/AdminList.aspx"); } } else { Response.Redirect("~/admin/AdminList.aspx"); } } else { deleteButton.Visible = false; saveButton.Text = "Create"; createEditLabel.Text = "Create"; } } }