Example #1
0
        private void printaFactura(string nomdocumento)
        {
            try
            {
                Herramientas herramientas = new Herramientas();

                var informe = herramientas.GetResourcesPath3();

                CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                rd.Load(informe + "\\" + nomdocumento + ".pdf");


                CrystalDecisions.CrystalReports.Engine.PrintOptions rptoption = rd.PrintOptions;
                rptoption.PrinterName = "\\\\192.168.1.35\\EPSON LX-350 ESC/P";
                rptoption.PaperSize   = (CrystalDecisions.Shared.PaperSize)GetIDPaperSize("\\\\192.168.1.35\\EPSON LX-350 ESC/P", "A4");//(CrystalDecisions.Shared.PaperSize)ext.GetIDPaperSize(Convert.ToString(System.Drawing.Printing.PrinterSettings.InstalledPrinters[3]), "documentoFioviza");

                rd.PrintToPrinter(1, false, 1, 1);

                rd.Close();
                rd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Se encontro el siguiente problema" + ex.Message, "Venta", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
        private void btnImprimir_Click(object sender, EventArgs e)
        {
            try
            {
                ser = AdmSerie.MuestraSerie(factur.CodSerie, frmLogin.iCodAlmacen);
                CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                rd.Load("CRNotaDebito.rpt");
                CRNotaDebito rpt = new CRNotaDebito();
                rd.SetDataSource(ds.ReportNotaDebitoCompra(Convert.ToInt32(CodNotaS), frmLogin.iCodAlmacen));
                CrystalDecisions.CrystalReports.Engine.PrintOptions rptoption = rd.PrintOptions;
                rptoption.PrinterName = ser.NombreImpresora;
                rptoption.PaperSize   = (CrystalDecisions.Shared.PaperSize)ext.GetIDPaperSize(ser.NombreImpresora, ser.PaperSize);
                rptoption.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(1100, 1850, 200, 1300));
                //CrystalDecisions.Shared.PageMargins margenes = rd.PrintOptions.PageMargins;
                rd.PrintToPrinter(1, false, 1, 1);
                rd.Close();
                rd.Dispose();

                //CRNotaDebito rpt = new CRNotaDebito();
                //frmRptNotaCredito frm = new frmRptNotaCredito();
                //CrystalDecisions.CrystalReports.Engine.PrintOptions rptoption = rpt.PrintOptions;
                //rptoption.PrinterName = ser.NombreImpresora;//Convert.ToString(System.Drawing.Printing.PrinterSettings.InstalledPrinters[3]);
                //rptoption.PaperSize = (CrystalDecisions.Shared.PaperSize)ext.GetIDPaperSize(ser.NombreImpresora, ser.PaperSize);
                //rpt.SetDataSource(ds.ReportNotaDebitoCompra(Convert.ToInt32(CodNotaS), frmLogin.iCodAlmacen).Tables[0]);
                //frm.crvNotaCredito.ReportSource = rpt;
                //frm.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Se encontro el siguiente problema " + ex.Message, "Nota de Credito", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #3
0
        public void PrintTicket()
        {
            try
            {
                CrystalDecisions.CrystalReports.Engine.ReportDocument etq = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                string spath = System.Windows.Forms.Application.StartupPath;
                etq.Load(spath + "\\" + @"\Reports\DRE_v3.RPT");

                CrystalDecisions.Shared.IConnectionInfo crConnectionInfo = etq.DataSourceConnections[0];

                string DbUser    = Properties.Settings.Default.DbUserName;
                string DbPwd     = Properties.Settings.Default.DbPassword;
                string Server    = Properties.Settings.Default.Server;
                string CompanyDB = Properties.Settings.Default.CompanyDB;

                crConnectionInfo.SetConnection(Server, CompanyDB, DbUser, DbPwd);

                //Parametro 0
                CrystalDecisions.Shared.ParameterField         objParameterField = etq.ParameterFields[0];
                CrystalDecisions.Shared.ParameterDiscreteValue objParameterDiscreteValue;

                objParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();

                objParameterField.CurrentValues.Clear();

                objParameterDiscreteValue.Description = "2017-10-01";

                objParameterDiscreteValue.Value = "2017-10-01";

                objParameterField.CurrentValues.Add(objParameterDiscreteValue);

                //Parametro 1
                CrystalDecisions.Shared.ParameterField         objParameterField1 = etq.ParameterFields[1];
                CrystalDecisions.Shared.ParameterDiscreteValue objParameterDiscreteValue1;

                objParameterDiscreteValue1 = new CrystalDecisions.Shared.ParameterDiscreteValue();

                objParameterField1.CurrentValues.Clear();

                objParameterDiscreteValue1.Description = "2017-10-31";

                objParameterDiscreteValue1.Value = "2017-10-31";

                objParameterField1.CurrentValues.Add(objParameterDiscreteValue1);

                //etq.PrintOptions.PrinterName = Properties.Settings.Default.PrinterNameTerra;

                etq.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\Temp\RPT.pdf");
                etq.Close();
            }
            catch (Exception ex)
            {
            }
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string strFormatoReporte = "PDF";  //PDF, XLS, DOC

            if (Session["FormatoReporte"] != null) strFormatoReporte = Session["FormatoReporte"].ToString();

            MemoryStream stream = new MemoryStream();
            myReportDocument = (CrystalDecisions.CrystalReports.Engine.ReportDocument)Session["ReporteCrystal"];

            switch (strFormatoReporte)
            {
                case "PDF":
                    stream = (MemoryStream)myReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    Response.ContentType = "application/pdf";
                    break;
                case "XLS":
                    stream = (MemoryStream)myReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                    Response.ContentType = "application/vnd.ms-excel";
                    break;
                case "DOC":
                    stream = (MemoryStream)myReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.WordForWindows);
                    Response.ContentType = "application/doc";
                    break;
                default:
                    stream = (MemoryStream)myReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    Response.ContentType = "application/pdf";
                    break;
            }

            myReportDocument.Close();
            myReportDocument.Dispose();

            //Escribir PDF
            Response.Clear();
            Response.Buffer = true;
            //Response.ContentType = "application/pdf";

            Response.BinaryWrite(stream.ToArray());
            Response.End();

            stream.Flush();
            stream.Close();
            stream.Dispose();

            //Cerrar Ventana
            //string lstScript = "<script language='JavaScript'>window.close(); </script>";
            //this.ClientScript.RegisterStartupScript(this.GetType(), "s", lstScript);
        }
Example #5
0
    private string generatefiles(DataSet ds, DataTable dt1, string fromdate, string todate, string FirstPath, DataTable mailsetting)
    {
        try
        {
            DataView dv                          = new DataView(ds.Tables[0]);
            string   strAttachFirst              = string.Empty;
            string   strAttachSecond             = string.Empty;
            bool     isSendData                  = false;
            System.Collections.ArrayList objList = new ArrayList();
            objList.Add(MailSetting(mailsetting));
            CrystalDecisions.CrystalReports.Engine.ReportDocument crystalReport;
            foreach (DataRow Row in dt1.Rows)
            {
                MailDetails objMails = new MailDetails();
                dv.RowFilter  = "SuperZoneID = " + Row["SuperZoneID"].ToString();
                crystalReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                crystalReport.Load(Server.MapPath("../Report/MissingRecieptNo.rpt"));
                crystalReport.SetDataSource(dv.ToTable());
                crystalReport.SetParameterValue("FromDP", Convert.ToDateTime(fromdate));
                crystalReport.SetParameterValue("TODp", Convert.ToDateTime(todate));
                isSendData     = dv.ToTable().Rows.Count > 0 ? true : false;
                strAttachFirst = Server.MapPath(FirstPath + "MissingRecieptNo_" + Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + "_" + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy") + "_" + Row["SuperZoneID"].ToString() + ".pdf");
                crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachFirst);

                crystalReport.Close();
                crystalReport.Dispose();
                crystalReport       = null;
                objMails.Attachment = strAttachSecond != "" ? strAttachFirst + "," + strAttachSecond : strAttachFirst;
                objMails.Name       = Row["SuperZoneName"].ToString();
                objMails.EmailId    = Row["Email"].ToString();
                string makesubject = "Missing Receipts from " + Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + " TO " + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy");
                objMails.Subject = makesubject;
                objMails.Desc    = makesubject;

                if (isSendData)
                {
                    objList.Add(objMails);
                }
                objMails = null;
            }
            return(JsonConvert.SerializeObject(objList));
        }
        catch (Exception ex)
        {
            throw;
        }
    }
Example #6
0
 private void btnImprimir_Click(object sender, EventArgs e)
 {
     try
     {
         ser = AdmSerie.MuestraSerie(venta.CodSerie, frmLogin.iCodAlmacen);
         CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
         rd.Load("CRNotaDebitoVenta.rpt");
         CRNotaDebitoVenta rpt = new CRNotaDebitoVenta();
         rd.SetDataSource(ds.ReportNotaDebitoVenta(Convert.ToInt32(venta.CodFacturaVenta), frmLogin.iCodAlmacen));
         CrystalDecisions.CrystalReports.Engine.PrintOptions rptoption = rd.PrintOptions;
         rptoption.PrinterName = ser.NombreImpresora;
         rptoption.PaperSize   = (CrystalDecisions.Shared.PaperSize)ext.GetIDPaperSize(ser.NombreImpresora, ser.PaperSize);
         rptoption.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(1100, 1850, 200, 1300));
         //CrystalDecisions.Shared.PageMargins margenes = rd.PrintOptions.PageMargins;
         rd.PrintToPrinter(1, false, 1, 1);
         rd.Close();
         rd.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Se encontro el siguiente problema" + ex.Message, "Nota Débito", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        static string _scanPath; //Repertoire de recherche

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            try
            {

                #region validation

                //Parametre sur la ligne de commande est obligatoire
                if (args.Length < 2)
                {
                    throw new ArgumentException(Resource1.ERR_ARG);
                }

                if (!Directory.Exists(args[0]))
                {
                    throw new System.IO.DirectoryNotFoundException(Resource1.ERR_NO_SOURCE_PATH);
                }

                if (!Directory.Exists(args[1]))
                {
                    throw new System.IO.DirectoryNotFoundException(Resource1.ERR_NO_DEST_PATH);
                }

                #endregion

                _scanPath = args[0];
                _ouputReportFile = args[1] + ((args[1].EndsWith("\\")) ? "" : "\\") + "report.csv";

                //Filtre pour les fichier rpt dans le répertoire et les sous-répertoires
                string[] filePaths = Directory.GetFiles(_scanPath, "*.rpt", SearchOption.AllDirectories);

                // Delete the file if it exists.
                if (File.Exists(_ouputReportFile))
                {
                    File.Delete(_ouputReportFile);
                }

                //Creation du fichier de rapport
                using (TextWriter tw = new StreamWriter(_ouputReportFile))
                {
                    tw.WriteLine("Create on : " + DateTime.Now);
                    tw.WriteLine("FileName;Version");

                    using (CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument())
                    {
                        //pour chaque fichier trouvé on lit la version du rapport et on l'inscrit dans le fichier
                        foreach (string file in filePaths)
                        {
                            //CrystalDecisions.Shared.ExportOptions t;
                            //t.ExportFormatType = (CrystalDecisions.Shared.ExportFormatType)34;

                            rpt.Load(file);

                            int majVer = rpt.ReportClientDocument.MajorVersion;
                            int minVer = rpt.ReportClientDocument.MinorVersion;
                            tw.WriteLine(file + ';' + majVer + '.' + minVer); //inscription au fichier
                            rpt.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                Console.WriteLine("ERREUR : " + ex.Message);
                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                Console.WriteLine("");
            }
        }
Example #8
0
    /// <summary>
    /// 利用 CrystalReport 列印 Excel 報表
    /// </summary>
    /// <param name="s_FileName">Excel報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="dt_Source">要列印的資料</param>
    /// /// <param name="reportFormatType">檔案型態</param>
    private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataSet dt_Source, string reportFormatType)
    {

        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source);
        #region 前置檢查與參數過濾
        string par_ProgramID = string.Empty;
        string par_LoginUser = string.Empty;

        string sTemp;
        par_ProgramID = this.PageCode;
        //        par_LoginUser = "******"; 
        //        par_LoginUser = Session["UID"].ToString();

        #endregion


        #region 組合查詢條件至Report ArrayList



        #endregion

        //判斷輸出檔案型態
        switch (reportFormatType)
        {
            case "EXCEL":

                System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                byte[] bytesXLS = new byte[streamXLS.Length];
                streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                streamXLS.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/vnd.ms-excel";
                Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;
            case "PDF":


                System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[] bytesPDF = new byte[streamPDF.Length];
                streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/pdf";

                Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                //Response.OutputStream.Write("AA", 0, 2);

                Response.Flush();
                Response.Close();
                report.Close();

                break;
            default:

                break;
        }

    }
Example #9
0
        protected void InicializaPagina()
        {
            int IdOrdenCompra;

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

            IdOrdenCompra = Convert.ToInt32(id);

            OrdenCompraDTO objOrdenCompraDTO = objOrdenCompraDAO.ListarPorClave(IdOrdenCompra);
            ProveedorDTO objProveedorDTO = objProveedorDAO.ListarPorClave(objOrdenCompraDTO.IdProveedor);
            List<OrdenCompraLineaDTO> objOrdenCompraLinea = objOrdenCompraLineaDAO.Listar(IdOrdenCompra);
            ParametroDTO objParametroDTO = objParametroDAO.ListarPorClave(1);
            FormaPagoDTO objFormaPagoDTO = objFormaPagoDAO.ListarPorClave(objOrdenCompraDTO.IdFormaPago);
            MonedaDTO objMonedaDTO = objMonedaDAO.ListarPorClave(objOrdenCompraDTO.CodMoneda);
            CotizacionDTO objCotizacionDTO = objCotizacionDAO.ListarPorClave(objOrdenCompraDTO.IdCotizacion);
            PedidoDTO objPedidoDTO = objPedidoDAO.ListarPorClave(objCotizacionDTO.IdPedido);
            UsuarioDTO objUsuarioDTO = objUsuarioDAO.ListarPorClave(objPedidoDTO.IdSolicitante);
            List<PedidoPresupuestoDTO> ListaPedidoPresupuestoDTO = objPedidoPresupuestoDAO.Listar(objPedidoDTO.IdPedido);

            dsReportes dsReporte = new dsReportes();

            dsReportes.ParametroRow drParametroRow = dsReporte.Parametro.NewParametroRow();
            drParametroRow.id_reporte = 1;
            drParametroRow.empresa = objParametroDTO.RazonSocial;

            if (objOrdenCompraDTO.IdTipoOrdenCompra == 1)
                drParametroRow.titulo1 = "ORDEN DE COMPRA N° " + objOrdenCompraDTO.IdOrdenCompra.ToString();
            else
                if (objOrdenCompraDTO.IdTipoOrdenCompra == 2)
                    drParametroRow.titulo1 = "ORDEN DE SERVICIO N° " + objOrdenCompraDTO.IdOrdenCompra.ToString();
                else
                    drParametroRow.titulo1 = "ORDEN N° " + objOrdenCompraDTO.IdOrdenCompra.ToString();

            dsReporte.Parametro.AddParametroRow(drParametroRow);

            //MONTO DE IGV
            IgvDTO objIGVDTO = objIGVDAO.ListarIGVVigente(objOrdenCompraDTO.FechaOrdenCompra);

            dsReportes.OrdenCompraRow drOrdenCompraRow = dsReporte.OrdenCompra.NewOrdenCompraRow();
            drOrdenCompraRow.IdReporte = 1;
            drOrdenCompraRow.IdOrdenCompra = objOrdenCompraDTO.IdOrdenCompra;

            if (objProveedorDTO != null)
            {
                drOrdenCompraRow.RazonSocial = objProveedorDTO.RazonSocial;
                drOrdenCompraRow.Ruc = objProveedorDTO.Ruc;
                drOrdenCompraRow.Direccion = objProveedorDTO.Direccion;
                drOrdenCompraRow.Contacto = objProveedorDTO.Contacto;
            }

            drOrdenCompraRow.Fecha = objOrdenCompraDTO.FechaOrdenCompra.ToString("dd/MM/yyyy");
            drOrdenCompraRow.Cotizacion = "Estimación N° " + objOrdenCompraDTO.IdCotizacion.ToString();

            if (objMonedaDTO!=null)
                drOrdenCompraRow.Moneda = objMonedaDTO.Simbolo;

            drOrdenCompraRow.Subtotal = objOrdenCompraDTO.ImporteOrdenCompra;

            if (objOrdenCompraDTO.FechaEntrega.Year!=1)
                drOrdenCompraRow.FechaEntrega = objOrdenCompraDTO.FechaEntrega.ToString("dd/MM/yyyy");

            if (objFormaPagoDTO!=null)
                drOrdenCompraRow.FormaPago = objFormaPagoDTO.NombreFormaPago;

            if (objParametroDTO != null)
            {
                drOrdenCompraRow.FacturarNombre = objParametroDTO.RazonSocial;
                drOrdenCompraRow.FacturarRuc = objParametroDTO.Ruc;
                drOrdenCompraRow.Direccion = objParametroDTO.Direccion;
            }

            drOrdenCompraRow.Proyecto = objOrdenCompraDTO.NombreProyecto;

            string codigos = "";
            if (ListaPedidoPresupuestoDTO.Count > 0)
            {
                foreach (PedidoPresupuestoDTO item in ListaPedidoPresupuestoDTO)
                {
                    codigos = codigos + " " + item.CodigoPresupuesto;
                }
            }

            drOrdenCompraRow.Descripcion = "Solicitado por " + objUsuarioDTO.NombreUsuario + " - Código: " + codigos;

            if (objOrdenCompraDTO.FlagIGV == "1")
            {
                drOrdenCompraRow.IGV = drOrdenCompraRow.Subtotal * (objIGVDTO.Igv / 100);
                drOrdenCompraRow.Total = drOrdenCompraRow.Subtotal + drOrdenCompraRow.IGV;
                drOrdenCompraRow.PorcentajeIGV = objIGVDTO.Igv.ToString() + "%";
            }
            else
            {
                drOrdenCompraRow.IGV = 0;
                drOrdenCompraRow.Total = drOrdenCompraRow.Subtotal + drOrdenCompraRow.IGV;
                drOrdenCompraRow.PorcentajeIGV = "0%";
            }

            /*
            if (objOrdenCompraDTO.IdTipoOrdenCompra == 2)
            {
                drOrdenCompraRow.IGV = 0;
                drOrdenCompraRow.Total = drOrdenCompraRow.Subtotal + drOrdenCompraRow.IGV;
                drOrdenCompraRow.PorcentajeIGV = "0%";
            }
            else
            {
                drOrdenCompraRow.IGV = drOrdenCompraRow.Subtotal * (objIGVDTO.Igv / 100);
                drOrdenCompraRow.Total = drOrdenCompraRow.Subtotal + drOrdenCompraRow.IGV;
                drOrdenCompraRow.PorcentajeIGV = objIGVDTO.Igv.ToString() + "%";
            }
            */
            drOrdenCompraRow.TotalLetras = "SON: " + AppUtilidad.numberToText(drOrdenCompraRow.Total.ToString()) + " " + objMonedaDTO.NombreMoneda;

            dsReporte.OrdenCompra.AddOrdenCompraRow(drOrdenCompraRow);

            foreach (OrdenCompraLineaDTO linea in objOrdenCompraLinea)
            {

                InvUnidadMedidaDTO objInvUnidadMedidaDTO = objInvUnidadMedidaDAO.ListarPorClave(linea.IdUnidadMedida);
                dsReportes.OrdenCompraLineasRow drOrdenCompraLineasRow = dsReporte.OrdenCompraLineas.NewOrdenCompraLineasRow();

                drOrdenCompraLineasRow.IdReporte = 1;
                drOrdenCompraLineasRow.IdOrdenCompra = objOrdenCompraDTO.IdOrdenCompra;
                drOrdenCompraLineasRow.Linea = linea.NumeroLinea;
                drOrdenCompraLineasRow.Cantidad = linea.Cantidad;

                if (objInvUnidadMedidaDTO != null)
                    drOrdenCompraLineasRow.UnidadMedida = objInvUnidadMedidaDTO.NombreCorto;

                drOrdenCompraLineasRow.DescripcionLinea = linea.DescripcionLinea;
                drOrdenCompraLineasRow.PrecioUnitario = linea.Precio;
                drOrdenCompraLineasRow.Importe = linea.Importe;
                dsReporte.OrdenCompraLineas.AddOrdenCompraLineasRow(drOrdenCompraLineasRow);
            }

            CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument;
            myReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRuta = Server.MapPath("rptOrdenCompra.rpt");
            myReportDocument.Load(strRuta);
            myReportDocument.SetDataSource(dsReporte);
            Session.Add("ReporteCrystal", myReportDocument);
            Session.Add("FormatoReporte", "PDF");

            MemoryStream stream = new MemoryStream();
            stream = (MemoryStream)myReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            Response.ContentType = "application/pdf";

            myReportDocument.Close();
            myReportDocument.Dispose();

            Response.Clear();
            Response.Buffer = true;

            Response.BinaryWrite(stream.ToArray());
            Response.End();

            stream.Flush();
            stream.Close();
            stream.Dispose();
        }
Example #10
0
        public byte[] RunReport(String reportName, String fileName, string travelRequestId)
        {
            byte[]         response         = null;
            ConnectionInfo crConnectionInFo = new ConnectionInfo();

            CrystalDecisions.CrystalReports.Engine.Tables crTables;
            TableLogOnInfo             crTableLogonInfo             = new TableLogOnInfo();
            DiskFileDestinationOptions crDiskFileDestinationOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            ExportOptions crExportOptions = new CrystalDecisions.Shared.ExportOptions();

            CrystalDecisions.CrystalReports.Engine.ReportDocument dReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            String rptPath = System.Web.Hosting.HostingEnvironment.MapPath(System.Configuration.ConfigurationManager.AppSettings["rptPath"]);
            String fName   = fileName;

            dReport.Load(rptPath + reportName);

            dReport.SetParameterValue("p_travelrequestID", travelRequestId);
            if (reportName == "Travel_Business_Expense.rpt")
            {
                dReport.SetParameterValue("p_travelrequestID", travelRequestId);
            }


            string defaultConnectionString = ConfigurationManager.ConnectionStrings["CrystalReport"].ConnectionString;
            var    builder = new DbConnectionStringBuilder();

            builder.ConnectionString = defaultConnectionString;

            crConnectionInFo.DatabaseName = "";
            crConnectionInFo.ServerName   = builder["SERVICE_NAME"].ToString();
            crConnectionInFo.UserID       = builder["User ID"].ToString();
            crConnectionInFo.Password     = builder["Password"].ToString();



            crTables = dReport.Database.Tables;
            crTableLogonInfo.ConnectionInfo = crConnectionInFo;

            foreach (CrystalDecisions.CrystalReports.Engine.Table rTable in crTables)
            {
                rTable.ApplyLogOnInfo(crTableLogonInfo);
            }
            foreach (CrystalDecisions.CrystalReports.Engine.ReportDocument subrpt in dReport.Subreports)
            {
                foreach (CrystalDecisions.CrystalReports.Engine.Table rTable in subrpt.Database.Tables)
                {
                    rTable.ApplyLogOnInfo(crTableLogonInfo);
                }
            }

            try
            {
                var memoryStream = new MemoryStream();
                var data         = dReport.ExportToStream(ExportFormatType.PortableDocFormat);
                data.CopyTo(memoryStream);
                response = memoryStream.ToArray();


                if (File.Exists(rptPath + "Exported/" + fileName + ".pdf"))
                {
                    File.Delete(rptPath + "Exported/" + fileName + ".pdf");
                }
                FileStream file = new FileStream(rptPath + "Exported/" + fileName + ".pdf", FileMode.Create, FileAccess.ReadWrite);
                memoryStream.WriteTo(file);
                file.Close();
                file.Dispose();
                memoryStream.Close();
                memoryStream.Dispose();

                //File.WriteAllBytes(rptPath+"Exported/"+fileName+".pdf", response);
            }
            catch (Exception ex)
            {
                LogMessage.Log("Error generating crystal report : " + ex.Message);
                throw new Exception(ex.Message);
            }
            finally
            {
                dReport.Close();
                dReport.Dispose();
            }
            return(response);
        }
Example #11
0
    /// <summary>
    /// 利用 CrystalReport 列印報表
    /// </summary>
    /// <param name="s_FileName">報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="dt_Source">要列印的資料</param>
    /// <param name="reportFormatType">檔案型態</param> 
    private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataTable dt_Source1, DataTable dt_Source2, string reportFormatType)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source2);
        string par_Vendor = string.Empty;
        string par_VendorName = string.Empty;
        string par_PurDate = string.Empty;
        string par_PurchaseNo = string.Empty;
        string par_FAX = string.Empty;
        string par_TEL = string.Empty;
        string par_BusinessContact = string.Empty;
        double par_Tax = 0;

        par_Vendor = dt_Source1.Rows[0]["VENDOR"].ToString();
        par_VendorName = dt_Source1.Rows[0]["VENDOR_NAME"].ToString();
        par_PurDate = dt_Source1.Rows[0]["PURCHSE_DATE"].ToString();
        par_PurchaseNo = dt_Source1.Rows[0]["PURCHASE_NO"].ToString();
        par_FAX = dt_Source1.Rows[0]["INV_FAX_AREA"].ToString() + "-" + dt_Source1.Rows[0]["INV_FAX"].ToString();
        par_TEL = dt_Source1.Rows[0]["INV_TEL_AREA"].ToString() + "-" + dt_Source1.Rows[0]["INV_TEL"].ToString();
        par_BusinessContact = dt_Source1.Rows[0]["BUSINESS_CONTACT"].ToString();
        if (dt_Source2.Rows.Count == 0)
            par_Tax = 0;
        else
            par_Tax = double.Parse(dt_Source2.Rows[0]["TAXRATE"].ToString());

        #region 組合查詢條件至ArrayList
        report.SetParameterValue("par_Vendor", par_Vendor);
        report.SetParameterValue("par_VendorName", par_VendorName);
        if (par_PurDate.Trim() != "")
        {
            report.SetParameterValue("par_PurDate", GetValueSetParameter(par_PurDate, "date"));
        }
        else
        {
            report.SetParameterValue("par_PurDate", "");
        }
        report.SetParameterValue("par_PurchaseNo", par_PurchaseNo);
        report.SetParameterValue("par_FAX", par_FAX);
        report.SetParameterValue("par_TEL", par_TEL);
        report.SetParameterValue("par_BusinessContact", par_BusinessContact);
        report.SetParameterValue("par_Tax", par_Tax);
        #endregion

        #region 判斷輸出檔案型態
        switch (reportFormatType)
        {
            case "PDF":
                System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[] bytesPDF = new byte[streamPDF.Length];
                streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/pdf";
                Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;
            default:

                break;
        }
        #endregion
    }
