Cell merge in DBF Browsing?

This forum is for eXpress++ general support.
Message
Author
Djiber
Posts: 27
Joined: Wed Feb 22, 2012 2:55 am

Re: Cell merge in DBF Browsing?

#11 Post by Djiber »

Thanks all for help, I'll try to "play" a bit with all that.

If you remember anything else I'll appreciate if you post your idea.

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Cell merge in DBF Browsing?

#12 Post by Tom »

I could create a sample showing that, but not this week. It's about one or two hours of work if you know how to do it. Ownerdrawing with browses is a powerful instrument.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Djiber
Posts: 27
Joined: Wed Feb 22, 2012 2:55 am

Re: Cell merge in DBF Browsing?

#13 Post by Djiber »

Tom wrote:I could create a sample showing that, but not this week. It's about one or two hours of work if you know how to do it. Ownerdrawing with browses is a powerful instrument.
If you are willing to do so it would help a lot, Thank you.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Cell merge in DBF Browsing?

#14 Post by skiman »

Tom wrote: I will not show anything at the DevCon - I'm a simple attendee. 8-)
I was convinced you was a speaker. Maybe a bar session?

They probably are looking for another speaker since Boris won't be there...
Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Cell merge in DBF Browsing?

#15 Post by Tom »

Hi, Djiber.

I found the time to create a simple sample. It shows a kind of scheduling calendar as you showed in your first message. The app may look different with other operating systems; you need to play with the presentation parameters. It doesn't paint a column separator, but the line separator shows how to do that. It's not very sophisticated, but just a sample how your issue can be solved:
test.png
test.png (45.79 KiB) Viewed 11626 times
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Cell merge in DBF Browsing?

#16 Post by Tom »

Here's the code (using eXpress++), with XPJ and manifest.
Attachments
test.zip
(2.68 KiB) Downloaded 652 times
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Djiber
Posts: 27
Joined: Wed Feb 22, 2012 2:55 am

Re: Cell merge in DBF Browsing?

#17 Post by Djiber »

Thank you, this is great now only thing I need to figure out is how to put Text over that colored line (Surname of the guest staying in that room).

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Cell merge in DBF Browsing?

#18 Post by Tom »

Hi, Djiber.

This took twenty minutes. ;) Beware: It doesn't reflect day changes (midnight) correctly.

You may place text using GraCaptionStr() inside the CustomDrawCell method after painting the box(es). Set are foreground color before (color settings for columns are reflected)! But you may face text size problems. GraCaptionStr() will cut the text if the box size is used for it. You may play around with font sizes to reflect this. But it's not a hard problem. Increase line size to show two lines of text if you want.

There are two "sizes" used in there: aInfo[XBP_DRAWINFO_RECT] gives you the output area reserved for the cell. CellRect(aInfo[XBP_DRAWINFO_ITEM]) gives the real size of the cell.

You can do lots of other things there. Place different icons. Add lines around the boxes to show an overlapping outline (not an outlines box!). Place a shadow. Whatever you want. Just change the data array and add what you need.

HTH.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Cell merge in DBF Browsing?

#19 Post by Tom »

This paints customer names on the boxes:

Code: Select all

#include 'dcdialog.ch'
#include 'gra.ch'
#pragma library("dclipx.lib")

#DEFINE MONDAY       1
#DEFINE TUESDAY      2
#DEFINE WEDNESDAY    3
#DEFINE THURSDAY     4
#DEFINE FRIDAY       5
#DEFINE SATURDAY     6
#DEFINE SUNDAY       7

#DEFINE RESERVED     GRA_CLR_GREEN
#DEFINE BOOKED       GRA_CLR_RED


