protected void Page_Load(object sender, EventArgs e) { string FileName; string cmd = Session["AttachmentCommand"] as string; string fname = Session["AttachmentFileName"] as string; if (cmd == 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 + "-" + System.Guid.NewGuid().ToString() + fname; string errmess; Easy_DataAccess Conn = GetVars.GetUserConn(this); object doc = Conn.DO_SYS_CMD(cmd, true); if (doc == null || doc == DBNull.Value) { Session["Messaggio"] = "Documento non trovato"; Session["CloseWindow"] = true; Session["AttachmentCommand"] = null; Session["AttachmentFileName"] = 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; string sw = Path.Combine(FilePath, FileName); FileStream FS = new FileStream(sw, FileMode.Create, FileAccess.Write); byte[] ByteArray = (byte[])doc; int n = ByteArray.Length; if (n == 0) { Session["Messaggio"] = "Documento non trovato"; Session["CloseWindow"] = true; Session["AttachmentCommand"] = null; Session["AttachmentFileName"] = null; Response.Redirect("Messaggio.aspx"); return; } try { FS.Write(ByteArray, 0, n);//<<<<<<<<< FS.Flush(); FS.Close(); } catch { string mym = "Non è stato possibile completare il salvataggio del file. \r"; 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["AttachmentCommand"] = null; Session["AttachmentFileName"] = null; Response.Redirect(PDFfilePathRedir); }
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); }
protected void Page_Load(object sender, System.EventArgs e) { string FileName; DataRow Rep = Session["ExportRow"] 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("%", ""); MetaMaster MM = Master as MetaMaster; FileName = prefix + Rep["procedurename"].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); // 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 fileFormat = Rep["fileformat"].ToString(); string extension = ""; switch (fileFormat) { case "F": extension = ".txt"; break; case "T": extension = ".txt"; break; case "C": extension = ".csv"; break; case "E": extension = ".xlsx"; break; } string PDFfilePathRedir = //FilePath + "ReportPDF/" + FileName + extension; string PDFfilePathToCreate = FilePath + FileName + extension; int count = 0; const string DummyPrimaryKey = "DummyPrimaryKeyField"; const string DummyField = "reportname"; object[] ReportParams = new object[UserPar.Columns.Count - 2]; foreach (DataColumn C in UserPar.Columns) { string colname = C.ColumnName; if (colname == DummyPrimaryKey) { continue; } if (colname == DummyField) { continue; } bool Convert = (bool)C.ExtendedProperties["ConvertNullToPerc"]; Type tipo = Par.Table.Columns[colname].DataType; if (Convert && (tipo == typeof(string)) && (Par[colname].ToString() == "")) { Par[colname] = "%"; } ReportParams[count++] = Par[colname]; } int timeout = 300; try { if (Rep["timeout"] != DBNull.Value) { timeout = Convert.ToInt32( Rep["timeout"]) * 60; if (timeout == 0) { timeout = 300; } } } catch { } string ExportName = Rep["procedurename"].ToString(); DataSet Out = Conn.CallSP(ExportName, ReportParams, true, timeout); if ((Out == null) || (Out.Tables.Count == 0)) { string mym = "La stored procedure " + ExportName + " è stata valutata e non ha restituito alcun risultato."; //MM.ShowClientMessage(mym, "Avviso", System.Windows.Forms.MessageBoxButtons.OK); Session["CloseWindow"] = true; Session["Messaggio"] = mym; Response.Redirect("Messaggio.aspx"); return; } if (Out.Tables[0].Rows.Count == 0) { string mym = "La stored procedure " + ExportName + " è stata valutata e non ha restituito alcun risultato."; //MM.ShowClientMessage(mym, "Avviso", System.Windows.Forms.MessageBoxButtons.OK); Session["CloseWindow"] = true; Session["Messaggio"] = mym; Session["UserPar"] = null; Session["ExportRow"] = null; Response.Redirect("Messaggio.aspx"); return; } DataTable OutTable = Out.Tables[0]; OutTable.TableName = Rep["description"].ToString(); string result = null; switch (fileFormat) { case "F": metadatalibrary.exportclass.dataTableToFixedLengthFile(OutTable, false, PDFfilePathToCreate); break; case "T": metadatalibrary.exportclass.dataTableToTabulationSeparatedValues(OutTable, false, PDFfilePathToCreate); break; case "C": metadatalibrary.exportclass.dataTableToCommaSeparatedValues(OutTable, false, PDFfilePathToCreate); break; case "E": result = metadatalibrary.exportclass.DataTableToExcel(OutTable, true, null, null, PDFfilePathToCreate); break; } if (!string.IsNullOrEmpty(result)) { Session["Messaggio"] = result; //MM.ShowClientMessage(result, "Avviso", System.Windows.Forms.MessageBoxButtons.OK); Session["CloseWindow"] = true; Response.Redirect("Messaggio.aspx"); return; } //Visualizza il Report in formato PDF //WebLog.Log(this,"Visualizza il file in formato PDF"); Response.Clear(); Session["UserPar"] = null; Session["ExportRow"] = null; Response.Redirect(PDFfilePathRedir); }