Example #12
0
        /// <summary>
        /// 產生輸出檔案
        /// </summary>
        /// <param name="s_FileName">產生檔案檔名</param>
        /// <param name="s_rptFilePath">RPT報表檔路徑及檔名</param>
        /// <param name="dt_Source">DB抓取的資料集(DataTable)</param>
        /// <param name="RP">報表變數,如無變數請輸入null</param>
        /// <param name="ROF">報表格式</param>        
        public void LoadCrystalReport(string s_FileName,
                                      string s_rptFilePath,
                                      ref DataTable dt_Source,
                                      ReportParameter[] RP,
                                      string ReportOutputFormat
                                      )
        {
            int bytesRead = 0;

            FileStream FS = new FileStream(s_FileName, FileMode.Create, FileAccess.Write);
            CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

            try
            {
                report.Load(s_rptFilePath);
                report.SetDataSource(dt_Source);

                //判斷輸出檔案型態
                switch (ReportOutputFormat)
                {
                    case "EXCEL":

                        //如果有報表參數
                        if (RP != null)
                        {
                            for (int i = 0; i < RP.Length; i++)
                            {
                                if ((RP[i].ParameterName != "") && (RP[i].ParameterValue != null))
                                {
                                    report.SetParameterValue(RP[i].ParameterName, RP[i].ParameterValue);
                                }
                            }
                        }

                        Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                        byte[] bytesXLS;

                        try
                        {
                            bytesXLS = new byte[streamXLS.Length];
                            bytesRead = streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                            //export file 
                            while (bytesRead > 0)
                            {
                                FS.Write(bytesXLS, 0, bytesRead);
                                bytesRead = streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            bytesXLS = null;

                            streamXLS.Flush();
                            streamXLS.Close();
                            streamXLS.Dispose();
                        }

                        break;


                    case "PDF":

                        //如果有報表參數
                        if (RP != null)
                        {
                            for (int i = 0; i < RP.Length; i++)
                            {
                                if ((RP[i].ParameterName != "") && (RP[i].ParameterValue != null))
                                {
                                    report.SetParameterValue(RP[i].ParameterName, RP[i].ParameterValue);
                                }
                            }
                        }

                        Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                        byte[] bytesPDF;

                        try
                        {
                            bytesPDF = new byte[streamPDF.Length];
                            bytesRead = streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                            //streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                            //export file
                            while (bytesRead > 0)
                            {
                                FS.Write(bytesPDF, 0, bytesRead);
                                bytesRead = streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            bytesPDF = null;

                            streamPDF.Flush();
                            streamPDF.Close();
                            streamPDF.Dispose();
                        }

                        break;
                    default:

                        break;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                FS.Flush();
                FS.Close();
                FS.Dispose();

                report.Close();
                report.Dispose();
                dt_Source.Dispose();
            }
        }
Example #13
0
    /// <summary>
    /// 利用 CrystalReport 列印 Excel 報表
    /// </summary>
    /// <param name="s_FileName">Excel報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="dt_Source">要列印的資料</param>
    /// /// <param name="reportFormatType">檔案型態</param>
    private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataTable dt_Source, string reportFormatType)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source);
        string par_ProgramID = string.Empty;
        string par_LoginUser = string.Empty;
        string par_Chan1 = string.Empty;
        string par_Chan2 = string.Empty;
        string par_Chan3 = string.Empty;

        #region 前置檢查與參數過濾

        string par_PlanAcceptData = this.txtPLAN_ACCEPT_DATE.Text;
        par_ProgramID = this.PageCode;
        string Login_Name = ((DataTable)Session["UserInfo"]).Rows[0]["Name"].ToString();

        par_LoginUser = Session["UID"].ToString() + " " + Login_Name;

        if (dt_Source.Rows[0]["No1_Name"] != System.DBNull.Value)
        {
            par_Chan1 = dt_Source.Rows[0]["No1_Name"].ToString();
        }


        if (dt_Source.Rows[0]["No2_Name"] != System.DBNull.Value)
        {
            par_Chan2 = dt_Source.Rows[0]["No2_Name"].ToString();
        }


        if (dt_Source.Rows[0]["No3_Name"] != System.DBNull.Value)
        {
            par_Chan3 = dt_Source.Rows[0]["No3_Name"].ToString();
        }        

        #endregion

        #region 組合查詢條件至ArrayList
        
        report.SetParameterValue("par_ProgramID", par_ProgramID);
        report.SetParameterValue("par_LoginUser", par_LoginUser);
        report.SetParameterValue("par_PlanAcceptDate", GetValueSetParameter(par_PlanAcceptData, "string"));
        report.SetParameterValue("par_Chan1", par_Chan1);
        report.SetParameterValue("par_Chan2", par_Chan2);
        report.SetParameterValue("par_Chan3", par_Chan3);
        #endregion

        #region 判斷輸出檔案型態
        switch (reportFormatType)
        {
            case "EXCEL":
                System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                byte[] bytesXLS = new byte[streamXLS.Length];
                streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                streamXLS.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名                
                Response.ContentType = "application/vnd.ms-excel";                
                Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;

            case "PDF":
                System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[] bytesPDF = new byte[streamPDF.Length];
                streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/pdf";
                Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;
            default:

                break;
        }
        #endregion

    }
