Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        _id_user = int.Parse(Session["id_user"].ToString());

        if (Session["id_rol"].Equals("null"))
        {
            Response.Redirect("index.aspx");
        }
        if (Session["verificar"].Equals("Verificada") && !Session["estado"].Equals("Normal"))
        {
            Response.Redirect("Configuracion.aspx");
        }
        if (!Session["verificar"].Equals("Verificada") && Session["estado"].Equals("Gratis"))
        {
            Response.Redirect("Configuracion.aspx");
        }
        if (!Session["verificar"].Equals("Verificada") && Session["estado"].Equals("Rechazada"))
        {
            Response.Redirect("Configuracion.aspx");
        }
        if (!IsPostBack)
        {
            Usuario obtener = new Usuario();
            obtener.obtenerImgSolicitud("LOGO", _id_user);
            GV_Logo.DataSource = obtener.obtenerImgSolicitud("LOGO", _id_user);
            GV_Logo.DataBind();

            obtener.obtenerImgSolicitud("RUT", _id_user);
            GV_Rut.DataSource = obtener.obtenerImgSolicitud("RUT", _id_user);
            GV_Rut.DataBind();

            obtener.obtenerImgSolicitud("CC", _id_user);
            GV_CC.DataSource = obtener.obtenerImgSolicitud("CC", _id_user);
            GV_CC.DataBind();
        }
    }
Ejemplo n.º 2
0
    protected void B_CC_Click(object sender, EventArgs e)
    {
        ClientScriptManager cm = this.ClientScript;
        DataTable           fotos3;

        if (Session["fotos3"] == null)
        {
            fotos3 = new DataTable();
            fotos3.Columns.Add("ruta3");
            Session["fotos3"] = fotos3;
        }

        fotos3 = (DataTable)Session["fotos3"];

        if (fotos3.Rows.Count == 1)
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('No se pueden agregar mas imagenes');</script>");
            return;
        }

        string nombreArchivo = System.IO.Path.GetFileName(FU_CC.PostedFile.FileName);
        string extension     = System.IO.Path.GetExtension(FU_CC.PostedFile.FileName);

        if (!(string.Compare(extension, ".png", true) == 0 || string.Compare(extension, ".jpg", true) == 0 || string.Compare(extension, ".jpeg", true) == 0 || string.Compare(extension, ".gif", true) == 0 || string.Compare(extension, ".jpe", true) == 0))
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Solo se admiten imagenes en formato Jpeg o Gif');</script>");
            return;
        }

        int tamano = FU_CC.PostedFile.ContentLength;

        if (tamano > (1024 * 1024))
        {
            double tamanoMb = (double)((double)tamano / ((double)1024 * 1024));
            cm.RegisterClientScriptBlock(this.GetType(), "", string.Format("<script type='text/javascript'>alert('Solo se admiten imagenes con un tamaño menor a 1 Megabyte. Tamaño del archivo: {0:F1}MB');</script>", tamanoMb));
            return;
        }
        string saveLocation = Server.MapPath("~\\Imagenes\\Empresas") + "\\" + nombreArchivo;


        if (System.IO.File.Exists(saveLocation))
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('Ya existe una imagen en el servidor con ese nombre');</script>");
            return;
        }

        try
        {
            FU_CC.PostedFile.SaveAs(saveLocation);
            cm.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('El archivo de imagen ha sido cargado');</script>");
        }
        catch (Exception exc)
        {
            cm.RegisterClientScriptBlock(this.GetType(), "", string.Format("<script type='text/javascript'>alert('Error: {0}');</script>", exc.Message));
            return;
        }

        string[] celdas = new string[1];

        celdas[0] = "~\\Imagenes\\Empresas\\" + nombreArchivo;
        Session["fotos_ruta3"] = "~\\Imagenes\\Empresas\\" + nombreArchivo;
        fotos3.Rows.Add(celdas);
        Session["fotos3"] = fotos3;

        DatosUsuario datos = new DatosUsuario();

        datos.Nombre  = "CC";
        datos.Url     = celdas[0].ToString();
        datos.Id_user = _id_user;

        Usuario obtener = new Usuario();

        obtener.InsertarImgSolicitud(datos);

        GV_CC.DataSource = obtener.obtenerImgSolicitud("CC", _id_user);
        GV_CC.DataBind();
    }