コード例 #1
0
ファイル: Solicitud.aspx.cs プロジェクト: wilmer-pachon/breve
    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();
        }
    }
コード例 #2
0
ファイル: Solicitud.aspx.cs プロジェクト: wilmer-pachon/breve
    protected void B_Logo_Click(object sender, EventArgs e)
    {
        ClientScriptManager cm = this.ClientScript;
        DataTable           fotos;

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

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

        if (fotos.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_Logo.PostedFile.FileName);
        string extension     = System.IO.Path.GetExtension(FU_Logo.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_Logo.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_Logo.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_ruta1"] = "~\\Imagenes\\Empresas\\" + nombreArchivo;
        fotos.Rows.Add(celdas);
        Session["fotos"] = fotos;

        DatosUsuario datos = new DatosUsuario();

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

        Usuario obtener = new Usuario();

        obtener.InsertarImgSolicitud(datos);

        GV_Logo.DataSource = obtener.obtenerImgSolicitud("LOGO", _id_user);
        GV_Logo.DataBind();
    }