datepick valid

datepick valid

Postby Silvio » Wed Jun 17, 2009 8:17 am

I have a dialog with two datepick
From and TO
I know the number of room and the type
I want see if I have a booking order on a dbf for this room and for this period

on the file.dbf I have these fields

CAMERA 6 N
dal 8 Date
Al 8 Date
tipoattrez 1 C

How I can make to control it ?

i made :

Code: Select all  Expand view
Function SE_Libera(dDataIniziale,dDataFinale,n,cTipo)
  Local lOk := FALSE
   LOCAL nRec:=(oDCot)->(Recno())

   (oDCot)->(OrdSetFocus(3))
   (oDCot)->(DbGoTop())

   set filter to alltrim((oDCot)->tipoattrez) == cTipoAttrez .AND. (oDCot)->CAMERA == n  ;
      .AND. ;
      (;
      ( (oDCot)->DAL >= dDataIniziale .AND. (oDCot)->DAL <= dDataFinale  ) .OR.;
      ( (oDCot)->AL >= dDataIniziale .AND. (oDCot)->AL <= dDataFinale  );
  )


   (oDCot)->(DbSeek(n))

      DO WHILE !(oDCot)->(EoF())




                  lOk := TRUE


              (oDCot)->(DbSKIP())

           ENDDO


  (oDCot)->(DbGoTo(nRec))

  Return lOk 


but not run ok
Best Regards, Saludos

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

Re: datepick valid

Postby ukoenig » Wed Jun 17, 2009 1:14 pm

Silvio,

from Your example :
Code: Select all  Expand view


#include "FiveWin.ch"
#include "dtpicker.ch"

#define TRUE  .T.
#define FALSE .F.

Function test()
Local ddataini := DATE()   //  CTOD("07.07.2009") // test from Database
local ddatafin := DATE()  // CTOD("21.07.2009") // test from Database
Local oDlg, oDateStart, oDateEnd
Local nOmbrellone :=20
lOCAL XTIPO:="O"

SET DATE GERMAN

cTipoAttrez := "O" // from Database
n := 3 // from Database

DEFINE DIALOG oDlg SIZE 600,280 TITLE"SEARCH DATES"

@ 1,2  DTPICKER  oDateStart VAR  ddataini  SIZE 80,12  OF oDlg
// Only Test after End-date defined !!
// ----------------------------------------------
@ 2,2  DTPICKER  oDateEnd VAR  ddatafin  SIZE 80,12 OF oDlg ;
ON CHANGE IF_FREE(ddataini,ddatafin,n,cTipoAttrez)

ACTIVATE DIALOG oDlg  CENTER

RETURN NIL

// ------------------------

Function IF_FREE(ddataini,ddatafin,n,cTipoAttrez)
*Function IF_FREE(dDataIniziale,dDataFinale ,n,cTipoAttrez)
Local lOk := FALSE

USE COTIZA  ALIAS COTIZA

// the index must be to cotiza-camera ordsetfocus(3)  // Better STR on numeric-field for index
// because I must set filter to cotiza->camera==n and cotiza->tipoattrez=ctipoattrez

// ---------------------------------
// Better to start with a seek-value and exit after found !!!!!
// Not  DbGoTop()
// ---------------------------------

