Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthenticationTicket ticket = null;

            try
            {
                FormsIdentity formsIdentity = HttpContext.Current.User.Identity as FormsIdentity;
                ticket = formsIdentity.Ticket;
            }
            catch
            {
                Response.Redirect("Default.aspx");
            }

            string empresaid = ticket.UserData.Split('|')[0];

            //Response.Expires = -1;
            Response.ContentType = "application/text";

            if (!Page.IsPostBack)
            {
                if (!Context.User.Identity.IsAuthenticated)
                {
                    // This is an unauthorized, authenticated request...
                    Response.Redirect("Default.aspx");
                }
            }

            string id = Request.QueryString["id"].ToString();



            Entity.Documento documento = new Repositorio.Documento().LoadByCodigo(empresaid, id);


            if (documento.ARCHIVO_TICKET_PATH != null)
            {
                FileInfo file = new FileInfo(documento.ARCHIVO_TICKET_PATH);

                if (file.Exists)
                {
                    Response.Clear();
                    Response.ContentType = "application/pdf";
                    //Response.AddHeader("content-disposition", string.Format(@"attachment;filename=""{0}""", documento.ARCHIVO_PDF_NOMBRE));
                    Response.WriteFile(documento.ARCHIVO_TICKET_PATH);
                }
                else
                {
                    Response.Clear();
                    Response.ContentType = "text/plain";
                    Response.Write(string.Format("El archivo no fue encontrado:{0}", documento.ARCHIVO_TICKET_PATH));
                }
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthenticationTicket ticket = null;

            try
            {
                FormsIdentity formsIdentity = HttpContext.Current.User.Identity as FormsIdentity;
                ticket = formsIdentity.Ticket;
            }
            catch
            {
                Response.Redirect("Default.aspx");
            }

            string empresaid             = ticket.UserData.Split('|')[0];
            string rucEmpresa            = ticket.UserData.Split('|')[1];
            string usuarioanum_documento = ticket.UserData.Split('|')[7];

            ViewState["usuarioanum_documento"] = usuarioanum_documento;


            if (!Page.IsPostBack)
            {
                if (!Context.User.Identity.IsAuthenticated)
                {
                    // This is an unauthorized, authenticated request...
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Repositorio.Cliente objcliente = new Repositorio.Cliente();
                    string limitepago = objcliente.LimitePago(rucEmpresa);
                    if (limitepago != "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text",
                                                            string.Format("alert('Tiene monto de deuda pendiente de pago, el sistema sera bloqueado dentro de {0} !');", limitepago), true);
                    }
                }
            }

            if (!String.IsNullOrEmpty(Request.QueryString["id"]))
            {
                string           id        = Request.QueryString["id"].ToString();
                Entity.Documento documento = new Repositorio.Documento().LoadByCodigo(empresaid, id);


                if (!String.IsNullOrEmpty(Request.QueryString["tipo"]))
                {
                    if (Request.QueryString["tipo"] == "1")
                    {
                        using (ZipFile zip = new ZipFile())
                        {
                            zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                            zip.AddDirectoryByName(documento.CODIGO);

                            FileInfo file1 = new FileInfo(documento.ARCHIVO_PDF_PATH);
                            FileInfo file2 = new FileInfo(documento.ARCHIVO_XML_PATH);
                            FileInfo file3 = new FileInfo(documento.ARCHIVO_CDR_PATH);

                            if (file1.Exists)
                            {
                                zip.AddFile(documento.ARCHIVO_PDF_PATH, documento.CODIGO);
                            }

                            if (file2.Exists)
                            {
                                zip.AddFile(documento.ARCHIVO_XML_PATH, documento.CODIGO);
                            }

                            if (file3.Exists)
                            {
                                zip.AddFile(documento.ARCHIVO_CDR_PATH, documento.CODIGO);
                            }

                            Response.Clear();
                            Response.BufferOutput = false;
                            string zipName = String.Format("{0}.zip", documento.CODIGO);
                            Response.ContentType = "application/zip";
                            Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                            zip.Save(Response.OutputStream);
                            Response.End();
                        }
                    }

                    if (Request.QueryString["tipo"] == "2")
                    {
                        FileInfo fileXml = new FileInfo(documento.ARCHIVO_XML_PATH);
                        Response.Clear();
                        string docname = String.Format("{0}.xml", documento.CODIGO);
                        Response.ContentType = "application/xml";
                        Response.AddHeader("content-disposition", "attachment; filename=" + docname);
                        Response.WriteFile(documento.ARCHIVO_XML_PATH);
                        Response.End();
                    }


                    if (Request.QueryString["tipo"] == "3")
                    {
                        FileInfo filePdf = new FileInfo(documento.ARCHIVO_PDF_PATH);
                        Response.Clear();
                        string docname = String.Format("{0}.pdf", documento.CODIGO);
                        Response.ContentType = "application/pdf";
                        Response.AddHeader("content-disposition", "attachment; filename=" + docname);
                        Response.WriteFile(documento.ARCHIVO_PDF_PATH);
                        Response.End();
                    }

                    if (Request.QueryString["tipo"] == "4")
                    {
                        using (ZipFile zip = new ZipFile())
                        {
                            zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                            zip.AddDirectoryByName(documento.CODIGO);

                            FileInfo file1 = new FileInfo(documento.ARCHIVO_FILE1_PATH);
                            FileInfo file2 = new FileInfo(documento.ARCHIVO_FILE2_PATH);
                            FileInfo file3 = new FileInfo(documento.ARCHIVO_FILE3_PATH);

                            if (file1.Exists)
                            {
                                zip.AddFile(documento.ARCHIVO_FILE1_PATH, documento.CODIGO);
                            }

                            if (file2.Exists)
                            {
                                zip.AddFile(documento.ARCHIVO_FILE2_PATH, documento.CODIGO);
                            }

                            if (file3.Exists)
                            {
                                zip.AddFile(documento.ARCHIVO_FILE3_PATH, documento.CODIGO);
                            }

                            Response.Clear();
                            Response.BufferOutput = false;
                            string zipName = String.Format("{0}.zip", documento.CODIGO);
                            Response.ContentType = "application/zip";
                            Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                            zip.Save(Response.OutputStream);
                            Response.End();
                        }
                    }
                }
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthenticationTicket ticket = null;

            try
            {
                FormsIdentity formsIdentity = HttpContext.Current.User.Identity as FormsIdentity;
                ticket = formsIdentity.Ticket;
            }
            catch
            {
                Response.Redirect("Default.aspx");
            }


            if (!Page.IsPostBack)
            {
                if (!Context.User.Identity.IsAuthenticated)
                {
                    // This is an unauthorized, authenticated request...
                    Response.Redirect("Default.aspx");
                }
            }



            string empresaid             = ticket.UserData.Split('|')[0];
            string usuarioanum_documento = ticket.UserData.Split('|')[7];


            if (!String.IsNullOrEmpty(Request.QueryString["ope"]))
            {
                ZipFile zip    = null;
                string  id     = Request.QueryString["ope"].ToString();
                string  filtro = string.Format("{0}{1}", Request.QueryString["anio"].ToString(), Request.QueryString["mes"].ToString());

                List <Entity.Documento> lista = new Repositorio.Documento().LoadByMonth(empresaid, filtro);

                if (lista.Count > 0)
                {
                    zip = new ZipFile();
                    zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                    //zip.AddDirectoryByName(filtro);
                }

                foreach (var documento in lista)
                {
                    FileInfo file1 = new FileInfo(documento.ARCHIVO_PDF_PATH);
                    FileInfo file2 = new FileInfo(documento.ARCHIVO_XML_PATH);
                    FileInfo file3 = new FileInfo(documento.ARCHIVO_CDR_PATH);

                    if (file1.Exists)
                    {
                        zip.AddFile(documento.ARCHIVO_PDF_PATH, documento.CODIGO);
                    }

                    if (file2.Exists)
                    {
                        zip.AddFile(documento.ARCHIVO_XML_PATH, documento.CODIGO);
                    }

                    if (file3.Exists)
                    {
                        zip.AddFile(documento.ARCHIVO_CDR_PATH, documento.CODIGO);
                    }
                }

                if (lista.Count > 0)
                {
                    Response.Clear();
                    Response.BufferOutput = false;
                    string zipName = String.Format("{0}.zip", filtro);
                    Response.ContentType = "application/zip";
                    Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                    zip.Save(Response.OutputStream);
                    Response.End();
                }
            }
        }