protected void Page_Load(object sender, System.EventArgs e) { string FileName; DataRow Rep = Session["ModuleReportRow"] as DataRow; if (Rep == null) { return; } string MyGuid = Session.SessionID.ToString(); string str; str = DateTime.Now.ToString(); str = str.Replace("/", ""); str = str.Replace(".", ""); str = str.Replace(" ", ""); //Costruisce il nome del File (AnnoMeseGiornoOraMinutiSecondi) //FileName = str.Substring(4,4) + str.Substring(2,2) + str.Substring(0,2) + "h" + str.Substring(8,str.Length - 8); string prefix = Session["TipoUtente"] as String; if (prefix == "fornitore") { prefix += "-" + Session["CodiceFornitore"].ToString(); } if (prefix == "responsabile") { prefix += "-" + Session["CodiceResponsabile"].ToString(); } prefix = GetVars.GetUsrVar(this, "CodiceDipartimento").ToString() + "-" + prefix + "-"; prefix = prefix.Replace("\\", ""); prefix = prefix.Replace("/", ""); prefix = prefix.Replace("*", ""); prefix = prefix.Replace("?", ""); prefix = prefix.Replace("$", ""); prefix = prefix.Replace("%", ""); FileName = prefix + Rep["reportname"].ToString() + "-" + System.Guid.NewGuid().ToString(); DataTable UserPar = (DataTable)Session["UserPar"]; if (UserPar == null) { return; } DataRow Par = UserPar.Rows[0]; string errmess; Easy_DataAccess Conn = GetVars.GetUserConn(this); ReportDocument myRptDoc = Easy_DataAccess.GetReport(Conn, Rep, Par, out errmess); if (myRptDoc == null) { Session["Messaggio"] = errmess; Session["CloseWindow"] = true; Session["UserPar"] = null; Session["ModuleReportRow"] = null; Response.Redirect("Messaggio.aspx"); return; } // Restituisce il percorso fisico locale della cartella ReportPDF ex: c:\inetpub\wwwroot\..... string FilePath = this.MapPath("ReportPDF"); if (!FilePath.EndsWith("\\")) { FilePath += "\\"; } string filenametodelete = FilePath + prefix + "*.*"; string [] existingreports = System.IO.Directory.GetFiles( FilePath, prefix + "*.*"); foreach (string filename in existingreports) { System.IO.File.Delete(filename); } string PDFfilePathRedir = //FilePath + "ReportPDF/" + FileName + ".pdf"; string myFilePdf = ExportToPdf(myRptDoc, FileName, FilePath); myRptDoc.Close(); myRptDoc.Dispose(); if (myFilePdf == null) { string mym = "Non è stato possibile completare l'esportazione in formato PDF. \r"; mym += "E' probabile che i parametri inseriti non siano corretti. \r"; mym += "Qualora avesse bisogno di assistenza può contattare il servizio assistenza "; Session["CloseWindow"] = true; Session["Messaggio"] = mym; Response.Redirect("Messaggio.aspx"); return; } //Visualizza il Report in formato PDF //WebLog.Log(this,"Visualizza il file in formato PDF"); Session["UserPar"] = null; Session["ModuleReportRow"] = null; GC.Collect(); Response.Redirect(PDFfilePathRedir); }
public bool ShowReport() { string errmess; //pdoc.DefaultPageSettings.PaperSize = GetSystemSize(ReportDoc.PrintOptions.PaperSize); //pdoc.DefaultPageSettings.Landscape = (ModuleReport["orientation"].ToString().ToUpper() == "P"); string papersize = ModuleReport["papersize"].ToString(); if (papersize.ToUpper() == "ASK") { frmSelectPrinter frm = new resultparameter_default.frmSelectPrinter(papersize); if (frm.ShowDialog(this) != DialogResult.OK) { return(false); } printerName = frm.cmbPrn.Text; } else { printerName = getPrinterNameFor(papersize); } if (printerName == null) { return(false); } ReportDoc = Easy_DataAccess.GetReport(Conn, ModuleReport, Params, out errmess); if (ReportDoc == null) { MessageBox.Show(errmess, "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); errore = true; return(false); } try { ReportDoc.PrintOptions.PrinterName = printerName; //PDIAL.PrinterSettings.PrinterName; } catch { errore = true; MessageBox.Show("La stampante di nome " + printerName + " non appare essere correttamente installata.", "Errore"); return(false); } ReportDispatcherClass.SetDefaultOrientation(ref ReportDoc, ModuleReport); //formato dal report al printer dialog //eseguo bind del report crViewer.ReportSource = ReportDoc; //ReportDoc; Cursor.Current = Cursors.Default; toolBar.Enabled = true; return(true); }