Example #14
0
    private void ShowReport()
    {
        #region

        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        try
        {
            string strFileName = "";

            report.Load(Server.MapPath("./REPORT/ALO21/ALO21R01.rpt"));
            strFileName = HttpUtility.UrlEncode("轉門市進貨單明細表.pdf", System.Text.Encoding.UTF8);


            #region 2010/02/11 重新查詢
            ArrayList ParameterList = new ArrayList();
            ParameterList.Clear();
            ParameterList.Add(SLP_SLPDate1.Text);//門市進貨日
            ParameterList.Add(SLP_SLPDate2.Text);//轉門市進貨單日
            ParameterList.Add(GetDisTypeSelectedValue());//配本方式
            ParameterList.Add(SLP_SLPNumber1.Text);//理貨批次
            ParameterList.Add(Session["UID"].ToString());//執行者
            ParameterList.Add(DateTime.Now);//執行日期
            ParameterList.Add(string.Format("{0}_{1}", PageTimeStamp.Value, Session["UID"].ToString()));//PageTimeStamp_LoginID :Session_ID
            ParameterList.Add(-1);//最大筆數

            ALOModel.MaintainStAccept BCO = new ALOModel.MaintainStAccept(ConnectionDB);

            string strErrMsg = "";
            DataTable Dt = null;

            if (rbtn_TransStatus1.Checked)//已轉單
            {
                #region
                Dt = BCO.QueryStOutAcceptData(ParameterList, out strErrMsg);
                #endregion
            }
            else//未轉單
            {
                #region
                Dt = BCO.QueryForFind(ParameterList, out strErrMsg);
                #endregion
            }

            #endregion

            report.SetDataSource(Dt);

            string Login_Name = ((DataTable)Session["UserInfo"]).Rows[0]["Name"].ToString();

            report.SetParameterValue("par_Program_ID", "ALO21R01");
            report.SetParameterValue("par_LoginUser", Session["UID"].ToString() + Login_Name);
            report.SetParameterValue("par_StAcceptDate", SLP_SLPDate1.Text);
            report.SetParameterValue("par_OutStAcceptDate", SLP_SLPDate2.Text);
            report.SetParameterValue("par_DisType", GetDisTypeSelectedText());

            System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            byte[] bytesPDF = new byte[streamPDF.Length];
            streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
            streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

            //export file  
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);//pdf檔名  
            Response.ContentType = "application/pdf";
            Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
            Response.Flush();
            Response.Close();
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
        finally
        {
            report.Close();
        }
        #endregion
    }
