Пример #1
0
        private void BindGrid(string Category)
        {
            try
            {
                UploadFileBL     objUploadFileBL     = new UploadFileBL();
                UploadFileSchema objUploadFileSchema = new UploadFileSchema();
                if (Category != null)
                {
                    DataTable dt;
                    dt = new DataTable();
                    objUploadFileSchema.FileCategory = Convert.ToInt32(Category);
                    ds = objUploadFileBL.ShowUploadFileBL(objUploadFileSchema);
                    dt = ds.Tables[0];
                    if (dt.Rows.Count < 1)
                    {
                        dt = null;
                    }

                    if (ds.Tables[1].Rows.Count > 0)
                    {
                        HdnExt.Value       = ds.Tables[1].Rows[0]["FileExtension"].ToString();
                        HdnSizeLimit.Value = ds.Tables[1].Rows[0]["FileSize_Kb"].ToString();
                    }

                    if (objUploadFileSchema.FileCategory == 1)
                    {
                        Session["KeyPersonCount"] = ds.Tables[0].Rows.Count;
                    }
                    grdupload.DataSource = dt;
                    grdupload.DataBind();
                }
            }
            catch (Exception ex) { throw ex; }
        }
Пример #2
0
        public HttpResponseMessage RetornarArquivo(string docClienteId)
        {
            //docClienteId = System.Web.HttpUtility.UrlDecode(docClienteId);
            docClienteId = MD5Crypt.Descriptografar(docClienteId);

            DocumentoCliente _documentoCliente = new UploadFileBL().RetornarArquivo(new DocumentoCliente()
            {
                DocClienteId = long.Parse(docClienteId)
            });
            UploadFileBL uploadFileBl = new UploadFileBL();

            WorkingFolder += "\\" + new UploadFileBL().RecuperarCaminhoPastaDocumentosByDocClienteId(long.Parse(docClienteId));

            var file = WorkingFolder + "\\" + _documentoCliente.DocClienteNomeArquivoSalvo;
            HttpResponseMessage result = null;

            if (!File.Exists(file))
            {
                result = new HttpResponseMessage(HttpStatusCode.Conflict);
                return(result);
            }
            else
            {
                result = new HttpResponseMessage(HttpStatusCode.OK);
                var stream = new FileStream(file, FileMode.Open);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = _documentoCliente.DocClienteNomeArquivoOriginal
                };
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");
                return(result);
            }
        }
Пример #3
0
 protected void grdupload_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "delete")
         {
             int              retnval             = 0;
             UploadFileBL     objUploadFileBL     = new UploadFileBL();
             UploadFileSchema objUploadFileSchema = new UploadFileSchema();
             objUploadFileSchema.RowId = Convert.ToInt32(e.CommandArgument);
             retnval = objUploadFileBL.DeleteFileBL(objUploadFileSchema);
             if (retnval > 0)
             {
                 ScriptManager.RegisterStartupScript(this, typeof(Page), "Message", "alert('Record Deleted Sucessfully!!! ');", true);
             }
             else
             {
                 ScriptManager.RegisterStartupScript(this, typeof(Page), "Message", "alert('Record Not Deleted !!! ');", true);
             }
         }
         if (e.CommandName == "view")
         {
             ds = new DataSet();
             UploadFileBL     objUploadFileBL     = new UploadFileBL();
             UploadFileSchema objUploadFileSchema = new UploadFileSchema();
             objUploadFileSchema.RowId        = Convert.ToInt32(e.CommandArgument);
             objUploadFileSchema.FileCategory = Convert.ToInt32(DDLcategory.SelectedValue);
             ds = objUploadFileBL.ShowFileDetailsdBL(objUploadFileSchema);
             if (ds.Tables[0].Rows.Count > 0)
             {
                 txtFDtl.Text       = ds.Tables[0].Rows[0]["FileDtl"].ToString();
                 txtFDtlLL.Text     = ds.Tables[0].Rows[0]["FileDtlLL"].ToString();
                 txtFTitle.Text     = ds.Tables[0].Rows[0]["FileTitle"].ToString();
                 txtFTitleLL.Text   = ds.Tables[0].Rows[0]["FileTitleLL"].ToString();
                 chkActive.Checked  = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsActive"]);
                 txtSeqNo.Text      = ds.Tables[0].Rows[0]["SequenceNo"].ToString();
                 HdnDelete.Value    = e.CommandArgument.ToString();;
                 HdnExt.Value       = ds.Tables[0].Rows[0]["FileExtension"].ToString();
                 HdnSizeLimit.Value = ds.Tables[0].Rows[0]["FileSize_Kb"].ToString();
                 txtFDtlUL.Text     = ds.Tables[0].Rows[0]["FileDtlUL"].ToString();
                 txtFTitleUL.Text   = ds.Tables[0].Rows[0]["FileTitleUL"].ToString();
             }
         }
         BindGrid(DDLcategory.SelectedValue);
     }
     catch (Exception ex)
     { throw ex; }
 }
