ADDING DATA INTO AN ARRAY....[X,Y]

Post Reply
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

ADDING DATA INTO AN ARRAY....[X,Y]

Post by Silvio »

If I have an archive where there are 3 field :

NumArt Datain DataOut

sample :
129 01/03/07 02/03/07
120 01/03/07 02/03/07
122 01/04/07 12/04/07
121 01/03/07 12/04/07
120 04/06/07 06/06/07

then I have an array type [x,y]

aMounth [m,day]

sample
aMounth[3,23] = march, day number 23

If I search on archive a article sample number 120

I want save on this array If the article number 120 is occupated or free and I must save .t. or .f. on the array aMounth [m,day] where m must be the mounth and the day must be the day nad for n days is free or occupated

sample :
120 01/03/07 02/03/07
120 04/06/07 06/06/07

aMounth[1,1] := .T.
aMounth[1,2] :=.T.
aMounth[1,3] :=.F.
aMounth[1,4] :=.F.
aMounth[1,5] :=.F.
....
aMounth[1,31] :=.F.

....

aMounth[4,1]:=.F.
aMounth[4,2]:=.F.
aMounth[4,3]:=.F.
aMounth[4,4]:=.T.
aMounth[4,5]:=.T.
aMounth[4,6]:=.T.

....
aMounth[4,30]:=.F.

SOMEONE CAN HELP ME PLEASE ?
Best Regards, Saludos

Falconi Silvio
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Antonio Linares »

Silvio,

You may use hashes to solve it. Please review some hashes examples.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Antonio Linares »

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Silvio »

perhaps I not explain you right or you not understand me

I have many tables of restaurant and when I move the mouse on each button table I want show a listbox on ribbonbar with the all mounth and days from 1 to 30

if the table is occupated it must show on each day a red ball or if is free it must show a green ball as you can see on this picture


Image


to have this solution I have an archive where I insert all reservation of that table

where I have only 3 field

numtable
dateinit
dateend


for create the xbrowse you can see on picture I used an array aDatiDisp[7,31]

7 = mounths from March to September
31 = the days

Now I must load on each array the data .t. or .f. if the table is free or not
Best Regards, Saludos

Falconi Silvio
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Antonio Linares »

Silvio,

And what is the problem ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Silvio »

I dont Know How make it ...
How Load into array these values
I try with this but then I not Know how make :


FUNCTION LOAD(nTable,aDatiDisp)

USE RESERVATION ALIAS RESERVA
INDEX ON RESERVA->NUMTABLE TO TABLES

DO wHILE ! EOF()

if RESERVA->NUMTABLE==nTable
DInit:=RESERVA->datain
DEnd:=RESERVA->datafin
mounth:=mounth( RESERVA->datain)
inDay:=day(RESERVA->datain)

aDatiDisp[ mounth][ inDay] :=2 //Occupated
If day(DEnd) > inDay
aDatiDisp[ mounth][ inDay] :=1 // Free
endif
endif
skip
enddo
RETURN
Best Regards, Saludos

Falconi Silvio
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by James Bott »

Use a three element array.

aadd( aDatiDisp, nMonth, nDay, if( lOccupated, .T., .F.) )
User avatar
xProgrammer
Posts: 464
Joined: Tue May 16, 2006 7:47 am
Location: Australia

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by xProgrammer »

Hi Silvio

I guess you are asking how to build the array from which to display the green and red balls, although I may have misunderstood.

If so I would have thought that you would intialise an array to all not occupated, and then iterate through marking which ones are
occupated. This code could, presumably, also check for any double ups.

Your array would have a start date and an end date and you would discard any records that fall entirely outside of these dates
and make appropriate adjustments where the occupation dates do not fall entirely between these start and end dates.

Happy to talk more specifically, but I'm not sure I understand exactly what you are after.

Regards
xProgrammer
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Silvio »

Thankx xPro,
When the user hovers over the button of the table with the mouse
on the listbox which is right at the ribbon should display the quantity for that table according to the archive of reservations.

Must be shown for all the months from January to December and each day if the table is free or not

This is to facilitate the user when the customer requests a reservation of a table.
Archive of the reservations I have three fields need for this calculation : a numeric field where you enter your table such as 12,two fields type date for the start date and end date.
Then there are other leaders like the name of the Clent and deposit paid but the latter are not necessary in my opinion in this context