Example #15
0
    /// <summary>
    /// 利用 CrystalReport 列印報表
    /// </summary>
    /// <param name="s_FileName">報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="dt_Source">要列印的資料</param>
    /// <param name="reportFormatType">檔案型態</param> 
    private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataTable dt_Source1, DataTable dt_Source2, string reportFormatType)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source2);
        string par_Vendor = string.Empty;
        string par_VendorName = string.Empty;
        string par_PurDate = string.Empty;
        string par_PurchaseNo = string.Empty;
        string par_PlanAcceptDate = string.Empty;

        par_Vendor = dt_Source1.Rows[0]["VENDOR"].ToString();
        par_VendorName = dt_Source1.Rows[0]["VENDOR_NAME"].ToString();
        par_PurDate = dt_Source1.Rows[0]["PURCHSE_DATE"].ToString();
        par_PurchaseNo = dt_Source1.Rows[0]["PURCHASE_NO"].ToString();

        if (dt_Source2.Rows.Count != 0)
        {
            par_PlanAcceptDate = dt_Source2.Rows[0]["PLAN_ACCEPT_DATE"].ToString();
        }
        #region 組合查詢條件至ArrayList
        report.SetParameterValue("par_Vendor", par_Vendor);
        report.SetParameterValue("par_VendorName", par_VendorName);
        if (par_PurDate.Trim() != "")
        {
            report.SetParameterValue("par_PurDate", GetValueSetParameter(par_PurDate, "date"));
        }
        else
        {
            report.SetParameterValue("par_PurDate", "");
        }
        report.SetParameterValue("par_PurchaseNo", par_PurchaseNo);
        if (par_PlanAcceptDate.Trim() != "")
        {
            report.SetParameterValue("par_PlanAcceptDate", GetValueSetParameter(par_PlanAcceptDate, "date"));
        }
        else
        {
            report.SetParameterValue("par_PlanAcceptDate", "");
        }
        #endregion
        #region 判斷輸出檔案型態
        try
        {
            switch (reportFormatType)
            {
                case "EXCEL":

                    System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                    byte[] bytesXLS = new byte[streamXLS.Length];
                    streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                    streamXLS.Seek(0, System.IO.SeekOrigin.Begin);

                    //export file  
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName); // excel 檔名  

                    Response.ContentType = "application/vnd.ms-excel";

                    Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
                    Response.Flush();
                    Response.Close();

                    break;
                case "PDF":
                    System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    byte[] bytesPDF = new byte[streamPDF.Length];
                    streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                    streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                    //export file  
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);
                    Response.ContentType = "application/pdf";
                    Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                    Response.Flush();
                    Response.Close();
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        { 
            this.ErrorMsgLabel.Text = ex.Message; 
        }
        finally 
        {
            report.Close();
        }
        #endregion
    }
