protected void B_Comprar_Click(object sender, EventArgs e)
    {
        if (Session["user"] != null && ((Usuario)Session["user"]).Id_rol == 1)
        {
            ClientScriptManager cm = this.ClientScript;
            bool entero            = validarEntero(TB_Cantidad.Text);
            if (entero == true)
            {
                int cantidadPedida = int.Parse(TB_Cantidad.Text);
                if (cantidadPedida < 0)
                {
                    cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('No se permiten números negativos');</script>");
                    return;
                }
                else if (cantidadPedida < 1)
                {
                    cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Ingrese una cantidad para comprar');</script>");
                    return;
                }
                else if (cantidadPedida > 10)
                {
                    cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('No está permitido adquirir más de 10 juegos');</script>");
                    return;
                }
                else
                {
                    int        id_juego   = int.Parse(Session["IdVideoJuego"].ToString());
                    int        id_usuario = int.Parse(Session["id_usuario"].ToString());
                    Videojuego añadir     = new DAOVideojuego().agragarjuego(id_juego);
                    if (cantidadPedida > añadir.Cantidad)
                    {
                        cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Cantidad excede a la disponible');</script>");
                        return;
                    }
                    else
                    {
                        new DAOBiblioteca().agregarBiblioteca(añadir, id_usuario, cantidadPedida);
                        Response.Redirect("Catalogo.aspx");
                    }
                    //añadir.Cantidad = 1;

                    /*new DAOBiblioteca().agregarBiblioteca(añadir, id_usuario);
                     * Response.Redirect("Catalogo.aspx");*/
                }
            }
            else
            {
                cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Ingrese un valor válido');</script>");
                return;
            }
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }
    protected void DDL_Categorias_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList opcion       = (DropDownList)sender;
        GridViewRow  fila         = (GridViewRow)opcion.Parent.Parent;
        int          juego        = int.Parse(((Label)fila.FindControl("L_Videojuego")).Text);
        int          id_categoría = int.Parse(opcion.SelectedValue);

        if (id_categoría != 0)
        {
            Videojuego videojuego = new DAOVideojuego().obtenerVideojuegoInformacion(juego);
            new DAOVideojuego().updateVideojuego(videojuego, id_categoría);

            GV_Juegos.DataBind();
        }
    }
    protected void B_Agregar_Click(object sender, EventArgs e)
    {
        ClientScriptManager cm = this.ClientScript;
        string nombreArchivo   = System.IO.Path.GetFileName(FU_Imagen.PostedFile.FileName);
        string extension       = System.IO.Path.GetExtension(FU_Imagen.PostedFile.FileName);

        string saveLocation = Server.MapPath("~\\Imagenes\\ImagenesJuegos") + "\\" + nombreArchivo;

        if (!(extension.Equals(".jpg") || extension.Equals(".gif") || extension.Equals(".jpeg") || extension.Equals(".png")))
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Tipo de archivo no valido');</script>");
            return;
        }

        if (System.IO.File.Exists(saveLocation))
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Ya existe un archivo en el servidor con ese nombre');</script>");
            return;
        }
        try
        {
            FU_Imagen.PostedFile.SaveAs(saveLocation);
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El archivo ha sido cargado');</script>");

            /*if (TB_Nombre.Text.Equals("") || TB_descripcion.Text.Equals("") || TB_Cantidad)
             * {
             *
             * }*/
            Videojuego videojuego = new Videojuego();
            videojuego.Id_categoría  = int.Parse(DDL_Categorias.SelectedValue);
            videojuego.Id_plataforma = int.Parse(DDL_Plataformas.SelectedValue);
            videojuego.Imagen        = "~\\Imagenes\\ImagenesJuegos" + "\\" + nombreArchivo;
            videojuego.Nom_juego     = TB_Nombre.Text;
            videojuego.Descripcion   = TB_descripcion.Text;

            /*if (videojuego.Nom_juego.Equals("") || videojuego.Descripcion.Equals("") || )
             * {
             *
             * }*/

            videojuego.Cantidad = int.Parse(TB_Cantidad.Text);
            if (videojuego.Cantidad == 0)
            {
                videojuego.Id_estadoV = 2;
            }
            else
            {
                videojuego.Id_estadoV = 1;
            }
            videojuego.Precio = int.Parse(TB_Precio.Text);
            //usuario.Precio = Double.Parse(TB_Precio.Text);
            Videojuego validacion = new DAOVideojuego().ValidacionVideojuego(videojuego);

            if (validacion == null)
            {
                new DAOVideojuego().insertJuego(videojuego);
            }
            else
            {
                if (validacion.Nom_juego == videojuego.Nom_juego)
                {
                    L_Mensaje.Text = "Nombre ya registrado";
                    TB_Nombre.Text = string.Empty;
                }
                if (validacion.Descripcion == videojuego.Descripcion)
                {
                    L_Mensaje.Text      = "Descripción ya ingresada";
                    TB_descripcion.Text = string.Empty;
                }
            }
        }
        catch (Exception)
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Error: ');</script>");
            return;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        /*
         * if (Session["user"] != null)
         * {
         *  int id_juego = int.Parse(Session["IdVideoJuego"].ToString());
         *  List<Videojuego> informacion = new DAOVideojuego().obtenerVideojuegoInformacion(id_juego);
         *  TB_nombreJ.Text = informacion[0].Nom_juego.ToString();
         *  TB_descripcion.Text = informacion[0].Descripcion.ToString();
         *  TB_Categoria.Text = informacion[0].Categoria.ToString();
         *  I_Perfil.ImageUrl = informacion[0].Imagen.ToString();
         *  int id_usuario = int.Parse(Session["id_usuario"].ToString());
         *  L_Carrito.Text = (new DAOBiblioteca().cantidadbilioteca(id_usuario).ToString());
         *  B_Comprar.Visible = true;
         *  B_Deseados.Visible = true;
         * }
         * else
         * {
         *  int id_juego = int.Parse(Session["IdVideoJuego"].ToString());
         *  List<Videojuego> informacion = new DAOVideojuego().obtenerVideojuegoInformacion(id_juego);
         *  TB_nombreJ.Text = informacion[0].Nom_juego.ToString();
         *  TB_descripcion.Text = informacion[0].Descripcion.ToString();
         *  TB_Categoria.Text = informacion[0].Categoria.ToString();
         *  I_Perfil.ImageUrl = informacion[0].Imagen.ToString();
         *  L_Carrito.Text = "0";
         *  B_Comprar.Visible = false;
         *  B_Deseados.Visible = false;
         * }
         */
        if (Session["user"] != null)
        {
            int id_juego   = int.Parse(Session["IdVideoJuego"].ToString());
            int id_usuario = int.Parse(Session["id_usuario"].ToString());



            Biblioteca validar = new DAOBiblioteca().obtenerVideojuego(id_juego, id_usuario);
            if (validar != null)
            {
                Videojuego informacion = new DAOVideojuego().obtenerVideojuegoInformacion(id_juego);
                TB_nombreJ.Text     = informacion.Nom_juego.ToString();
                TB_descripcion.Text = informacion.Descripcion.ToString();
                TB_Categoria.Text   = informacion.Categoria.ToString();
                I_Perfil.ImageUrl   = informacion.Imagen.ToString();

                L_Carrito.Text    = (new DAOBiblioteca().cantidadbilioteca(id_usuario).ToString());
                B_Comprar.Visible = false;
                // B_Deseados.Visible = false;
            }
            else
            {
                Videojuego informacion = new DAOVideojuego().obtenerVideojuegoInformacion(id_juego);
                TB_nombreJ.Text     = informacion.Nom_juego.ToString();
                TB_descripcion.Text = informacion.Descripcion.ToString();
                TB_Categoria.Text   = informacion.Categoria.ToString();
                I_Perfil.ImageUrl   = informacion.Imagen.ToString();

                L_Carrito.Text      = (new DAOBiblioteca().cantidadbilioteca(id_usuario).ToString());
                B_Comprar.Visible   = true;
                L_Cantidad.Visible  = true;
                TB_Cantidad.Visible = true;
                //B_Deseados.Visible = true;
            }
        }
        else
        {
            int        id_juego    = int.Parse(Session["IdVideoJuego"].ToString());
            Videojuego informacion = new DAOVideojuego().obtenerVideojuegoInformacion(id_juego);
            TB_nombreJ.Text     = informacion.Nom_juego.ToString();
            TB_descripcion.Text = informacion.Descripcion.ToString();
            TB_Categoria.Text   = informacion.Categoria.ToString();
            I_Perfil.ImageUrl   = informacion.Imagen.ToString();
            L_Carrito.Text      = "0";
            B_Comprar.Visible   = false;
            L_Cantidad.Visible  = false;
            TB_Cantidad.Visible = false;
            //B_Deseados.Visible = false;
        }
    }