home *** CD-ROM | disk | FTP | other *** search
/ Program Metropolis - Software Boutique 95 / SOFTWARECD.iso / project4 / disk6 / gridfunc.ba_ / gridfunc.bin
Encoding:
Text File  |  1994-04-14  |  16.0 KB  |  549 lines

  1. '  GRIDFUNC.BAS  - Contains all the major Grid "properties", "methods",
  2. 'and validation functions.
  3. '
  4.  
  5. Option Explicit
  6. Option Compare Text
  7.  
  8. ' This array determines which cells in the grid can be edited.  Each
  9. 'cell in the grid has a corresponding entry in the CellEditTable.
  10. 'Procedures that write values to the grid check the CellEditTable to
  11. 'see if a given cell is one that is allowed to be changed.  A "True"
  12. 'entry indicates that editing is allowed; "False" prevents editing.
  13. Dim mabCellEditTable() As Integer
  14.  
  15. ' This array is similar to mabCellEditTable, except that it indicates
  16. 'whether the user has changed the contents of a given cell.
  17. Dim mabCellChangedTable() As Integer
  18.  
  19. ' True if the grid is empty
  20. Dim mbGridEmpty As Integer
  21.  
  22.  
  23. ' Grid title row (column headings)
  24.  Const TITLE_ROW = 0
  25.  
  26. '  ColAlignment,FixedAlignment Properties
  27.  Const GRID_ALIGNLEFT = 0
  28.  Const GRID_ALIGNRIGHT = 1
  29.  Const GRID_ALIGNCENTER = 2
  30.  
  31. '  Fillstyle Property
  32.  Const GRID_SINGLE = 0
  33.  Const GRID_REPEAT = 1
  34.  
  35. '  Contains the information from a grid row after the TInfo form has
  36. 'been edited by the user.
  37. Type utRowRec
  38.    nAUID As Integer              ' unique assignment id
  39.    nTID As Integer               ' task id
  40.    nActWork As Integer           ' actual resource work
  41.    nRemWork As Integer           ' remaining resource work
  42.    nAddWork As Integer           ' additional work
  43.    bAddWorkDirty As Integer      ' indicates if user edited addwork field
  44.    nETC As Integer               ' estimated work remaining
  45.    bETCDirty As Integer          ' indicates if user edited etc field
  46.    dtStart As Variant            ' resource start date on task
  47.    bStartDirty As Integer        ' indicates if user edited start field
  48.    dtFinish As Variant           ' resource finish date on task
  49.    bFinishDirty As Integer       ' indicates if user edited finish field
  50. End Type
  51.  
  52. '  This structure is used for the Edit Undo buffer in frmTaskInfo.
  53. Type utUndo
  54.    sUndo As String         ' string to restore.
  55.    nRow As Integer         ' nRow and nCol store the grid coordinates
  56.    nCol As Integer         'for the value in sUndo.
  57.    nTag As Integer          ' type of control that contained the undo string. 0 = contents invalid, 1 = grid, 2 = textbox
  58. End Type
  59.  
  60. ' Makes an entry in the CellEditTable for the cell specified by iCol, iRow.
  61. 'The value of bEdit determines whether or not the specified cell may be
  62. 'edited; True = allow editing, False = don't allow editing.
  63. '
  64. 'If iCol = -1 and iRow = -1, then AllowCellEditing uses the coordinates
  65. 'of the currently-selected cell in the grid.
  66. '
  67. Sub AllowCellEditing (ByVal iCol As Integer, ByVal iRow As Integer, bEdit As Integer)
  68.  
  69.    
  70.    Dim F As frmTInfo
  71.    Set F = frmTInfo
  72.  
  73.    ' Check the args
  74.    Select Case iCol
  75.       Case -1
  76.          iCol = F!Grid.SelStartCol
  77.       Case AUID To FINISH
  78.          'ok
  79.       Case Else
  80.          'subscript out of range
  81.          Error 9
  82.    End Select
  83.    Select Case iRow
  84.       Case -1
  85.          iRow = F!Grid.SelStartRow
  86.       Case 1 To UBound(mabCellEditTable, 2)
  87.          'ok
  88.       Case Else
  89.          'subscript out of range
  90.          Error 9
  91.    End Select
  92.  
  93.    mabCellEditTable(iCol, iRow) = bEdit
  94.  
  95. End Sub
  96.  
  97. Function CellIsDirty (ByVal iCol As Integer, ByVal iRow As Integer) As Integer
  98.  
  99.    Dim F As frmTInfo
  100.    Set F = frmTInfo
  101.  
  102.    ' Check the args
  103.    Select Case iCol
  104.       Case -1
  105.          iCol = F!Grid.SelStartCol
  106.       Case ADDWORK To FINISH
  107.          'ok
  108.       Case Else
  109.          'subscript out of range
  110.          Error 9
  111.    End Select
  112.    Select Case iRow
  113.       Case -1
  114.          iRow = F!Grid.SelStartRow
  115.       Case 1 To UBound(mabCellChangedTable, 2)
  116.          'ok
  117.       Case Else
  118.          'subscript out of range
  119.          Error 9
  120.    End Select
  121.    CellIsDirty = mabCellChangedTable(iCol, iRow)
  122.  
  123. End Function
  124.  
  125. ' Returns the edit status from the CellEditTable for the given cell
  126. 'coordinates.  If iCol = -1 and iRow = -1, then the coordinates of the
  127. 'currently-selected cell in the grid will be used.
  128. '
  129. Function CellIsEditable (iCol, iRow) As Integer
  130.  
  131.    Dim F As frmTInfo
  132.    Set F = frmTInfo
  133.  
  134.    ' Check the args
  135.    Select Case iCol
  136.       Case -1
  137.          iCol = F!Grid.SelStartCol
  138.       Case AUID To FINISH
  139.          'ok
  140.       Case Else
  141.          'subscript out of range
  142.          Error 9
  143.    End Select
  144.    Select Case iRow
  145.       Case -1
  146.          iRow = F!Grid.SelStartRow
  147.       Case 1 To UBound(mabCellEditTable, 2)
  148.          'ok
  149.       Case Else
  150.          'subscript out of range
  151.          Error 9
  152.    End Select
  153.  
  154.    CellIsEditable = mabCellEditTable(iCol, iRow)
  155.  
  156. End Function
  157.  
  158. '  Validates entries in the grid.  Returns True if the entry is valid;
  159. 'False if not.
  160. '
  161. Function CheckEdit () As Integer
  162.  
  163.    Dim F As frmTInfo
  164.    Dim iRow As Integer
  165.    Dim iCol As Integer
  166.    Dim sGridText As String
  167.    Dim iTmpCol As Integer
  168.    Dim dtStart As Variant
  169.    Dim dtFinish As Variant
  170.    Dim tmp As Variant
  171.    Dim nAddWork As Integer
  172.    Dim nETC As Integer
  173.  
  174.    On Error GoTo CheckEditError
  175.    
  176.    Set F = frmTInfo
  177.    iRow = F!Grid.Row
  178.    iCol = F!Grid.Col
  179.    sGridText = F!Grid.Text
  180.  
  181.    Select Case iCol
  182.       Case ADDWORK
  183. 2010     nAddWork = goProjApp.DurationValue(sGridText)
  184.          Select Case nAddWork
  185.             Case Is < 0
  186.             ' Invalid entry.
  187.                Beep
  188.                MsgBox MB_LESS_THAN_ZERO, MB_ICONEXCLAMATION, MB_TIMESHEET
  189.                CheckEdit = False
  190.             Case Is = 0
  191.                ' Copy remaining work into ETC.
  192.                F!Grid.Col = REMWORK
  193.                tmp = F!Grid.Text
  194.                F!Grid.Col = ETC
  195.                F!Grid.Text = tmp
  196.                F!Grid.Col = iCol
  197.                CheckEdit = True
  198.             Case Is > 0
  199.                ' Subtract additional hours from remaining work and put the
  200.                'result into ETC.
  201.                F!Grid.Col = ETC
  202.                tmp = goProjApp.DurationValue(F!Grid.Text)
  203.                tmp = tmp - nAddWork
  204.             
  205.                If tmp > 0 Then
  206.                   F!Grid.Text = goProjApp.DurationFormat(tmp, gnDefWorkUnit)
  207.                Else
  208.                   F!Grid.Text = "0" + gsDefWorkUnit
  209.                   AllowCellEditing FINISH, -1, True
  210.                End If
  211.                F!Grid.Col = iCol
  212.                CheckEdit = True
  213.          End Select
  214.       Case ETC
  215. 2020    nETC = goProjApp.DurationValue(sGridText)
  216.         Select Case nETC
  217.             Case Is < 0
  218.             ' Invalid entry.
  219.                Beep
  220.                MsgBox MB_LESS_THAN_ZERO, MB_OK + MB_ICONEXCLAMATION, MB_TIMESHEET
  221.                CheckEdit = False
  222.             Case Is = 0
  223.             ' If ETC = 0 then allow editing on finish
  224.                AllowCellEditing FINISH, -1, True
  225.                CheckEdit = True
  226.             Case Is > 0
  227.             ' A valid entry... probably.
  228.                AllowCellEditing FINISH, -1, False
  229.                CheckEdit = True
  230.             Case Else
  231.             ' Invalid entry.
  232.                Beep
  233.                MsgBox MB_UNRECOGNIZED_ENTRY, MB_OK + MB_ICONEXCLAMATION, MB_TIMESHEET
  234.                CheckEdit = False
  235.          End Select
  236.       Case Start
  237. 2030     Select Case DateValue(sGridText)
  238.             Case Is >= DateValue(goActiveProj.Start)
  239.                CheckEdit = True
  240.             Case Else
  241.                Beep
  242.                MsgBox MB_START_NOT_VALID, MB_OK + MB_ICONEXCLAMATION, MB_TIMESHEET
  243.                CheckEdit = False
  244.          End Select
  245.       Case FINISH
  246.          ' Check to make sure that the finish is greater than the start.
  247. 2040     dtFinish = DateValue(sGridText)
  248.          F!Grid.Col = Start
  249. 2050     dtStart = DateValue(F!Grid.Text)
  250.          If DateDiff("d", dtStart, dtFinish) < 0 Then
  251.             Beep
  252.             MsgBox MB_FINISH_NOT_VALID, MB_OK + MB_ICONEXCLAMATION, MB_TIMESHEET
  253.             CheckEdit = False
  254.          Else
  255.             CheckEdit = True
  256.          End If
  257.          F!Grid.Col = iCol
  258.    End Select
  259. Exit Function
  260.  
  261. CheckEditError:
  262.    Select Case Erl
  263.       Case 2010, 2020
  264.          ' Invalid entry.
  265.          Beep
  266.          MsgBox MB_UNRECOGNIZED_ENTRY, MB_OK + MB_ICONEXCLAMATION, MB_TIMESHEET
  267.          CheckEdit = False
  268.       Case 2030, 2040
  269.          ' bad date format
  270.          Beep
  271.          MsgBox MB_BAD_DATE_FORMAT, MB_ICONEXCLAMATION, MB_TIMESHEET
  272.          CheckEdit = False
  273.       Case 2050
  274.          ' bad date format
  275.          F!Grid.Col = iTmpCol
  276.          Beep
  277.          MsgBox MB_BAD_DATE_FORMAT, MB_ICONEXCLAMATION, MB_TIMESHEET
  278.          CheckEdit = False
  279.       Case Else
  280.          ' unanticipated error
  281.          CheckEdit = False
  282.    End Select
  283.    Exit Function
  284.  
  285. End Function
  286.  
  287. '  Returns the count of rows placed into the autInfo array.  Modifies
  288. 'the autInfo array by redim'ing it.
  289. '
  290. Function GetGridInfo (autInfo() As utRowRec) As Integer
  291.    
  292.    Dim oApp As object               ' Winproj application object.
  293.    Dim F As frmTInfo                ' frmTInfo form object.
  294.    Dim nRows As Integer             ' The count of rows in the grid.
  295.    Dim iRow As Integer              ' Loop counter, used to index grid rows.
  296.    Dim iCol As Integer              ' Loop counter, used it index grid columns.
  297.    Dim vntGVal As Variant           ' Text or value from the grid.
  298.    Dim tmp As Variant               ' Scratch variable used to store sundry values.
  299.    
  300.    On Error GoTo GetGridInfoError
  301.  
  302.    Set oApp = goProjApp
  303.    Set F = frmTInfo
  304.    
  305.    ' Check to see if the grid is empty, if so, exit.
  306.    If mbGridEmpty Then
  307.       GetGridInfo = 0
  308.       Exit Function
  309.    End If
  310.  
  311.    nRows = F!Grid.Rows
  312.    ReDim autInfo(1 To nRows - 1) As utRowRec
  313.    For iRow = 1 To nRows - 1
  314.       For iCol = AUID To FINISH
  315.          F!Grid.Row = iRow
  316.          F!Grid.Col = iCol
  317.          vntGVal = F!Grid.Text
  318.          Select Case iCol
  319.             Case AUID
  320.                autInfo(iRow).nAUID = vntGVal
  321.             Case TASKID
  322.                autInfo(iRow).nTID = vntGVal
  323.             Case TASKNAME
  324.                ' We don't need the task name.
  325.             Case ACTWORK
  326.                tmp = oApp.DurationValue(vntGVal)
  327.                autInfo(iRow).nActWork = CInt(tmp)
  328.             Case REMWORK
  329.                tmp = oApp.DurationValue(vntGVal)
  330.                autInfo(iRow).nRemWork = CInt(tmp)
  331.             Case ADDWORK
  332.                tmp = oApp.DurationValue(vntGVal)
  333.                autInfo(iRow).nAddWork = CInt(tmp)
  334.                autInfo(iRow).bAddWorkDirty = CellIsDirty(iCol, iRow)
  335.             Case ETC
  336.                tmp = oApp.DurationValue(vntGVal)
  337.                autInfo(iRow).nETC = CInt(tmp)
  338.                autInfo(iRow).bETCDirty = CellIsDirty(iCol, iRow)
  339.             Case Start
  340.                autInfo(iRow).dtStart = vntGVal
  341.                autInfo(iRow).bStartDirty = CellIsDirty(iCol, iRow)
  342.             Case FINISH
  343.                autInfo(iRow).dtFinish = vntGVal
  344.                autInfo(iRow).bFinishDirty = CellIsDirty(iCol, iRow)
  345.          End Select
  346.       Next iCol
  347.    Next iRow
  348.    GetGridInfo = nRows
  349.    
  350. Exit Function
  351.  
  352. GetGridInfoError:
  353.    Beep
  354.    MsgBox MB_GENERIC_ERROR + " Err#" + Str$(Err), MB_ICONEXCLAMATION, MB_TIMESHEET
  355.    TerminateApplication
  356.  
  357. End Function
  358.  
  359. Sub GridAddRow (utRowInfo As utAssignment)
  360.  
  361.    Dim iCurRow As Integer
  362.    Dim oApp As object
  363.    Dim F As frmTInfo
  364.    Set F = frmTInfo
  365.    Set oApp = goProjApp
  366.  
  367.    If mbGridEmpty Then
  368.       F!Grid.Row = 1
  369.    Else
  370.       F!Grid.Rows = F!Grid.Rows + 1
  371.       F!Grid.Row = F!Grid.Rows - 1
  372.       ReDim Preserve mabCellEditTable(AUID To FINISH, TITLE_ROW To F!Grid.Row) As Integer
  373.       ReDim Preserve mabCellChangedTable(ADDWORK To FINISH, 0 To F!Grid.Row) As Integer
  374.    End If
  375.    
  376.    iCurRow = F!Grid.Row
  377.  
  378.    F!Grid.Col = AUID
  379.    F!Grid.Text = utRowInfo.nAUID
  380.    AllowCellEditing AUID, iCurRow, False
  381.  
  382.    F!Grid.Col = TASKID
  383.    F!Grid.Text = utRowInfo.nTID
  384.    AllowCellEditing TASKID, iCurRow, False
  385.    
  386.    F!Grid.Col = TASKNAME
  387.    F!Grid.Text = utRowInfo.sTName
  388.    AllowCellEditing TASKNAME, iCurRow, False
  389.  
  390.    F!Grid.Col = ACTWORK
  391.    F!Grid.Text = oApp.DurationFormat(utRowInfo.nActWork, gnDefWorkUnit)
  392.    AllowCellEditing ACTWORK, iCurRow, False
  393.  
  394.    F!Grid.Col = REMWORK
  395.    F!Grid.Text = oApp.DurationFormat(utRowInfo.nRemWork, gnDefWorkUnit)
  396.    AllowCellEditing REMWORK, iCurRow, False
  397.  
  398.    F!Grid.Col = ADDWORK
  399.    F!Grid.Text = "0"
  400.    AllowCellEditing ADDWORK, iCurRow, True
  401.    MarkCellDirty ADDWORK, iCurRow, False
  402.    
  403.    F!Grid.Col = ETC
  404.    F!Grid.Text = oApp.DurationFormat(utRowInfo.nRemWork, gnDefWorkUnit)
  405.    AllowCellEditing ETC, iCurRow, True
  406.    MarkCellDirty ETC, iCurRow, False
  407.  
  408.    F!Grid.Col = Start
  409.    F!Grid.Text = utRowInfo.dtStart
  410.    ' Allow the user to enter an actual start date only if
  411.    'actual work is zero.
  412.    If utRowInfo.nActWork > 0 Then
  413.       AllowCellEditing Start, iCurRow, False
  414.    Else
  415.       AllowCellEditing Start, iCurRow, True
  416.    End If
  417.    MarkCellDirty Start, iCurRow, False
  418.  
  419.    F!Grid.Col = FINISH
  420.    F!Grid.Text = utRowInfo.dtFinish
  421.    ' Allow the user to enter an actual finish date only if
  422.    'remaining work is zero.
  423.    If utRowInfo.nRemWork > 0 Then
  424.       AllowCellEditing FINISH, iCurRow, False
  425.    Else
  426.       AllowCellEditing FINISH, iCurRow, True
  427.    End If
  428.    MarkCellDirty FINISH, iCurRow, False
  429.  
  430.    mbGridEmpty = False
  431.    
  432. End Sub
  433.  
  434. ' Clears the current contents of the grid, and sets the rows property
  435. 'back to 2.  Also alters mabCellEditTable and mbGridEmtpy. Does not
  436. 'affect the column titles.
  437. '
  438. Sub GridReset ()
  439.  
  440.    Dim iCol As Integer, iRow As Integer, i As Integer
  441.    Dim F As frmTInfo
  442.    Set F = frmTInfo
  443.  
  444.    F!Grid.Rows = 2
  445.    F!Grid.Row = 1
  446.    For i = AUID To FINISH
  447.       F!Grid.Col = i
  448.       F!Grid.Text = ""
  449.    Next i
  450.  
  451.    ' Update the Cell Edit Table
  452.    ReDim mabCellEditTable(AUID To FINISH, TITLE_ROW To 1) As Integer
  453.    For iCol = AUID To FINISH
  454.       For iRow = TITLE_ROW To 1
  455.          mabCellEditTable(iCol, iRow) = False
  456.       Next iRow
  457.    Next iCol
  458.  
  459.    ' Update the Cell Changed Table
  460.    ReDim mabCellChangedTable(ADDWORK To FINISH, TITLE_ROW To 1) As Integer
  461.    For iCol = ADDWORK To FINISH
  462.       For iRow = TITLE_ROW To 1
  463.          mabCellChangedTable(iCol, iRow) = False
  464.       Next iRow
  465.    Next iCol
  466.  
  467.    ' Indicate that the grid is now empty
  468.    mbGridEmpty = True
  469.  
  470. End Sub
  471.  
  472. ' Sets the column headings and column widths for the Grid control.
  473. 'Also sets the initial values in mabCellEditTable and mbGridEmtpy.
  474. 'InitializeGrid is called from the TInfo form load procedure.
  475. '
  476. Sub InitializeGrid ()
  477.  
  478. Dim F As frmTInfo, iGCol As Integer, iCol As Integer, iRow As Integer
  479. Set F = frmTInfo
  480.  
  481. Const TITLE_ROW = 0
  482.  
  483.    F!Grid.Row = TITLE_ROW
  484.    F!Grid.Col = AUID
  485.    F!Grid.Text = "auid"
  486.    F!Grid.Col = TASKID
  487.    F!Grid.Text = GRID_TASKID
  488.    F!Grid.Col = TASKNAME
  489.    F!Grid.Text = GRID_TASKNAME
  490.    F!Grid.Col = ACTWORK
  491.    F!Grid.Text = GRID_ACTWORK
  492.    F!Grid.Col = REMWORK
  493.    F!Grid.Text = GRID_REMWORK
  494.    F!Grid.Col = ADDWORK
  495.    F!Grid.Text = GRID_ADDWORK
  496.    F!Grid.Col = ETC
  497.    F!Grid.Text = GRID_ETC
  498.    F!Grid.Col = Start
  499.    F!Grid.Text = GRID_START
  500.    F!Grid.Col = FINISH
  501.    F!Grid.Text = GRID_FINISH
  502.  
  503.    F!Grid.RowHeight(TITLE_ROW) = 500
  504.  
  505.    F!Grid.ColWidth(AUID) = 1  'This column is not visible to the user.
  506.    F!Grid.ColWidth(TASKID) = 500
  507.    F!Grid.ColWidth(TASKNAME) = 2200
  508.    For iGCol = ACTWORK To FINISH
  509.       F!Grid.ColWidth(iGCol) = 900
  510.    Next iGCol
  511.  
  512.    
  513.    ' Indicate that the grid is empty.
  514.    mbGridEmpty = True
  515.  
  516.    F!Grid.Row = 1
  517.    F!Grid.Col = ADDWORK
  518. End Sub
  519.  
  520. Sub MarkCellDirty (ByVal iCol As Integer, ByVal iRow As Integer, bDirty As Integer)
  521.  
  522.    Dim F As frmTInfo
  523.    Set F = frmTInfo
  524.  
  525.    ' Check the args
  526.    Select Case iCol
  527.       Case -1
  528.          iCol = F!Grid.SelStartCol
  529.       Case ADDWORK To FINISH
  530.          'ok
  531.       Case Else
  532.          'subscript out of range
  533.          Error 9
  534.    End Select
  535.    Select Case iRow
  536.       Case -1
  537.          iRow = F!Grid.SelStartRow
  538.       Case 1 To UBound(mabCellChangedTable, 2)
  539.          'ok
  540.       Case Else
  541.          'subscript out of range
  542.          Error 9
  543.    End Select
  544.    
  545.    mabCellChangedTable(iCol, iRow) = bDirty
  546.    
  547. End Sub
  548.  
  549.