FUNCTION Main()
LOCAL GetList := {}, oDialog, aMyDates := {}, i, oBrowse,;
      aMyPres := ;
        { { XBP_PP_COL_HA_FGCLR, GRA_CLR_WHITE },    /*  Header FG Color  */     ;
          { XBP_PP_COL_HA_BGCLR, GRA_CLR_DARKCYAN }, /*  Header BG Color  */     ;
          { XBP_PP_COL_DA_ROWHEIGHT, 30 },                  /* Row Height */     ;
          { XBP_PP_COL_DA_CELLHEIGHT, 30 },                /* Cell Height */     ;
          { XBP_PP_COL_DA_ROWSEPARATOR, XBPCOL_SEP_NONE },  /* Row Sep  */     ;
          { XBP_PP_COL_DA_COLSEPARATOR, XBPCOL_SEP_NONE },  /* Col Sep  */     ;
          { XBP_PP_COL_DA_FGCLR, GRA_CLR_BLACK } , ;
          { XBP_PP_COL_DA_CELLFRAMELAYOUT, XBPFRAME_BOX }, ;
          { XBP_PP_COL_DA_FRAMELAYOUT,     XBPFRAME_NONE}, ;
          { XBP_PP_COL_DA_BGCLR, GRA_CLR_WHITE } }


FOR i := 1 TO 10 // show ten lines with "dates"
  aAdd(aMyDates,{i,'','','','','','',''})
NEXT

@ 1,1 DCBROWSE oBrowse DATA aMyDates SIZE 100,20 FIT SUBCLASS 'MyDates()' USEVISUALSTYLE NOHSCROLL PRESENTATION aMyPres

DCBROWSECOL ELEMENT 1 HEADER 'Room #' WIDTH 3 PARENT oBrowse

DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),MONDAY)}    HEADER DayInfo(MONDAY   ) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),TUESDAY)}   HEADER DayInfo(TUESDAY  ) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),WEDNESDAY)} HEADER DayInfo(WEDNESDAY) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),THURSDAY)}  HEADER DayInfo(THURSDAY ) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),FRIDAY)}    HEADER DayInfo(FRIDAY   ) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),SATURDAY)}  HEADER DayInfo(SATURDAY ) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}
DCBROWSECOL DATA {||DateInfo(DC_GetColArray(1,oBrowse),SUNDAY)}    HEADER DayInfo(SUNDAY   ) WIDTH 15 PARENT oBrowse EVAL {|o|o:DataArea:DrawMode := XBP_DRAW_OWNER}

DCREAD GUI ADDBUTTONS TITLE 'Test' FIT PARENT @oDialog EVAL {||SetAppFocus(oBrowse)}

RETURN nil

FUNCTION DateInfo(nRoomNumber,nDay)
LOCAL cDateInfo := "{}"
* retrieve your reservation information here!
* just sample data:
DO CASE
  CASE nRoomNumber = 1 .AND. nDay = MONDAY
  cDateInfo := "{{'19:00','14:00','reserved','Donnay'},{'19:00','24:00','booked','Smith'}}"
  CASE nRoomNumber = 1 .AND. nDay = TUESDAY
  cDateInfo := "{{'00:00','10:00','booked','Smith'}}"
  CASE nRoomNumber = 3 .AND. nDay = WEDNESDAY
  cDateInfo := "{{'07:00','16:00','booked','Jones'}}"
ENDCASE
RETURN cDateInfo

FUNCTION DayInfo(nDay)
DO CASE
  CASE nDay = MONDAY
  RETURN 'Monday'
  CASE nDay = TUESDAY
  RETURN 'Tuesday'
  CASE nDay = WEDNESDAY
  RETURN 'Wednesday'
  CASE nDay = THURSDAY
  RETURN 'Thursday'
  CASE nDay = FRIDAY
  RETURN 'Friday'
  CASE nDay = SATURDAY
  RETURN 'Saturday'
  CASE nDay = SUNDAY
  RETURN 'Sunday'
ENDCASE
RETURN ''

PROC AppSys() ; RETURN

***************************************
CLASS MyDates FROM DC_XbpBrowse
***************************************

EXPORTED:
   METHOD        CustomDrawCell

   INLINE METHOD destroy
   *********************
      ::DC_XbpBrowse:destroy()
   RETURN self

   INLINE METHOD init( oParent, oOwner, aPos, aSize, aPP, lVisible, oGetList )
   *****************************************************************
      ::DC_XbpBrowse:init( oParent, oOwner, aPos, aSize, aPP, lVisible, oGetList )
         ::drawMode:= XBP_DRAW_OWNER
   RETURN self

   INLINE METHOD create( oParent, oOwner, aPos, aSize, aPP, lVisible )
   *******************************************************************
      ::DC_XbpBrowse:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
   RETURN self

ENDCLASS

METHOD MyDates:customDrawCell( oPS, aInfo )
   ******************************************
LOCAL xData, nPos, aRect, nFgCol, bColBlock, nAlign := 1, nFound, aPP, xData1, xData2, xData3, nHeight,;
      aAttr := ARRAY( GRA_AL_COUNT ), aPaintPos := aInfo[ XBP_DRAWINFO_AREA ]:CellRect( aInfo[ XBP_DRAWINFO_ITEM ] ),;
      aBoxLength := {},;
      aBoxAttrs := Array(GRA_AA_COUNT)

aAttr [ GRA_AL_WIDTH ]  := GRA_LINEWIDTH_NORMAL
aAttr [ GRA_AL_COLOR ]  := GRA_CLR_DARKGRAY
aAttr [ GRA_AL_TYPE ]   := GRA_LINETYPE_DOT

* get column data
xData:= aInfo[ XBP_DRAWINFO_AREA ]:getCell( aInfo[ XBP_DRAWINFO_ITEM ] )

* get column foreground color
aInfo[ XBP_DRAWINFO_AREA ]:getCellColor( aInfo[ XBP_DRAWINFO_ITEM ],@nFgCol )

IF xData <> nil

  GraSetAttrLine( oPS, aAttr )
  GraLine(oPs,{ aPaintPos[ 1 ],aPaintPos[ 2 ] }, { aPaintPos[ 3 ], aPaintPos[ 2 ] } )

  xData := &xData // create array

  IF Len(xData) > 0
    FOR nFound := 1 TO Len(xData) // every item is: begin time, end time, reservation info
      aBoxLength := BoxLength(xData[nFound,1],xData[nFound,2],aPaintPos[3]-aPaintPos[1])
      aBoxAttrs[GRA_AA_COLOR] := IF(xData[nFound,3]='reserved',RESERVED,BOOKED)
      GraSetAttrArea( oPS,aBoxAttrs)
      GraBox(oPs,{aBoxLength[1], aInfo[ XBP_DRAWINFO_RECT,2 ]}, { aBoxLength[2], aInfo[ XBP_DRAWINFO_RECT, 4 ] },GRA_FILL)
      oPS:setColor( nFgCol )
      GraCaptionStr( oPS, {aBoxLength[1], aInfo[ XBP_DRAWINFO_RECT,2 ]}, { aBoxLength[2], aInfo[ XBP_DRAWINFO_RECT, 4 ] }, xData[nFound,4], nAlign )
    NEXT
  ENDIF

  RETURN .F.

ENDIF
RETURN .T.

FUNCTION BoxLength(cTime1,cTime2,nLength)
LOCAL n1, n2, nDayInMinutes := 1440
IF cTime1 > cTime2 // day changed!
  cTime1 := "00:00"
ENDIF
* Time to minutes (a day has 1440 minutes):
n1 := (Val(Left(cTime1,2))*60)+Val(Right(cTime1,2))
n2 := (Val(Left(cTime2,2))*60)+Val(Right(cTime2,2))
* fraction regarding length:
n1 := Int((n1/nDayInMinutes)*nLength)
n2 := Int((n2/nDayInMinutes)*nLength)
return {n1,n2}
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Cell merge in DBF Browsing?

#20 Post by rdonnay »

Tom -

I thought about telling him about using Ownerdraw for this but thought that may be pushing him in a direction that could be difficult. If I went down this road I could see myself spending hours just trying to explain it. My next suggestion was going to be to use DCGRA* commands.

I am doing an ownerdraw session at the Hanover Devcon and could discuss it there.

Roger
The eXpress train is coming - and it has more cars.

Post Reply