Пример #4
0
        private void SaveUpdateDB()
        {
            DateTime date    = Convert.ToDateTime(DateTime.Now);
            int      retnVal = 0;
            string   ext     = null;;

            byte[]           t_Image             = null;
            Double           FileSize            = 0;
            UploadFileBL     objUploadFileBL     = new UploadFileBL();
            UploadFileSchema objUploadFileSchema = new UploadFileSchema();


            if (DDLcategory.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Select File Category ')", true);
                return;
            }
            if (HdnDelete.Value != "0" && UploadImage.HasFile)
            {
                if (isValidAttachmentFile(UploadImage))
                {
                    objUploadFileSchema.RowId = Convert.ToInt32(HdnDelete.Value);
                    ext      = System.IO.Path.GetExtension(UploadImage.FileName);
                    t_Image  = UploadImage.FileBytes;
                    FileSize = UploadImage.PostedFile.ContentLength / 1024;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Supports Only " + HdnExt.Value + " File types Upto " + HdnSizeLimit.Value + " KB')", true);
                    return;
                }
            }
            else if (HdnDelete.Value == "0")
            {
                if (isValidAttachmentFile(UploadImage))
                {
                    ext      = System.IO.Path.GetExtension(UploadImage.FileName);
                    t_Image  = UploadImage.FileBytes;
                    FileSize = UploadImage.PostedFile.ContentLength / 1024;
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Supports Only " + HdnExt.Value + " File types Upto " + HdnSizeLimit.Value + " KB')", true);
                    return;
                }
            }

            //if ((UploadImage.HasFile))
            //{
            //    FileInfo file = new FileInfo(UploadImage.FileName);
            //    Bitmap img = new Bitmap(UploadImage.FileContent);
            //    var imageHeight = img.Height;
            //    var imageWidth = img.Width;

            //    if (DDLcategory.SelectedValue == "1")
            //    {
            //        if (imageHeight != 54 && imageWidth != 51)
            //        {
            //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Key Person photograph should fall between 51 to 54 pixels.')", true);
            //            return;
            //        }
            //    }
            //    else if (DDLcategory.SelectedValue == "2")
            //    {
            //        if (imageHeight != 627 && imageWidth != 2000)
            //        {
            //            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Banner photograph should fall between 2000 to 627 pixels.')", true);
            //            return;
            //        }
            //    }


            //}

            try
            {
                byte[] t_Image1 = new byte[UploadImage.PostedFile.ContentLength];

                objUploadFileSchema.FileCategory = Convert.ToInt32(DDLcategory.SelectedValue);
                objUploadFileSchema.FileTitle    = txtFTitle.Text;
                objUploadFileSchema.FileTitleLL  = txtFTitleLL.Text;
                objUploadFileSchema.FileDetail   = txtFDtl.Text;
                objUploadFileSchema.FileDetailLL = txtFDtlLL.Text;
                objUploadFileSchema.ImageType    = ext;
                objUploadFileSchema.FileSize     = FileSize.ToString();
                objUploadFileSchema.IsActive     = chkActive.Checked;
                objUploadFileSchema.SequenceNo   = Convert.ToInt32(txtSeqNo.Text);
                objUploadFileSchema.CreatedBy    = HttpContext.Current.Profile.UserName;
                objUploadFileSchema.CreatedDate  = Convert.ToDateTime(date.ToString("yyyy-MM-dd"));
                objUploadFileSchema.UpdatedDate  = Convert.ToDateTime(date.ToString("yyyy-MM-dd"));
                objUploadFileSchema.IpAddress    = Request.UserHostAddress;
                objUploadFileSchema.FileDetailUL = txtFDtlUL.Text;
                objUploadFileSchema.FileTitleUL  = txtFTitleUL.Text;

                ClearControls();
                if (HdnDelete.Value != "0")
                {
                    if ((UploadImage.HasFile))
                    {
                        objUploadFileSchema.ImageContent = t_Image;
                    }
                    else
                    {
                        objUploadFileSchema.ImageContent = t_Image1;
                    }
                    objUploadFileSchema.RowId = Convert.ToInt32(HdnDelete.Value);
                    retnVal = objUploadFileBL.UpdateUploadFileBL(objUploadFileSchema);
                }
                else
                {
                    int count = Convert.ToInt32(Session["KeyPersonCount"]);
                    if (objUploadFileSchema.FileCategory == 1)
                    {
                        if (count >= 6)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Key Person should not be more than 6')", true);
                            return;
                        }
                    }

                    objUploadFileSchema.ImageContent = t_Image;
                    retnVal = objUploadFileBL.SaveUploadFileBL(objUploadFileSchema);
                }
                if (retnVal > 0)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Message", "alert('Data Saved sucessfully !!! ');", true);
                }
                BindGrid(DDLcategory.SelectedValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                HdnDelete.Value = "0".ToString();
            }
        }
