private void displayReport() { if (helper == null) { helper = new EndOfRunReportHelper(); } string Path1 = @"..\..\TempData.XML"; string Path2 = @"..\..\EndOfRunReport.rpt"; string Temp1 = textBox1.Text.Trim(); string Temp2 = textBox2.Text.Trim(); if (!string.IsNullOrEmpty(Temp1) && !string.IsNullOrEmpty(Temp2)) { Path1 = Temp1; Path2 = Temp2; } try { helper.FormatReport(Path1, Path2); crystalReportViewer1.ReportSource = helper.ReportDoc; crystalReportViewer1.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void exportReportInPdf() { if (helper == null) { helper = new EndOfRunReportHelper(); } string Path1 = @"..\..\TempData.XML"; string Path2 = @"..\..\EndOfRunReport.rpt"; string Path3 = @"..\..\TempData.pdf"; string Temp1 = textBox1.Text.Trim(); string Temp2 = textBox2.Text.Trim(); string Temp3 = String.Empty; FileInfo fInfo = null; try { if (!string.IsNullOrEmpty(Temp1) && !string.IsNullOrEmpty(Temp2)) { Path1 = Temp1; Path2 = Temp2; fInfo = new FileInfo(Path1); if (!string.IsNullOrEmpty(fInfo.Name)) { Temp3 = fInfo.Name.Replace(fInfo.Extension, ".pdf"); Path3 = fInfo.DirectoryName; int lastBackslashIndex = Path3.LastIndexOf('\\'); if (lastBackslashIndex + 1 != Path3.Length) { Path3 += "\\"; } Path3 += Temp3; } } if (File.Exists(Path3)) { Temp2 = String.Format(sMsgFileExisted, Temp3, fInfo.DirectoryName); DialogResult dlg = MessageBox.Show(this, Temp2, sCaptionFileExisted, MessageBoxButtons.YesNo); if (dlg != System.Windows.Forms.DialogResult.Yes) { return; } File.Delete(Path3); } helper.ExportReport(Path1, Path2, Path3); if (File.Exists(Path3)) { Temp2 = String.Format(sMsgExportSuccessfully, Temp3, fInfo.DirectoryName); MessageBox.Show(Temp2); File.Delete(Path3); } else { Temp2 = String.Format(sMsgExportFailed, Temp3); MessageBox.Show(Temp2); } // crystalReportViewer1.ReportSource = helper.ReportDoc; // crystalReportViewer1.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }