private void CargarPermisosUsuario()
        {
            //Marca los permisos del usuario seleccionado
            DataTable dt        = new DataTable();
            string    mensaje   = string.Empty;
            int       idUsuario = Convert.ToInt32(HfIdUsuario.Value);

            dt = inicio.DatosPermisos(idUsuario, lblCadena.Text, ref mensaje);
            if (!mensaje.Equals(string.Empty))
            {
                AlertError(mensaje);
            }
            else
            {
                CargarPermisos(dt);
            }
        }
Exemple #2
0
        private void CreaMenu()
        {
            DataTable      dt               = new DataTable();
            DataTable      dwModulos        = new DataTable();
            string         mensaje          = string.Empty;
            string         filterExpression = string.Empty;
            LiteralControl literal          = new LiteralControl();

            dt = login.DatosPermisos((int)Session["IdUsuario"], ref mensaje);
            if (!mensaje.Equals(string.Empty))
            {
                AlertError(mensaje);
                return;
            }
            //Consulta modulos padre (encabezados de menu)
            filterExpression = "IdModuloPadre IS NULL";
            if (dt.Select(filterExpression).Count() > 0)
            {
                Session.Add("Permisos", dt);
                dwModulos     = dt.Select("IdModuloPadre IS NULL AND Consultar = '1'", "Orden ASC").CopyToDataTable();
                literal.Text += @"<ul class='nav navbar-nav'>";
                foreach (DataRow rowModulos in dwModulos.Rows)
                {
                    string file = rowModulos["Archivo"].ToString();
                    literal.Text += "<li class='dropdown'><a href='" + file + "' class='dropdown-toggle" + (file.Length > 0 ? " disabled" : "") + "' data-toggle='dropdown'>" + rowModulos["RibbonName"].ToString();
                    //Consulta submodulos de modulos padre
                    filterExpression = "IdModuloPadre = '" + rowModulos["IdModulo"].ToString() + "'";
                    if (dt.Select(filterExpression).Count() > 0)
                    {
                        DataTable dtModulos2 = new DataTable();
                        dtModulos2    = dt.Select("IdModuloPadre = '" + rowModulos["IdModulo"].ToString() + "' AND Consultar = '1'", "Orden ASC").CopyToDataTable();
                        literal.Text += @"&nbsp;&nbsp;<span class='caret'></span></a>";
                        literal.Text += @"<ul class='dropdown-menu'>";
                        foreach (DataRow rowModulos2 in dtModulos2.Rows)
                        {
                            //Consulta submodulos de submodulos
                            filterExpression = "IdModuloPadre = '" + rowModulos2["IdModulo"].ToString() + "'";
                            if (dt.Select(filterExpression).Count() > 0)
                            {
                                DataTable dtModulos3 = new DataTable();
                                dtModulos3    = dt.Select("IdModuloPadre = '" + rowModulos2["IdModulo"].ToString() + "' AND Consultar = '1'", "Orden ASC").CopyToDataTable();
                                literal.Text += "<li class='dropdown-submenu'><a href='" + rowModulos2["Archivo"].ToString() + "'><img src='../img/" + rowModulos2["Icono"].ToString() + "' style='height: 1.5em;' />&nbsp;&nbsp;" + rowModulos2["RibbonName"].ToString() + @"</a>
                                    <ul class='dropdown-menu'>";
                                foreach (DataRow rowModulos3 in dtModulos3.Rows)
                                {
                                    literal.Text += "<li><a href='" + rowModulos3["Archivo"].ToString() + "'><img src='../img/" + rowModulos3["Icono"].ToString() + "' style='height: 1.5em;' />&nbsp;&nbsp;" + rowModulos3["RibbonName"].ToString() + "</a></li>";
                                }

                                literal.Text += "</ul></li>";
                            }
                            else
                            {
                                literal.Text += "<li><a href='" + rowModulos2["Archivo"].ToString() + "'><img src='../img/" + rowModulos2["Icono"].ToString() + "' style='height: 1.5em;' />&nbsp;&nbsp;" + rowModulos2["RibbonName"].ToString() + "</a></li>";
                            }
                        }
                        literal.Text += "</ul>";
                    }
                    else
                    {
                        literal.Text += "</a>";
                    }

                    literal.Text += "</li>";
                }
                literal.Text += "</ul>";
            }

            //Crear opciones para perfil y crea logo del cliente
            literal.Text += @"<ul class='nav navbar-nav navbar-right'>
                <li class='dropdown'>
                    <a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + Session["Nombre"] + @"&nbsp;&nbsp;<span class='caret'></span></a>
                    <ul class='dropdown-menu'>
                        <li><a href='AcercaDe.aspx'><span class='glyphicon glyphicons-info-sign'></span>&nbsp;&nbsp;Acerca de</a></li>
                        <li role='separator' class='divider'></li>
                        <li><a href='Login.aspx'><span class='glyphicon glyphicons-log-out'></span>&nbsp;&nbsp;Cerrar Sesión</a></li>
                    </ul>
                </li>
                <a class='navbar-brand' href='Default.aspx' style='float: right !important;'>
                    <img src='../img/logo_cliente.png' style='padding-top: 15px; height: 40px; width: 70px;'>
                </a>
            </ul>";

            Session["Menu"] = literal.Text;
        }
        private void CreaMenu()
        {
            try
            {
                Inicio login = new Inicio();

                //Traer Logo Izq
                DataTable dtL        = new DataTable();
                string    cmdString  = string.Empty;
                string    connString = lblCadena.Text;
                cmdString = "SELECT * FROM [LOGO] WHERE [ValidaIzquierdo] = 1";
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    conn.Open();
                    using (SqlCommand comm = new SqlCommand())
                    {
                        comm.Connection  = conn;
                        comm.CommandText = cmdString;
                        using (SqlDataReader reader = comm.ExecuteReader())
                        {
                            if (!reader.HasRows)
                            {
                                dtL = null;
                            }
                            else
                            {
                                dtL.Load(reader);
                            }
                        }
                    }
                    conn.Close();
                }

                if (dtL != null && dtL.Rows.Count > 0)
                {
                    byte[] bytes      = null;
                    string path       = string.Empty;
                    string pathName   = string.Empty;
                    string fileN      = string.Empty;
                    string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
                    path     = Server.MapPath(FolderPath);
                    path     = path + "\\Logo";
                    pathName = path + "\\logo_izquierdo.bmp";

                    //Si no existe la carpeta la crea, si existe la borra con su contenido y vuelve a crear la carpeta
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //else
                    //{
                    //    Directory.Delete(path, true);
                    //    Directory.CreateDirectory(path);
                    //}

                    //Descargar imagen en la carpeta
                    fileN = dtL.Rows[0]["FileName"].ToString();
                    bytes = (byte[])dtL.Rows[0]["Logo"];
                    File.WriteAllBytes(pathName, bytes);
                }
                else
                {
                    string path       = string.Empty;
                    string pathName1  = string.Empty;
                    string pathName2  = string.Empty;
                    string fileN      = string.Empty;
                    string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
                    path      = Server.MapPath(FolderPath);
                    path      = path + "\\Logo";
                    pathName1 = path + "\\sice_m3.jpg";
                    pathName2 = path + "\\logo_izquierdo.bmp";
                    File.Copy(pathName1, pathName2, true);
                }


                //Traer Logo Der
                int       valida_vacio = 0;
                DataTable dtD          = new DataTable();
                string    cmdStringD   = string.Empty;
                cmdStringD = "SELECT * FROM [LOGO] WHERE [ValidaDerecho] = 1";
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    conn.Open();
                    using (SqlCommand comm = new SqlCommand())
                    {
                        comm.Connection  = conn;
                        comm.CommandText = cmdStringD;
                        using (SqlDataReader reader = comm.ExecuteReader())
                        {
                            if (!reader.HasRows)
                            {
                                dtD = null;
                            }
                            else
                            {
                                dtD.Load(reader);
                            }
                        }
                    }
                    conn.Close();
                }

                if (dtD != null && dtD.Rows.Count > 0)
                {
                    byte[] bytes      = null;
                    string path       = string.Empty;
                    string pathName   = string.Empty;
                    string fileN      = string.Empty;
                    string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
                    path     = Server.MapPath(FolderPath);
                    path     = path + "\\Logo";
                    pathName = path + "\\logo_derecho.bmp";

                    //Descargar imagen en la carpeta
                    fileN = dtD.Rows[0]["FileName"].ToString();
                    bytes = (byte[])dtD.Rows[0]["Logo"];
                    File.WriteAllBytes(pathName, bytes);
                }
                else
                {
                    valida_vacio = 1;
                }


                DataTable      dt        = new DataTable();
                DataTable      dwModulos = new DataTable();
                string         mensaje   = string.Empty;
                LiteralControl literal   = new LiteralControl();
                dt = login.DatosPermisos(int.Parse(Session["IdUsuario"].ToString()), lblCadena.Text, ref mensaje);
                if (!mensaje.Equals(string.Empty))
                {
                    AlertError(mensaje);
                    return;
                }
                //Consulta modulos padre (encabezados de menu)
                try
                {
                    dwModulos = dt.Select("IdModuloPadre IS NULL AND Consultar = '1'", "Orden ASC").CopyToDataTable();
                    Session.Add("Permisos", dt);
                }
                catch (Exception ex)
                {
                    //AlertError(excepcion.SerializarExMessage(lblCadena.Text,ex));
                }
                //Crear menu html
                literal.Text += @"<ul class='nav navbar-nav'>";
                if (dwModulos.Rows.Count > 0)
                {
                    foreach (DataRow rowModulos in dwModulos.Rows)
                    {
                        ////SI EL NOMBRE DEL MENÚ ES DATA STAGE QUITARLE PROPIEDADES DE CLASE
                        //if (rowModulos["RibbonName"].ToString().ToUpper().Contains("DATA STAGE"))
                        //    literal.Text += @"<li><a href='" + rowModulos["Archivo"].ToString() + "'>" + rowModulos["RibbonName"].ToString();
                        //else
                        //literal.Text += @"<li class='dropdown'><a href='" + rowModulos["Archivo"].ToString() + "' class='dropdown-toggle' data-toggle='dropdown' style='background-color:" + Session["MenuBackColor"].ToString() + "'><font color='" + Session["MenuFontColor"].ToString() + @"'>" + rowModulos["RibbonName"].ToString();
                        literal.Text += @"<li class='dropdown'><a href='#' class='dropdown-toggle' data-toggle='dropdown' style='background-color:" + Session["MenuBackColor"].ToString() + "'><font color='" + Session["MenuFontColor"].ToString() + @"'>" + rowModulos["RibbonName"].ToString();

                        DataTable dtModulos2 = new DataTable();
                        //Consulta submodulos de modulos padre
                        try
                        {
                            dtModulos2 = dt.Select("IdModuloPadre = '" + rowModulos["IdModulo"].ToString() + "' AND Consultar = '1'", "Orden ASC").CopyToDataTable();
                        }
                        catch (Exception ex)
                        {
                            //AlertError(excepcion.SerializarExMessage(lblCadena.Text, ex));
                        }

                        if (dtModulos2.Rows.Count > 0)
                        {
                            literal.Text += @"&nbsp;&nbsp;<span class='caret'></span></font></a>";

                            //SI EL NOMBRE DEL MENÚ ES Informes Generales PONERLE LA CLASE QUE LLAMA A UN DROPDOWN dropdown-InformesGenerales
                            if (rowModulos["RibbonName"].ToString().Equals("Informes Generales"))
                            {
                                literal.Text += @"<ul class='dropdown-InformesGenerales'>";
                            }
                            else
                            {
                                literal.Text += @"<ul class='dropdown-menu'>";
                            }
                            foreach (DataRow rowModulos2 in dtModulos2.Rows)
                            {
                                //Consulta submodulos de submodulos
                                DataTable dtModulos3 = new DataTable();
                                try
                                {
                                    dtModulos3 = dt.Select("IdModuloPadre = '" + rowModulos2["IdModulo"].ToString() + "' AND Consultar = '1'", "Orden ASC").CopyToDataTable();
                                }
                                catch (Exception ex)
                                {
                                    //AlertError(excepcion.SerializarExMessage(lblCadena.Text, ex));
                                }

                                if (dtModulos3.Rows.Count > 0)
                                {
                                    literal.Text += "<li class='dropdown-submenu'><a href='" + rowModulos2["Archivo"].ToString() + "'><img src='../img/" + rowModulos2["Icono"].ToString() + "' style='height: 2em;' />&nbsp;&nbsp;" + rowModulos2["RibbonName"].ToString() + @"</a>
                                    <ul class='dropdown-menu'>";
                                    foreach (DataRow rowModulos3 in dtModulos3.Rows)
                                    {
                                        literal.Text += "<li><a href='" + rowModulos3["Archivo"].ToString() + "'><img src='../img/" + rowModulos3["Icono"].ToString() + "' style='height: 2em;' />&nbsp;&nbsp;" + rowModulos3["RibbonName"].ToString() + "</a></li>";
                                    }

                                    literal.Text += "</ul></li>";
                                }
                                else
                                {
                                    literal.Text += "<li><a href='" + rowModulos2["Archivo"].ToString() + "'><img src='../img/" + rowModulos2["Icono"].ToString() + "' style='height: 2em;' />&nbsp;&nbsp;" + rowModulos2["RibbonName"].ToString() + "</a></li>";
                                }
                            }
                            literal.Text += "</ul>";
                        }
                        else
                        {
                            literal.Text += "</a>";
                        }

                        literal.Text += "</li>";
                    }
                }
                literal.Text += "</ul>";

                Random rnd = new Random();

                //Crear opciones para perfil y crea logo del cliente
                literal.Text += @"<ul class='nav navbar-nav navbar-right'>
                <li class='dropdown'>
                    <a href='#' class='dropdown-toggle' data-toggle='dropdown' style='width:130px;height:50px;border:0; padding:0px;'>";
                if (valida_vacio.Equals(0))
                {
                    literal.Text += @"<img src='../Presentacion/Logo/logo_derecho.bmp?" + rnd.Next() + @"' class='imagen-logo-right' />";
                }
                else
                {
                    literal.Text += @"";
                }
                literal.Text += @"</a>
                    <ul class='dropdown-menu'>
                        <li><a>&nbsp;&nbsp;" + Session["Nombre"].ToString().Trim() + @"</a></li>
                        <li role='separator' class='divider'></li>";
                if (Session["Nombre"] != null && Session["Nombre"].ToString().ToUpper().Trim().Contains("ADMINISTRADOR"))
                {
                    literal.Text += @"<li><a href='Colores.aspx'><span class='glyphicon glyphicon-th'></span>&nbsp;&nbsp;Colores</a></li>
                        <li role='separator' class='divider'></li><li><a href='ImagenLogo.aspx'><span class='glyphicon glyphicon-th'></span>&nbsp;&nbsp;Logos</a></li>
                        <li role='separator' class='divider'></li>";
                }

                literal.Text   += @"<li><a href='AcercaDe.aspx'><span class='glyphicon glyphicon-info-sign'></span>&nbsp;&nbsp;Acerca de</a></li>
                        <li role='separator' class='divider'></li>
                        <li><a href='Login.aspx?valor=cerrar'><span class='glyphicon glyphicon-log-out'></span>&nbsp;&nbsp;Cerrar Sesión</a></li>
                        
                    </ul>
                </li>                
            </ul>";
                Session["Menu"] = literal.Text;
            }
            catch (Exception ex)
            {
                string mensaje   = string.Empty;
                int    idusuario = 0;
                if (Session["IdUsuario"] != null)
                {
                    idusuario = int.Parse(Session["IdUsuario"].ToString());
                }
                excepcion.RegistrarExcepcion(idusuario, "Colores-CreaMenu", ex, lblCadena.Text, ref mensaje);
                if (mensaje.Length == 0)
                {
                    mensaje = "Error: " + excepcion.SerializarExMessage(lblCadena.Text, ex);
                }
            }
        }