#include "FiveWin.ch"
STATIC nDAYS := 0, nPRICE := 0
FUNCTION MAIN()
local oWnd
SetBalloon( .T. ) // Balloon shape required for tooltips
SET DATE GERMAN
SET CENTURY ON
SET DECIMALS TO 2
PRIVATE aDAYS[1][2]
PRIVATE aSEASON[4][3]
cYEAR := LTRIM( STR( YEAR(DATE()) ))
aSEASON[1] := { "17.05." + cYEAR, "27.06." + cYEAR, 7.00 } // LOW
aSEASON[2] := { "28.06." + cYEAR, "25.07." + cYEAR, 9.00 } // AVERAGE
aSEASON[3] := { "26.07." + cYEAR, "29.08." + cYEAR, 11.00 } // HIGHT
aSEASON[4] := { "30.08." + cYEAR, "20.09." + cYEAR, 7.00 } // LOW
dDAY1 := CTOD("18.05." + cYEAR )
dDAY2 := CTOD("15.09." + cYEAR )
lPRICE := .F.
cSEASON := "LOW"
nCOUNT1 := 0 // LOW
nCOUNT2 := 0 // AVERAGE
nCOUNT3 := 0 // HIGHT
nCOUNT4 := 0 // LOW
nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW
DEFINE WINDOW oWnd TITLE "Price-Test" MDI ;
MENU BuildMenu(oWnd) // TMenu():New()
SET MESSAGE OF oWnd TO "Price-Test" ;
CENTERED CLOCK KEYBOARD 2007
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT PRICE_TEST(oWnd) ;
ON PAINT gradpaint0( hDC, oWnd )
RETURN NIL
// -----------------------------------------------
static func gradpaint0( hDC, oWnd )
local aGrad := { { 0.50, 16054371, 11892819 } }
GradientFill( hDC, 0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, .F. )
RETURN NIL
//----------------------------------------------------------------------------//
FUNCTION BuildMenu(oWnd)
local oMenu, oSub1, oSub2, oSub3, oSub4, oSub5, oSub7, oSub8, oSub9, oSub10, oSub11
MENU oMenu
MENUITEM "&Season-Price-Tests"
MENU
MENUITEM oSub1 PROMPT "17.05. - 27.06. => Only LOW" ;
ACTION ( nPRICE := GET_PRICE( cTOD("17.05.2009"), cTOD("27.06.2009"), aSEASON ))
MENUITEM oSub2 PROMPT "28.06. - 25.07. => Only AVERAGE" ;
ACTION ( nPRICE := GET_PRICE( cTOD("28.06.2009"), cTOD("25.07.2009"), aSEASON ))
MENUITEM oSub3 PROMPT "26.07. - 29.08. => Only HIGHT" ;
ACTION ( nPRICE := GET_PRICE( cTOD("26.07.2009"), cTOD("29.08.2009"), aSEASON ))
MENUITEM oSub4 PROMPT "30.08. - 20.09. => Only LOW" ;
ACTION ( nPRICE := GET_PRICE( cTOD("30.08.2009"), cTOD("20.09.2009"), aSEASON ))
SEPARATOR
MENUITEM oSub5 PROMPT "17.05. - 20.09. => ALL" ;
ACTION ( nPRICE := GET_PRICE( cTOD("17.05.2009"), cTOD("20.09.2009"), aSEASON ))
SEPARATOR
MENUITEM oSub6 PROMPT "18.05. - 23.07. => Combi LOW + AVARAGE" ;
ACTION ( nPRICE := GET_PRICE( cTOD("18.05.2009"), cTOD("23.07.2009"), aSEASON ))
MENUITEM oSub7 PROMPT "22.07. - 26.08. => Combi AVARAGE + HIGHT" ;
ACTION ( nPRICE := GET_PRICE( cTOD("22.07.2009"), cTOD("26.08.2009"), aSEASON ))
MENUITEM oSub8 PROMPT "28.07. - 18.09. => Combi HIGH + LOW" ;
ACTION ( nPRICE := GET_PRICE( cTOD("28.07.2009"), cTOD("18.09.2009"), aSEASON ))
SEPARATOR
MENUITEM oSub9 PROMPT "18.05. - 26.08. => Combi LOW + AVARAGE + HIGH" ;
ACTION ( nPRICE := GET_PRICE( cTOD("18.05.2009"), cTOD("26.08.2009"), aSEASON ))
MENUITEM oSub10 PROMPT "23.07. - 14.09. => Combi AVARAGE + HIGH + LOW" ;
ACTION ( nPRICE := GET_PRICE( cTOD("23.07.2009"), cTOD("14.09.2009"), aSEASON ))
SEPARATOR
MENUITEM oSub11 PROMPT "START DIALOG" ;
ACTION ( PRICE_TEST(oWnd) )
ENDMENU
ENDMENU
RETURN oMenu
// ---------------------------
FUNCTION PRICE_TEST(oWnd)
LOCAL oDlg, oBtn1, oBtn2, oSay, oGET1, oGET2, oGET3
DEFINE DIALOG oDlg SIZE 300, 220 TITLE "Price Test"
@ 0.5, 3 SAY oSay PROMPT "Price = .T. only used for Price-calculation"
@ 2, 5 SAY oSay PROMPT "Start"
@ 2, 13 SAY oSay PROMPT "End"
@ 2, 19 SAY oSay PROMPT "Price ?"
@ 3.2, 2 GET oGet1 VAR dDAY1 OF oDlg SIZE 40, 15 PICTURE "##.##.####"
@ 3.2, 8 GET oGet2 VAR dDAY2 OF oDlg SIZE 40, 15 PICTURE "##.##.####"
@ 3.2, 16 CHECKBOX oGet3 VAR lPRICE PROMPT "&Price" SIZE 100, 20 OF oDlg
@ 4, 2 BUTTON oBtn1 PROMPT "Date-Test" size 50, 25 OF oDlg ;
ACTION ( oGet1:Refresh(), oGet2:Refresh(), oGet3:Refresh(), ;
IIF( lPRICE = .F., ( nPRICE := GET_DATE( dDAY1, dDAY2, aSEASON ), ;
MsgAlert( STR(nDAYS1) + CRLF + STR(nDAYS2), cSEASON ) ), ;
( nPRICE := GET_PRICE( dDAY1, dDAY2, aSEASON ) ) ) )
@ 4, 15 BUTTON oBtn2 PROMPT "Close" size 50, 25 OF oDlg ;
ACTION ( oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
RETURN ( NIL )
// --------------------------------------
FUNCTION GET_PRICE( dDAY1, dDAY2, aSEASON )
nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days
nCOUNT1 := 0 // LOW
nCOUNT2 := 0 // AVERAGE
nCOUNT3 := 0 // HIGHT
nCOUNT4 := 0 // LOW
nPRICE1 := 0 // LOW
nPRICE2 := 0 // AVERAGE
nPRICE3 := 0 // HIGHT
nPRICE4 := 0 // LOW
nDAYS := 0
nPRICE := 0
// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW
// -------- Days Start and End inside Season-Group -------------
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])
nCOUNT1 := 1 + ( dDAY2 - dDAY1 )
ENDIF
// ---------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
nCOUNT2 := 1 + (dDAY2 - dDAY1)
ENDIF
// ---------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. dDAY2 <= cTOD(aSEASON[3][2])
nCOUNT3 := 1 + (dDAY2 - dDAY1)
ENDIF
// ----------------------------------------------------------------------------
IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
nCOUNT4 := 1 + (dDAY2 - dDAY1)
ENDIF
ENDIF
// -------- Days Start in 1. Season and End in 4. Season -------------
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
nCOUNT1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
nCOUNT3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
nCOUNT4 := 1 + ( dDAY2 - cTOD(aSEASON[4][1]) )
ENDIF
// -------- Days Start in LOW Season and End in AVERAGE Season -------------
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2])
nCOUNT1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
nCOUNT2 := 1 + dDAY2 - ( cTOD(aSEASON[2][1]) )
ENDIF
// -------- Days Start in AVERAGE Season and End in HIGHT Season -------------
IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
nCOUNT3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF
// -------- Days Start in HIGHT Season and End in LOW Season -------------
IF dDAY1 >= cTOD(aSEASON[3][1]) .and. dDAY1 <= cTOD(aSEASON[3][2]) .and. ;
dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
nCOUNT3 := 1 + ( cTOD(aSEASON[3][2]) - dDAY1 )
nCOUNT4 := 1 + dDAY2 - ( cTOD(aSEASON[4][1]) )
ENDIF
// -------- Days Start in LOW Season and End in HIGHT Season -------------
IF dDAY1 >= cTOD(aSEASON[1][1]) .and. dDAY1 <= cTOD(aSEASON[1][2]) .and. ;
dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2])
nCOUNT1 := 1 + ( cTOD(aSEASON[1][2]) - dDAY1 )
nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - cTOD(aSEASON[2][1]) )
nCOUNT3 := 1 + dDAY2 - ( cTOD(aSEASON[3][1]) )
ENDIF
// -------- Days Start in AVERAGE Season and End in LOW Season -------------
IF dDAY1 >= cTOD(aSEASON[2][1]) .and. dDAY1 <= cTOD(aSEASON[2][2]) .and. ;
dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2])
nCOUNT2 := 1 + ( cTOD(aSEASON[2][2]) - dDAY1 )
nCOUNT3 := 1 + ( cTOD(aSEASON[3][2]) - cTOD(aSEASON[3][1]) )
nCOUNT4 := 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
nPRICE1 := nCOUNT1 * aSEASON[1][3]
nPRICE2 := nCOUNT2 * aSEASON[2][3]
nPRICE3 := nCOUNT3 * aSEASON[3][3]
nPRICE4 := nCOUNT4 * aSEASON[4][3]
nDAYS := nCOUNT1 + nCOUNT2 + nCOUNT3 + nCOUNT4
nPRICE := nPRICE1 + nPRICE2 + nPRICE3 + nPRICE4
MsgAlert( "LOW : " + STR(nCOUNT1) + " * " + LTRIM(STR(aSEASON[1][3])) + ;
" = " + LTRIM(STR(nPRICE1)) + CRLF + ;
"AVERAGE : " + STR(nCOUNT2) + " * " + LTRIM(STR(aSEASON[2][3])) + ;
" = " + LTRIM(STR(nPRICE2)) + CRLF + ;
"HIGHT : " + STR(nCOUNT3) + " * " + LTRIM(STR(aSEASON[3][3])) + ;
" = " + LTRIM(STR(nPRICE3)) + CRLF + ;
"LOW : " + STR(nCOUNT4) + " * " + LTRIM(STR(aSEASON[4][3])) + ;
" = " + LTRIM(STR(nPRICE4)) + CRLF + CRLF + ;
"Days complete : " + LTRIM( STR ( 1 + (dDAY2 - dDAY1) ) ) + CRLF + CRLF + ;
"Price : " + STR( nPRICE ) + " Euro" , cSEASON )
RETURN( nDAYS, nPRICE )
// --------------------------------------
FUNCTION GET_DATE(dDAY1, dDAY2, aSEASON)
nDAYS1 := 0 // Basic Days
nDAYS2 := 0 // next Season Days
// LOW
// aSEASON[1] := { "17.05", "27.06" } // LOW
// -------- 20.05 - 24.06 = 36 x LOW -------------------
IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. dDAY2 <= cTOD(aSEASON[1][2])
cSEASON := "LOW"
nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF
// LOW + AVERAGE
// aSEASON[1] := { "17.05", "27.06" } // LOW
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// ---------- 26.05 - 12.07 = 33 x LOW +15 x AVERAGE ------------
IF dDAY1 >= cTOD(aSEASON[1][1] ) .and. ;
( dDAY2 >= cTOD(aSEASON[2][1]) .and. dDAY2 <= cTOD(aSEASON[2][2]) )
cSEASON := "LOW+AVERAGE"
nDAYS1 := 1 + (cTOD(aSEASON[1][2]) - dDAY1)
nDAYS2 := 1 + (dDAY2 - cTOD(aSEASON[2][1]))
ENDIF
// AVERAGE
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
//------------- 29.06 - 22.07 = 25 x AVERAGE --------
IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. dDAY2 <= cTOD(aSEASON[2][2])
cSEASON := "AVERAGE"
nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF
//--------------------------------------------------------------
// AVERAGE + HIGHT
// aSEASON[2] := { "28.06", "25.07" } // AVERAGE
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------10.07 - 14.08 = 16 x AVERAGE + 20 x HIGHT -------
IF dDAY1 >= cTOD(aSEASON[2][1] ) .and. ;
( dDAY2 >= cTOD(aSEASON[3][1]) .and. dDAY2 <= cTOD(aSEASON[3][2]) )
cSEASON := "AVERAGE+HEIGHT"
nDAYS1 := 1 + (cTOD(aSEASON[2][2]) - dDAY1)
nDAYS2 := 1 + (dDAY2 - cTOD(aSEASON[3][1]))
ENDIF
// HIGHT
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// --------18.08 - 14.09 = 28 x HEIGHT -------------
IF cTOD(aSEASON[3][1] ) >= dDAY1 .and. cTOD(aSEASON[3][2]) <= dDAY2
cSEASON := "HIGH"
nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF
// HIGHT + LOW
// aSEASON[3] := { "26.07", "29.08" } // HIGHT
// aSEASON[4] := { "30.08", "20.09" } // LOW
// --------- 14.08 - 16.09 = 16 x HIGHT + 17 x LOW ------
IF dDAY1 >= cTOD(aSEASON[3][1] ) .and. ;
( dDAY2 >= cTOD(aSEASON[4][1]) .and. dDAY2 <= cTOD(aSEASON[4][2]) )
cSEASON := "HIGH+LOW"
nDAYS1 := 1 + (cTOD(aSEASON[3][2]) - dDAY1)
nDAYS2 := 1 + (dDAY2 - cTOD(aSEASON[4][1]))
ENDIF
// ----------------------------------------------------------------
// LOW
// aSEASON[4] := { "30.08", "20.09" } // LOW
// ---------------- 30.08 - 15.09 = 16 x LOW ----------------
IF dDAY1 >= cTOD(aSEASON[4][1] ) .and. dDAY2 <= cTOD(aSEASON[4][2])
cSEASON := "LOW"
nDAYS1 := 1 + (dDAY2 - dDAY1)
ENDIF
RETURN( nDAYS1, nDAYS2, cSEASON )