/// <summary> /// Eseguo la store procedure e recupero i campi /// Eseguo il Binding sul Repeater /// </summary> private void Execute(DataSet _dsRpt) { // try // { bool ciSonoCosti = false; dsRapportino dsP = new dsRapportino(); int i = 0; for (i = 0; i <= _dsRpt.Tables[0].Rows.Count - 1; i++) { dsP.Tables["rapportoTecnicoIntervento"].ImportRow(_dsRpt.Tables[0].Rows[i]); } if (i == 0) { throw new Exception("* DATI PER IL DOCUMENTO NON PRESENTI"); } //Immagine logo string Logo = String.Empty; foreach (DataRow dr in dsP.Tables["rapportoTecnicoIntervento"].Rows) { if (Convert.ToInt32(dr["ID_PROGETTO"]) == 1) { Logo = Server.MapPath("../" + System.Configuration.ConfigurationSettings.AppSettings["Logo1"]); dr["IMMAGINE_LOGO"] = GetPhoto(Logo); } else { Logo = Server.MapPath("../" + System.Configuration.ConfigurationSettings.AppSettings["Logo2"]); dr["IMMAGINE_LOGO"] = GetPhoto(Logo); } } i = 0; for (i = 0; i <= _dsRpt.Tables[1].Rows.Count - 1; i++) { dsP.Tables["ListaManodopera"].ImportRow(_dsRpt.Tables[1].Rows[i]); } if (i == 0) { //per inserire una riga DataRow o_Dr = dsP.Tables["ListaManodopera"].NewRow(); o_Dr["ID"] = "-1"; o_Dr["IdAddetto"] = 0; o_Dr["IdAddettoWR"] = 0; o_Dr["CognomeNome"] = DBNull.Value; o_Dr["Livello"] = "<b>TOTALE</b>"; o_Dr["PrezzoUnitario"] = DBNull.Value; o_Dr["OreLavorate"] = DBNull.Value; o_Dr["Totale"] = 0; o_Dr["DescrizioneIntervento"] = DBNull.Value; dsP.Tables["ListaManodopera"].Rows.Add(o_Dr); } else { ciSonoCosti = true; } i = 0; for (i = 0; i <= _dsRpt.Tables[2].Rows.Count - 1; i++) { dsP.Tables["ListaMateriali"].ImportRow(_dsRpt.Tables[2].Rows[i]); } if (i == 0) { //per inserire una riga DataRow o_Dr = dsP.Tables["ListaMateriali"].NewRow(); o_Dr["ID"] = "-1"; o_Dr["MATERIALE"] = DBNull.Value; o_Dr["PREZZO_UNITARIO"] = DBNull.Value; o_Dr["UNITAMISURA"] = ""; o_Dr["QUANTITA"] = 0; o_Dr["PREZZOTOTALE"] = 0; o_Dr["ID_MATERIALI"] = -1; dsP.Tables["ListaMateriali"].Rows.Add(o_Dr); } else { ciSonoCosti = true; } float totaleManodoperaF = 0; float totaleMaterialeF = 0; if (ciSonoCosti) { foreach (DataRow dr in dsP.Tables["ListaManodopera"].Rows) { totaleManodoperaF += float.Parse(Convert.ToString(dr["TOTALE"])); } foreach (DataRow dr in dsP.Tables["ListaMateriali"].Rows) { totaleMaterialeF += float.Parse(Convert.ToString(dr["PREZZOTOTALE"])); } DataRow o_Dr = dsP.Tables["TOTALI"].NewRow(); o_Dr["TotaleManodopera"] = totaleManodoperaF; o_Dr["TotaleMateriali"] = totaleMaterialeF; dsP.Tables["TOTALI"].Rows.Add(o_Dr); } // //LOGO // DataRow drLogo = dsP.Tables["TblLogo"].NewRow() ; // drLogo["Immagine"] = GetPhoto(Server.MapPath("../Report/" + @"Images/cofatheclogo.jpg")); // drLogo["ID_PROGETTO"]=1; // dsP.Tables["TblLogo"].ImportRow(drLogo); pathRptSource = Server.MapPath("../Report/RptTecnicoIntervento2.rpt"); crReportDocument.Load(pathRptSource); crReportDocument.SetDataSource(dsP); string Fname = Server.MapPath("../Report/" + Session.SessionID.ToString() + ".pdf"); //pathRptSource + Session.SessionID.ToString() + ".pdf" ; // crDiskFileDestinationOptions = new DiskFileDestinationOptions(); // crDiskFileDestinationOptions.DiskFileName = Fname; // crExportOptions = crReportDocument.ExportOptions; // crExportOptions.DestinationOptions = crDiskFileDestinationOptions; // crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; // crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; ExportOptions optExp; DiskFileDestinationOptions optDsk = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions optPdfRtf = new PdfRtfWordFormatOptions(); optExp = crReportDocument.ExportOptions; optExp.ExportFormatType = ExportFormatType.PortableDocFormat; optExp.FormatOptions = optPdfRtf; optExp.ExportDestinationType = ExportDestinationType.DiskFile; optDsk.DiskFileName = Fname; optExp.DestinationOptions = optDsk; crReportDocument.Export(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.WriteFile(Fname); Response.Flush(); Response.Close(); System.IO.File.Delete(Fname); //CrystalReportViewer1.ReportSource=Server.MapPath("../Report/RptTecnicoIntervento.rpt"); // } // catch(Exception ex) // { // Server.Transfer("../ErrorPage.aspx?msgErr="+ex.Message + " *FEDERICO: Errore nel riempimento del DataSet"); // } }
public string GENERAPDFSGA(int wr_id, string sga, string username) { System.Web.UI.Page pg = new Page(); string pathRptSource; ReportDocument crReportDocument = new ReportDocument(); Classi.ManCorrettiva.MANCORRETTIVASFOGLIARDL _RichiestaIntervento = new Classi.ManCorrettiva.MANCORRETTIVASFOGLIARDL(); DataSet Ds = _RichiestaIntervento.ReportSGA(wr_id); dsRapportino dsP = new dsRapportino(); int i = 0; for (i = 0; i <= Ds.Tables[0].Rows.Count - 1; i++) { dsP.Tables["sga"].ImportRow(Ds.Tables[0].Rows[i]); } pathRptSource = pg.Server.MapPath("../Report/RptSGA1.rpt"); crReportDocument.Load(pathRptSource); crReportDocument.SetDataSource(dsP); //string Fname = pg.Server.MapPath("../Report/" + pg.Session.SessionID.ToString() + ".pdf");// ExportOptions optExp; DiskFileDestinationOptions optDsk = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions optPdfRtf = new PdfRtfWordFormatOptions(); optExp = crReportDocument.ExportOptions; optExp.ExportFormatType = ExportFormatType.PortableDocFormat; optExp.FormatOptions = optPdfRtf; optExp.ExportDestinationType = ExportDestinationType.DiskFile; //-----inserire nome del file nuovo string STORENAME = "PACK_TRACCIA_DOC.SP_INS_SGA"; conn.Open(); System.Data.OracleClient.OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = STORENAME; OracleParameter par1 = new OracleParameter(); par1.ParameterName = "p_id_wr"; par1.OracleType = System.Data.OracleClient.OracleType.Number; par1.Direction = ParameterDirection.Input; par1.Value = wr_id; par1.Size = 100; cmd.Parameters.Add(par1); OracleParameter par2 = new OracleParameter(); par2.ParameterName = "p_user"; par2.OracleType = System.Data.OracleClient.OracleType.VarChar; par2.Direction = ParameterDirection.Input; par2.Size = 50; par2.Value = username; cmd.Parameters.Add(par2); OracleParameter par3 = new OracleParameter(); par3.ParameterName = "p_sga"; par3.OracleType = System.Data.OracleClient.OracleType.VarChar; par3.Direction = ParameterDirection.Input; par3.Size = 100; par3.Value = sga; cmd.Parameters.Add(par3); OracleParameter par4 = new OracleParameter(); par4.ParameterName = "p_codice"; par4.OracleType = System.Data.OracleClient.OracleType.VarChar; par4.Direction = ParameterDirection.Output; par4.Size = 50; par4.Value = ""; cmd.Parameters.Add(par4); cmd.ExecuteNonQuery(); string NOMESGA = cmd.Parameters["p_codice"].Value.ToString(); // OracleDataReader rdr = cmd.ExecuteReader(); // string pr=rdr.GetString(); //string pr=cmd.ExecuteScalar(); conn.Close(); cmd.Dispose(); //@"C:\Inetpub\wwwroot\RL\Doc_DB\" //optDsk.DiskFileName = pathRptSource+sga+".pdf"; optDsk.DiskFileName = @System.Configuration.ConfigurationSettings.AppSettings["DIRSGA"] + NOMESGA; //Fname; optExp.DestinationOptions = optDsk; crReportDocument.Export(); string FileZip = Path.GetDirectoryName(optDsk.DiskFileName) + @"\" + Path.GetFileNameWithoutExtension(optDsk.DiskFileName) + ".zip"; if (File.Exists(FileZip)) { File.Delete(FileZip); } ZipOutputStream s = new ZipOutputStream(File.Create(FileZip)); s.SetLevel(5); // 0 - store only to 9 - FileStream fs = File.OpenRead(optDsk.DiskFileName); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(Path.GetFileName(optDsk.DiskFileName)); s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); s.Finish(); s.Close(); fs.Close(); TheSite.Classi.MailSend mail = new TheSite.Classi.MailSend(); //mail.SendMail(optDsk.DiskFileName,wr_id,DocType.SGA); mail.SendMail(FileZip, wr_id, DocType.SGA); return(optDsk.DiskFileName); }
/// <summary> /// Imposto tutte le variabili per la generazione del report /// Eseguo il Binding sul Repeater /// </summary> public dsRapportino ImpostaRpt(string [] arOdl) { try { RichiestaIntervento _RichiestaIntervento = new RichiestaIntervento(userName); dsRapportino _ds = new dsRapportino(); foreach (string wrId in arOdl) { bool ciSonoCosti = false; DataRow MainDr = _ds.Tables["MainTable"].NewRow(); MainDr["WR_ID"] = Convert.ToInt32(wrId); DataSet _dsAppoggio1 = _RichiestaIntervento.GetSingleData(getWo(int.Parse(wrId))); //Aggiunge al dataset l riga con i dettagli dell'intervento DataRow drc = _dsAppoggio1.Tables[0].Rows[0]; MainDr["WO_ID"] = Convert.ToInt32(drc["VAR_WO_WO_ID"]); _ds.Tables["rapportoTecnicoIntervento"].ImportRow(drc); ClManCorrettiva ioDati = new ClManCorrettiva(); DataTable Dt = ioDati.GetListaManodopera(Convert.ToInt32(wrId)).Tables[0].Copy(); Dt.TableName = "ListaManodopera"; // DataColumn dcWrId = new DataColumn("WR_ID"); // Dt.Columns.Add(dcWrId); if (Dt.Rows.Count == 0) { //per inserire una riga DataRow o_Dr = _ds.Tables["ListaManodopera"].NewRow(); o_Dr["ID"] = "-1"; o_Dr["IdAddetto"] = 0; o_Dr["IdAddettoWR"] = 0; o_Dr["CognomeNome"] = DBNull.Value; o_Dr["Livello"] = "<b>TOTALE</b>"; o_Dr["PrezzoUnitario"] = DBNull.Value; o_Dr["OreLavorate"] = DBNull.Value; o_Dr["Totale"] = 0; o_Dr["DescrizioneIntervento"] = DBNull.Value; o_Dr["WR_ID"] = Convert.ToInt32(wrId); _ds.Tables["ListaManodopera"].Rows.Add(o_Dr); MainDr["HA_MANODOPERA"] = "-1"; } else { if (!Dt.Columns.Contains("WR_ID")) { DataColumn myDataColumn; myDataColumn = new DataColumn(); myDataColumn.DataType = System.Type.GetType("System.Int32"); myDataColumn.ColumnName = "WR_ID"; // Add the Column to the DataColumnCollection. Dt.Columns.Add(myDataColumn); } ciSonoCosti = true; MainDr["HA_MANODOPERA"] = "1"; foreach (DataRow dr in Dt.Rows) { dr["WR_ID"] = Convert.ToInt32(wrId); _ds.Tables["ListaManodopera"].ImportRow(dr); } } DataTable Dt2 = ioDati.GetListaMateriali(Convert.ToInt32(wrId)).Tables[0].Copy(); Dt2.TableName = "ListaMateriali"; // DataColumn dcWrId2 = new DataColumn("WR_ID"); // Dt2.Columns.Add(dcWrId2); if (Dt2.Rows.Count == 0) { //per inserire una riga DataRow o_Dr = _ds.Tables["ListaMateriali"].NewRow(); o_Dr["ID"] = "-1"; o_Dr["MATERIALE"] = DBNull.Value; o_Dr["PREZZO_UNITARIO"] = DBNull.Value; o_Dr["UNITAMISURA"] = ""; o_Dr["QUANTITA"] = 0; o_Dr["PREZZOTOTALE"] = 0; o_Dr["ID_MATERIALI"] = -1; o_Dr["WR_ID"] = Convert.ToInt32(wrId); _ds.Tables["ListaMateriali"].Rows.Add(o_Dr); MainDr["HA_MATERIALI"] = "-1"; } else { if (!Dt2.Columns.Contains("WR_ID")) { DataColumn myDataColumn; myDataColumn = new DataColumn(); myDataColumn.DataType = System.Type.GetType("System.Int32"); myDataColumn.ColumnName = "WR_ID"; // Add the Column to the DataColumnCollection. Dt2.Columns.Add(myDataColumn); } ciSonoCosti = true; MainDr["HA_MATERIALI"] = "1"; foreach (DataRow dr in Dt2.Rows) { dr["WR_ID"] = Convert.ToInt32(wrId); _ds.Tables["ListaMateriali"].ImportRow(dr); } } _ds.Tables["MainTable"].Rows.Add(MainDr); float totaleManodoperaF = 0; float totaleMaterialeF = 0; if (ciSonoCosti) { foreach (DataRow dr in _ds.Tables["ListaManodopera"].Rows) { if (Convert.ToInt32(dr["WR_ID"]) == Convert.ToInt32(wrId)) { totaleManodoperaF += float.Parse(Convert.ToString(dr["TOTALE"])); } } foreach (DataRow dr in _ds.Tables["ListaMateriali"].Rows) { if (Convert.ToInt32(dr["WR_ID"]) == Convert.ToInt32(wrId)) { totaleMaterialeF += float.Parse(Convert.ToString(dr["PREZZOTOTALE"])); } } DataRow o_Dr = _ds.Tables["TOTALI"].NewRow(); o_Dr["TotaleManodopera"] = totaleManodoperaF; o_Dr["TotaleMateriali"] = totaleMaterialeF; o_Dr["WR_ID"] = Convert.ToInt32(wrId); _ds.Tables["TOTALI"].Rows.Add(o_Dr); } else { DataRow o_Dr = _ds.Tables["TOTALI"].NewRow(); o_Dr["TotaleManodopera"] = -1; o_Dr["TotaleMateriali"] = -1; o_Dr["WR_ID"] = Convert.ToInt32(wrId); _ds.Tables["TOTALI"].Rows.Add(o_Dr); } } return(_ds); } catch (Exception exc) { return(null); } }