Пример #5
0
        public async Task <IHttpActionResult> EnviarArquivo(int usuarioId, long clienteId, int docCliTipoId, bool reenvio)
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                return(BadRequest("Unsupported media type"));
            }

            DocumentoCliente _documentoCliente = new DocumentoCliente();

            try
            {
                string directory = new UploadFileBL().RecuperarCaminhoPastaDocumentosByClienteId(clienteId);

                WorkingFolder += "\\" + directory;

                if (!Directory.Exists(WorkingFolder))
                {
                    Directory.CreateDirectory(WorkingFolder);
                }

                var streamProvider = new MultipartFormDataStreamProvider(WorkingFolder);
                await Request.Content.ReadAsMultipartAsync(streamProvider);

                _documentoCliente = new DocumentoCliente()
                {
                    UsuarioId    = usuarioId,
                    ClienteId    = clienteId,
                    DocCliTipoId = docCliTipoId,
                    DocClienteCaminhoCompletoArquivoSalvo = streamProvider.FileData.Select(entry => entry.LocalFileName).First(),
                    DocClienteNomeArquivoSalvo            = System.IO.Path.GetFileName(streamProvider.FileData.Select(entry => entry.LocalFileName).First()),
                    DocClienteNomeArquivoOriginal         = System.IO.Path.GetFileName(streamProvider.FileData.Select(entry => entry.Headers.ContentDisposition.FileName).First().Replace("\"", "")),
                    DocClienteTipoArquivo = streamProvider.FileData.Select(entry => entry.Headers.ContentType.MediaType).First(),
                    DocClienteDataUpload  = DateTime.Now
                };

                #region 1 - Verifica tipo/ versão pdf
                if (UtilFile.GetMIMEType(_documentoCliente.DocClienteNomeArquivoOriginal).ToLower() != "application/pdf")
                {
                    throw new Exception("Erro - Documento deve ser do tipo PDF");
                }
                #endregion

                Cliente cliente = new Cliente()
                {
                    ClienteId = _documentoCliente.ClienteId
                };
                UploadFileBL uploadFileBL = null;

                switch (cliente.ClienteNomeEnum)
                {
                case Cliente.EnumCliente.Bradesco:
                    uploadFileBL = new UploadFileBradescoBL();
                    ((UploadFileBradescoBL)uploadFileBL).Reenvio       = reenvio;
                    ((UploadFileBradescoBL)uploadFileBL).WorkingFolder = WorkingFolder;
                    _documentoCliente = uploadFileBL.EnviarDocumentoCliente(_documentoCliente);
                    break;

                default:
                    uploadFileBL      = new UploadFileBL();
                    _documentoCliente = uploadFileBL.EnviarDocumentoCliente(_documentoCliente);
                    break;
                }

                return(Ok((new Retorno()
                {
                    Dados = _documentoCliente, Mensagem = "Arquivo(s) incluído(s) com sucesso.", TipoMensagem = EnumTipoMensagem.Sucesso
                })));
            }
            catch (BusinessException ex)
            {
                if (File.Exists(WorkingFolder + "\\" + _documentoCliente.DocClienteNomeArquivoSalvo))
                {
                    File.Delete(WorkingFolder + "\\" + _documentoCliente.DocClienteNomeArquivoSalvo);
                }

                return(Ok(ex.GetRetorno()));
            }
            catch (Exception ex)
            {
                if (File.Exists(WorkingFolder + "\\" + _documentoCliente.DocClienteNomeArquivoSalvo))
                {
                    File.Delete(WorkingFolder + "\\" + _documentoCliente.DocClienteNomeArquivoSalvo);
                }

                throw new CustomException.CustomException(ex.Message, ex);
            }
        }