Subject Re: snake report addition
From Mervyn Bick <invalid@invalid.invalid>
Date Thu, 1 Dec 2016 15:13:42 +0200
Newsgroups dbase.getting-started
Attachment(s) mbgolfers_scores.wfmmbgolfers_scores.rep

On 2016-12-01 2:19 AM, Charlie wrote:
> Hi Mervyn.. Yes dbname is a combination of the day of the week and date which identifies the filter for each tournament.  (We have 3 a week).   Grp is of course the group.
>
> The date and day actually come from another table (dbname) but that shouldn't affect this.
> lname fname are in the detail band in that order.
>
> Just filter on dbname and that would give you each individual tourney.  I have no index for this report.
>
> The other fields are not really used in this report but another one with the results from each tournament.


This was quite an interesting exercise and I've learnt a bit more of how
the report engine works "behind the scenes".

Attached is a report that uses your golfers_scores table.  Because you
have many matches in the table you need to be able to tell the report
which one you want printed.  You could, of course, edit the report file
every time and change the match name but it is far better to have a
little form to allow you to select the match and then pass the match to
the report.

The form and the report are named mbgolfers_scores so as not to
overwrite anything if you have used golfers_scores as names.  You can
change the names of the form and the report if you want to.  It is
normally a good idea to change the classname if you change the file name
but it won't cause problems here so don't bother about it.

You didn't say if you wanted the names shown as "John Doe" or "Doe,
John" so I've given you both.  Open the report in the designer, select
the version you don't want and press the delete key.

I've used preview.wfm from the dUFLP as this gives you the ability to
print the report once you have viewed it.  If you don't want this
comment out the line form.preview.open() and uncomment the line
form.rep.render().

Mervyn.






** END HEADER -- do not remove this line
//
// Generated on 2016-12-01
//
parameter bModal
local f
f = new mbgolfers_scoresForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class mbgolfers_scoresForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 16.0
      left = 58.7143
      top = 14.6818
      width = 40.0
      text = "Print matches"
   endwith

   this.GOLFERS_SCORES1 = new QUERY(this)
   with (this.GOLFERS_SCORES1)
      left = 4.0
      sql = 'select distinct dbname,day_w,t_date from "golfers_scores.DBF"'
      active = true
   endwith

   this.COMBOBOX1 = new COMBOBOX(this)
   with (this.COMBOBOX1)
      onOpen = class::COMBOBOX1_ONOPEN
      height = 1.0
      left = 8.0
      top = 4.5
      width = 25.0
      dataSource = form.golfers_scores1.rowset.fields["dbname"]
      style = 1        // DropDown
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.0909
      left = 11.0
      top = 11.5
      width = 15.2857
      text = "Print report"
   endwith

   this.rowset = this.golfers_scores1.rowset

     function COMBOBOX1_onOpen()
          this.value = 'Select match'
          return

     function PUSHBUTTON1_onClick()
          form.rowset.applyLocate( "dbname = '" + form.combobox1.value + "'" )
          form.rep.pagetemplate1.text1.text = form.rowset.fields['day_w'].value
          form.rep.pagetemplate1.text2.text = form.rowset.fields['t_date'].value
          form.rep.temp_golfers_scores1.params['dbname'] = form.combobox1.value
          form.rep.temp_golfers_scores1.requery()
      //    form.rep.render()
          form.preview.open()
          return

     function form_onOpen()
          set procedure to mbgolfers_scores.rep
          form.rep = new mbgolfers_scoresReport()
          set procedure to :duflp:preview.wfm additive
          form.preview = new PreviewForm()
          form.preview.bClose = false
          form.preview.viewer.ref := form.rep
          return

endclass






if file("temp_golfers_scores.dbf")
   drop table temp_golfers_scores
endif

copy table golfers_scores to temp_golfers_scores
alter table temp_golfers_scores add late_entry boolean
update temp_golfers_scores set late_entry = false
insert into temp_golfers_scores (grp,late_entry) values (99,true)

** END HEADER -- do not remove this line
//
// Generated on 2016-12-01
//
local r
r = new MBGOLFERS_SCORESREPORT()
r.render()

