Beispiel #1
0
        public async Task <ActionResult> UploadHomeReport(string id)
        {
            string table    = "";
            int    idResult = 0;

            try
            {
                foreach (string item in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
                    if (file.ContentLength == 0)
                    {
                        continue;
                    }
                    if (file.ContentLength > 0)
                    {
                        //Pega o nome do arquivo
                        string nome = System.IO.Path.GetFileName(file.FileName);
                        //Pega a extensão do arquivo
                        string extensao = Path.GetExtension(file.FileName);
                        //Gera nome novo do Arquivo numericamente
                        string filename = string.Format("{0:00000000000000}", GerarID());
                        //Caminho a onde será salvo
                        file.SaveAs(Server.MapPath("~/Areas/Admin/Upload/") + filename + extensao);

                        //Prefixo P/ img pequena
                        var prefixoP = "_80x80";
                        //Prefixo M/ img media
                        var prefixoM = "_400x250";
                        //Prefixo G/ img grande
                        var prefixoG = "_800x400";

                        //pega o arquivo já carregado
                        string pth = Server.MapPath("~/Areas/Admin/Upload/") + filename + extensao;

                        string arquivo = Constantes.UrlImagens + filename + prefixoG + extensao;
                        string imagem1 = Redefinir.resizeImageAndSave(pth, Constantes.ImagemW80, Constantes.ImagemH80, prefixoP);
                        string imagem2 = Redefinir.resizeImageAndSave(pth, Constantes.ImagemW400, Constantes.ImagemH250, prefixoM);
                        string imagem3 = Redefinir.resizeImageAndSave(pth, Constantes.ImagemW800, Constantes.ImagemH400, prefixoG);

                        idResult++;// = RetornaId(idResult);
                        table += "<tr><td>" + idResult.ToString() + "</td><td><span id='p_" + idResult + "'>" + arquivo + "</span></td><td><a href='javascript:;' onclick='copyToClipboard(\"#p_" + idResult + "\")' class='btn btn-icon-only grey-cascade'><i class='fa fa-link'></i></a><a href='" + arquivo + "' target='_blank' class='btn btn-icon-only green'><i class='fa fa-file-image-o'></i></a></td></tr>";
                        //idResult++;
                        //table += "<tr><td>" + idResult.ToString() + "</td><td><span id='p_" + idResult + "'>" + imagem2 + "</span></td><td>400x250</td><td><a href='javascript:;' onclick='copyToClipboard(\"#p_" + idResult + "\")' class='btn btn-icon-only grey-cascade'><i class='fa fa-link'></i></a></td></tr>";
                        //idResult++;
                        //table += "<tr><td>" + idResult.ToString() + "</td><td><span id='p_" + idResult + "'>" + imagem3 + "</span></td><td>800x400</td><td><a href='javascript:;' onclick='copyToClipboard(\"#p_" + idResult + "\")' class='btn btn-icon-only grey-cascade'><i class='fa fa-link'></i></a></td></tr>";
                    }
                }
            }
            catch (Exception)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Upload failed"));
            }
            return(Content(table));
        }
Beispiel #2
0
        public ActionResult Upload(FormCollection formCollection)
        {
            foreach (string item in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
                if (file.ContentLength == 0)
                {
                    continue;
                }
                if (file.ContentLength > 0)
                {
                    //Pega o nome do arquivo
                    string nome = System.IO.Path.GetFileName(file.FileName);
                    //Pega a extensão do arquivo
                    string extensao = Path.GetExtension(file.FileName);
                    //Gera nome novo do Arquivo numericamente
                    string filename = string.Format("{0:00000000000000}", GerarID());
                    //Caminho a onde será salvo
                    file.SaveAs(Server.MapPath("~/uploads/fotos/") + filename + extensao);

                    //Prefixo p/ img pequena
                    var prefixoP = "-p";
                    //Prefixo p/ img grande
                    var prefixoG = "-g";

                    //pega o arquivo já carregado
                    string pth = Server.MapPath("~/uploads/fotos/") + filename + extensao;

                    //Redefine altura e largura da imagem e Salva o arquivo + prefixo
                    Redefinir.resizeImageAndSave(pth, 70, 53, prefixoP);
                    Redefinir.resizeImageAndSave(pth, 500, 331, prefixoG);
                }
            }

            return(View());
        }