// COTIZA->(DbGoTop())
DBSEEK ( n )  // better index on STR( COTIZA->CAMERA )
DO WHILE !COTIZA->(EoF() .and. COTIZA->CAMERA = n  // Main-Index
   IF alltrim(COTIZA->tipoattrez) = cTipoAttrez ;
      .AND. COTIZA->DAL >= ddataini .AND. COTIZA->DAL <= ddatafin ;
      .AND. COTIZA->AL >=  ddataini .AND. COTIZA->AL <= ddatafin
      MSGINFO("SONOQUI")
      lOk :=TRUE
      EXIT  // Exit after found one ???
   ENDIF
   COTIZA->(DbSkip())
ENDDO

Return lOk
 


Best Regards
Uwe :lol:
Last edited by ukoenig on Wed Jun 17, 2009 4:14 pm, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: datepick valid

Postby Silvio » Wed Jun 17, 2009 3:56 pm

I cannot add a new field on this archive
I explain U...


I have two date fields cotiza->dal ( initial date) and cotiza->al ( end date)

the index must be to cotiza-camera ordsetfocus(3) beacuse I must set filter to cotiza->camera==n and cotiza->tipoattrez=ctipoattrez

when on the dialog I insert the initial date and end date the procedure must to control if on the cotiza.dbf there are records have the

fields cotoza->dal ( initial date) and cotiza->al ( end date) equal to the period I inserted.

if it found records it must return .t.
Best Regards, Saludos

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

Re: datepick valid

Postby ukoenig » Wed Jun 17, 2009 9:25 pm

Silvio,

I tested with some small changes in Your example and it returns for 2 given dates TRUE or FALSE.

Tested Record from Your Database :

Camera = 3
Tipo = O
Start = 07.07.2009
End = 21.07.2009

Code: Select all  Expand view

#include "FiveWin.ch"
#include "dtpicker.ch"

#define TRUE  .T.
#define FALSE .F.

Function test()
Local ddataini := DATE()   //  CTOD("07.07.2009") // from Database
local ddatafin := DATE()  // CTOD("21.07.2009") // from Database
Local oDlg, oDateStart, oDateEnd
Local nOmbrellone :=20
lOCAL XTIPO:="O" // from Database

SET DATE GERMAN
REQUEST DBFCDX
Rddsetdefault("DBFCDX")

cTipoAttrez := "O" // Test from Your Database
n := 3 // Test from Your Database

DEFINE DIALOG oDlg SIZE 600,280 TITLE"SEARCH DATES"

@ 1,2  DTPICKER  oDateStart VAR  ddataini  SIZE 80,12  OF oDlg // valid IF_FREE(ddataini,ddatafin ,nOmbrellone,XTIPO)
// Only Test after End-date defined !!
// ----------------------------------------------
@ 2,2  DTPICKER  oDateEnd VAR  ddatafin  SIZE 80,12 OF oDlg ;
ON CHANGE IIF ( IF_FREE(ddataini,ddatafin,n,cTipoAttrez), ;
      MsgAlert( "Date found !","Attention"), ;
      MsgAlert( "Date not found !","Attention") )

ACTIVATE DIALOG oDlg  CENTER

RETURN NIL

// -------- Start 07.07.2009 - End 21.07.2009 ----------------

Function IF_FREE(ddataini,ddatafin,n,cTipoAttrez)
Local lOk := FALSE

USE COTIZA  ALIAS COTIZA
DBSETORDER(3)
DBSEEK( n )
IF Found()
   DO WHILE !COTIZA->(EoF()) .and. COTIZA->CAMERA = n
      IF alltrim(COTIZA->tipoattrez) = cTipoAttrez ;
         .AND. COTIZA->DAL >= ddataini .AND. COTIZA->DAL <= ddatafin ;
         .AND. COTIZA->AL >=  ddataini .AND. COTIZA->AL <= ddatafin
         MSGINFO("SONOQUI")
         lOk :=TRUE
         EXIT
      ENDIF
      COTIZA->(DbSkip())
   ENDDO
ENDIF

Return lOk
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: datepick valid

Postby Silvio » Thu Jun 18, 2009 11:25 am

before to open the dialog I see the msginfo.....
and then ....

WHAT IS IT ?
Image
Best Regards, Saludos

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

Re: datepick valid

Postby ukoenig » Thu Jun 18, 2009 12:08 pm

Silvio,

The message < date not found > is just a control for You, that .T. and .F. works.
Any datapicker-selection will show .F. until You chose the correct values.
You only need to use < found OK >, the message < Not found > You don't need and must set to NIL.

With test-values Start : 07.07.2009 and End : 21.07.2009 from Your database,
You will get the Message : Date found !
It is very fast ( seek on CAMERA ) , because no filter is used.

Index : CAMERA 6 N
Start : dal 8 Date
End : Al 8 Date
Type : tipoattrez 1 C

@ 2,2 DTPICKER oDateEnd VAR ddatafin SIZE 80,12 OF oDlg ;
ON CHANGE IIF ( IF_FREE(ddataini,ddatafin,n,cTipoAttrez), ;
MsgAlert( "Date found !","Attention"), NIL )

Image

Best regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 79 guests