private void SaveGroupChanges() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { if (ViewState["Insert"] == null || (bool)ViewState["Insert"] == false) { UpdateGroup(); if (ListBox4.SelectedItem != null) { LoginGroupItem item = new LoginGroupItem(); FillGroupsListBox(); InsertPageAccess(ListBox4.SelectedItem.Text, Crypt.Encripta(TextBox6.Text)); SetGroupChecks(ListBox3.SelectedValue, ListBox4.SelectedItem.Text); } } else { CreateGroup(); ClearGroupChecks(); ViewState["Insert"] = false; } ViewState["SalvaPaginas"] = true; ShowError(); } } catch { } }
/// <summary> /// Metodo usado para inserir um grupo no banco de dados /// </summary> private void CreateGroup() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { if (TextBox6.Text == "") { ErrorList.Add("GrupoInvalido", "Nome do grupo tem que ser preenchido"); return; } try { LoginGroupItem item = new LoginGroupItem(); item.Fields["Id"].SetValue(TextBox6.Text); item.Fields["Name"].SetValue(Crypt.Encripta(TextBox6.Text)); item.Fields["IsAdmin"].SetValue(CheckBox1.Checked); vgMembership.GroupProvider.DataProvider.InsertItem(item); FillGroupsListBox(); ListBox3.SelectedIndex = ListBox3.Items.Count - 1; FillUserListBox(); ViewState["Insert"] = false; EnableGroupButtons(true, true, true, true); ListBox3.Enabled = true; } catch (Exception e) { ErrorList.Add("dadosError", e.Message); } } } catch { } }
public bool ChangePW(string UserName, string Password) { CurrentItem = new LoginUserItem(); CurrentItem.Fields["Login"].SetValue(Crypt.Encripta(UserName)); CurrentItem = DataProvider.SelectItem(0, FormPositioningEnum.First) as LoginUserItem; CurrentItem.Fields["Password"].SetValue(Crypt.Encripta(Password)); return(DataProvider.UpdateItem(CurrentItem) > 0); }
/// <summary> /// Update um registo de usuario /// </summary> private void UpdateUser() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { string vgPass = ""; if (TextBox8.Text != "") { if (TextBox8.Text == TextBox9.Text) { vgPass = TextBox8.Text.ToUpper(); } else { ErrorList.Add("SenhaErrada", "Confirmação de senha invalida"); return; } } try { LoginUserItem item = new LoginUserItem(); item.Fields["Group"].SetValue(ListBox5.SelectedValue); item.Fields["Login"].SetValue(Crypt.Encripta(TextBox7.Text)); item.Fields["Id"].SetValue(ListBox6.SelectedValue); if (vgPass != "") { item.Fields["Password"].SetValue(Crypt.Encripta(vgPass)); } else { LoginUserItem OldItem = vgMembership.GetUser(ListBox6.SelectedValue); item.Fields["Password"].SetValue(OldItem.Fields["Password"].GetFormattedValue()); } item.Fields["Obs"].SetValue(Crypt.Encripta(TextBox10.Text)); item.Fields["Name"].SetValue(Crypt.Encripta(TextBox11.Text.ToUpper())); vgMembership.UpdateUser(item); ListBox6.Items[ListBox6.SelectedIndex].Text = TextBox7.Text; ListBox6.Enabled = true; ListBox5.Enabled = true; EnableUserButtons(true, true, true, true); } catch (Exception e) { ErrorList.Add("UpdateUserError", e.Message); } } } catch { } }
private bool CheckUser(string UserName, string Password) { CurrentItem = new LoginUserItem(); CurrentItem.Fields["Login"].SetValue(Crypt.Encripta(UserName)); CurrentItem = DataProvider.SelectItem(0, FormPositioningEnum.First) as LoginUserItem; if (CurrentItem != null) { return(CurrentItem.Fields["Password"].Value.Equals(Crypt.Encripta(Password))); } return(false); }
/// <summary> /// Metodo que mostra o registro do usuario selecionado /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ChangedUser() { if (ListBox6.SelectedItem != null) { LoginUserItem vgUser = vgMembership.GetUser(Crypt.Encripta(ListBox6.SelectedItem.Text)); TextBox7.Text = Crypt.Decripta(vgUser.Fields["Login"].GetFormattedValue()); TextBox11.Text = Crypt.Decripta(vgUser.Fields["Name"].GetFormattedValue()); TextBox10.Text = Crypt.Decripta(vgUser.Fields["Obs"].GetFormattedValue()); TextBox9.Enabled = true; TextBox9.Text = ""; TextBox10.Enabled = true; TextBox8.Text = ""; TextBox7.Enabled = true; TextBox8.Enabled = true; ViewState["IncluiUsuario"] = false; EnableUserButtons(true, true, true, true); } }
/// <summary> /// Exclui usuario do banco de dados /// </summary> private void DeleteUser() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { if (ListBox5.SelectedIndex == 0 && ListBox6.Items.Count == 1) { ErrorList.Add("ExcluirUltimoAdmin", "Ultimo administrador não pode ser excluido!"); } else { vgMembership.DeleteUser(Crypt.Encripta(ListBox6.SelectedItem.Text)); FillUserListBox(); TextBox10.Text = ""; TextBox7.Text = ""; } } } catch { } }
public void UpdateGroup() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { LoginGroupItem item = new LoginGroupItem(); item.Fields["Name"].SetValue(Crypt.Encripta(TextBox6.Text)); item.Fields["Id"].SetValue(ListBox3.SelectedValue); item.Fields["IsAdmin"].SetValue(CheckBox1.Checked); ListBox3.Items[ListBox3.SelectedIndex].Text = TextBox6.Text; ListBox3.Items[ListBox3.SelectedIndex].Value = Crypt.Encripta(TextBox6.Text); FillGroupsListBox(true); vgMembership.UpdateGroup(item); } } catch { } }
private void CancelUserChanges() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { if (ViewState["IncluiUsuario"] != null && (bool)ViewState["IncluiUsuario"] == true) { TextBox7.Text = ""; TextBox11.Text = ""; TextBox9.Text = ""; TextBox8.Text = ""; TextBox10.Text = ""; ViewState["IncluiUsuario"] = false; } else if (ListBox6.SelectedIndex != -1 && ListBox6.SelectedValue != null) { LoginUserItem vgUser = vgMembership.GetUser(Crypt.Encripta(ListBox6.SelectedItem.Text)); TextBox7.Text = Crypt.Decripta(vgUser.Fields["Login"].GetFormattedValue()); TextBox11.Text = Crypt.Decripta(vgUser.Fields["Name"].GetFormattedValue()); TextBox10.Text = Crypt.Decripta(vgUser.Fields["Obs"].GetFormattedValue()); } EnableUserButtons(true, true, true, true); ListBox6.Enabled = true; ListBox5.Enabled = true; TextBox9.Enabled = true; TextBox7.Enabled = true; TextBox8.Enabled = true; TextBox10.Enabled = true; } } catch { } }
/// <summary> /// Insere um usuario no banco de dados /// </summary> private void CreateUser() { try { if (CurrentGroup != null && (bool)CurrentGroup.Fields["IsAdmin"].Value) { if (ListBox5.SelectedIndex == -1) { ErrorList.Add("UsuarioGrupoInvalido", "Escolha um grupo"); } else { if (TextBox7.Text == "") { ErrorList.Add("UsuarioNomeInvalido", "Nome do Login de usuário tem que ser preenchido"); } if (TextBox11.Text == "") { ErrorList.Add("UsuarioNomeInvalido", "Nome Completo do usuário tem que ser preenchido"); } if (TextBox8.Text == "") { ErrorList.Add("UsuarioSenhaInvalido", "Senha do usuário tem que ser preenchido"); } if (TextBox9.Text == "") { ErrorList.Add("UsuarioCsenhaInvalido", "Confirmação de senha tem que ser preenchido"); } } if (ErrorList.Count > 0) { return; } if (TextBox8.Text != TextBox9.Text) { ErrorList.Add("SenhaEconfirmacaoDif", "Confirmação de senha invalida"); } if (ErrorList.Count > 0) { return; } try { LoginUserItem item = new LoginUserItem(); item.Fields["Login"].SetValue(Crypt.Encripta(TextBox7.Text.ToUpper())); item.Fields["Id"].SetValue(ListBox6.SelectedValue); item.Fields["Password"].SetValue(Crypt.Encripta(TextBox8.Text.ToUpper())); item.Fields["Group"].SetValue(ListBox5.SelectedValue); item.Fields["Obs"].SetValue(Crypt.Encripta(TextBox10.Text)); item.Fields["Name"].SetValue(Crypt.Encripta(TextBox11.Text)); if (vgMembership.CreateUser(item) == 0) { throw new Exception("Erro na criação do usuario"); } FillUserListBox(); ListBox6.Enabled = true; ListBox5.Enabled = true; ListBox6.SelectedIndex = ListBox6.Items.Count - 1; EnableUserButtons(false, false, true, true); } catch (Exception ex) { ErrorList.Add("ErroDeCriacao", ex.Message); } } } catch { } }