Beispiel #3
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string foto = "";

        if (FileUploadControl.PostedFile.ContentLength < 8388608)
        {
            try
            {
                if (FileUploadControl.HasFile)
                {
                    try
                    {
                        //Aqui ele vai filtrar pelo tipo de arquivo
                        if (FileUploadControl.PostedFile.ContentType == "image/jpeg" ||
                            FileUploadControl.PostedFile.ContentType == "image/png" ||
                            FileUploadControl.PostedFile.ContentType == "image/gif" ||
                            FileUploadControl.PostedFile.ContentType == "image/bmp")
                        {
                            try
                            {
                                //Obtem o  HttpFileCollection
                                HttpFileCollection hfc = Request.Files;
                                for (int i = 0; i < hfc.Count; i++)
                                {
                                    HttpPostedFile hpf = hfc[i];
                                    if (hpf.ContentLength > 0)
                                    {
                                        //Pega o nome do arquivo
                                        string nome = System.IO.Path.GetFileName(hpf.FileName);
                                        //Pega a extensão do arquivo
                                        string extensao = Path.GetExtension(hpf.FileName);
                                        //Gera nome novo do Arquivo numericamente
                                        string filename = string.Format("{0:00000000000000}", GerarID());
                                        //Caminho a onde será salvo
                                        hpf.SaveAs(Server.MapPath("~/uploads/fotos/") + filename + i
                                                   + extensao);

                                        //Prefixo p/ img pequena
                                        var prefixoP = "-p";
                                        //Prefixo p/ img grande
                                        var prefixoG = "-g";

                                        //pega o arquivo já carregado
                                        string pth = Server.MapPath("~/uploads/fotos/")
                                                     + filename + i + extensao;
                                        foto = filename + "0" + extensao;

                                        //Redefine altura e largura da imagem e Salva o arquivo + prefixo
                                        Redefinir.resizeImageAndSave(pth, 70, 53, prefixoP);
                                        Redefinir.resizeImageAndSave(pth, 500, 331, prefixoG);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                            // Mensagem se tudo ocorreu bem
                            StatusLabel.Text = "Todas imagens carregadas com sucesso!";

                            Pef_Pessoa_Fisica pef = (Pef_Pessoa_Fisica)Session["usuario"];

                            pef.Pef_foto_perfil = foto;
                            switch (Pef_Pessoa_FisicaBD.UpdateFoto(pef))
                            {
                            case 0:
                                break;

                            case -2:
                                break;
                            }
                            Page.Response.Redirect(Page.Request.Url.ToString(), true);
                        }
                        else
                        {
                            // Mensagem notifica que é permitido carregar apenas
                            // as imagens definida la em cima.
                            StatusLabel.Text = "É permitido carregar apenas imagens!";
                        }
                    }
                    catch (Exception ex)
                    {
                        // Mensagem notifica quando ocorre erros
                        StatusLabel.Text = "O arquivo não pôde ser carregado.  O seguinte erro ocorreu: " + ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                // Mensagem notifica quando ocorre erros
                StatusLabel.Text = "O arquivo não pôde ser carregado.  O seguinte erro ocorreu: " + ex.Message;
            }
        }
        else
        {
            // Mensagem notifica quando imagem é superior a 8 MB
            StatusLabel.Text = "Não é permitido carregar mais do que 8 MB";
        }
    }
Beispiel #4
0
        //Carregamento da imagem
        protected void carregarImagem()
        {
            if (FileUploadControl.PostedFile.ContentLength < 8388608)
            {
                try
                {
                    if (FileUploadControl.HasFile)
                    {
                        try
                        {
                            //Aqui ele vai filtrar pelo tipo de arquivo
                            if (FileUploadControl.PostedFile.ContentType == "image/jpeg" ||
                                FileUploadControl.PostedFile.ContentType == "image/png" ||
                                FileUploadControl.PostedFile.ContentType == "image/gif" ||
                                FileUploadControl.PostedFile.ContentType == "image/bmp")
                            {
                                try
                                {
                                    //Obtem o  HttpFileCollection
                                    HttpFileCollection hfc = Request.Files;
                                    for (int i = 0; i < hfc.Count; i++)
                                    {
                                        HttpPostedFile hpf = hfc[i];
                                        if (hpf.ContentLength > 0)
                                        {
                                            //Pega o nome do arquivo
                                            string nome = System.IO.Path.GetFileName(hpf.FileName);
                                            //Pega a extensão do arquivo
                                            string extensao = Path.GetExtension(hpf.FileName);
                                            //Gera nome novo do Arquivo numericamente
                                            string filename = string.Format("{0:00000000000000}", GerarID());
                                            //Caminho a onde será salvo
                                            hpf.SaveAs(Server.MapPath("~/uploads/fotos/") + filename + i + extensao);

                                            //Prefixo p/ img pequena
                                            //var prefixoP = "-p";
                                            //Prefixo p/ img grande
                                            var prefixoG = "-g";

                                            //pega o arquivo já carregado
                                            string pth = Server.MapPath("~/uploads/fotos/") + filename + i + extensao;

                                            //Redefine altura e largura da imagem e Salva o arquivo + prefixo
                                            //Redefinir.resizeImageAndSave(pth, 70, 53, prefixoP);
                                            Redefinir.resizeImageAndSave(pth, 172, 180, prefixoG);

                                            infosEditado.TITULOIMAGEM = filename + i.ToString() + extensao;
                                            Session["10"]             = infosEditado.TITULOIMAGEM;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ex.ToString();
                                }
                                // Mensagem se tudo ocorreu bem
                                StatusLabel.Text = "Imagem carregada com sucesso!";
                            }
                            else
                            {
                                // Mensagem notifica que é permitido carregar apenas
                                // as imagens definida la em cima.
                                StatusLabel.Text = "É permitido carregar apenas imagens!";
                            }
                        }
                        catch (Exception ex)
                        {
                            // Mensagem notifica quando ocorre erros
                            StatusLabel.Text = "O arquivo não pôde ser carregado. O seguinte erro ocorreu: " + ex.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Mensagem notifica quando ocorre erros
                    StatusLabel.Text = "O arquivo não pôde ser carregado. O seguinte erro ocorreu: " + ex.Message;
                }
            }
            else
            {
                // Mensagem notifica quando imagem é superior a 8 MB
                StatusLabel.Text = "Não é permitido carregar mais do que 8 MB";
            }
        }
Beispiel #5
0
    protected void btnSalvar_Click(object sender, EventArgs e)
    {
        Empresas id  = (Empresas)Session["emp_empresa"];
        Empresas emp = new Empresas();
        Imagens  img = new Imagens();



        if (EscolheCategoria.SelectedValue == "1")
        {
            Produtos pro = new Produtos();
            pro.Pro_nome           = ProNome.Text;
            pro.Pro_tipo           = ProTipo.Text;
            pro.Pro_descricao      = ProDesc.Text;
            pro.Pro_caracteristica = ProCarac.Text;
            pro.Pro_quantidade     = Convert.ToInt32(ProQtd.Text);
            pro.Pro_vencimento     = Convert.ToDateTime(ProVenc.Text);
            pro.Pro_valor          = Convert.ToDouble(ProValor.Text);

            //FK
            emp.Emp_id = Convert.ToInt32(id.Emp_id);
            pro.Emp_id = emp;
            pro.Pro_id = ProdutosDB.Insert(pro);


            img.Pro_id = pro;
            if (FileUploadControl.PostedFile.ContentLength < 8388608)
            {
                try
                {
                    if (FileUploadControl.HasFile)
                    {
                        try
                        {
                            //Aqui ele vai filtrar pelo tipo de arquivo
                            if (FileUploadControl.PostedFile.ContentType == "image/jpeg" ||
                                FileUploadControl.PostedFile.ContentType == "image/png" ||
                                FileUploadControl.PostedFile.ContentType == "image/gif" ||
                                FileUploadControl.PostedFile.ContentType == "image/bmp")
                            {
                                try
                                {
                                    //Obtem o  HttpFileCollection
                                    HttpFileCollection hfc = Request.Files;
                                    for (int i = 0; i < hfc.Count; i++)
                                    {
                                        HttpPostedFile hpf = hfc[i];
                                        if (hpf.ContentLength > 0)
                                        {
                                            //Pega o nome do arquivo
                                            string nome = System.IO.Path.GetFileName(hpf.FileName);
                                            //Pega a extensão do arquivo
                                            string extensao = Path.GetExtension(hpf.FileName);
                                            //Gera nome novo do Arquivo numericamente
                                            string filename = string.Format("{0:00000000000000}", GerarID());
                                            //Caminho a onde será salvo
                                            hpf.SaveAs(Server.MapPath("~/FotoProduto/") + filename + i
                                                       + extensao);

                                            //Prefixo p/ img m
                                            var prefixoG = "-m";

                                            //pega o arquivo já carregado
                                            string pth = Server.MapPath("~/FotoProduto/")
                                                         + filename + i + extensao;

                                            //Redefine altura e largura da imagem e Salva o arquivo + prefixo
                                            Redefinir.resizeImageAndSave(pth, 500, 331, prefixoG);
                                            //     H    V

                                            img.Img_url = "../FotoProduto/" + filename + i + prefixoG + extensao;

                                            File.Delete(Request.PhysicalApplicationPath + "FotoProduto\\" + filename + i + extensao);

                                            switch (ImagensDB.InsertImgProduto(img))
                                            {
                                            case -2:
                                                ltl.Text = "<p class='text-success'>Erro no produto</p>";
                                                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#myModal').modal('show');</script>", false);
                                                break;

                                            default:
                                                ltl.Text = "<p class='text-success'>Produto adicionado com sucesso</p>";
                                                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#myModal').modal('show');</script>", false);
                                                LimpaCampos();
                                                break;
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw;
                                }
                                // Mensagem se tudo ocorreu bem
                                StatusLabel.Text = "Todas imagens carregadas com sucesso!";
                            }
                            else
                            {
                                // Mensagem notifica que é permitido carregar apenas
                                // as imagens definida la em cima.
                                StatusLabel.Text = "É permitido carregar apenas imagens!";
                            }
                        }
                        catch (Exception ex)
                        {
                            // Mensagem notifica quando ocorre erros
                            StatusLabel.Text = "O arquivo não pôde ser carregado. O seguinte erro ocorreu: " + ex.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Mensagem notifica quando ocorre erros
                    StatusLabel.Text = "O arquivo não pôde ser carregado. O seguinte erro ocorreu: " + ex.Message;
                }
            }
            else
            {
                // Mensagem notifica quando imagem é superior a 8 MB
                StatusLabel.Text = "Não é permitido carregar mais do que 8 MB";
            }
        }
        else
        {
            Servicos ser = new Servicos();
            ser.Ser_nome           = ServNome.Text;
            ser.Ser_descricao      = ServDesc.Text;
            ser.Ser_caracteristica = ServCarac.Text;
            ser.Ser_valor          = Convert.ToInt32(ServValor.Text);

            //FK
            emp.Emp_id = Convert.ToInt32(id.Emp_id);
            ser.Emp_id = emp;
            ser.Ser_id = ServicosDB.Insert(ser);

            img.Ser_id = ser;



            if (FileUploadControl.PostedFile.ContentLength < 8388608)
            {
                try
                {
                    if (FileUploadControl.HasFile)
                    {
                        try
                        {
                            //Aqui ele vai filtrar pelo tipo de arquivo
                            if (FileUploadControl.PostedFile.ContentType == "image/jpeg" ||
                                FileUploadControl.PostedFile.ContentType == "image/png" ||
                                FileUploadControl.PostedFile.ContentType == "image/gif" ||
                                FileUploadControl.PostedFile.ContentType == "image/bmp")
                            {
                                try
                                {
                                    //Obtem o  HttpFileCollection
                                    HttpFileCollection hfc = Request.Files;
                                    for (int i = 0; i < hfc.Count; i++)
                                    {
                                        HttpPostedFile hpf = hfc[i];
                                        if (hpf.ContentLength > 0)
                                        {
                                            //Pega o nome do arquivo
                                            string nome = System.IO.Path.GetFileName(hpf.FileName);
                                            //Pega a extensão do arquivo
                                            string extensao = Path.GetExtension(hpf.FileName);
                                            //Gera nome novo do Arquivo numericamente
                                            string filename = string.Format("{0:00000000000000}", GerarID());
                                            //Caminho a onde será salvo
                                            hpf.SaveAs(Server.MapPath("~/FotoProduto/") + filename + i
                                                       + extensao);

                                            //Prefixo p/ img m
                                            var prefixoG = "-m";

                                            //pega o arquivo já carregado
                                            string pth = Server.MapPath("~/FotoProduto/")
                                                         + filename + i + extensao;

                                            //Redefine altura e largura da imagem e Salva o arquivo + prefixo
                                            Redefinir.resizeImageAndSave(pth, 500, 331, prefixoG);
                                            //     H    V

                                            img.Img_url = "../FotoProduto/" + filename + i + prefixoG + extensao;

                                            File.Delete(Request.PhysicalApplicationPath + "FotoProduto\\" + filename + i + extensao);

                                            switch (ImagensDB.InsertImgServico(img))
                                            {
                                            case -2:
                                                ltl.Text = "<p class='text-success'>Erro no serviço</p>";
                                                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#myModal').modal('show');</script>", false);
                                                break;

                                            default:
                                                ltl.Text = "<p class='text-success'>Serviço adicionado com sucesso</p>";
                                                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#myModal').modal('show');</script>", false);
                                                LimpaCampos();
                                                break;
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw;
                                }
                                // Mensagem se tudo ocorreu bem
                                StatusLabel.Text = "Todas imagens carregadas com sucesso!";
                            }
                            else
                            {
                                // Mensagem notifica que é permitido carregar apenas
                                // as imagens definida la em cima.
                                StatusLabel.Text = "É permitido carregar apenas imagens!";
                            }
                        }
                        catch (Exception ex)
                        {
                            // Mensagem notifica quando ocorre erros
                            StatusLabel.Text = "O arquivo não pôde ser carregado. O seguinte erro ocorreu: " + ex.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Mensagem notifica quando ocorre erros
                    StatusLabel.Text = "O arquivo não pôde ser carregado. O seguinte erro ocorreu: " + ex.Message;
                }
            }
            else
            {
                // Mensagem notifica quando imagem é superior a 8 MB
                StatusLabel.Text = "Não é permitido carregar mais do que 8 MB";
            }
        }
    }