protected void btnGuardar_Click(object sender, EventArgs e)
        {
            //Actualiza los permisos de los botones en grid
            PermisosUsuario();

            if (ValidarCampos())
            {
                string mensaje  = string.Empty;
                string idPerfil = string.Empty;
                if (HfIdPerfil.Value.Length > 0)
                {
                    perfiles.PerfilEditar(
                        Convert.ToInt32(Session["IdUsuario"])
                        , Convert.ToInt32(HfIdPerfil.Value)
                        , TxtNombre.Text.Trim()
                        , TxtClave.Text.Trim()
                        , lblCadena.Text
                        , ref mensaje);
                }
                else
                {
                    perfiles.PerfilAgregar(
                        Convert.ToInt32(Session["IdUsuario"])
                        , ref idPerfil
                        , TxtNombre.Text.Trim()
                        , TxtClave.Text.Trim()
                        , lblCadena.Text
                        , ref mensaje);
                }

                if (mensaje.Equals(ControlExcepciones.Ok))
                {
                    //Agregar perfil modulo accion
                    string mensaje2 = string.Empty;
                    for (int i = 0; i < Grid2.VisibleRowCount; i++)
                    {
                        ASPxCheckBox chkConsultar = Grid2.FindRowCellTemplateControl(i, (GridViewDataColumn)Grid2.Columns["Consultar"], "chkConsultar") as ASPxCheckBox;
                        ASPxCheckBox chkAgregar   = Grid2.FindRowCellTemplateControl(i, (GridViewDataColumn)Grid2.Columns["Agregar"], "chkAgregar") as ASPxCheckBox;
                        ASPxCheckBox chkEditar    = Grid2.FindRowCellTemplateControl(i, (GridViewDataColumn)Grid2.Columns["Editar"], "chkEditar") as ASPxCheckBox;
                        ASPxCheckBox chkEliminar  = Grid2.FindRowCellTemplateControl(i, (GridViewDataColumn)Grid2.Columns["Eliminar"], "chkEliminar") as ASPxCheckBox;
                        ASPxCheckBox chkExportar  = Grid2.FindRowCellTemplateControl(i, (GridViewDataColumn)Grid2.Columns["Exportar"], "chkExportar") as ASPxCheckBox;

                        perfiles.PerfilModuloAccionAgregar(
                            Convert.ToInt32(Session["IdUsuario"])
                            , Convert.ToInt32(idPerfil.Equals(string.Empty) ? HfIdPerfil.Value : idPerfil)
                            , Convert.ToInt32(Grid2.GetRowValues(i, "IdModulo").ToString())
                            , chkAgregar.Checked
                            , chkConsultar.Checked
                            , chkEditar.Checked
                            , chkEliminar.Checked
                            , chkExportar.Checked
                            , lblCadena.Text
                            , ref mensaje2);
                        if (!mensaje2.Equals(string.Empty))
                        {
                            AlertError(mensaje2);
                            return;
                        }
                    }

                    OcultarModal();
                    AlertSuccess("El perfil se " + (HfIdPerfil.Value.Length > 0 ? "actualizó" : "agregó") + ".");
                    Page_Init(null, null);
                    HfIdPerfil.Value = string.Empty;
                }
                else if (mensaje.Equals(ControlExcepciones.Existe))
                {
                    AlertError("El perfil \"" + TxtNombre.Text + "\" ya existe.");
                }
                else
                {
                    AlertError(mensaje);
                }

                //Actualiza los permisos de los botones en grid
                PermisosUsuario();
            }
            else
            {
                AlertError("Datos incompletos.");
            }
        }
示例#2
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            string ModuloPermisos   = string.Empty;
            string mensaje          = string.Empty;
            int    idPerfil         = 0;
            int    IdUsuarioSession = Convert.ToInt32(Session["IdUsuario"]);

            if (ValidarCampos())
            {
                //EDITAR
                if (HfIdPerfil.Value.Length > 0)
                {
                    idPerfil = Convert.ToInt32(HfIdPerfil.Value);
                }

                //AGREGAR PERMISOS al IdPerfil seleccionado
                int      i        = 0;
                string   permisos = "";
                string[] sDatos   = new string[RadGrid2.MasterTableView.Items.Count];

                foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
                {
                    bool agregar = false;
                    permisos = item["IdModulo"].Text;

                    foreach (DataRow drAccion in dtAcciones.Rows)
                    {
                        string   sAccion  = drAccion["Accion"].ToString().Replace(" ", "");
                        CheckBox cbAccion = ((CheckBox)(item[sAccion].Controls[0]));
                        permisos = permisos + "," + Convert.ToInt32(cbAccion.Checked);

                        if (cbAccion.Checked)
                        {
                            agregar = true;
                        }
                    }

                    if (!agregar)
                    {
                        continue;
                    }

                    sDatos[i] = permisos;
                    i++;
                    item.Selected = false;
                }

                //Elimina los valores items nulos
                sDatos = sDatos.Where(c => c != null).ToArray();
                //Unir la lista de registros con un   \r\n
                ModuloPermisos = string.Join("|", sDatos);

                //ACTUALIZA los permisos del perfil
                perfiles.PerfilModuloAccionAgregar(idPerfil, TxtNombre.Text.Trim(), TxtClave.Text.Trim(), ModuloPermisos, IdUsuarioSession, ref mensaje);

                //MOSTRAR RESULTADO
                if (mensaje.Equals(ControlExcepciones.Ok))
                {
                    OcultarModal();
                    (this.Master as Principal).AlertSuccess("El perfil se " + (HfIdPerfil.Value.Length > 0 ? "actualizó" : "agregó") + ".");
                    RadGrid1.Rebind();
                    HfIdPerfil.Value = string.Empty;
                }
                else if (mensaje.Equals(ControlExcepciones.Existe))
                {
                    (this.Master as Principal).AlertError("El perfil \"" + TxtNombre.Text + "\" ya existe.");
                }
                else
                {
                    (this.Master as Principal).AlertError(mensaje);
                }
            }
            else
            {
                (this.Master as Principal).AlertError("Datos incompletos.");
            }
        }