private void PreencheTela() { if (id == 0) { ddlMenus.Enabled = false; BtnAdd.Enabled = false; return; } var usuario = service.RetornaUsuario(id); lblidUsuario.Text = usuario.id_user.ToString(); txtCodigo.Text = usuario.codigo; txtSenha.Text = usuario.Senha; txtNome.Text = usuario.Nome; txtDepartamento.Text = usuario.Depto; txtCadastro.Text = usuario.Data; txtDtInicio.Text = usuario.DataInicio; txtTelefone.Text = usuario.Tel1; txtTelRes.Text = usuario.Tel2; txtTelCel.Text = usuario.Tel3; txtEmail.Text = usuario.Email; chkAtivo.Checked = Convert.ToBoolean(usuario.ativo); if (!this.IsPostBack) { GridAcessos.DataSource = usuario.Acessos; GridAcessos.DataBind(); } foreach (var mod in usuario.Modulos) { if (mod.id_modulo == 1) { chkCategorias.Checked = true; } if (mod.id_modulo == 2) { chkUsuarios.Checked = true; } if (mod.id_modulo == 3) { chkIndexar.Checked = true; } } var frmcadcategoria = service.PreencheTela(); foreach (var item in frmcadcategoria.Menus.OrderBy(x => x.Nivel).ToList()) { ddlMenus.Items.Add(new ListItem(item.DescNivel, item.id_Oper.ToString())); } }
protected void BtnAdd_Click(object sender, EventArgs e) { // RemontaTela(); var acessos = RetornaListaAcessos(); if (ddlMenus.SelectedIndex > 0) { var selec = service.PesquisaCategoria(Convert.ToInt32(ddlMenus.SelectedValue)); acessos.Add(new AcessosViewModel(selec.id_Oper, selec.Descricao, selec.Nivel)); } GridAcessos.DataSource = acessos; GridAcessos.DataBind(); }
protected void BtnExcluir_Click(object sender, ImageClickEventArgs e) { //RemontaTela(); ImageButton button = sender as ImageButton; var idoper = Convert.ToInt32(button.CommandArgument); var acessos = new List <AcessosViewModel>(); foreach (GridViewRow row in GridAcessos.Rows) { var id = (Label)row.Cells[0].Controls[1]; var desc = (Label)row.Cells[1].Controls[1]; var nivel = (Label)row.Cells[2].Controls[1]; var item = new AcessosViewModel(Convert.ToInt32(id.Text), desc.Text.TrimEnd(), nivel.Text); acessos.Add(item); } acessos.Remove(acessos.Where(x => x.id_oper == idoper).FirstOrDefault()); GridAcessos.DataSource = acessos.ToList(); GridAcessos.DataBind(); }