Exemple #1
0
        private void ProcessDownload(string EmpresaID)
        {
            FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService();

            string strId = Request.QueryString["nc"];
            string strTipoCbte = Request.QueryString["nt"];
            string strNumeroLegal = Request.QueryString["leg"];

            try
            {
                Settings oSettings = new Settings(EmpresaID);

                FEPrintService.Url = oSettings.UrlPrintWebService;
                FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                byte[] fileData = null;

                switch (Request.QueryString["type"])
                {
                    case "o":
                        fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Original);//(byte[])sqlDReader["PDF" + strType];
                        break;
                    case "d":
                        fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Duplicado);
                        break;
                    case "t":
                        fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Triplicado);
                        break;
                    case "c":
                        fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Copia);
                        break;
                }

                if (fileData != null)
                {
                    Response.ClearContent();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + strNumeroLegal + ".pdf");
                    Response.ContentType = "application/pdf";

                    BinaryWriter bw = new BinaryWriter(Response.OutputStream);
                    bw.Write(fileData);
                    bw.Close();

                    Response.End();
                }
                else
                {
                    lblMsg.Text = "No se pudo generar archivo PDF.<br>No se encontro detalle del comprobante.";
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        //todo: hacer
        private void ProcessDownload(string EmpresaID)
        {
            Settings oSettings = new Settings(EmpresaID);

            FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService();
            FEPrintService.Url = oSettings.UrlPrintWebService;
            FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            string strIds = Request.QueryString["ids"];
            string strId = string.Empty;
            string strTipoCbte = string.Empty;
            string strNumeroLegal = string.Empty;
            string strTipoCbteName = string.Empty;

            try
            {
                foreach (string strCbte in strIds.Split('|'))
                {
                    if (strCbte != string.Empty && strCbte.Split(';').Length == 3)
                    {
                        strId = strCbte.Split(';')[0];
                        strTipoCbte = strCbte.Split(';')[1];
                        strNumeroLegal = strCbte.Split(';')[2];

                        string fileName = oSettings.PathTemporales + @"\" + strNumeroLegal;

                        FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Original);//(byte[])sqlDReader["PDF" + strType];

                        if (!fiZip.EntryFileNames.Contains("Comprobantes/" + strNumeroLegal + "-" + strTipoCbteName + "-Original.pdf"))
                            fiZip.AddFile(fileName + "-" + strTipoCbteName + "-Original.pdf", "Comprobantes");

                        if (!fiZip.EntryFileNames.Contains("Comprobantes/" + strNumeroLegal + "-" + strTipoCbteName + "-Duplicado.pdf"))
                            fiZip.AddFile(fileName + "-" + strTipoCbteName + "-Duplicado.pdf", "Comprobantes");

                        if (!fiZip.EntryFileNames.Contains("Comprobantes/" + strNumeroLegal + "-" + strTipoCbteName + "-Triplicado.pdf"))
                            fiZip.AddFile(fileName + "-" + strTipoCbteName + "-Triplicado.pdf", "Comprobantes");
                    }
                }

                if (fiZip.Count > 0)
                {
                    LoadZipFile(fiZip);
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                Response.End();
            }

            Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "window.close();", true);
        }