I've already done the listbox inside the ribbon and I assigned the array aDatiDisp value of 1 or 2 if the table is free or busy : to make a quick example I asegnato only 7 months and 31 regions for each month but this is not real because we know that not all months have 31 days.

for the calculation of days for a particular month I use an old function to calculate how many days are there in that month

Code: Select all

FUNCTION  nDaysMonth( dDate )
Local nMes, cYear
Local dDay
Local aDays := {31,28,31,30,31,30,31,31,30,31,30,31}
Local nReturn
Local dateformat
if empty( dDate )
   return 0
endif
nMes := Month( dDate )
cYear := str( year( dDate ),4 )
if nMes == 2
   dateformat := set( _SET_DATEFORMAT, "dd-mm-yyyy" )
   if day( ctod( "29-02-" + cYear ) ) != 0
      nReturn := 29
   else
      nReturn := 28
   endif
   set( _SET_DATEFORMAT, dateformat )
else
   nReturn := aDays[ nMes ]
endif
Return nReturn

to create the xbrowse in rbbon I used an array aData this created :

Code: Select all

aData := { {'Marzo',   aDatiDisp[1][1],aDatiDisp[1][2],aDatiDisp[1][3],aDatiDisp[1][4],aDatiDisp[1][5],aDatiDisp[1][6],aDatiDisp[1][7],aDatiDisp[1][8],aDatiDisp[1][9],aDatiDisp[1][10],;
                         aDatiDisp[1][11],aDatiDisp[1][12],aDatiDisp[1][13],aDatiDisp[1][14],aDatiDisp[1][15],aDatiDisp[1][16],aDatiDisp[1][17],aDatiDisp[1][18],aDatiDisp[1][19],aDatiDisp[1][20],;
                         aDatiDisp[1][21],aDatiDisp[1][22],aDatiDisp[1][23],aDatiDisp[1][24],aDatiDisp[1][25],aDatiDisp[1][26],aDatiDisp[1][27],aDatiDisp[1][28],aDatiDisp[1][29],aDatiDisp[1][30],aDatiDisp[1][31]},;
           {'Aprile',    aDatiDisp[2][1],aDatiDisp[2][2],aDatiDisp[2][3],aDatiDisp[2][4],aDatiDisp[2][5],aDatiDisp[2][6],aDatiDisp[2][7],aDatiDisp[2][8],aDatiDisp[2][9],aDatiDisp[2][10],;
                         aDatiDisp[2][11],aDatiDisp[2][12],aDatiDisp[2][13],aDatiDisp[2][14],aDatiDisp[2][15],aDatiDisp[2][16],aDatiDisp[2][17],aDatiDisp[2][18],aDatiDisp[2][19],aDatiDisp[2][20],;
                         aDatiDisp[2][21],aDatiDisp[2][22],aDatiDisp[2][23],aDatiDisp[2][24],aDatiDisp[2][25],aDatiDisp[2][26],aDatiDisp[2][27],aDatiDisp[2][28],aDatiDisp[2][29],aDatiDisp[2][30],aDatiDisp[2][31]},;
           {'Maggio',    aDatiDisp[3][1],aDatiDisp[3][2],aDatiDisp[3][3],aDatiDisp[3][4],aDatiDisp[3][5],aDatiDisp[3][6],aDatiDisp[3][7],aDatiDisp[3][8],aDatiDisp[3][9],aDatiDisp[3][10],;
                         aDatiDisp[3][11],aDatiDisp[3][12],aDatiDisp[3][13],aDatiDisp[3][14],aDatiDisp[3][15],aDatiDisp[3][16],aDatiDisp[3][17],aDatiDisp[3][18],aDatiDisp[3][19],aDatiDisp[3][20],;
                         aDatiDisp[3][21],aDatiDisp[3][22],aDatiDisp[3][23],aDatiDisp[3][24],aDatiDisp[3][25],aDatiDisp[3][26],aDatiDisp[3][27],aDatiDisp[3][28],aDatiDisp[3][29],aDatiDisp[3][30],aDatiDisp[3][31]},;
           {'Giugno',    aDatiDisp[4][1],aDatiDisp[4][2],aDatiDisp[4][3],aDatiDisp[4][4],aDatiDisp[4][5],aDatiDisp[4][6],aDatiDisp[4][7],aDatiDisp[4][8],aDatiDisp[4][9],aDatiDisp[4][10],;
                         aDatiDisp[4][11],aDatiDisp[4][12],aDatiDisp[4][13],aDatiDisp[4][14],aDatiDisp[4][15],aDatiDisp[4][16],aDatiDisp[4][17],aDatiDisp[4][18],aDatiDisp[4][19],aDatiDisp[4][20],;
                         aDatiDisp[4][21],aDatiDisp[4][22],aDatiDisp[4][23],aDatiDisp[4][24],aDatiDisp[4][25],aDatiDisp[4][26],aDatiDisp[4][27],aDatiDisp[4][28],aDatiDisp[4][29],aDatiDisp[4][30],aDatiDisp[4][31]},;
           {'Luglio',    aDatiDisp[5][1],aDatiDisp[5][2],aDatiDisp[5][3],aDatiDisp[5][4],aDatiDisp[5][5],aDatiDisp[5][6],aDatiDisp[5][7],aDatiDisp[5][8],aDatiDisp[5][9],aDatiDisp[5][10],;
                         aDatiDisp[5][11],aDatiDisp[5][12],aDatiDisp[5][13],aDatiDisp[5][14],aDatiDisp[5][15],aDatiDisp[5][16],aDatiDisp[5][17],aDatiDisp[5][18],aDatiDisp[5][19],aDatiDisp[5][20],;
                         aDatiDisp[5][21],aDatiDisp[5][22],aDatiDisp[5][23],aDatiDisp[5][24],aDatiDisp[5][25],aDatiDisp[5][26],aDatiDisp[5][27],aDatiDisp[5][28],aDatiDisp[5][29],aDatiDisp[5][30],aDatiDisp[5][31]},;
           {'Agosto',    aDatiDisp[6][1],aDatiDisp[6][2],aDatiDisp[6][3],aDatiDisp[6][4],aDatiDisp[6][5],aDatiDisp[6][6],aDatiDisp[6][7],aDatiDisp[6][8],aDatiDisp[6][9],aDatiDisp[6][10],;
                         aDatiDisp[6][11],aDatiDisp[6][12],aDatiDisp[6][13],aDatiDisp[6][14],aDatiDisp[6][15],aDatiDisp[6][16],aDatiDisp[6][17],aDatiDisp[6][18],aDatiDisp[6][19],aDatiDisp[6][20],;
                         aDatiDisp[6][21],aDatiDisp[6][22],aDatiDisp[6][23],aDatiDisp[6][24],aDatiDisp[6][25],aDatiDisp[6][26],aDatiDisp[6][27],aDatiDisp[6][28],aDatiDisp[6][29],aDatiDisp[6][30],aDatiDisp[6][31]},;
           {'Settembre', aDatiDisp[7][1],aDatiDisp[7][2],aDatiDisp[7][3],aDatiDisp[7][4],aDatiDisp[7][5],aDatiDisp[7][6],aDatiDisp[7][7],aDatiDisp[7][8],aDatiDisp[7][9],aDatiDisp[7][10],;
                         aDatiDisp[7][11],aDatiDisp[7][12],aDatiDisp[7][13],aDatiDisp[7][14],aDatiDisp[7][15],aDatiDisp[7][16],aDatiDisp[7][17],aDatiDisp[7][18],aDatiDisp[7][19],aDatiDisp[7][20],;
                         aDatiDisp[7][21],aDatiDisp[7][22],aDatiDisp[7][23],aDatiDisp[7][24],aDatiDisp[7][25],aDatiDisp[7][26],aDatiDisp[7][27],aDatiDisp[7][28],aDatiDisp[7][29],aDatiDisp[7][30],aDatiDisp[7][31]}}
 

