// Export data in HTML/CSV/Word/Excel/XML/Email/PDF format public void ExportData() { cXMLDocument XmlDoc = null; cExportDocument ExportDoc = null; bool utf8 = ew_SameText(EW_CHARSET, "utf-8"); // Load recordset SqlDataReader Rs = LoadRecordset(); StartRec = 1; // Export all if (Areas.ExportAll) { DisplayRecs = TotalRecs; StopRec = TotalRecs; } else { // Export one page only SetUpStartRec(); // Set up start record position // Set the last record to display if (DisplayRecs < 0) { StopRec = TotalRecs; } else { StopRec = StartRec + DisplayRecs - 1; } } if (Rs == null) { ew_AddHeader("Content-Type", ""); // Remove header ew_AddHeader("Content-Disposition", ""); ShowMessage(); return; } if (Areas.Export == "xml") { XmlDoc = new cXMLDocument(); } else { ExportDoc = new cExportDocument(this, Areas, "h"); } string ParentTable = ""; if (Areas.Export == "xml") { Areas.ExportXmlDocument(ref XmlDoc, ew_NotEmpty(ParentTable), ref Rs, StartRec, StopRec, ""); } else { string sHeader = PageHeader; Page_DataRendering(ref sHeader); ExportDoc.Text += sHeader; Areas.ExportDocument(ref ExportDoc, ref Rs, StartRec, StopRec, ""); string sFooter = PageFooter; Page_DataRendered(ref sFooter); ExportDoc.Text += sFooter; } // Close recordset Rs.Close(); Rs.Dispose(); // Export header and footer if (Areas.Export != "xml") ExportDoc.ExportHeaderAndFooter(); // Clean output buffer if (!EW_DEBUG_ENABLED) HttpContext.Current.Response.Clear(); // Write BOM if utf-8 if (utf8 && Areas.Export != "email" && Areas.Export != "xml") HttpContext.Current.Response.BinaryWrite(new byte[]{0xEF, 0xBB, 0xBF}); // Write debug message if enabled if (EW_DEBUG_ENABLED) ew_Write(ew_DebugMsg()); // Output data if (Areas.Export == "xml") { ew_AddHeader("Content-Type", "text/xml"); ew_Write(XmlDoc.XML()); } else if (Areas.Export == "pdf") { ExportPDF(ExportDoc.Text); } else { ew_Write(ExportDoc.Text); } }
// Export data in HTML/CSV/Word/Excel/Email/PDF format public void ExportDocument(ref cExportDocument Doc, ref SqlDataReader Recordset, int StartRec, int StopRec, string ExportPageType) { if (Recordset == null || Doc == null) return; // Write header Doc.ExportTableHeader(); if (Doc.Horizontal) { // Horizontal format, write header Doc.BeginExportRow(); if (ExportPageType == "view") { Doc.ExportCaption(IdTipoVehiculo); Doc.ExportCaption(TipoVehiculo); } else { Doc.ExportCaption(IdTipoVehiculo); Doc.ExportCaption(TipoVehiculo); } Doc.EndExportRow(Export == "pdf"); } // Move to first record int RecCnt = StartRec - 1; for (int i = 1; i <= StartRec - 1; i++) Recordset.Read(); while (Recordset.Read() && RecCnt < StopRec) { RecCnt++; if (RecCnt >= StartRec) { int RowCnt = RecCnt - StartRec + 1; // Page break for PDF if (Export == "pdf" && ExportPageBreakCount > 0) { if (RowCnt > 1 && (RowCnt - 1) % ExportPageBreakCount == 0) Doc.ExportPageBreak(); } LoadListRowValues(ref Recordset); // Render row RowType = EW_ROWTYPE_VIEW; // Render view ResetAttrs(); RenderListRow(); Doc.BeginExportRow(RowCnt); // Allow CSS styles if enabled if (ExportPageType == "view") { Doc.ExportField(IdTipoVehiculo); Doc.ExportField(TipoVehiculo); } else { Doc.ExportField(IdTipoVehiculo); Doc.ExportField(TipoVehiculo); } Doc.EndExportRow(false); } } Doc.ExportTableFooter(); }
// Export data in HTML/CSV/Word/Excel/XML/Email/PDF format public void ExportData() { cXMLDocument XmlDoc = null; cExportDocument ExportDoc = null; bool utf8 = ew_SameText(EW_CHARSET, "utf-8"); // Load recordset SqlDataReader Rs = LoadRecordset(); StartRec = 1; // Export all if (Personas.ExportAll) { DisplayRecs = TotalRecs; StopRec = TotalRecs; } else { // Export one page only SetUpStartRec(); // Set up start record position // Set the last record to display if (DisplayRecs < 0) { StopRec = TotalRecs; } else { StopRec = StartRec + DisplayRecs - 1; } } if (Rs == null) { ew_AddHeader("Content-Type", ""); // Remove header ew_AddHeader("Content-Disposition", ""); ShowMessage(); return; } if (Personas.Export == "xml") { XmlDoc = new cXMLDocument(); } else { ExportDoc = new cExportDocument(this, Personas, "h"); } string ParentTable = ""; // Export master record if (EW_EXPORT_MASTER_RECORD && ew_NotEmpty(Personas.MasterFilter) && Personas.CurrentMasterTable == "Areas") { SqlDataReader rsmaster = Areas.LoadRs(DbMasterFilter); // Load master record if (rsmaster != null && rsmaster.HasRows) { if (Personas.Export == "xml") { ParentTable = "Areas"; Areas.ExportXmlDocument(ref XmlDoc, false, ref rsmaster, 1, 1, ""); } else { string ExportStyle = ExportDoc.Style; ExportDoc.ChangeStyle("v"); // Change to vertical if (Personas.Export != "csv" || EW_EXPORT_MASTER_RECORD_FOR_CSV) { Areas.ExportDocument(ref ExportDoc, ref rsmaster, 1, 1, ""); ExportDoc.ExportEmptyLine(); } ExportDoc.ChangeStyle(ExportStyle); // Restore } rsmaster.Close(); rsmaster.Dispose(); } } if (Personas.Export == "xml") { Personas.ExportXmlDocument(ref XmlDoc, ew_NotEmpty(ParentTable), ref Rs, StartRec, StopRec, ""); } else { string sHeader = PageHeader; Page_DataRendering(ref sHeader); ExportDoc.Text += sHeader; Personas.ExportDocument(ref ExportDoc, ref Rs, StartRec, StopRec, ""); string sFooter = PageFooter; Page_DataRendered(ref sFooter); ExportDoc.Text += sFooter; } // Close recordset Rs.Close(); Rs.Dispose(); // Export header and footer if (Personas.Export != "xml") ExportDoc.ExportHeaderAndFooter(); // Clean output buffer if (!EW_DEBUG_ENABLED) HttpContext.Current.Response.Clear(); // Write BOM if utf-8 if (utf8 && Personas.Export != "email" && Personas.Export != "xml") HttpContext.Current.Response.BinaryWrite(new byte[]{0xEF, 0xBB, 0xBF}); // Write debug message if enabled if (EW_DEBUG_ENABLED) ew_Write(ew_DebugMsg()); // Output data if (Personas.Export == "xml") { ew_AddHeader("Content-Type", "text/xml"); ew_Write(XmlDoc.XML()); } else if (Personas.Export == "pdf") { ExportPDF(ExportDoc.Text); } else { ew_Write(ExportDoc.Text); } }