Exemple #3
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            string strIds = Request.QueryString["ids"];
            string strId = string.Empty;

            MailMessage oMessage = null;
            Attachment oAttach = null;
            SmtpClient emailClient = null;
            System.Net.NetworkCredential SMTPUserInfo = null;

            FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService();

            byte[] fileData = null;
            Stream oStream = null;

            DataTable dtCbte = new DataTable();
            DataTable dtUser = new DataTable();

            TableRow tbRow;
            TableCell tbCell;

            try
            {
                tblComprobantes.Rows.Clear();
                btnSend.Visible = false;

                EmpresaID = Request.QueryString["eid"];
                Settings oSettings = new Settings(EmpresaID);

                FEPrintService.Url = oSettings.UrlPrintWebService;
                FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                foreach (string strCbte in strIds.Split('|'))
                {
                    tbCell = new TableCell();
                    tbRow = new TableRow();

                    if (strCbte != string.Empty && strCbte.Split(';').Length == 2)
                    {
                        strId = strCbte.Split(';')[0];

                        dtCbte = GetComprobanteDataTable(strId);

                        if (dtCbte.Rows[0]["COMPRADORCODIGOCLIENTE"].ToString() != string.Empty)
                        {
                            dtUser = GetUserData(oSettings.Entrada.Split('\\')[0], oSettings.Entrada.Split('\\')[1], "IFMSFA_TERCEROS_AFIP", dtCbte.Rows[0]["COMPRADORCODIGOCLIENTE"].ToString());

                            if (dtUser.Rows.Count > 0)
                            {
                                if (dtUser.Rows[0]["CORREO"].ToString() != string.Empty)
                                {
                                    fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Original);

                                    oStream = new MemoryStream(fileData);
                                    oAttach = new Attachment(oStream, "Comprobante.pdf");

                                    oMessage = new MailMessage(oSettings.SMTPFrom, dtUser.Rows[0]["CORREO"].ToString(), oSettings.MailSubject, oSettings.MailMessage);
                                    oMessage.Attachments.Add(oAttach);

                                    if (oSettings.SMTPServer != string.Empty)
                                    {
                                        emailClient = new SmtpClient(oSettings.SMTPServer);

                                        if (oSettings.SMTPUser != string.Empty && oSettings.SMTPPassword != string.Empty)
                                        {
                                            SMTPUserInfo = new System.Net.NetworkCredential(oSettings.SMTPUser, oSettings.SMTPPassword);

                                            emailClient.UseDefaultCredentials = false;
                                            emailClient.Credentials = SMTPUserInfo;
                                        }

                                        emailClient.Send(oMessage);

                                        tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - OK.<br>"));
                                    }
                                }
                                else
                                {
                                    tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - El cliente no tiene correo.<br>"));
                                }
                            }
                            else
                            {
                                tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - No hay información de Usuario para este cliente.<br>"));
                            }
                        }
                        else
                        {
                            tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - El cliente no tiene un usuario creado.<br>"));
                        }
                    }

                    tbRow.Cells.Add(tbCell);

                    tblComprobantes.Rows.Add(tbRow);
                }
            }
            catch (Exception ex)
            {
                tblComprobantes.Rows.Clear();
                lblErrors.Text = "Error Enviando Correos. " + ex.Message;
            }
        }
Exemple #4
0
        private void ProcessPrint()
        {
            string EmpresaId = Request.QueryString["eid"];
            string strIds = Request.QueryString["ids"];
            string strTipos = Request.QueryString["t"];
            string strId = string.Empty;
            string strTipoCbte = string.Empty;
            string fileName = string.Empty;
            string strMergedFileName = string.Empty;

            Settings oSettings = new Settings(EmpresaId);

            FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService();
            FEPrintService.Url = oSettings.UrlPrintWebService;
            FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            PdfMerge pdfMerger = new PdfMerge();

            try
            {
                foreach (string strCbte in strIds.Split('|'))
                {
                    if (strCbte != string.Empty && strCbte.Split(';').Length == 2)
                    {
                        strId = strCbte.Split(';')[0];
                        strTipoCbte = strCbte.Split(';')[1];

                        // imprimir original?
                        if (strTipos.IndexOf("o") > -1)
                        {
                            fileName = FEPrintService.SendToFileSystem(EmpresaId, strId, "Original");

                            if (fileName != string.Empty)
                                pdfMerger.AddDocument(fileName);
                        }

                        // imprimir duplicado?
                        if (strTipos.IndexOf("d") > -1)
                        {
                            fileName = FEPrintService.SendToFileSystem(EmpresaId, strId, "Duplicado");

                            if (fileName != string.Empty)
                                pdfMerger.AddDocument(fileName);
                        }

                        // imprimir triplicado?
                        if (strTipos.IndexOf("t") > -1)
                        {
                            // triplicado solo para comprobantes A y E
                            if (strTipoCbte != "6" || strTipoCbte != "7" || strTipoCbte != "8")
                            {
                                fileName = FEPrintService.SendToFileSystem(EmpresaId, strId, "Triplicado");

                                if (fileName != string.Empty)
                                    pdfMerger.AddDocument(fileName);
                            }
                        }

                        // imprimir copia?
                        if (strTipos.IndexOf("c") > -1)
                        {
                            fileName = FEPrintService.SendToFileSystem(EmpresaId, strId, "Copia");

                            if (fileName != string.Empty)
                                pdfMerger.AddDocument(fileName);
                        }
                    }
                }

                //cantidad de ids + fecha y hora actual
                if (pdfMerger != null && pdfMerger.Documents.Count > 0)
                {
                    strMergedFileName = pdfMerger.Documents.Count.ToString() + "_" + DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + "-" + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + DateTime.Now.Millisecond.ToString("000");

                    pdfMerger.Merge(Server.MapPath("Temp") + "\\" + strMergedFileName + ".pdf");

                    PDFName = "Temp/" + strMergedFileName + ".pdf";
                }
                else
                {
                    PDFName = "Temp/blank.pdf";
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                Response.End();
            }
        }