and the I created the listbox on the ribbon

Code: Select all

DEFINE RIBBONBAR oRBar WINDOW oWnd PROMPT "Disponibiltà", "test", "test"

   ADD GROUP oGr RIBBON oRBar TO OPTION 1 PROMPT "Disponibiltà" width 950



   @ 2,2 xbrowse oBrw ;
   COLUMNS 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32  ;
   HEADERS  "Mese","1","2","3","4","5","6","7","8","9","10","11","12","13","14",;
             "15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31" ;
             ARRAY aData of oGr size oGr:nWidth -5, oGr:nHeight - oGr:nHeight/7 - 2 pixel  ;
             SIZES 50, 25, 25, 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25

   for n = 2 to Len( oBrw:aCols )
      // COLORS
           oBrw:aCols[ n ]:bClrStd := ;
         {|| { RGB( 216, 230, 246 ), ;
               IF ( EVAL (oBrw:bKeyno, NIL, oBrw ) %2 == 0, ;
                    CLR_WHITE,RGB( 255, 255, 189 ) ) } }



          // BMPDATA
         oBrw:aCols[ n ]:AddBmpFile("SELECT.BMP")
         oBrw:aCols[ n ]:AddBmpFile("UNSELECT.BMP")
         oBrw:aCols[ n ]:bBmpData := {|| oBrw:nArrayAt }

        Next