class MBGOLFERS_SCORESREPORT of REPORT
   with (this)
      metric = 0        // Chars
      autoSort = false
   endwith

   this.TEMP_GOLFERS_SCORES1 = new QUERY(this)
   with (this.TEMP_GOLFERS_SCORES1)
      left = 22.0
      sql = 'select t.*,fname||" "||lname as name1,lname||", "||fname as name2  from "temp_golfers_scores.DBF" t where (dbname = :dbname or late_entry = true ) order by grp,lname '
      requestLive = false
      params["dbname"] = "SATURDAY20161203"
      active = true
   endwith

   this.STREAMSOURCE1 = new STREAMSOURCE(this)
   this.STREAMSOURCE1.GROUP1 = new GROUP(this.STREAMSOURCE1)
   with (this.STREAMSOURCE1.GROUP1)
      groupBy = "late_entry"
   endwith

   with (this.STREAMSOURCE1.GROUP1.headerBand)
      preRender = class::HEADERBAND_PRERENDER
      onRender = class::HEADERBAND_ONRENDER
      expandable = false
      height = 1.0
   endwith

   this.STREAMSOURCE1.GROUP2 = new GROUP(this.STREAMSOURCE1)
   with (this.STREAMSOURCE1.GROUP2)
      groupBy = "grp"
      headerEveryFrame = true
   endwith

   with (this.STREAMSOURCE1.GROUP2.footerBand)
      onRender = class::FOOTERBAND_ONRENDER
      height = 1.0
   endwith

   this.STREAMSOURCE1.GROUP2.footerBand.TEXT1 = new TEXT(this.STREAMSOURCE1.GROUP2.footerBand)
   with (this.STREAMSOURCE1.GROUP2.footerBand.TEXT1)
      canRender = {||false}
      height = 1.0
      left = 6.5
      top = 0.0
      width = 12.0
      prefixEnable = false
      text = "Text1"
   endwith

   with (this.STREAMSOURCE1.GROUP2.headerBand)
      preRender = class::HEADERBAND_PRERENDER1
      height = 6.0
   endwith

   this.STREAMSOURCE1.GROUP2.headerBand.TEXT1 = new TEXT(this.STREAMSOURCE1.GROUP2.headerBand)
   with (this.STREAMSOURCE1.GROUP2.headerBand.TEXT1)
      canRender = class::TEXT1_CANRENDER
      height = 1.0
      left = 2.5
      top = 4.25
      width = 12.0
      prefixEnable = false
      alignHorizontal = 2        // Right
      text = "Match No"
   endwith

   this.STREAMSOURCE1.GROUP2.headerBand.TEXTGRP1 = new TEXT(this.STREAMSOURCE1.GROUP2.headerBand)
   with (this.STREAMSOURCE1.GROUP2.headerBand.TEXTGRP1)
      canRender = class::TEXTGRP1_CANRENDER
      height = 1.0
      left = 16.1667
      top = 4.25
      width = 4.0
      variableHeight = true
      prefixEnable = false
      alignHorizontal = 2        // Right
      picture = "999"
      text = {||this.form.temp_golfers_scores1.rowset.fields["grp"].value}
   endwith

   this.STREAMSOURCE1.GROUP2.headerBand.TEXT2 = new TEXT(this.STREAMSOURCE1.GROUP2.headerBand)
   with (this.STREAMSOURCE1.GROUP2.headerBand.TEXT2)
      height = 1.0
      left = 2.5
      top = 1.6
      width = 25.3333
      prefixEnable = false
      fontSize = 11.0
      fontBold = true
      text = "Additional matches"
   endwith

   with (this.STREAMSOURCE1.detailBand)
      onRender = class::DETAILBAND_ONRENDER
      height = 0.8333
   endwith

   this.STREAMSOURCE1.detailBand.TEXTNAME11 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTNAME11)
      height = 0.9767
      left = 0.0
      top = 0.0267
      width = 21.1667
      variableHeight = true
      prefixEnable = false
      text = {||this.form.temp_golfers_scores1.rowset.fields["name1"].value}
   endwith

   this.STREAMSOURCE1.detailBand.TEXTNAME21 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTNAME21)
      height = 0.9767
      left = 25.3333
      top = 0.0267
      width = 20.8334
      variableHeight = true
      prefixEnable = false
      text = {||this.form.temp_golfers_scores1.rowset.fields["name2"].value}
   endwith

   with (this.printer)
      duplex = 1        // None
      orientation = 1        // Portrait
      paperSource = 7
      paperSize = 9
      resolution = 3        // Medium
      color = 2        // Color
      trueTypeFonts = 1        // Bitmap
   endwith

   this.PAGETEMPLATE1 = new PAGETEMPLATE(this)
   with (this.PAGETEMPLATE1)
      height = 56.1233
      width = 132.2778
      marginTop = 3.6
      marginLeft = 12.0
      marginBottom = 3.6
      marginRight = 12.0
      gridLineWidth = 0
   endwith

   this.PAGETEMPLATE1.STREAMFRAME1 = new STREAMFRAME(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.STREAMFRAME1)
      height = 43.0
      left = 3.8334
      top = 4.0
      width = 50.0
      form.STREAMFRAME1 = form.pagetemplate1.streamframe1
   endwith

   this.PAGETEMPLATE1.STREAMFRAME2 = new STREAMFRAME(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.STREAMFRAME2)
      height = 43.0
      left = 56.3333
      top = 4.0
      width = 50.0
      form.STREAMFRAME2 = form.pagetemplate1.streamframe2
   endwith

   this.PAGETEMPLATE1.TEXT1 = new TEXT(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.TEXT1)
      height = 1.0
      left = 6.3334
      top = 1.8
      width = 14.0
      prefixEnable = false
      text = "Day"
      form.TEXT1 = form.pagetemplate1.text1
   endwith

   this.PAGETEMPLATE1.TEXT2 = new TEXT(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.TEXT2)
      height = 1.0
      left = 21.5001
      top = 1.75
      width = 12.0
      prefixEnable = false
      text = "Date"
      form.TEXT2 = form.pagetemplate1.text2
   endwith

   with (this.reportGroup.footerBand)
      height = 0.8333
   endwith

   this.firstPageTemplate = this.form.pagetemplate1
   this.form.pagetemplate1.nextPageTemplate = this.form.pagetemplate1
   this.form.pagetemplate1.streamframe1.streamSource = this.form.streamsource1
   this.form.pagetemplate1.streamframe2.streamSource = this.form.streamsource1
   this.form.streamsource1.rowset = this.form.temp_golfers_scores1.rowset

   function DETAILBAND_onRender()
          this.parent.group2.footerband.text1.text :=  this.renderOffset
      return

   function FOOTERBAND_onRender()
     //group2 footerband.
     //check if there is enough space for another match.  If not go to a new fame
           if  this.parent.parent.parent.streamframe1.height - this.parent.footerband.text1.text <  8
                        this.parent.headerband.beginNewframe := true
                else
                        this.parent.headerband.beginNewframe := false
                endif    
      return


    function HEADERBAND_onRender()
      //group1 headerband
     //Check if there is enough space for additional matches.  If not force group2 headerband to a new frame
     //Adjust the value if necessary
           if  this.parent.parent.parent.streamframe1.height - this.parent.parent.group2.footerband.text1.text <  12
                        this.parent.parent.group2.headerband.beginNewframe := true
                else
                        this.parent.parent.group2.headerband.beginNewframe := false
                endif          
      return

   function HEADERBAND_preRender()
        //group1 headerband
        //Set height to 0 here so that the headerband shows in the designer
       this.height  := 0
        return

   function HEADERBAND_preRender1()
      //group2 headerband
          if this.parent.parent.parent.temp_golfers_scores1.rowset.fields["late_entry"].value = true
              //Resize the group2 headerband  and show "Late entries"  text and hide the match no
               this.beginNewframe := true
               this.text2.height := 1
               this.text2.top := 1
               this.text1.top := 0
               this.textgrp1.top := 0
               this.height := 3
           else
              //Resize the group2 headerband and hide the "Late entries" text.
              this.text2.height := 0
              this.text2.top := 0
               this.text1.top := 2
               this.textgrp1.top := 2    
               this.height := 3
            endif      
      return


   function TEXT1_canRender()
     //Don't print for dummy match 99
     local lRet
      lRet = true
      if this.parent.textgrp1.text() =' 99'
         lRet = false
       endif  
      return lRet

     function TEXTGRP1_canRender()
     //Don't print for dummy match 99
     local lRet
      lRet = true
      if this.text() = 99
          lRet = false
      endif    
      return lRet



endclass