Example #16
0
    private string generatefiles(DataSet ds, string FirstPath, DataTable mailsetting)
    {
        try
        {
            DataView dvmaster        = new DataView(ds.Tables[0]);
            DataView dv              = new DataView(ds.Tables[1]);
            string   strAttachFirst  = string.Empty;
            string   strAttachSecond = string.Empty;


            bool isSendData = false;
            System.Collections.ArrayList objList = new ArrayList();
            CrystalDecisions.CrystalReports.Engine.ReportDocument crystalReport;
            objList.Add(MailSetting(mailsetting));
            XmlDocument doc   = new XmlDocument();
            XmlNode     inode = doc.CreateElement("f");
            XmlNode     fnode = doc.CreateElement("r");

            foreach (DataRow Row in ds.Tables[0].Rows)
            {
                MailDetails objMails = new MailDetails();
                dv.RowFilter       = "SubDocId = " + Row["subdocno"].ToString();
                dvmaster.RowFilter = "subdocno = " + Row["subdocno"].ToString();
                crystalReport      = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                crystalReport.Load(Server.MapPath("../Report/PrintInvoiceMM.rpt"));
                crystalReport.SetDataSource(dv);
                isSendData     = dv.ToTable().Rows.Count > 0 ? true : false;
                strAttachFirst = Server.MapPath(FirstPath + dvmaster[0]["CustCode"] + "-" + dvmaster[0]["subdocno"] + ".pdf");
                crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachFirst);
                crystalReport.Close();
                crystalReport.Dispose();
                crystalReport       = null;
                objMails.Attachment = strAttachSecond != "" ? strAttachFirst + "," + strAttachSecond : strAttachFirst;
                objMails.Name       = dvmaster[0]["CustName"].ToString();
                objMails.EmailId    = Row["EmailID"].ToString();
                string makesubject = dvmaster[0]["subject"].ToString();
                objMails.Subject = makesubject;
                objMails.Desc    = Row["msg"].ToString();

                XmlNode element = doc.CreateElement("i");

                inode           = doc.CreateElement("subdoc");
                inode.InnerText = Row["subdocno"].ToString();
                element.AppendChild(inode);

                inode           = doc.CreateElement("fyu");
                inode.InnerText = Row["FY"].ToString();
                element.AppendChild(inode);

                inode           = doc.CreateElement("mod");
                inode.InnerText = Row["module"].ToString();
                element.AppendChild(inode);

                fnode.AppendChild(element);

                if (isSendData)
                {
                    objList.Add(objMails);
                }
                objMails = null;
            }
            Other_Z.OtherBAL ObjBal = new Other_Z.OtherBAL();
            ObjBal.UpdateEmailLog(fnode.OuterXml, "", "", "");
            return(JsonConvert.SerializeObject(objList));
        }
        catch (Exception ex)
        {
            throw;
        }
    }
Example #17
0
    //列印報表
    private void ShowReport(DataSet ds)
    {
        #region 利用CrystalReport列印報表

        //使用者名稱
        DataTable dt1 = new DataTable();
        dt1 = (DataTable)Session["UserInfo"];
        string Login_Name = dt1.Rows[0]["Name"].ToString();

        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        report.Load(Server.MapPath("./REPORT/ITM061R.rpt"));
        report.SetDataSource(ds);
        report.Subreports["ITM061R2"].SetDataSource(ds);
        report.Subreports["ITM061R3"].SetDataSource(ds);

        report.SetParameterValue("ProgramName", "ITM061R");
        report.SetParameterValue("UserName", Session["UID"].ToString() + Login_Name);

        if (this.txtCREATEDATE.StartDate.ToString() == "" && this.txtCREATEDATE.EndDate.ToString() == "")
            report.SetParameterValue("QueryDateRange", "全部");
        else
            report.SetParameterValue("QueryDateRange", this.txtCREATEDATE.StartDate.ToString() + "~" + this.txtCREATEDATE.EndDate.ToString());

        if (this.SLP_TimeRange1.StartTime.ToString() == "" && this.SLP_TimeRange1.EndTime.ToString() == "")
            report.SetParameterValue("QueryTime", "全部");
        else
            report.SetParameterValue("QueryTime", this.SLP_TimeRange1.StartTime.ToString() + "~" + this.SLP_TimeRange1.EndTime.ToString());

        report.SetParameterValue("Par_Count", Convert.ToString(ds.Tables["DataTable1"].Rows.Count) + "筆");

        //檔案匯出
        System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        byte[] bytesPDF = new byte[streamPDF.Length];
        streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
        streamPDF.Seek(0, System.IO.SeekOrigin.Begin);
        //Export File  
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("商品期別異動表.PDF", System.Text.Encoding.UTF8));//匯出檔名  
        Response.ContentType = "application/pdf";
        Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
        Response.Flush();
        Response.Close();
        report.Close();
        #endregion
    }
