home *** CD-ROM | disk | FTP | other *** search
/ Total C++ 2 / TOTALCTWO.iso / vfp5.0 / vfp / samples / solution / reports / datepick.prg < prev    next >
Encoding:
Text File  |  1996-08-21  |  5.7 KB  |  236 lines

  1.  
  2. *!* First we create an instance of the form class defined below
  3. *!* (This is the form that allows the user to pick a start and end date)
  4. oFrmDate = CREATEOBJECT("frmdatepick")
  5.  
  6. *!* Now, we show it.  Since the form is modal, execution suspends
  7. *!* until the form is released (and the user has selected a valid
  8. *!* start and end date)
  9. oFrmDate.Show
  10.  
  11. *!* Note that there is no error checking here because the form is
  12. *!* designed so that the user cannot exit with invalid data returned.
  13.  
  14. *!* The form has put the user's selection into two public variables
  15. *!* (dStart_date and dEnd_date), so now we can just release the form
  16. *!* and return back to the report.
  17. RELEASE oFrmDate
  18. RETURN
  19.  
  20.  
  21. PUBLIC ofrmdatepick
  22.  
  23. ofrmdatepick=CREATEOBJECT("frmdatepick")
  24. ofrmdatepick.Show()
  25. RETURN
  26.  
  27.  
  28.  
  29. **************************************************
  30. *-- Form:         frmdatepick 
  31. *-- ParentClass:  form
  32. *-- BaseClass:    form
  33. *
  34. DEFINE CLASS frmdatepick AS form
  35.  
  36.  
  37.     Height = 101
  38.     Width = 335
  39.     DoCreate = .T.
  40.     AutoCenter = .T.
  41.     BorderStyle = 2
  42.     Caption = "Date Range to Print"
  43.     Closable = .F.
  44.     MaxButton = .F.
  45.     MinButton = .F.
  46.     WindowType = 1
  47.     Name = "frmdatepick"
  48.  
  49.  
  50.     ADD OBJECT label1 AS label WITH ;
  51.         AutoSize = .T., ;
  52.         FontName = "MS Sans Serif", ;
  53.         FontSize = 8, ;
  54.         Caption = "Select dates to print a range of invoices.", ;
  55.         Height = 15, ;
  56.         Left = 10, ;
  57.         Top = 10, ;
  58.         Width = 196, ;
  59.         TabIndex = 1, ;
  60.         Name = "Label1"
  61.  
  62.  
  63.     ADD OBJECT label2 AS label WITH ;
  64.         AutoSize = .T., ;
  65.         FontName = "MS Sans Serif", ;
  66.         FontSize = 8, ;
  67.         Caption = "\<From:", ;
  68.         Height = 15, ;
  69.         Left = 10, ;
  70.         Top = 39, ;
  71.         Width = 28, ;
  72.         TabIndex = 2, ;
  73.         Name = "Label2"
  74.  
  75.  
  76.     ADD OBJECT cbofrommonth AS combobox WITH ;
  77.         FontName = "MS Sans Serif", ;
  78.         FontSize = 8, ;
  79.         BoundColumn = 2, ;
  80.         ColumnCount = 2, ;
  81.         ColumnWidths = "72,0", ;
  82.         RowSourceType = 1, ;
  83.         RowSource = "Jan,1,Feb,2,Mar,3,Apr,4,May,5,Jun,6,Jul,7,Aug,8,Sep,9,Oct,10,Nov,11,Dec,12", ;
  84.         Value = (STR(1)), ;
  85.         Height = 23, ;
  86.         Left = 49, ;
  87.         Style = 2, ;
  88.         TabIndex = 3, ;
  89.         Top = 35, ;
  90.         Width = 72, ;
  91.         Name = "cboFromMonth"
  92.  
  93.  
  94.     ADD OBJECT label3 AS label WITH ;
  95.         AutoSize = .T., ;
  96.         FontName = "MS Sans Serif", ;
  97.         FontSize = 8, ;
  98.         Caption = "\<To:", ;
  99.         Height = 15, ;
  100.         Left = 10, ;
  101.         Top = 70, ;
  102.         Width = 18, ;
  103.         TabIndex = 5, ;
  104.         Name = "Label3"
  105.  
  106.  
  107.     ADD OBJECT cbotomonth AS combobox WITH ;
  108.         FontName = "MS Sans Serif", ;
  109.         FontSize = 8, ;
  110.         BoundColumn = 2, ;
  111.         ColumnCount = 2, ;
  112.         ColumnWidths = "72,0", ;
  113.         RowSourceType = 1, ;
  114.         RowSource = "Jan,1,Feb,2,Mar,3,Apr,4,May,5,Jun,6,Jul,7,Aug,8,Sep,9,Oct,10,Nov,11,Dec,12", ;
  115.         Value = (STR(2)), ;
  116.         Height = 23, ;
  117.         Left = 49, ;
  118.         Style = 2, ;
  119.         TabIndex = 6, ;
  120.         Top = 66, ;
  121.         Width = 72, ;
  122.         Name = "cboToMonth"
  123.  
  124.  
  125.     ADD OBJECT cmdok AS commandbutton WITH ;
  126.         Top = 10, ;
  127.         Left = 254, ;
  128.         Height = 23, ;
  129.         Width = 72, ;
  130.         FontName = "MS Sans Serif", ;
  131.         FontSize = 8, ;
  132.         Caption = "OK", ;
  133.         Default = .F., ;
  134.         TabIndex = 8, ;
  135.         Name = "cmdOK"
  136.  
  137.  
  138.     ADD OBJECT cbofromyear AS combobox WITH ;
  139.         FontName = "MS Sans Serif", ;
  140.         FontSize = 8, ;
  141.         RowSourceType = 1, ;
  142.         RowSource = "1992,1993,1994,1995", ;
  143.         Value = (STR(1994)), ;
  144.         Height = 23, ;
  145.         Left = 128, ;
  146.         TabIndex = 4, ;
  147.         Top = 35, ;
  148.         Width = 100, ;
  149.         Name = "cboFromYear"
  150.  
  151.  
  152.     ADD OBJECT cbotoyear AS combobox WITH ;
  153.         FontName = "MS Sans Serif", ;
  154.         FontSize = 8, ;
  155.         RowSourceType = 1, ;
  156.         RowSource = "1992,1993,1994,1995", ;
  157.         Value = (STR(1994)), ;
  158.         Height = 23, ;
  159.         Left = 128, ;
  160.         TabIndex = 7, ;
  161.         Top = 66, ;
  162.         Width = 100, ;
  163.         Name = "cboToYear"
  164.  
  165.     PROCEDURE cmdok.Click
  166.         #DEFINE FROM_GREATER_TO_LOC "The from date must be less than or equal to the to date."
  167.         #DEFINE FROM_MONTH_LOC "You must select a month to start."
  168.         #DEFINE FROM_YEAR_LOC "You must select or enter a year to start."
  169.         #DEFINE TO_MONTH_LOC "You must select a month to end."
  170.         #DEFINE TO_YEAR_LOC "You must select or enter a year to end."
  171.  
  172.         PUBLIC dStart_Date,dEnd_Date
  173.  
  174.         *!* First, get the values the user entered into the combo boxes.
  175.         nFromMonth = VAL(THISFORM.cboFromMonth.value)
  176.         nFromYear = VAL(THISFORM.cboFromYear.value)
  177.         nToMonth = VAL(THISFORM.cboToMonth.value)
  178.         nToYear = VAL(THISFORM.cboToYear.value)
  179.  
  180.         *!* We need to check to make sure that the user entered a value
  181.         *!* into all four combo boxes; If not, send them back to try again.
  182.         DO CASE
  183.             CASE EMPTY(nFromMonth)
  184.                 MESSAGEBOX(FROM_MONTH_LOC)
  185.                 THISFORM.cboFromMonth.SetFocus
  186.                 RETURN
  187.             CASE EMPTY(nFromYear)
  188.                 MESSAGEBOX(FROM_YEAR_LOC)
  189.                 THISFORM.cboFromYear.SetFocus
  190.                 RETURN
  191.             CASE EMPTY(nToMonth)
  192.                 MESSAGEBOX(TO_MONTH_LOC)
  193.                 THISFORM.cboToMonth.SetFocus
  194.                 RETURN
  195.             CASE EMPTY(nToYear)
  196.                 MESSAGEBOX(TO_YEAR_LOC)
  197.                 THISFORM.cboToYear.SetFocus
  198.                 RETURN
  199.         ENDCASE
  200.  
  201.         *!* We need to check to make sure the end date selected is 
  202.         *!* after the start date.
  203.         IF (nFromYear > nToYear) OR (nFromYear = nToYear AND ;
  204.             nFromMonth > nToMonth) THEN
  205.             MESSAGEBOX(FROM_GREATER_TO_LOC)
  206.             THISFORM.cboFromYear.SetFocus
  207.             RETURN
  208.         ENDIF
  209.  
  210.         *!* For the end date, we need to figure out the last day of the month
  211.         *!* that was selected.
  212.         *!* (Note that the one flaw in this CASE statement is that it doesn't
  213.         *!* take into account leap year.)
  214.         DO CASE
  215.             CASE nToMonth = 2
  216.                 nEndDay = 28
  217.             CASE INLIST(nToMonth,4,6,9,11)
  218.                 nEndDay = 30
  219.             OTHERWISE
  220.                 nEndDay = 31
  221.         ENDCASE
  222.  
  223.         *!* Finally, we can set up our start and end date public variables
  224.         dStart_Date = CTOD(STR(nFromMonth) + "/01/" + STR(nFromYear))
  225.  
  226.         dEnd_Date = CTOD(STR(nToMonth) + "/" + STR(nEndDay) + "/" + STR(nToYear))
  227.  
  228.         THISFORM.Release
  229.     ENDPROC
  230.  
  231.  
  232. ENDDEFINE
  233. *
  234. *-- EndDefine: frmdatepick
  235. **************************************************
  236.