static public Boolean ShowReport(CrystalDecisions.CrystalReports.Engine.ReportClass ReportName, string SelectionFormula) { try { frmReport ofrmReport = new frmReport(); ofrmReport.crvReportViewer.ReportSource = ReportName; ReportName.RecordSelectionFormula = SelectionFormula; ofrmReport.Show(); return(true); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Report .....", MessageBoxButtons.OK); return(false); } }
protected void PrintReport(ReportClass rpt, string printerName, int nCopies) { if (rpt != null) { try { System.Drawing.Printing.PrinterSettings printer_settings = new System.Drawing.Printing.PrinterSettings(); printer_settings.PrinterName = printerName; printer_settings.Copies = (short)nCopies; System.Drawing.Printing.PageSettings page_settings = new System.Drawing.Printing.PageSettings(printer_settings); CrystalDecisions.CrystalReports.Engine.ReportClass report = rpt; report.PrintToPrinter(printer_settings, page_settings, false); } catch { rpt.PrintToPrinter(nCopies, true, 0, 0); } } else { PgMng.ShowInfoException(Resources.Messages.NO_DATA_REPORTS); } }
private void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft) { selectedReport.ExportOptions.ExportFormatType = eft; string contentType = ""; // Make sure asp.net has create and delete permissions in the directory string tempDir = System.Configuration.ConfigurationSettings.AppSettings["TempDir"]; string tempFileName = Session.SessionID.ToString() + "."; switch (eft) { case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat: tempFileName += "pdf"; contentType = "application/pdf"; break; case CrystalDecisions.Shared.ExportFormatType.WordForWindows: tempFileName += "doc"; contentType = "application/msword"; break; case CrystalDecisions.Shared.ExportFormatType.Excel: tempFileName += "xls"; contentType = "application/vnd.ms-excel"; break; case CrystalDecisions.Shared.ExportFormatType.HTML32: case CrystalDecisions.Shared.ExportFormatType.HTML40: tempFileName += "htm"; contentType = "text/html"; CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions(); hop.HTMLBaseFolderName = tempDir; hop.HTMLFileName = tempFileName; selectedReport.ExportOptions.FormatOptions = hop; break; } CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions(); dfo.DiskFileName = tempDir + tempFileName; selectedReport.ExportOptions.DestinationOptions = dfo; selectedReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; selectedReport.Export(); selectedReport.Close(); string tempFileNameUsed; //if (eft == CrystalDecisions.Shared.ExportFormatType.HTML32 || eft == CrystalDecisions.Shared.ExportFormatType.HTML40) //{ // string[] fp = selectedReport.FilePath.Split("\\".ToCharArray()); // string leafDir = fp[fp.Length - 1]; // // strip .rpt extension // leafDir = leafDir.Substring(0, leafDir.Length–4); // tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName); //} //else tempFileNameUsed = tempDir + tempFileName; Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = contentType; Response.WriteFile(tempFileNameUsed); Response.Flush(); Response.Close(); System.IO.File.Delete(tempFileNameUsed); }