FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour range date : the return !!!
Posts: 167
Joined: Thu Mar 22, 2007 11:24 AM
Re: range date : the return !!!
Posted: Mon Jul 06, 2009 01:17 PM
Silvio,

Could you try this code ?
It should be a good starting

Code (fw): Select all Collapse
function Main()

local aFlds := {{"IdNumber","C",4,0},{"Date","C",8,0},{"AfterNoon","L",1,0}}
local el , i
//DELETE FILE "Umbrella.dbf"
//DELETE FILE "Umbrella.cdx"
IF ! File("Umbrella.dbf")
    DbCreate("Umbrella",aFlds)
END
IF ! File("Umbrella.cdx")
    USE UMBRELLA
    INDEX ON FIELD->IdNumber+Date+IIF(FIELD->AfterNoon,"1","0") TAG "IdNumber"
    //INDEX ON Date+Field->IdNumber+IIF(FIELD->AfterNoon,"1","0") TAG "Date"
    // With one seek we can check for a date AND Idnumber
    CLOSE ALL
END
USE UMBRELLA SHARED
IF RECCOUNT() == 0
    BuildTestData()
END
OrdSetFocus("IDNumber")
TestFree("0001" , CTOD("10/07/2009") , .F. , CTOD("21/07/2009") , .T.) // Number umbrella , from date , Not afternoon , to date , afternoon
return nil
***********************************************************************************
INIT PROCEDURE InitUmbrella()
******************************
ANNOUNCE RDDSYS                          // This line must not change
REQUEST DBFCDX                           // Causes DBFNTX RDD to be linked in
rddSetDefault( "DBFCDX" )                // Set up DBFNTX as default driver
SET(_SET_AUTOPEN, .T. )
SET DATE FRENCH
RETURN
//----------------------------------------------------------------------------//
PROC BuildTestData()
**************************
LOCAL aData := {} , el
AADD(aData,{"0001","20090711",.F.})
AADD(aData,{"0001","20090711",.T.})
AADD(aData,{"0001","20090712",.F.})
AADD(aData,{"0001","20090712",.T.})
AADD(aData,{"0002","20090718",.F.})
AADD(aData,{"0002","20090718",.T.})
AADD(aData,{"0002","20090719",.F.})
AADD(aData,{"0002","20090719",.T.})
FOR EACH el IN aData
    DBAPPEND()
    IF NETERR()
        EXIT
    END
    FOR i := 1 TO FCOUNT()
        FieldPut(i,el[i])
    NEXT
    UNLOCK
NEXT
RETURN
//-----------------------------------------------------------------------------//
FUNC TestFree(IdNumber , FromDate , FromNoon , ToDate , ToNoon)
***************************************************
LOCAL Date , lNoon
LOCAL el , Txt , i
LOCAL nCount := IIF(FromNoon,1,2)
LOCAL aFree[0]
IF ToDate > FromDate
    nCount += (ToDate-FromDate-1)*2
    nCount += IIF(ToNoon,2,1)
END
Date := FromDate
Txt := ""
FOR i := 1 TO nCount
    IF lNoon == nil
        lNoon := FromNoon
    ELSE
        IF ! lNoon
            Date += 1
        END
    END
    IF ! DBSEEK(IdNumber+DTOS(Date)+IIF(lNoon,"1","0"))
        Txt += (el := DTOC(Date)  + IIF(lNoon," After"," Before")) + CRLF
        AADD(aFree,el)
    END
    lNoon := ! lNoon
NEXT
? Txt
RETURN aFree
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: range date : the return !!!
Posted: Fri Jul 10, 2009 12:49 AM

Silvio,

I was looking at your problem again.

What is the fieldname for the umbrella number? Is it CAMERA? Literally translated it seems to be "room" in English.

If not, then also what is the CAMERA field for?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: range date : the return !!!
Posted: Fri Jul 10, 2009 08:22 AM

yes

Best Regards, Saludos



Falconi Silvio
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: range date : the return !!!
Posted: Fri Jul 10, 2009 12:11 PM

Ok, then I wonder why there are multiple reservations for the same date range for the same umbrella? In some cases, I see three records for the same date range. I know you mentioned morning and afternoon reservations, but that would account for only two.

Is there a field for morning, afternoon?

How did the sample database get filled out? Is it likely to have unrealistic data in it?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion