File: u_datawindow.sru
Size: 4900
Date: Tue, 02 Aug 2022 15:45:14 +0200
$PBExportHeader$u_datawindow.sru
forward
global type u_datawindow from datawindow
end type
end forward

global type u_datawindow from datawindow
integer width = 686
integer height = 400
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type
global u_datawindow u_datawindow

forward prototypes
public function string of_exporttext ()
public function string of_exportxml ()
public function string of_exportjson ()
public function string of_exporthtml ()
end prototypes

public function string of_exporttext ();// -----------------------------------------------------------------------------
// SCRIPT:     of_ExportText
//
// PURPOSE:    This function returns the DataWindow content in Tab-Text format.
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 03/17/2019  RolandS     Initial coding
// -----------------------------------------------------------------------------

Date ld_date
DateTime ldt_datetime
Dec ldec_decimal
Long ll_row, ll_rmax, ll_col, ll_cmax, ll_number
String ls_data, ls_colname, ls_coltype, ls_string
Time lt_time

ll_cmax = Long(this.Describe("DataWindow.Column.Count"))
ll_rmax = this.RowCount()

For ll_row = 1 To ll_rmax
   For ll_col = 1 To ll_cmax
      ls_colname = this.Describe("#" + String(ll_col) + ".Name")
      ls_coltype = this.Describe(ls_colname + ".ColType")
      choose case Left(ls_coltype, 5)
         case "date"
            ld_date = this.GetItemDate(ll_row, ls_colname)
            If Not IsNull(ld_date) Then
               ls_data += '"' + String(ld_date) + '"'
            End If
         case "datet", "times"
            ldt_datetime = this.GetItemDateTime(ll_row, ls_colname)
            If Not IsNull(ldt_datetime) Then
               ls_data += '"' + String(ldt_datetime) + '"'
            End If
         case "decim"
            ldec_decimal = this.GetItemDecimal(ll_row, ls_colname)
            If Not IsNull(ldec_decimal) Then
               ls_data += '"' + String(ldec_decimal) + '"'
            End If
         case "numbe", "long", "ulong", "real"
            ll_number = this.GetItemNumber(ll_row, ls_colname)
            If Not IsNull(ll_number) Then
               ls_data += String(ll_number)
            End If
         case "char(", "strin"
            ls_string = this.GetItemString(ll_row, ls_colname)
            If Not IsNull(ls_string) Then
               ls_data += '"' + ls_string + '"'
            End If
         case "time"
            lt_time = this.GetItemTime(ll_row, ls_colname)
            If Not IsNull(lt_time) Then
               ls_data += '"' + String(lt_time) + '"'
            End If
      end choose
      If ll_col < ll_cmax Then
         ls_data += "~t"
      End If
   Next
   ls_data += "~r~n"
Next

Return ls_data

end function

public function string of_exportxml ();// -----------------------------------------------------------------------------
// SCRIPT:     of_ExportXml
//
// PURPOSE:    This function returns the DataWindow content in XML format.
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 03/17/2019  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return this.Object.DataWindow.Data.XML

end function

public function string of_exportjson ();// -----------------------------------------------------------------------------
// SCRIPT:     of_ExportJson
//
// PURPOSE:    This function returns the DataWindow content in JSON format. It
//             is only available in PowerBuilder 2017 and higher.
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 03/17/2019  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return ""
//Return this.ExportJson()

end function

public function string of_exporthtml ();// -----------------------------------------------------------------------------
// SCRIPT:     of_ExportHtml
//
// PURPOSE:    This function returns the DataWindow content in Html format.
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 03/17/2019  RolandS     Initial coding
// -----------------------------------------------------------------------------

String ls_html, ls_stylesheet

// set html properties
this.Modify("DataWindow.HTMLTable.GenerateCSS='yes'")
this.Modify("DataWindow.HTMLTable.NoWrap='yes'")
this.Modify("DataWindow.HTMLTable.border=0")

// format the html
ls_html  = "<HTML>~r~n<HEAD>~r~n"
ls_stylesheet = this.Object.DataWindow.HTMLTable.StyleSheet
ls_html += ls_stylesheet + "~r~n</HEAD>~r~n<BODY>"
ls_html += this.Object.DataWindow.data.HTMLTable
ls_html += "~r~n</BODY>~r~n</HTML>"

Return ls_html

end function

on u_datawindow.create
end on

on u_datawindow.destroy
end on