Now the problem is to put the right information for each array 1 if the table is free 2 if the table is occupied

How do I do this?
Best Regards, Saludos

Falconi Silvio
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by nageswaragunupudi »

Is what is wanted something like this?
Image

Logic to load data into array is very simple, as can be seen from the LoadData() function given below. (Length of array in each row is different. But Xbrowse can handle that.)

Even coding of xbrowse can be much shorter.

Code: Select all

#include 'fivewin.ch'
#include 'ord.ch'
#include 'xbrowse.ch'

REQUEST DBFCDX

#define NUM_TABLES  3

function Main()

   RDDSetDefault( 'DBFCDX' )
   CreateDBF()  // Create Sample Data
   ShowTables(  LoadData() )

return nil

static function LoadData()

   local i, n, aRes  := Array( NUM_TABLES, 0 )
   local dMonth      := AddMonth( BOY( DATE() ), 2 ) //  1st March

   for n := 1 to 7
      for i := 1 to NUM_TABLES
         AAdd( aRes[ i ], Array( LastDayOM( dMonth ) + 1 ) )
         AFill( aRes[ i ][ -1 ], .f. )
         aRes[ i ][ -1 ][ 1 ]   := cMonth( dMonth )
      next i
      dMonth      := AddMonth( dMonth, 1 )
   next n

   USE RESERVATION

   do while ! Eof()
      for n := FIELD->DATAIN to FIELD->DATAFIN
         aRes[ FIELD->NUMTABLE ][ Month( n ) - 2 ][ Day( n ) + 1 ] := .t.
      next
      SKIP
   enddo

   CLOSE RESERVATION

return aRes

static function ShowTables( aRes )

   local oTabs, aTabs   := {}
   local oDlg, oBrw, oCol, n


   DEFINE DIALOG oDlg SIZE 960,200 PIXEL
   @ 05,05 XBROWSE oBrw SIZE 470, 80 PIXEL OF oDlg ;
      ARRAY aRes[ 1 ] AUTOCOLS LINES CELL NOBORDER

   oBrw:aCols[ 1 ]:cHeader    := 'Month'
   for n := 2 to 32
      WITH OBJECT oBrw:aCols[ n ]
         :cHeader    := LTrim( Str( n - 1 ) )
         :SetCheck( { 'c:\fwh\bitmaps\level1.bmp', 'c:\fwh\bitmaps\level2.bmp' } )
      END
   next

   WITH OBJECT oBrw
      :lHScroll      := :lVScroll := .f.
      :nStretchCol   := 1
      :nFreeze       := 1
   END

   oBrw:CreateFromCode()

   for n := 1 to NUM_TABLES
      AAdd( aTabs, 'Table-' + LTrim( Str( n ) ) )
   next

   @ 85, 05 TABS oTabs OF oDlg SIZE oBrw:nWidth, 17 PIXEL
   WITH OBJECT oTabs
      :aPrompts      := aTabs
      :bAction       := { | n  | oBrw:aArrayData := aRes[ n ], oBrw:Refresh() }
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil

//-------------------------- CREATION OF SAMPLE DATA -----------//

function CreateDBF()

   FIELD NUMTABLE

   local n, dStart
   local aCols := {  { 'NUMTABLE', 'N', 2, 0 }, ;
                     { 'DATAIN'  , 'D', 8, 0 }, ;
                     { 'DATAFIN' , 'D', 8, 0 }  }

   DbCreate( 'RESERVATION', aCols )

   USE RESERVATION
   INDEX ON NUMTABLE TAG NUMTABLE

   dStart   := AddMonth( BOY( Date() ), 2 ) // 1st March
   for n := 1 to 100 * NUM_TABLES
      APPEND BLANK
      FIELD->NUMTABLE      := HB_RandomInt( 1, NUM_TABLES )
      FIELD->DATAIN        := dStart + HB_RandomInt( 0, 200 )
      FIELD->DATAFIN       := FIELD->DATAIN + HB_RandomInt( 0, 5 )
   next n

   CLOSE RESERVATION

