private void rptPDFAdjunto(String Reporte, String Nombre, String Referencia, String Importe, String Vigencia, String Concepto, String Observaciones) { System.Web.UI.Page p = new System.Web.UI.Page(); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); try { report.Load(p.Server.MapPath("~") + Reporte); report.SetParameterValue(0, Nombre); report.SetParameterValue(1, Referencia); report.SetParameterValue(2, Importe); report.SetParameterValue(3, Vigencia); report.SetParameterValue(4, Concepto); report.SetParameterValue(5, Observaciones); report.PrintOptions.PaperSize = PaperSize.PaperLetter; string archivo = p.Server.MapPath("~") + "/ArchivoReferencia/Referencia - " + Referencia + ".PDF"; report.ExportToDisk(ExportFormatType.PortableDocFormat, archivo); // "FichaReferenciada-" + Nombre.Substring(0, 15)); } catch (Exception ex) { lblMensajeCorreo.Text = ex.Message; } finally { //CR_Reportes.ReportSource = report; report.Close(); report.Dispose(); //CR_Reportes.Dispose(); } }
private void rptPDFReferencia(String Reporte, String Nombre, String Referencia) { System.Web.UI.Page p = new System.Web.UI.Page(); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); try { // ConnectionInfo connectionInfo = new ConnectionInfo(); //string J = System.AppDomain.CurrentDomain.BaseDirectory + Reporte; report.Load(p.Server.MapPath("~") + Reporte); //report.Load(System.AppDomain.CurrentDomain.BaseDirectory + Reporte); report.SetParameterValue(0, Referencia); report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FichaReferenciada-" + Nombre.Substring(0, 15)); } catch (Exception ex) { } finally { CR_Reportes.ReportSource = report; report.Close(); report.Dispose(); CR_Reportes.Dispose(); GC.Collect(); } }
/// <summary> /// 產生PDF檔案 /// </summary> private void RrintToPDF() { // 匯出檔名的設定 string sReportFileName = @"\rpt\T022_rpt.rpt"; string sMapPath = Server.MapPath(""); string sHost = Request.Url.Host; string sApplicationPath = Request.ApplicationPath; string reportID = DBCenter.GetSystemID(); string sExportFileName = Server.MapPath("../../") + @"PDF\T022_rpt" + reportID + ".pdf"; string strPath = sMapPath + sReportFileName; string ReportPath = "http://" + sHost + sApplicationPath + "/PDF/T022_rpt" + reportID + ".pdf"; DataSet dsLot = (DataSet)Session["T022View"]; rptdoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); rptdoc.Load(strPath); rptdoc.SetDataSource(dsLot); // 設定匯出路徑及檔名 DiskFileDestinationOptions df = new DiskFileDestinationOptions(); df.DiskFileName = sExportFileName; rptdoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; rptdoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; rptdoc.ExportOptions.DestinationOptions = df; rptdoc.Export(); rptdoc.Dispose(); //打開文件 Response.Write("<script>window.open('" + ReportPath + "','_blank','resizable,scrollbars=no,menubar=no,toolbar=no,location=no,status=no',false);</script> "); Response.Write("<script>window.close();</script>"); }
private void rptPDF_Ingresos(String Reporte, object[] Parametros, string NombreReporte) { System.Web.UI.Page p = new System.Web.UI.Page(); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); try { ConnectionInfo connectionInfo = new ConnectionInfo(); p = new System.Web.UI.Page(); report.Load(p.Server.MapPath("~") + "\\" + Reporte); for (int i = 0; i <= Parametros.Length - 1; i++) { report.SetParameterValue(i, Parametros[i]); } connectionInfo.ServerName = "dsia"; connectionInfo.UserID = "ingresos"; connectionInfo.Password = "******"; SetDBLogonForReport(connectionInfo, report); report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, NombreReporte); } catch (Exception ex) { throw new Exception(ex.Message); } finally { CR_Reportes.ReportSource = report; report.Close(); report.Dispose(); CR_Reportes.Dispose(); GC.Collect(); } }
protected void CrystalReportViewer1_Unload(object sender, EventArgs e) { if (cr != null) { cr.Close(); cr.Dispose(); GC.Collect(); } }
private string generatefiles(DataSet ds, string fromdate, string todate, string FirstPath, DataTable mailsetting) { try { DataTable dt1 = 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(); objList.Add(MailSetting(mailsetting)); CrystalDecisions.CrystalReports.Engine.ReportDocument crystalReport; foreach (DataRow Row in dt1.Rows) { MailDetails objMails = new MailDetails(); dv.RowFilter = "CustID = " + Row["custid"].ToString(); crystalReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crystalReport.Load(Server.MapPath("../Report/AutoOSMailCustomer.rpt")); crystalReport.SetDataSource(dv.ToTable()); isSendData = dv.ToTable().Rows.Count > 0 ? true : false; strAttachFirst = Server.MapPath(FirstPath + "CustomerOS_" + Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + "_" + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy") + "_" + Row["custid"].ToString() + ".pdf"); crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachFirst); crystalReport.Close(); crystalReport.Dispose(); crystalReport = null; objMails.Attachment = strAttachSecond != "" ? strAttachFirst + "," + strAttachSecond : strAttachFirst; objMails.Name = Row["custName"].ToString(); objMails.EmailId = Row["EmailID"].ToString(); string makesubject = "Chetana Publications :: Outstanding Statement :: 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; } }
private void rptPDFAdjunto(String Reporte, String Nombre, String Referencia, Double Importe, String Vigencia, String Concepto, String Observaciones) { System.Web.UI.Page p = new System.Web.UI.Page(); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); try { // ConnectionInfo connectionInfo = new ConnectionInfo(); //string J = System.AppDomain.CurrentDomain.BaseDirectory + Reporte; report.Load(p.Server.MapPath("~") + Reporte); //report.Load(System.AppDomain.CurrentDomain.BaseDirectory + Reporte); report.SetParameterValue(0, Nombre); report.SetParameterValue(1, Referencia); report.SetParameterValue(2, Importe); report.SetParameterValue(3, Vigencia); report.SetParameterValue(4, Concepto); report.SetParameterValue(5, Observaciones); report.PrintOptions.PaperSize = PaperSize.PaperLetter; //connectionInfo.ServerName = "ucad"; //connectionInfo.UserID = "ingresos"; //connectionInfo.Password = "******"; //SetDBLogonForReport(connectionInfo, report); string archivo = p.Server.MapPath("~") + "/ArchivoReferencia/Referencia - " + Referencia + ".PDF"; //report.SaveAs(archivo); report.ExportToDisk(ExportFormatType.PortableDocFormat, archivo); // "FichaReferenciada-" + Nombre.Substring(0, 15)); //report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "Referencia - " + Referencia); } catch (Exception ex) { } finally { CR_Reportes.ReportSource = report; report.Close(); report.Dispose(); CR_Reportes.Dispose(); GC.Collect(); } }
private void rptReporte_FE(String Reporte, object[] Valores) { System.Web.UI.Page p = new System.Web.UI.Page(); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); try { ConnectionInfo connectionInfo = new ConnectionInfo(); p = new System.Web.UI.Page(); report.Load(p.Server.MapPath("~") + "\\" + Reporte); for (int i = 0; i <= Valores.Length - 1; i++) { report.SetParameterValue(i, Valores[i]); } report.PrintOptions.PaperSize = PaperSize.PaperLetter; connectionInfo.ServerName = "dsia"; connectionInfo.UserID = "felectronica"; connectionInfo.Password = "******"; SetDBLogonForReport(connectionInfo, report); report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "RepComprobanteFiscal"); //CR_Reportes.ReportSource = report; //report.Close(); //report.Dispose(); } catch (Exception ex) { } finally { //CR_Reportes.Dispose(); CR_Reportes.ReportSource = report; report.Close(); report.Dispose(); CR_Reportes.Dispose(); GC.Collect(); } }
private void rptPDF2(String Reporte, string Evento, string Matricula) { ConnectionInfo connectionInfo = new ConnectionInfo(); System.Web.UI.Page p = new System.Web.UI.Page(); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); try { report.Load(p.Server.MapPath("~") + Reporte); report.SetParameterValue(0, Matricula); report.SetParameterValue(1, Evento); report.PrintOptions.PaperSize = PaperSize.PaperLetter; connectionInfo.ServerName = "dsia"; connectionInfo.UserID = "ingresos"; connectionInfo.Password = "******"; SetDBLogonForReport(connectionInfo, report); report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FichaReferenciada"); //CR_Reportes.ReportSource = report; //report.Close(); //report.Dispose(); } catch (Exception ex) { } finally { //CR_Reportes.ReportSource = report; //CR_Reportes.Dispose(); CR_Reportes.ReportSource = report; report.Close(); report.Dispose(); CR_Reportes.Dispose(); GC.Collect(); } }
public string ReportExportToFile(string reportTemplateFileName, string ExportFormat, bool IsLocalize) { if (reportTemplateFileName != string.Empty) { CrystalDecisions.CrystalReports.Engine.ReportDocument rptDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); rptDocument.Load(reportTemplateFileName); LoadReportDocument(rptDocument); } CrystalDecisions.CrystalReports.Engine.ReportDocument result = GenerateReport(); if (result.ParameterFields["ChineseFontName"] != null) { //System.Drawing.FontFamily chineseFontFamily = AppUtils.GetChineseFontFamily(dbConn); //if (chineseFontFamily != null) // result.SetParameterValue("ChineseFontName", chineseFontFamily.Name); //else result.SetParameterValue("ChineseFontName", string.Empty); } // result.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.CrystalReport, System.IO.Path.GetTempPath() + @"\" + OutputFilenamePrefix + "_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss")); //result.Load(System.IO.Path.GetTempPath() + @"\" + OutputFilenamePrefix + "_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss")); if (reportTemplateFileName == string.Empty && IsLocalize) { ReportSectionsLocalization(!ExportFormat.Equals("EXCEL", StringComparison.CurrentCultureIgnoreCase)); } // Do NOT set the papersize by default for customized paper size //result.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4; CrystalDecisions.Shared.ExportFormatType exportFormatType; string exportFileName = System.IO.Path.GetTempFileName(); System.IO.File.Delete(exportFileName); string exportFileNameExtension = string.Empty; if (ExportFormat.Equals("EXCEL", StringComparison.CurrentCultureIgnoreCase)) { result.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperEsheet; //ExcelLibrary.SpreadSheet.Workbook workbook = ExcelLibrary.SpreadSheet.Workbook.Load(result.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel)); //foreach (ExcelLibrary.SpreadSheet.Worksheet workSheet in workbook.Worksheets) //{ // ExcelLibrary.SpreadSheet.CellCollection cellCollection = new ExcelLibrary.SpreadSheet.CellCollection(); // int count = 1; // foreach (int key in workSheet.Cells.Rows.Keys) // { // ExcelLibrary.SpreadSheet.Row row = workSheet.Cells.Rows[key]; // cellCollection.Rows.Add(count, row); // count++; // } // workSheet.Cells.Rows.Clear(); // foreach (int key in cellCollection.Rows.Keys) // { // workSheet.Cells.Rows.Add(key, cellCollection.Rows[key]); // } //} //string exportFileName = System.IO.Path.GetTempFileName(); //System.IO.File.Delete(exportFileName); //exportFileName += ".xls"; //workbook.Save(exportFileName); //WebUtils.TransmitFile(Response, exportFileName, OutputFilenamePrefix + "_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".xls", true); //result.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.Excel, Response, true, OutputFilenamePrefix + "_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss")); exportFileNameExtension = ".xls"; exportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel; } else if (ExportFormat.Equals("WORD", StringComparison.CurrentCultureIgnoreCase)) { exportFileNameExtension = ".doc"; exportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText; } else //if (ExportFormat.Equals("PDF", StringComparison.CurrentCultureIgnoreCase)) { exportFileNameExtension = ".pdf"; if (UsePDFCreator) { exportFormatType = CrystalDecisions.Shared.ExportFormatType.NoFormat; try { PDFCreaterPrinter printer = new PDFCreaterPrinter(); string outputFile = printer.printCrystalReportsToPDF(result); System.IO.File.Move(outputFile, exportFileName + exportFileNameExtension); } catch (Exception ex) { throw ex; // if any error occurs or driver not installed, use crystal report export function // exportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; } } else { exportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; } //ReportSectionsIncreaseFontSize(result); } exportFileName += exportFileNameExtension; if (exportFormatType != CrystalDecisions.Shared.ExportFormatType.NoFormat) { if (exportFormatType == CrystalDecisions.Shared.ExportFormatType.PortableDocFormat) { if (reportTemplateFileName == string.Empty) { SetChineseFont(result, IsLocalize); } else { SetChineseFont(result, false); } } //result.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.CrystalReport, exportFileName); result.ExportToDisk(exportFormatType, exportFileName); } if (exportFileNameExtension == ".rtf" || exportFileNameExtension == ".doc") { string exportFileName_modified = exportFileName + "_modified" + exportFileNameExtension; System.IO.StreamReader oStrRdr = new System.IO.StreamReader(exportFileName); System.IO.StreamWriter oStrWrt = new System.IO.StreamWriter(exportFileName_modified); while (!oStrRdr.EndOfStream) { string content = oStrRdr.ReadLine(); content = content.Replace(@"{\rtf1\ansi\ansicpgA.R..", @"{\rtf1\ansi\ansicpg"); oStrWrt.WriteLine( content ); } oStrRdr.Close(); oStrWrt.Close(); System.IO.File.Delete(exportFileName); exportFileName = exportFileName_modified; } //if (exportFileNameExtension == ".rtf") //{ // string newExportFilename = exportFileName + ".pdf"; // // iTextSharp.text.Document document = new iTextSharp.text.Document(); // // iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, System.IO.File.Create(newExportFilename)); // // document.Open(); // // iTextSharp.text.rtf.parser.RtfParser parser = new iTextSharp.text.rtf.parser.RtfParser(null); // // System.IO.FileStream rtfStream = System.IO.File.OpenRead(exportFileName); // // parser.ConvertRtfDocument(rtfStream, document); // // rtfStream.Close(); // // document.Close(); // System.IO.File.Delete(exportFileName); // exportFileName = newExportFilename; //} result.Close(); result.Dispose(); LoadReportDocument(null); return(exportFileName); }
private void LoadReport() { try { this.Cursor = Cursors.WaitCursor; ParameterFieldDefinition _paramF = null;; ParameterDiscreteValue _disValue = new ParameterDiscreteValue(); ParameterValues _cValues = null; if (m_struct.Action == SReport.EAction.SAVE_TO_DISK) { this.Visible = false; } //Test call report by old or new method if (m_ReportName.Substring(m_ReportName.Length - 6, 2).Equals("NT")) { //New Code m_ReportDoc.Load(m_ReportPath, OpenReportMethod.OpenReportByTempCopy); //clsReportEngine objReportEngine = new clsReportEngine(this.DBEngine, m_ReportName,m_ParamNames,m_ParamValues); clsReportEngine objReportEngine = new clsReportEngine(this.DBEngine, m_ReportName, m_ParamsNameAndValue); m_ReportDoc.SetDataSource(objReportEngine.getDataSetValue()); m_ReportView.ReportSource = m_ReportDoc; this.Cursor = Cursors.Default; m_ReportView.Zoom(1); //Fix //End New Code } else { // * OLD CODE //m_ReportDoc.Load(m_ReportPath); m_ReportDoc.Load(m_ReportPath, OpenReportMethod.OpenReportByTempCopy); /* * LogonToReport(DBEngine.DataSourceName, * "", * DBEngine.User, * DBEngine.Password); */ LogonToReport(DBEngine.Server, DBEngine.Database, DBEngine.User, DBEngine.Password); // ============================================================ // Get the ParameterFieldDefinition object by name. if (m_PLength != 0) { for (int i = 0; i < m_PLength; i++) { _paramF = m_ReportDoc.DataDefinition.ParameterFields[m_ParamNames[i].ToString()]; _cValues = _paramF.CurrentValues; _disValue.Value = (object)m_ParamValues[i]; _cValues.Add(_disValue); _paramF.ApplyCurrentValues(_cValues); } } if (m_struct.Action == SReport.EAction.SAVE_TO_DISK) { m_ReportDoc.ExportToDisk(ExportFormatType.PortableDocFormat, m_struct.SaveToFileName); m_ReportDoc.Dispose(); this.Close(); return; } //m_ReportDoc.SaveAs("test.rpt", ReportFileFormat.VSNetFileFormat); m_ReportView.ReportSource = m_ReportDoc; this.Cursor = Cursors.Default; if (m_struct.Action == HPA.Common.SReport.EAction.PREVIEW) { m_ReportView.Zoom(1); } else if (m_struct.Action == HPA.Common.SReport.EAction.PRINT) { m_ReportView.PrintReport(); this.Close(); } //* END OLD CODE } } catch (Exception e) { MessageBox.Show(e.ToString()); throw e; } }
private string generatefiles(DataSet ds, DataSet ds1, DataTable dt1, string fromdate, string todate, string s_fromdate, string s_todate, string FirstPath, string SecondPath, DataTable mailsetting) { try { bool isSecondDataPresent = false; DataView dv = new DataView(ds.Tables[0]); DataView dv1 = new DataView(); bool isSendFirstData = false; bool isSendSecondata = false; if (ds1 != null) { isSecondDataPresent = true; dv1.Table = ds1.Tables[0]; } string strAttachFirst = string.Empty; string strAttachSecond = string.Empty; 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(); #region First Data dv.RowFilter = "Superzone = " + Row["SuperZoneID"].ToString(); crystalReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crystalReport.Load(Server.MapPath("../Report/CollectionReport.rpt")); crystalReport.SetDataSource(dv.ToTable()); isSendFirstData = dv.ToTable().Rows.Count > 0 ? true : false; strAttachFirst = Server.MapPath(FirstPath + "Wkly_Col_" + Convert.ToDateTime(fromdate).ToString("dd-MMM-yy") + "_" + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy") + "_" + Row["SuperZoneID"].ToString() + ".pdf"); crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachFirst); crystalReport.Close(); crystalReport.Dispose(); crystalReport = null; #endregion #region "Second Data" if (isSecondDataPresent) { dv1.RowFilter = "Superzone = " + Row["SuperZoneID"].ToString(); crystalReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crystalReport.Load(Server.MapPath("../Report/CollectionReport.rpt")); crystalReport.SetDataSource(dv1.ToTable()); isSendSecondata = dv1.ToTable().Rows.Count > 0 ? true : false; strAttachSecond = Server.MapPath(SecondPath + "_Wkly_Col_" + Convert.ToDateTime(s_fromdate).ToString("dd-MMM-yy") + "_" + Convert.ToDateTime(s_todate).ToString("dd-MMM-yy") + "_" + Row["SuperZoneID"].ToString() + ".pdf"); crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachSecond); crystalReport.Close(); crystalReport.Dispose(); crystalReport = null; } #endregion objMails.Attachment = strAttachSecond != "" ? strAttachFirst + "," + strAttachSecond : strAttachFirst; objMails.Name = Row["SuperZoneName"].ToString(); objMails.EmailId = Row["Email"].ToString(); string makesubject = "Collection from " + (isSecondDataPresent == true ? Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + " TO " + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy") + " & " + Convert.ToDateTime(s_fromdate).ToString("dd-MMM-yyyy") + " TO " + Convert.ToDateTime(s_todate).ToString("dd-MMM-yyyy") : Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + " TO " + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy")); objMails.Subject = makesubject; objMails.Desc = makesubject; if (isSendFirstData) { objList.Add(objMails); } objMails = null; } return(JsonConvert.SerializeObject(objList)); } catch (Exception ex) { throw; } }
private void btn_Run_Click(object sender, EventArgs e) { if (txtUsername.Text.Length > 1 && txtPassword.Text.Length > 1) { String username = txtUsername.Text; String password = txtPassword.Text; rTextBoxOutput.AppendText("Starting...\n\n"); rTextBoxOutput.ScrollToCaret(); String path = this.cboDirectoryList.Text;//"C:\\SVN\\CrystalReports\\OBS"; CreateDirectoryStructure(); foreach (string file in Directory.GetFiles(path, "*.rpt")) { Console.WriteLine(String.Format("Processing {0}...", file)); rTextBoxOutput.AppendText(String.Format("Processing {0}...\n", file)); rTextBoxOutput.ScrollToCaret(); // Declarations CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument; CrystalDecisions.ReportAppServer.Controllers.RowsetController boRowsetController; CrystalDecisions.ReportAppServer.DataDefModel.ISCRGroupPath boGroupPath; string temp = ""; try { // Load the report from the application directory boReportDocument.Load(file); // Access the ReportClientDocument in the ReportDocument (EROM bridge) // Note this is available without a dedicated RAS with SP2 for XI R2 boReportClientDocument = boReportDocument.ReportClientDocument; boReportDocument.DataSourceConnections[0].SetLogon(username, password); if (boReportDocument.Subreports.Count == 0) { CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions parameterList = boReportDocument.DataDefinition.ParameterFields; for (int i = 0; i < parameterList.Count; i++) { Console.WriteLine("i = " + i + "... " + parameterList[i].ParameterFieldName.ToString()); if (parameterList[i].ParameterFieldName.ToString() == "ReportType") { boReportDocument.SetParameterValue(i, "D"); } else if (parameterList[i].ParameterFieldName.ToString() == "@ControlID") { boReportDocument.SetParameterValue(i, 76461450); } else if (parameterList[i].ParameterFieldName.ToString() == "@RevisionCode") { boReportDocument.SetParameterValue(i, 0); } } // use the RowsetController to get the SQL query // Note: If a report has parameters they must be supplied before getting the // SQL query. boRowsetController = boReportClientDocument.RowsetController; boGroupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath(); String s = boRowsetController.GetSQLStatement(boGroupPath, out temp); s = u.RemoveQuotes(s); bool ret = false; if (u.HasSQL(s)) { if (u.HasProduct(s)) { if (du.DoesDirectoryExist(path + "\\HasEmbeddedSQL\\HasProductReference")) { ret = du.MoveFileToDirectory(file, path + "\\HasEmbeddedSQL\\HasProductReference\\" + Path.GetFileName(file)); temp = "Processed " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\HasEmbeddedSQL\\HasProductReference\\"; } } else if (u.HasView(s)) { if (du.DoesDirectoryExist(path + "\\HasEmbeddedSQL\\HasView")) { ret = du.MoveFileToDirectory(file, path + "\\HasEmbeddedSQL\\HasView\\" + Path.GetFileName(file)); temp = "Processed " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\HasEmbeddedSQL\\HasView\\"; views.Add(boReportDocument.Database.Tables[0].Name); } } else { if (du.DoesDirectoryExist(path + "\\HasEmbeddedSQL\\ProbablyOK")) { ret = du.MoveFileToDirectory(file, path + "\\HasEmbeddedSQL\\ProbablyOK\\" + Path.GetFileName(file)); temp = "Processed " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\HasEmbeddedSQL\\ProbablyOK\\"; } } } else if (u.UsesExec(s)) { if (du.DoesDirectoryExist(path + "\\NoEmbeddedSQL")) { ret = du.MoveFileToDirectory(file, path + "\\NoEmbeddedSQL\\" + Path.GetFileName(file)); temp = "Processed " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\NoEmbeddedSQL\\"; } } else { if (du.DoesDirectoryExist(path + "\\ShouldReview")) { ret = du.MoveFileToDirectory(file, path + "\\ShouldReview\\" + Path.GetFileName(file)); temp = "Processed " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\ShouldReview\\"; } } rTextBoxOutput.AppendText(temp + "\n"); rTextBoxOutput.ScrollToCaret(); } else { ConnectionInfo ci = new ConnectionInfo(); ci.UserID = username; ci.Password = password; ApplyLogOnInfoForSubreports(boReportDocument, ci); if (du.DoesDirectoryExist(path + "\\HasSubReports")) { bool ret = du.MoveFileToDirectory(file, path + "\\HasSubReports\\" + Path.GetFileName(file)); temp = "HAS SUBREPORT(S)" + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\HasSubReports\\"; } rTextBoxOutput.AppendText(temp + "\n"); rTextBoxOutput.ScrollToCaret(); } } catch (System.ArgumentOutOfRangeException aor) { if (du.DoesDirectoryExist(path + "\\ShouldReview")) { bool ret = du.MoveFileToDirectory(file, path + "\\ShouldReview\\" + Path.GetFileName(file)); temp = "Should REVIEW " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\ShouldReview\\"; } rTextBoxOutput.AppendText(temp + "\n"); rTextBoxOutput.AppendText(aor.Message + "\n"); rTextBoxOutput.ScrollToCaret(); } catch (System.Runtime.InteropServices.COMException comex) { if (du.DoesDirectoryExist(path + "\\ShouldReview")) { bool ret = du.MoveFileToDirectory(file, path + "\\ShouldReview\\" + Path.GetFileName(file)); temp = "Should REVIEW " + Path.GetFileName(file) + ", moved file: " + ret + ", moved to " + path + "\\ShouldReview\\"; } rTextBoxOutput.AppendText(temp + "\n"); rTextBoxOutput.AppendText(comex.Message + "\n"); rTextBoxOutput.ScrollToCaret(); } finally { // Clean up by closing and disposing of the ReportDocument object boReportDocument.Close(); boReportDocument.Dispose(); } } List <String> noDupes_procs = procedures.Distinct().ToList(); List <String> noDupes_sr_views = sr_views.Distinct().ToList(); List <String> noDupes_views = views.Distinct().ToList(); u.WriteToFile(path + "\\HasSubReports", "_subreportSPs.txt", noDupes_procs); u.WriteToFile(path + "\\HasSubReports", "_subreportViews.txt", noDupes_sr_views); u.WriteToFile(path + "\\HasEmbeddedSQL\\HasView", "_reportViews.txt", noDupes_views); } else { MessageBox.Show("Please enter a username and password!"); } }