Example #18
0
    /// <summary>
    /// 利用 CrystalReport 列印 Excel 報表
    /// </summary>
    /// <param name="s_FileName">Excel報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="dt_Source">要列印的資料</param>
    /// /// <param name="reportFormatType">檔案型態</param>
    private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataSet dt_Source, string reportFormatType)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source);

        #region 前置檢查與參數過濾

        string par_ProgramID = string.Empty;
        string par_LoginUser = string.Empty;

        string sTemp;
        par_ProgramID = this.PageCode;
        par_LoginUser = Session["UID"].ToString();

        #endregion

        #region 組合查詢條件至Report ArrayList

        report.SetParameterValue("ProgramName", par_ProgramID);
        report.SetParameterValue("UserName", par_LoginUser); //"/"

        report.SetParameterValue("AcceptDate", this.SLP_Accept_Range.RangeStartTextBox.Text + " - " + this.SLP_Accept_Range.RangeEndTextBox.Text);

        if (this.SLP_VENDER_BEGIN.Text == string.Empty && this.SLP_VENDER_END.Text == string.Empty)
            sTemp = string.Empty;
        else if (this.SLP_VENDER_BEGIN.Text == string.Empty)
            sTemp = "          " + " - " + this.SLP_VENDER_END.Text + "" + this.SLP_VENDER_END.Name;
        else if (this.SLP_VENDER_END.Text == string.Empty)
            sTemp = this.SLP_VENDER_BEGIN.Text + "" + this.SLP_VENDER_BEGIN.Name + " - ";
        else
            sTemp = this.SLP_VENDER_BEGIN.Text + "" + this.SLP_VENDER_BEGIN.Name + " - "
                  + this.SLP_VENDER_END.Text + "" + this.SLP_VENDER_END.Name;

        report.SetParameterValue("Vendor", sTemp);

        if (this.SLP_RootNoStart.Text == string.Empty && this.SLP_RootNoEnd.Text == string.Empty)
            sTemp = string.Empty;
        else if (this.SLP_RootNoStart.Text == string.Empty)
            sTemp = "          " + " - " + this.SLP_RootNoEnd.Text + "" + this.SLP_RootNoEnd.Name;
        else if (this.SLP_RootNoEnd.Text == string.Empty)
            sTemp = this.SLP_RootNoStart.Text + "" + this.SLP_RootNoStart.Name + " - ";
        else
            sTemp = this.SLP_RootNoStart.Text + "" + this.SLP_RootNoStart.Name + " - "
                  + this.SLP_RootNoEnd.Text + "" + this.SLP_RootNoEnd.Name;

        report.SetParameterValue("RootNo", sTemp);

        if (this.SLP_PMA_BEGIN.Text == string.Empty && this.SLP_PMA_END.Text == string.Empty)
            sTemp = string.Empty;
        else if (this.SLP_PMA_BEGIN.Text == string.Empty)
            sTemp = "          " + " - " + this.SLP_PMA_END.Text + "" + this.SLP_PMA_END.Name;
        else if (this.SLP_PMA_END.Text == string.Empty)
            sTemp = this.SLP_PMA_BEGIN.Text + "" + this.SLP_PMA_BEGIN.Name + " - ";
        else
            sTemp = this.SLP_PMA_BEGIN.Text + "" + this.SLP_PMA_BEGIN.Name + " - "
                  + this.SLP_PMA_END.Text + "" + this.SLP_PMA_END.Name;

        report.SetParameterValue("PMA", sTemp);

        if (this.SLP_CATEGORY_BEGIN.Text == string.Empty && this.SLP_CATEGORY_END.Text == string.Empty)
            sTemp = string.Empty;
        else if (this.SLP_CATEGORY_BEGIN.Text == string.Empty)
            sTemp = "          " + " - " + this.SLP_CATEGORY_END.Text + "" + this.SLP_CATEGORY_END.Name;
        else if (this.SLP_CATEGORY_END.Text == string.Empty)
            sTemp = this.SLP_CATEGORY_BEGIN.Text + "" + this.SLP_CATEGORY_BEGIN.Name + " - ";
        else
            sTemp = this.SLP_CATEGORY_BEGIN.Text + "" + this.SLP_CATEGORY_BEGIN.Name + " - "
                  + this.SLP_CATEGORY_END.Text + "" + this.SLP_CATEGORY_END.Name;

        report.SetParameterValue("CATEGORY", sTemp);

        report.SetParameterValue("Item", this.SLP_SKU.Text);
        report.SetParameterValue("Period", this.SLP_PERIOD.Text);
        if (this.rdabNormal.Checked == true)
            report.SetParameterValue("Type", this.rdabNormal.Text);
        else if (this.rdNormal.Checked == true)
            report.SetParameterValue("Type", this.rdNormal.Text);

        #endregion

        //判斷輸出檔案型態
        switch (reportFormatType)
        {
            case "EXCEL":

                System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                byte[] bytesXLS = new byte[streamXLS.Length];
                streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                streamXLS.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/vnd.ms-excel";
                Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;
            case "PDF":


                System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[] bytesPDF = new byte[streamPDF.Length];
                streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                streamPDF.Seek(0, System.IO.SeekOrigin.Begin);
                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/pdf";

                Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                //Response.OutputStream.Write("AA", 0, 2);

                Response.Flush();
                Response.Close();
                report.Close();

                break;
            default:

                break;
        }

    }
Example #19
0
    //匯出Excel
    private void ShowReportB(DataTable dt)
    {
        #region 利用CrystalReport匯出Excel

        //使用者名稱
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        report.Load(Server.MapPath("./REPORT/ITM061/ITM062R01.rpt"));
        report.SetDataSource(dt);        

        //檔案匯出
        System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
        byte[] bytesXLS = new byte[streamXLS.Length];
        streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
        streamXLS.Seek(0, System.IO.SeekOrigin.Begin);
        //Export File  
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("商品期別異動表_" + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + ".XLS", System.Text.Encoding.UTF8));//匯出檔名  
        Response.ContentType = "application/xls";
        Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
        Response.Flush();
        Response.Close();
        report.Close();
        #endregion
    }
Example #20
0
    /// <summary>
    /// 利用 CrystalReport 列印 Excel 報表
    /// </summary>
    /// <param name="s_FileName">Excel報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="dt_Source">要列印的資料</param>
    /// /// <param name="reportFormatType">檔案型態</param>
    private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataTable dt_Source, string reportFormatType)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source);


        string par_ProgramID = string.Empty;
        string par_LoginUser = string.Empty;

        #region 前置檢查與參數過濾

        string par_AcceptDate = this.txtST_ACCEPT_DATE.Text;
        string par_ChanName = this.ddlChanNo.SelectedItem.Text.Replace("(", " ") ;
        par_ChanName = par_ChanName.Replace(")", "");

        string par_StoreName = string.Empty;
        if (this.ddlStore.SelectedIndex > 0 )
            par_StoreName = this.ddlStore.SelectedItem.Text;

        par_StoreName = par_StoreName.Replace("(", " ");
        par_StoreName = par_StoreName.Replace(")", " "); 

        par_ProgramID = this.PageCode;
//        par_LoginUser = "******"; 
        par_LoginUser = Session["UID"].ToString();

        #endregion


        #region 組合查詢條件至ArrayList

        ArrayList returnList = new ArrayList();

        returnList.Clear();
        
        report.SetParameterValue("AcceptDate", par_AcceptDate);
        report.SetParameterValue("ProgramName", par_ProgramID);
        report.SetParameterValue("UserName", par_LoginUser);
        report.SetParameterValue("ChanName", par_ChanName);
        report.SetParameterValue("StoreName", par_StoreName);
        

        #endregion

        //判斷輸出檔案型態
        switch (reportFormatType)
        {
            case "EXCEL":

                System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                byte[] bytesXLS = new byte[streamXLS.Length];
                streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                streamXLS.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  


                Response.ContentType = "application/vnd.ms-excel";


                Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;
            case "PDF":


                System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[] bytesPDF = new byte[streamPDF.Length];
                streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                //export file  
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                Response.ContentType = "application/pdf";

                Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                Response.Flush();
                Response.Close();
                report.Close();
                break;
            default:

                break;
        }

    }
