Aiuto con il calcolo dei giorni

Moderator: Enrico Maria Giordano

Aiuto con il calcolo dei giorni

Postby Silvio » Mon Apr 27, 2009 4:54 pm

Sto usando una funzione per il calcolo dei giorni un po' particolare
A me serve il totale dei giorni per la stagione bassa,media e alta



Prima di tutto mi vado a caricare da un file INI i settaggi per ledate esatte delle stagioni :


#include "fivewin.ch"
#include "dtpicker.ch"

STATIC nDAYS := 0, LDAYS := .T.
STATIC nDAYS1 := 0, nDAYS2 := 0, nDAYS3 := 0, nDAYS4 := 0

Function test()
Local oDlg
Local dInizio:=date()
Local dFine:=date()
Local cIniFile:= ".\rivamania.ini"

Local cYEAR := LTRIM( STR( YEAR(DATE()) ))
Local dBassa1 := GetPvProfString("Stagioni", "BASSA1","17.05.", cIniFile)
Local dBassa2 := GetPvProfString("Stagioni", "BASSA2","27.06.", cIniFile)
Local dMedia1 := GetPvProfString("Stagioni", "MEDIA1","28.06.", cIniFile)
Local dMedia2 := GetPvProfString("Stagioni", "MEDIA2","25.07.", cIniFile)
Local dAlta1 := GetPvProfString("Stagioni", "ALTA1","26.07.", cIniFile)
Local dAlta2 := GetPvProfString("Stagioni", "ALTA2","29.08.", cIniFile)
Local dBassa3 := GetPvProfString("Stagioni", "BASSA3","30.08.", cIniFile)
Local dBassa4 := GetPvProfString("Stagioni", "BASSA4","20.09.", cIniFile)



Poi devo calcolare i giorni partendo da una data di inizio e una data di fine ( ma probabilmente mi sono incartato da qualche parte)


PRIVATE aSEASON[4][3]
PRIVATE aDAYS[3][1]
aDAYS[1][1] := 0
aDAYS[2][1] := 0
aDAYS[3][1] := 0

lDAYS = .F.

aSEASON[1] := { dBassa1 + cYEAR, dBassa2 + cYEAR }// Bassa
aSEASON[2] := { dMedia1 + cYEAR, dMedia2 + cYEAR } // media
aSEASON[3] := { dAlta1 + cYEAR, dAlta2 + cYEAR } // alta
aSEASON[4] := { dBassa3 + cYEAR, dBassa4 + cYEAR } // bassa




define dialog oDlg from 10,20 to 24,80
@ 1,2 say "Calcolo giorni"
@ 2, 3 DTPICKER dINIzio of oDlg SIZE 80,10
@ 3, 3 DTPICKER dfine of oDlg SIZE 80,10
@ 4, 2 BUTTON "fai calcolo ..." of oDlg ;
ACTION (MSGINFO("CONTO A VIDEO ","Info"),CalcolaDays(DInizio, DFine ,aSEASON) )
activate dialog oDlg

STATIC FUNCTION CalcolaDays( dDAY1, dDAY2, aSEASON )

nDAYS1 := 0 // LOW
nDAYS2 := 0 // AVERAGE
nDAYS3 := 0 // HIGHT
nDAYS4 := 0 // LOW


nDAYS := 0





IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <= cTOD(aSEASON[1][2] ) .or. ;
dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2] ) .or. ;
dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2] ) .or. ;
dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2] )

IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <= cTOD(aSEASON[1][2])
nDAYS1 := 1 + ( dDAY2 - dDAY1 )
ENDIF
// ---------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
nDAYS2 := 1 + (dDAY2 - dDAY1)
ENDIF
// ---------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2])
nDAYS3 := 1 + (dDAY2 - dDAY1)
ENDIF
// ----------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
nDAYS4 := 1 + (dDAY2 - dDAY1)
ENDIF
ENDIF


IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
nDAYS1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
nDAYS3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
nDAYS4 := 1 + ( dDAY2 - cTOD(aSEASON[4][1]) )
ENDIF


IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2])
nDAYS1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
nDAYS2 := 1 + dDAY2 - ( cTOD(aSEASON[2][1]) )
ENDIF



IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
nDAYS3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF



IF dDAY1 >= cTOD(aSEASON[3][1]) .and. dDAY1 <= cTOD(aSEASON[3][2]) .and. ;
dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
nDAYS3 := 1 + ( cTOD(aSEASON[3][2]) - dDAY1 )
nDAYS4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF


IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
nDAYS1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
nDAYS3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF


IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
nDAYS2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
nDAYS3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
nDAYS4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF

cSTART := ""
cEND := ""
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2])
cSTART := "LOW"
ENDIF
IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2])
cSTART := "AVERAGE"
ENDIF
IF dDAY1 >= cTOD(aSEASON[3][1]) .and. dDAY1 <= cTOD(aSEASON[3][2])
cSTART := "HIGH"
ENDIF
IF dDAY1 >= cTOD(aSEASON[4][1]) .and. dDAY1 <= cTOD(aSEASON[4][2])
cSTART := "LOW"
ENDIF

IF dDAY2 >= cTOD(aSEASON[1][1]) .and. dDAY2 <= cTOD(aSEASON[1][2])
cEND := "LOW"
ENDIF
IF dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2])
cEND := "AVERAGE"
ENDIF
IF dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
cEND := "HIGH"
ENDIF
IF dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
cEND := "LOW"
ENDIF

cSEASON := cSTART + " - " + cEND
nDAYS := nDAYS1 + nDAYS2 + nDAYS3 + nDAYS4

IF lDAYS = .F.
MsgInfo( "Stagione Bassa: " + STR(nDAYS1) + " giorni" + CRLF + ;
"Stagione Media: " + STR(nDAYS2) + " giorni" + CRLF + ;
"Stagione Alta : " + STR(nDAYS3) + " giorni" + CRLF + ;
"Stagione Bassa: " + STR(nDAYS4) + " giorni" + CRLF + CRLF + ;
"Calcolo totale: " + LTRIM( STR ( 1 + (dDAY2 - dDAY1) ) ) + " giorni", "RivaMania Pro" )
ENDIF
aDAYS[1][1] := nDAYS1 + nDAYS4
aDAYS[2][1] := nDAYS2
aDAYS[3][1] := nDAYS3
RETURN( nDAYS, aDAYS )




provate aprendere una data di inizio uguale o maggiore di 20 giugno e una data finale di 20 settembre( o minore di 20) per provare
Best Regards, Saludos

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

Return to All products support

Who is online

Users browsing this forum: No registered users and 6 guests