return nil
 
This is a self contained program that can complied and executed independently. The program creates a sample DBF.
The logic can be adopted to the actual requirements.

I have used xHarbour with FWH 10.1. CT.LIB of xHarbour needs to be linked for the date functions.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Silvio »

Thanks Nages,
I try it and run ok , now I must insert it on my application but I'm sure it will not be difficult to include it in my application
I certainly would not have been able to do a function like this: you're a Great Friend!
Best Regards, Saludos

Falconi Silvio
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Otto »

Mr. NagesWaraRao,

I would like to work with your xbrowse solution.

Would you be so kind to post theses functions:

Unresolved external '_HB_FUN_ADDMONTH'
Unresolved external '_HB_FUN_BOY' refer
Unresolved external '_HB_FUN_LASTDAYOM'

for me.
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by anserkk »

Dear Mr.Otto,

You need to link xHarbour's CT.Lib for the Date functions to work. Mr.Rao has already mentioned about this on his post.

Regards
Anser
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by Otto »

Mr. NageswaraRao,
I used your code to build a Statistics on arrivals and overnight stays.
Best regards,
Otto
Image

Code: Select all

oBrw:aCols[34]:bPaintText    := { |oCol, hDC, cText, aCoord|  DrawText( oCol, hDC, cText, aCoord, oBrw, aRes[ 1 ],aRes[ 2 ]  ) }




static function DrawText( oCol, hDC, cText, aCoord, oBrw, aZeile,aZeile2)
   local nTop        := aCoord[ 1 ]
   local nBottom     := aCoord[ 3 ]
   local nLeft       := aCoord[ 2 ]
   local nRight      := aCoord[ 4 ]
   local nRow        := nTop
   local cLine 
   local nFontHt
   local nAt
   local oBrush
   local oBrush2
   local aRect1      := {}
   local rcttop      := nTop
   local rctleft     := nLeft
   local rctbottom   := nBottom 
   local rctright    := nRight
   local I           := 0
   local nRowheight  := nBottom - nTop
   local nWidth      := 0
   local cPen        := CreatePen( 0, 0.3, RGB(255,128,64) ) //RGB(128,128,255)
   local cPenRed     := CreatePen( 0, 0.3, RGB(128,128,255) )
   local nMax        := 20                      // missing: get the Maxvalue here I use  100
   *----------------------------------------------------------

   DEFINE BRUSH oBrush2  COLOR   4646935
   DEFINE BRUSH oBrush  COLOR   3092271  


   FOR I := 3 to 33

      rcttop   := INT( rctbottom - nRowheight / nMax * aZeile[ oBrw:nArrayAt,I] ) //oBrw:aCols[I]:value )
      rctleft  := rctleft + 4                   //8
      rctright := rctleft + 3
      aRect1   := { rcttop, rctleft, rctbottom, rctright }
      FillRect( hDC, aRect1, oBrush:hBrush )

      rcttop   := INT( rctbottom - nRowheight / nMax * aZeile2[ oBrw:nArrayAt,I] ) //oBrw:aCols[I]:value )
      rctleft  := rctleft + 4                   //8
      rctright := rctleft + 3
      aRect1   := { rcttop, rctleft, rctbottom, rctright }
      FillRect( hDC, aRect1, oBrush2:hBrush )
      rctleft := rctleft + 0.5

   next

   SelectObject( hDC, cPen )

   rcttop   := INT( rctbottom  - oBrw:nRowHeight/2  )

   MoveTo( hDC, rctleft-260, rcttop )
   LineTo( hDC, rctleft + 5 ,rcttop  )


return nil
*----------------------------------------------------------

    
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: ADDING DATA INTO AN ARRAY....[X,Y]

Post by nageswaragunupudi »

Excellant Mr. Otto
Its the Graph that makes the information clear and conveys the meaning effectively.
Your presentation is an example of how to convert data into information.
Regards

G. N. Rao.
Hyderabad, India
Post Reply