Example #21
0
        void GenerarArchivo(Int32 Id_evento, Boolean GenerarArchivo)
        {
            try
            {
                pSeleccionarParametros_Result p = new pSeleccionarParametros_Result();
                Programa e = new Programa();
                pSeleccionarReportes_Result            r = new pSeleccionarReportes_Result();
                List <pSeleccionarValores_prog_Result> v = new List <pSeleccionarValores_prog_Result>();
                string returnValue = null;

                using (Profit_RGEntities context = new Profit_RGEntities())
                {
                    p = context.pSeleccionarParametros().FirstOrDefault();
                    e = context.Programas.Where(ev => ev.id_evento == Id_evento).FirstOrDefault();
                    r = context.pSeleccionarReportes(e.cod_rep.Trim()).FirstOrDefault();
                    v = context.pSeleccionarValores_prog(e.id_evento).ToList();
                }

                ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ProfitContenedor.Properties.Settings.Profit_RGConnectionString"];

                if (settings != null)
                {
                    returnValue = settings.ConnectionString;
                }

                SqlConnection sqlConn = new SqlConnection(returnValue);

                SqlCommand comd;
                comd             = new SqlCommand();
                comd.Connection  = sqlConn;
                comd.CommandType = CommandType.StoredProcedure;
                comd.CommandText = r.funcion.Trim();

                foreach (var item in v)
                {
                    switch (item.tipo.Trim())
                    {
                    case "Char":
                        comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Char);
                        comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_char;
                        break;

                    case "Int":
                        comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Int);
                        comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_int;
                        break;

                    case "Decimal":
                        comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Decimal);
                        comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_dec;
                        break;

                    case "DateTime":
                        comd.Parameters.Add(item.parametro.Trim(), SqlDbType.DateTime);
                        comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_date;
                        break;

                    case "Time":
                        comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Time);
                        comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_time;
                        break;

                    case "Bit":
                        comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Bit);
                        comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_bit;
                        break;
                    }
                }

                SqlDataAdapter sqlAdapter = new SqlDataAdapter();
                sqlAdapter.SelectCommand = comd;
                DataSet ds = new DataSet();
                sqlAdapter.Fill(ds, r.funcion.Trim());

                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("Sin datos para mostrar.", "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    string Filename = r.ruta + @"\" + r.Archivo;
                    CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    oRpt.Load(@Filename);
                    oRpt.SetDataSource(ds);

                    if (GenerarArchivo == false)
                    {
                        FrmRep Fr = new FrmRep(ds, r.Archivo, false);
                        Fr.ShowDialog();
                    }
                    else
                    {
                        Archivo = "";

                        //string Fecha = ((DateTime.Now.Day < 10) ? "0" : "") + DateTime.Now.Day.ToString() +
                        //      ((DateTime.Now.Month < 10) ? "0" : "") + DateTime.Now.Month.ToString() +
                        //      (DateTime.Now.Year.ToString());

                        //string Hora = ((DateTime.Now.Hour < 10) ? "0" : "") + DateTime.Now.Hour.ToString() +
                        //              ((DateTime.Now.Minute < 10) ? "0" : "") + DateTime.Now.Minute.ToString() +
                        //              ((DateTime.Now.Second < 10) ? "0" : "") + DateTime.Now.Second.ToString();

                        switch (e.Tipo.Trim())
                        {
                        case "PDF":
                            //Archivo = @p.ruta_pdf + @"\" + e.descrip.Trim() + " F[" + Fecha + "] H[" + Hora + "].pdf";
                            Archivo = @p.ruta_pdf + @"\" + e.descrip.Trim() + ".pdf";
                            oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Archivo.TrimEnd());
                            break;

                        case "XLS":
                            Archivo = @p.ruta_pdf + @"\" + e.descrip.Trim() + ".xls";
                            oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.ExcelRecord, Archivo.TrimEnd());
                            break;
                        }
                    }
                    oRpt.Close();
                    oRpt.Dispose();
                }
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (SqlException ex0)
            {
                MessageBox.Show(ex0.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #22
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="PickNo">揀貨單號</param>
    /// <param name="s_FileName">Excel報表的檔名</param>
    /// <param name="s_rptFilePath">rpt檔的路徑</param>
    /// <param name="reportFormatType">檔案型態</param>
    /// <param name="ReportOrderOption">排序類型 "item":品項 "locate":儲位 </param>
    private void LoadCrystalReport(string PickNo, string s_FileName, string s_rptFilePath, string reportFormatType, string ReportOrderOption)
    {

        try
        {
            IVMModel.MaintainPickData BCO = new IVMModel.MaintainPickData(ConntionDB);
            CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

            report.Load(Server.MapPath(s_rptFilePath));

            ParameterList.Clear();
            ParameterList.Add(PickNo);

            if (s_rptFilePath != "./REPORT/IVM15/CRIVM15R03.rpt")
            {

                DataTable dtResult = new DataTable();

                string ProgName = "";

                if (s_rptFilePath == "./REPORT/IVM15/CRIVM15R01.rpt")
                {
                    dtResult = BCO.GetPrintRpt01(ParameterList);
                    ProgName = "IVM15R01";
                }
                else
                {
                    dtResult = BCO.GetPrintRpt02(ParameterList);
                    ProgName = "IVM15R02";
                }

                DataView dv = new DataView(dtResult);

                switch (ReportOrderOption)
                {
                    case "item":
                        dv.Sort = "item";
                        break;

                    case "locate":
                        dv.Sort = "BLocate_No";
                        break;

                    default:
                        dv.Sort = "item";
                        break;
                }

                report.SetDataSource(dv.ToTable());

                report.SetParameterValue("paraProg", ProgName);
                report.SetParameterValue("paraUserID", Session["UID"].ToString());
                report.SetParameterValue("paraPickNo", PickNo);
                report.SetParameterValue("paraSource", this.MenuIVM15.SelectedItem.Text);
                report.SetParameterValue("paraAccDate", "");
                report.SetParameterValue("paraReturnNo", "");
                report.SetParameterValue("paraRemoveNo", "");
                report.SetParameterValue("paraBLocate", "");
                report.SetParameterValue("paraELocate", "");
                report.SetParameterValue("paraVendor", "");

            }
            else
            {
                DataTable dtResult = new DataTable();

                dtResult = BCO.GetPrintRpt03(ParameterList);

                report.SetDataSource(dtResult);

                report.SetParameterValue("paraProg", "IVM15R03");
                report.SetParameterValue("paraUserID", Session["UID"].ToString());
                //report.SetParameterValue("paraKind", "");
            }

            switch (reportFormatType)
            {
                case "EXCEL":

                    System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                    byte[] bytesXLS = new byte[streamXLS.Length];
                    streamXLS.Read(bytesXLS, 0, bytesXLS.Length);
                    streamXLS.Seek(0, System.IO.SeekOrigin.Begin);

                    //export file  
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  


                    Response.ContentType = "application/vnd.ms-excel";


                    Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length);
                    Response.Flush();
                    Response.Close();

                    break;
                case "PDF":


                    System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    byte[] bytesPDF = new byte[streamPDF.Length];
                    streamPDF.Read(bytesPDF, 0, bytesPDF.Length);
                    streamPDF.Seek(0, System.IO.SeekOrigin.Begin);

                    //export file  
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名  
                    Response.ContentType = "application/pdf";
                    Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length);
                    Response.Flush();
                    Response.Close();
                    break;
                default:

                    break;
            }

            report.Close();

        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }

    }
Example #23
0
        protected void InicializaPagina()
        {
            int linea = 0;

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

            Decimal dStockArticulo = 0;
            List<InvTransaccionDTO> objTransaccionLista = objTransaccionDAO.ListarPorArticuloProyecto(Convert.ToInt32(id), Convert.ToInt32(id2));
            ParametroDTO objParametroDTO = objParametroDAO.ListarPorClave(1);
            ArticuloDTO objArticuloDTO = objArticuloDAO.ListarPorClave(Convert.ToInt32(id));
            InvUnidadMedidaDTO objInvUnidadMedidaDTO = objUnidadMedidaDAO.ListarPorClave(objArticuloDTO.IdUnidadMedida);
            ProyectoDTO objProyectoDTO = objProyectoDAO.ListarPorClave(Convert.ToInt32(id2));

            dsReportes dsReporte = new dsReportes();
            dsReportes.ParametroRow drParametroRow = dsReporte.Parametro.NewParametroRow();
            drParametroRow.id_reporte = 1;
            drParametroRow.empresa = objParametroDTO.RazonSocial;
            drParametroRow.fecha = DateTime.Now.ToString("dd/MM/yyyy");
            dsReporte.Parametro.AddParametroRow(drParametroRow);

            foreach (InvTransaccionDTO fila in objTransaccionLista)
            {
                InvTipoTransaccionDTO objInvTipoTransaccionDTO = objTipoTransaccionDAO.ListarPorClave(fila.IdTipoTransaccion);
                dsReportes.KardexRow drKardexRow = dsReporte.Kardex.NewKardexRow();
                linea = linea + 1;
                drKardexRow.id_reporte = 1;
                drKardexRow.linea = linea;
                drKardexRow.fecha = fila.Fecha.ToString("dd/MM/yyyy");
                drKardexRow.nombre_articulo = objArticuloDTO.Descripcion;
                drKardexRow.codigo_articulo = objArticuloDTO.CodigoArticulo;
                drKardexRow.unidad_medida = objInvUnidadMedidaDTO.NombreUnidadMedida;
                drKardexRow.area = objProyectoDTO.NombreProyecto;
                drKardexRow.observaciones = fila.Descripcion;// objInvTipoTransaccionDTO.NombreTransaccion;

                if (objInvTipoTransaccionDTO.Clase.Equals("I"))
                {
                    dStockArticulo += fila.Cantidad;
                    drKardexRow.entrada = fila.Cantidad;
                    drKardexRow.saldo = dStockArticulo;
                }
                else
                {
                    dStockArticulo -= fila.Cantidad;
                    drKardexRow.salida = fila.Cantidad;
                    drKardexRow.saldo = dStockArticulo;
                }

                dsReporte.Kardex.AddKardexRow(drKardexRow);

            }

            CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument;
            myReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRuta = Server.MapPath("KardexArticulo.rpt");
            myReportDocument.Load(strRuta);
            myReportDocument.SetDataSource(dsReporte);
            Session.Add("ReporteCrystal", myReportDocument);
            Session.Add("FormatoReporte", "PDF");

            MemoryStream stream = new MemoryStream();
            stream = (MemoryStream)myReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            Response.ContentType = "application/pdf";

            myReportDocument.Close();
            myReportDocument.Dispose();

            Response.Clear();
            Response.Buffer = true;

            Response.BinaryWrite(stream.ToArray());
            Response.End();

            stream.Flush();
            stream.Close();
            stream.Dispose();
        }
Example #24
0
        void GenerarArchivo(Boolean GenerarArchivo)
        {
            try
            {
                string Co_lin   = cboLinea.SelectedIndex == -1 ? null : cboLinea.SelectedValue.ToString().Trim();
                string Co_subl  = cboSub_lin.SelectedIndex == -1 ? null : cboSub_lin.SelectedValue.ToString().Trim();
                string Co_col   = cboColores.SelectedIndex == -1 ? null : cboColores.SelectedValue.ToString().Trim();
                string Co_cat   = cboCat_art.SelectedIndex == -1 ? null : cboCat_art.SelectedValue.ToString().Trim();
                string Cod_proc = cboProce.SelectedIndex == -1 ? null : cboProce.SelectedValue.ToString().Trim();
                string Grupo;
                string Archivo;

                pSeleccionarParametros_Result p = new pSeleccionarParametros_Result();
                //Programa e = new Programa();
                pSeleccionarReportes_Result r = new pSeleccionarReportes_Result();
                //List<pSeleccionarValores_prog_Result> v = new List<pSeleccionarValores_prog_Result>();
                //string returnValue = null;

                using (Profit_RGEntities context = new Profit_RGEntities())
                {
                    p     = context.pSeleccionarParametros().FirstOrDefault();
                    r     = context.pSeleccionarReportes("006").FirstOrDefault();
                    Grupo = context.pObtenerGrupo(txtCo_empresa.Text.Trim()).AsParallel().FirstOrDefault().grupo.Trim();
                }

                DataSet ds = new DataSet();
                ds.Tables.Add("pAnalisisCompras");
                ds.Tables[0].Columns.Add("A", typeof(string));
                ds.Tables[0].Columns.Add("co_art", typeof(string));
                ds.Tables[0].Columns.Add("art_des", typeof(string));
                ds.Tables[0].Columns.Add("referencia", typeof(string));
                ds.Tables[0].Columns.Add("comentario", typeof(string));
                ds.Tables[0].Columns.Add("lc_descrip2", typeof(string));
                ds.Tables[0].Columns.Add("ene", typeof(decimal));
                ds.Tables[0].Columns.Add("feb", typeof(decimal));
                ds.Tables[0].Columns.Add("mar", typeof(decimal));
                ds.Tables[0].Columns.Add("abr", typeof(decimal));
                ds.Tables[0].Columns.Add("may", typeof(decimal));
                ds.Tables[0].Columns.Add("jun", typeof(decimal));
                ds.Tables[0].Columns.Add("jul", typeof(decimal));
                ds.Tables[0].Columns.Add("ago", typeof(decimal));
                ds.Tables[0].Columns.Add("sep", typeof(decimal));
                ds.Tables[0].Columns.Add("oct", typeof(decimal));
                ds.Tables[0].Columns.Add("nov", typeof(decimal));
                ds.Tables[0].Columns.Add("dic", typeof(decimal));
                ds.Tables[0].Columns.Add("uni_ventas", typeof(decimal));
                ds.Tables[0].Columns.Add("sugerido", typeof(decimal));
                ds.Tables[0].Columns.Add("orden", typeof(Int32));
                ds.Tables[0].Columns.Add("costo", typeof(decimal));
                ds.Tables[0].Columns.Add("comprar", typeof(decimal));
                ds.Tables[0].Columns.Add("total", typeof(decimal));

                ds.Tables[0].Clear();

                List <Acom> ListaAc = Ac.Where(a => a.comprar > 0).ToList();

                if (ListaAc.Count == 0)
                {
                    MessageBox.Show("Sin datos para mostrar.", "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    for (int i = 0; i < ListaAc.Count; i++)
                    {
                        DataRow row = ds.Tables[0].NewRow();
                        row["co_art"]      = ListaAc[i].co_art;
                        row["art_des"]     = ListaAc[i].art_des;
                        row["referencia"]  = ListaAc[i].referencia;
                        row["comentario"]  = ListaAc[i].comentario;
                        row["LC_DESCRIP2"] = ListaAc[i].lc_descrip2;
                        row["Costo"]       = ListaAc[i].costo;
                        row["Comprar"]     = ListaAc[i].comprar;
                        row["Total"]       = ListaAc[i].costo * ListaAc[i].comprar;

                        ds.Tables[0].Rows.Add(row);
                        ds.Tables[0].AcceptChanges();
                    }

                    string Filename = r.ruta + @"\" + r.Archivo;
                    CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    oRpt.Load(@Filename);
                    oRpt.SetDataSource(ds);

                    if (GenerarArchivo == false)
                    {
                        FrmRep Fr = new FrmRep(ds, r.Archivo, false);
                        Fr.ShowDialog();
                    }
                    else
                    {
                        Archivo = "";
                        Archivo = @p.ruta_pdf + @"\" + r.Archivo.Replace(".rpt", "").Trim() + " " + System.DateTime.Now.ToFileTime() + ".pdf";
                        oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Archivo.TrimEnd());
                    }
                    oRpt.Close();
                    oRpt.Dispose();
                }
            }
            catch (EntitySqlException ex)
            {
                MessageBox.Show(ex.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (SqlException ex0)
            {
                MessageBox.Show(ex0.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #25
0
        public void Convert()
        {
            //System.Web.HttpContext.Current.Response.Write("hello");
            string vstExcep;
            this._stNmRpt = this._stNmRpt.Replace(".rpt", "");
            this._stNmRpt = this._stNmRpt.Replace(".RPT", "");
            try
            {
                    //System.Web.HttpContext.Current.Response.Write(_stNmRpt);
                System.IO.MemoryStream vioMemor = new System.IO.MemoryStream();
                CrystalDecisions.CrystalReports.Engine.ReportDocument vrpRepor = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                string vstRepor = System.Web.HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString() + "report\\"+this._stNmRpt + ".rpt";
                                //System.Web.HttpContext.Current.Response.Write(vstRepor);
                vrpRepor.Load(vstRepor);
                if (_dsDatas == null) { return; }
                vrpRepor.Database.Tables[0].SetDataSource(this._dsDatas.Tables[0]);
                vrpRepor.Refresh();
                //vioMemor = (System.IO.MemoryStream)vrpRepor.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                vioMemor = (System.IO.MemoryStream)vrpRepor.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                vrpRepor.Close();
                try
                {
                    System.Web.HttpContext.Current.Response.Buffer = false;
                    System.Web.HttpContext.Current.Response.ClearContent();
                    System.Web.HttpContext.Current.Response.ClearHeaders();
                    System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
                    System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + this._stNmRpt.Replace("\\", "") + ".pdf");
                    System.Web.HttpContext.Current.Response.BinaryWrite(vioMemor.ToArray());
                    System.Web.HttpContext.Current.Response.Buffer = true;
                }
                catch (System.Exception vsqExcep) { vstExcep = vsqExcep.Message; }
                finally
                {
                    if (vioMemor != null) { vioMemor.Flush(); vioMemor = null; }
                    else { vioMemor = null; }
                    if (vrpRepor != null) vrpRepor = null;
                }
            }
            catch (System.Exception vsqExcep) { vstExcep = vsqExcep.Message; }
        }