home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l405 / 4.ddi / DYNAGRID.FR_ / DYNAGRID.bin (.txt)
Encoding:
Visual Basic Form  |  1993-04-28  |  17.4 KB  |  580 lines

  1. VERSION 2.00
  2. Begin Form fGridFrm 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   3105
  5.    ClientLeft      =   930
  6.    ClientTop       =   3585
  7.    ClientWidth     =   6690
  8.    Height          =   3510
  9.    Icon            =   DYNAGRID.FRX:0000
  10.    Left            =   870
  11.    LinkTopic       =   "Form1"
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   3096
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   6708
  16.    Tag             =   "Dynaset"
  17.    Top             =   3240
  18.    Width           =   6810
  19.    Begin Grid cGrid 
  20.       FixedCols       =   0
  21.       FixedRows       =   0
  22.       Height          =   2412
  23.       Left            =   0
  24.       TabIndex        =   0
  25.       Top             =   480
  26.       Width           =   6732
  27.    End
  28.    Begin PictureBox ViewButtons 
  29.       BackColor       =   &H00C0C0C0&
  30.       BorderStyle     =   0  'None
  31.       Height          =   375
  32.       Left            =   0
  33.       ScaleHeight     =   372
  34.       ScaleMode       =   0  'User
  35.       ScaleWidth      =   5171.607
  36.       TabIndex        =   1
  37.       Top             =   24
  38.       Width           =   5175
  39.       Begin CommandButton SortButton 
  40.          Caption         =   "&Sort"
  41.          Height          =   372
  42.          Left            =   3720
  43.          TabIndex        =   9
  44.          Top             =   0
  45.          Width           =   612
  46.       End
  47.       Begin CommandButton FilterButton 
  48.          Caption         =   "Fil&ter"
  49.          Height          =   372
  50.          Left            =   3120
  51.          TabIndex        =   8
  52.          Top             =   0
  53.          Width           =   612
  54.       End
  55.       Begin CommandButton RefreshButton 
  56.          Caption         =   "&Redo"
  57.          Height          =   372
  58.          Left            =   2520
  59.          TabIndex        =   7
  60.          Top             =   0
  61.          Width           =   612
  62.       End
  63.       Begin CommandButton CloseButton 
  64.          Cancel          =   -1  'True
  65.          Caption         =   "&Close"
  66.          Height          =   372
  67.          Left            =   4320
  68.          TabIndex        =   6
  69.          Top             =   0
  70.          Width           =   612
  71.       End
  72.       Begin CommandButton MoreButton 
  73.          Caption         =   "&More"
  74.          Height          =   372
  75.          Left            =   1320
  76.          TabIndex        =   5
  77.          Top             =   0
  78.          Width           =   612
  79.       End
  80.       Begin CommandButton NextButton 
  81.          Caption         =   "&Next"
  82.          Height          =   372
  83.          Left            =   120
  84.          TabIndex        =   4
  85.          Top             =   0
  86.          Width           =   612
  87.       End
  88.       Begin CommandButton FirstButton 
  89.          Caption         =   "&First"
  90.          Height          =   372
  91.          Left            =   720
  92.          TabIndex        =   3
  93.          Top             =   0
  94.          Width           =   612
  95.       End
  96.       Begin CommandButton FindButton 
  97.          Caption         =   "F&ind"
  98.          Height          =   372
  99.          Left            =   1920
  100.          TabIndex        =   2
  101.          Top             =   0
  102.          Width           =   612
  103.       End
  104.    End
  105. Option Explicit
  106. 'form variables
  107. 'Dim FDS As dynaset         'current form's dynaset
  108. Dim FDS As snapshot        'current form's snapshot
  109. Dim FDynSt As String       'dynaset open string
  110. Dim FTblName As String     'form dynaset table name
  111. Dim FCurrentRow As Long    'current row in dynaset
  112. Dim FGridRow As Integer    'current grid row
  113. Dim FNotFound As Integer   'find not found flag
  114. Dim FFindForm As New fFind 'find form
  115. Dim FNumbRows As Long      'total number of rows in table
  116. Dim FDynaString As String  'dynaset open string
  117. Sub cGrid_DblClick ()
  118.   Dim r As Integer       'return from execute sql
  119.   Dim fn As String       'field name
  120.   On Error GoTo ZoomErr
  121.   r = cGrid.Row
  122.   cGrid.Row = 0
  123.   'get field name
  124.   fn = cGrid.Text
  125.   cGrid.Row = r
  126.   'make sure it's a string or memo field
  127.   If FDS(fn).Type = FT_STRING Or FDS(fn).Type = FT_MEMO Then
  128.      gstZoomData = cGrid.Text
  129.      fZoom.Caption = fn
  130.      fZoom.Top = Top + 1200
  131.      fZoom.Left = Left + 250
  132.      fZoom.CloseZoomButton.Visible = True
  133.      fZoom.Show MODAL
  134.   End If
  135.   GoTo ZoomEnd
  136. ZoomErr:
  137.   ShowError
  138.   Resume ZoomEnd
  139. ZoomEnd:
  140. End Sub
  141. Sub cGrid_KeyUp (KeyCode As Integer, Shift As Integer)
  142.   'zoom on F4 key press
  143.   If KeyCode = &H73 Then   'F4
  144.     cGrid_DblClick
  145.   End If
  146. End Sub
  147. Sub CloseButton_Click ()
  148.   Unload Me
  149. End Sub
  150. Sub FilterButton_Click ()
  151.   On Error GoTo FilterErr
  152. '  Dim ds1 As dynaset, ds2 As dynaset
  153.   Dim ds1 As snapshot, ds2 As snapshot
  154.   Dim FilterStr As String
  155.   Dim numbrows As Long    'local number of rows
  156.   Set ds1 = FDS            'save the dynaset
  157.   FilterStr = InputBox("Enter Filter Expression:")
  158.   If FilterStr = "" Then Exit Sub
  159.   FDS.Filter = FilterStr
  160. '  Set ds2 = FDS.CreateDynaset()            'establish the filter
  161.   Set ds2 = FDS.CreateSnapshot()            'establish the filter
  162.   Set FDS = ds2            'assign back to original dynaset object
  163.   'everything must be okay so redisplay form on 1st record
  164.   FNumbRows = GetNumbRecsSS(FDS)          'query numb of recs
  165.    If FNumbRows = -1 Then
  166.      'error occurred but go on anyway
  167.      'because row count is non-critical
  168.      Caption = "Dynaset: " + FTblName
  169.      numbrows = gwMaxGridRows
  170.      FCurrentRow = numbrows
  171.    ElseIf FNumbRows = 0 Then
  172.      Beep
  173.      MsgBox "No Records found!", 48
  174.      Unload Me
  175.      Exit Sub
  176.    ElseIf FNumbRows > gwMaxGridRows Then
  177.      Caption = "Dynaset: " + FTblName + " [" + CStr(FNumbRows) + " total rows]"
  178.      numbrows = gwMaxGridRows
  179.      FCurrentRow = numbrows
  180.    Else
  181.      numbrows = FNumbRows
  182.      Caption = "Dynaset: " + FTblName + " [" + CStr(FNumbRows) + " rows]"
  183.    End If
  184.   If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  185.     Unload Me
  186.     Exit Sub
  187.   End If
  188.   GoTo FilterEnd
  189. FilterErr:
  190.   ShowError
  191.   Set FDS = ds1            're-assign back to original
  192.   Resume FilterEnd
  193. FilterEnd:
  194. End Sub
  195. Sub FindButton_Click ()
  196.    Dim i As Integer, r As Integer, c As Integer
  197.    On Error GoTo FindErr
  198.    'load the column names into the find form
  199.    'the 1st time it is loaded
  200.    If FFindForm.cFieldList.ListCount = 0 Then
  201.      FFindForm.cFieldList.Clear
  202.      r = cGrid.Row
  203.      c = cGrid.Col
  204.      cGrid.Row = 0
  205.      cGrid.Col = 0
  206.      For i = 1 To cGrid.Cols - 1
  207.        cGrid.Col = cGrid.Col + 1
  208.        FFindForm.cFieldList.AddItem cGrid.Text
  209.      Next
  210.      cGrid.Row = r
  211.      cGrid.Col = c
  212.    End If
  213. FindStart:       'used to loop around on not found
  214.    'reset the flags
  215.    gfFindFailed = False
  216.    gfFromTableView = True
  217.    MsgBar "Enter Search Parameters", False
  218.    FFindForm.Show MODAL
  219.    MsgBar "Searching for record", True
  220.    If gfFindFailed = True Then Exit Sub
  221.    FNotFound = False
  222.    SetHourglass Me
  223.    'search for the record
  224.    cGrid.SetFocus        'start at the top
  225.    SendKeys "^{Home}"
  226.    cGrid.Col = 1
  227.    cGrid.Row = 0
  228.    'move the right column
  229.    While cGrid.Text <> UCase(gstFindField)
  230.      If cGrid.Col = cGrid.Cols Then 'reached max col
  231.      Else
  232.        cGrid.Col = cGrid.Col + 1
  233.        SendKeys "{Right}"
  234.      End If
  235.    Wend
  236.    cGrid.Row = 1
  237.    While cGrid.Row < cGrid.Rows - 1
  238.        If gfFindMatch = False Then
  239.          Select Case gstFindOp
  240.            Case "="
  241.              If UCase(cGrid.Text) = UCase(gstFindExpr) Then GoTo AfterWhile
  242.            Case "<>"
  243.              If UCase(cGrid.Text) <> UCase(gstFindExpr) Then GoTo AfterWhile
  244.            Case ">="
  245.              If UCase(cGrid.Text) >= UCase(gstFindExpr) Then GoTo AfterWhile
  246.            Case "<="
  247.              If UCase(cGrid.Text) <= UCase(gstFindExpr) Then GoTo AfterWhile
  248.            Case ">"
  249.              If UCase(cGrid.Text) > UCase(gstFindExpr) Then GoTo AfterWhile
  250.            Case "<"
  251.              If UCase(cGrid.Text) < UCase(gstFindExpr) Then GoTo AfterWhile
  252.            Case "Like"
  253.              If UCase(cGrid.Text) Like UCase(gstFindExpr) Then GoTo AfterWhile
  254.          End Select
  255.        Else
  256.          Select Case gstFindOp
  257.            Case "="
  258.              If cGrid.Text = gstFindExpr Then GoTo AfterWhile
  259.            Case "<>"
  260.              If cGrid.Text <> gstFindExpr Then GoTo AfterWhile
  261.            Case ">="
  262.              If cGrid.Text >= gstFindExpr Then GoTo AfterWhile
  263.            Case "<="
  264.              If cGrid.Text <= gstFindExpr Then GoTo AfterWhile
  265.            Case ">"
  266.              If cGrid.Text > gstFindExpr Then GoTo AfterWhile
  267.            Case "<"
  268.              If cGrid.Text < gstFindExpr Then GoTo AfterWhile
  269.            Case "Like"
  270.              If cGrid.Text Like gstFindExpr Then GoTo AfterWhile
  271.          End Select
  272.        End If
  273.      cGrid.Row = cGrid.Row + 1
  274.      SendKeys "{Down}"
  275.    Wend
  276.    FNotFound = True       'didn't find it
  277. AfterWhile:
  278.    ResetMouse Me
  279.    'show the first record
  280.    If FNotFound Then
  281.      Beep
  282.      MsgBox "Record Not Found", 48
  283.      GoTo FindStart
  284.    End If
  285.    DoEvents
  286.    cGrid.SelStartRow = cGrid.Row
  287.    cGrid.SelStartCol = 1
  288.    cGrid.SelEndRow = cGrid.Row
  289.    cGrid.SelEndCol = FDS.Fields.Count
  290.    GoTo FindEnd
  291. FindErr:
  292.    ResetMouse Me
  293.    ShowError
  294.    Resume FindEnd
  295. FindEnd:
  296.    MsgBar "", False
  297. End Sub
  298. Sub FirstButton_Click ()
  299.    Dim numbrows As Long         'number of rows
  300.    On Error GoTo GoFirstError
  301.    SetHourglass Me
  302.    MsgBar "Going to first record", True
  303.    cGrid.SetFocus
  304.    cGrid.Row = 1
  305.    cGrid.Col = 0
  306.    'get current starting row in grid
  307.    If cGrid.Text <> "1" Then
  308.      FDS.Close
  309. '     Set FDS = gCurrentDB.CreateDynaset(FDS.Name)
  310.      Set FDS = gCurrentDB.CreateSnapshot(FDS.Name)
  311.      FNumbRows = GetNumbRecsSS(FDS)
  312.      If FNumbRows > gwMaxGridRows Then
  313.        numbrows = gwMaxGridRows
  314.        FCurrentRow = numbrows
  315.      Else
  316.        numbrows = FNumbRows
  317.      End If
  318.      If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  319.        Unload Me
  320.        Exit Sub
  321.      End If
  322.   End If
  323.   cGrid.Col = 1
  324.   SendKeys "{Home}"
  325.   GoTo GoFirstEnd
  326. GoFirstError:
  327.   ShowError
  328.   Resume GoFirstEnd
  329. GoFirstEnd:
  330.   ResetMouse Me
  331.   MsgBar "", False
  332. End Sub
  333. Sub Form_Load ()
  334.    Dim t As TableDef       'local table structure
  335.    Dim sp As Integer       'starting point of table name
  336.    Dim ep As Integer       'ending point of table name
  337.    Dim wh As String        'where clause
  338.    Dim i As Integer, j As Integer
  339.    Dim fn As String        'field name
  340.    Dim rc As Integer       'record count
  341.    Dim numbrows As Long    'local number of rows
  342.    Dim ss As snapshot
  343.    Dim Start1, Finish1, Start2, Finish2
  344.    On Error GoTo DynasetErr
  345.    SetHourglass Me
  346.    MsgBar "Opening Dynaset", True
  347.    'assign the temp string with the select statement
  348.    'if it is not empty, otherwise, use the table list name
  349.    If gfFromSQL = True Then
  350.      If gstDynaString = "" Then
  351.        FDynSt = fSQL.cSQLStatement
  352.      Else
  353.        FDynSt = gstDynaString
  354.      End If
  355.    Else
  356.      FDynSt = fTables.cTableList
  357.    End If
  358.    'attemp to open the dynaset
  359.    Start1 = Timer
  360.    If UCase(FDynSt) = "LISTTABLES" Then
  361.      Set FDS = gCurrentDB.ListTables()
  362.    Else
  363.      If gfFromSQL = True And fSQL.cPassThru = 1 Then
  364. '       Set FDS = gCurrentDB.CreateDynaset(FDynSt, VBDA_SQLPASSTHROUGH)
  365.        Set FDS = gCurrentDB.CreateSnapshot(FDynSt, VBDA_SQLPASSTHROUGH)
  366.      Else
  367. '       Set FDS = gCurrentDB.CreateDynaset(FDynSt)
  368.        Set FDS = gCurrentDB.CreateSnapshot(FDynSt)
  369.      End If
  370.    End If
  371.    Finish1 = Timer
  372.    Start2 = Timer
  373.    'parse off table name to store in global gstTblName
  374.    wh = ""
  375.    sp = InStr(1, UCase(FDynSt), "FROM")
  376.    If sp > 0 Then
  377.      'must be a "select from" statement
  378.      sp = sp + 5
  379.      For ep = sp To Len(FDynSt)
  380.        'search for a space or the end of FDynSt
  381.        If Mid$(FDynSt, ep, 1) = " " Then
  382.          'get where clause if there is one
  383.          wh = Mid$(FDynSt, sp, Len(FDynSt) - sp + 1)
  384.          Exit For
  385.        End If
  386.      Next
  387.      FTblName = UCase(Mid$(FDynSt, sp, ep - sp))
  388.      If wh = "" Then wh = FTblName
  389.    Else
  390.      'must be a table name only
  391.      FTblName = UCase(FDynSt)
  392.      wh = FTblName
  393.    End If
  394.    FDynaString = wh
  395.    'show the first record
  396.    FNumbRows = GetNumbRecsSS(FDS)          'query numb of recs
  397.    If FNumbRows = -1 Then
  398.      'error occurred but go on anyway
  399.      'because row count is non-critical
  400.      Caption = "SnapShot: " + FTblName
  401.      numbrows = gwMaxGridRows
  402.      FCurrentRow = numbrows
  403.    ElseIf FNumbRows = 0 Then
  404.      Beep
  405.      MsgBox "No Records found!", 48
  406.      Unload Me
  407.      Exit Sub
  408.    ElseIf FNumbRows > gwMaxGridRows Then
  409.      Caption = "SnapShot: " + FTblName + " [" + CStr(FNumbRows) + " total rows]"
  410.      numbrows = gwMaxGridRows
  411.      FCurrentRow = numbrows
  412.    Else
  413.      numbrows = FNumbRows
  414.      Caption = "SnapShot: " + FTblName + " [" + CStr(FNumbRows) + " rows]"
  415.    End If
  416.    If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  417.      Unload Me
  418.      Exit Sub
  419.    End If
  420.    Height = 3800
  421.    Width = 5300
  422.    Left = 1000
  423.    Top = 1000
  424.    Finish2 = Timer
  425.    If VDMDI.PrefShowPerf.Checked Then
  426.      Me.Show
  427.      MsgBox CStr(FNumbRows) + " rows found in " + CStr(Finish1 - Start1) + " seconds!" + Chr(13) + Chr(10) + CStr(Finish2 - Start2) + " seconds to Load Grid!", 48
  428.    End If
  429.    GoTo OkayEnd
  430. DynasetErr:
  431.    ShowError
  432.    ResetMouse Me
  433.    MsgBar "", False
  434.    Unload Me
  435.    Exit Sub
  436.    Resume OkayEnd
  437. OkayEnd:
  438.    ResetMouse Me
  439.    MsgBar "", False
  440. End Sub
  441. Sub Form_Resize ()
  442.   On Error Resume Next
  443.   'resize grid to window
  444.   If WindowState <> 1 Then   'not minimized
  445.     cGrid.Height = Height - 900
  446.     cGrid.Width = Width - 100
  447.   End If
  448. End Sub
  449. Sub Form_Unload (Cancel As Integer)
  450.   On Error Resume Next
  451.   'unload the find form
  452.   Unload FFindForm
  453.   'close the associated dynaset
  454.   FDS.Close
  455.   MsgBar "", False
  456. End Sub
  457. Sub MoreButton_Click ()
  458.   Dim ret As Integer   'return value from loadgrid
  459.   On Error Resume Next
  460.   MsgBar "Getting more records", True
  461.   If FDS.EOF <> True Then
  462.     SetHourglass Me
  463.     ret = LoadGrid(cGrid, FDS, FDynSt, gwMaxGridRows, FCurrentRow)
  464.     If ret = False Then
  465.       'failed so bail out of form
  466.       FDS.Close
  467.       Unload Me
  468.     End If
  469.     'set new current row
  470.     FCurrentRow = FCurrentRow + ret
  471.     ResetMouse Me
  472.   End If
  473.   MsgBar "", False
  474. End Sub
  475. Sub NextButton_Click ()
  476.    Dim c As Integer      'current column
  477.    On Error GoTo GoNextError
  478.    c = cGrid.Col
  479.    cGrid.Col = 0
  480.    If cGrid.Text = "" Then
  481.      Beep
  482.    ElseIf cGrid.Row = gwMaxGridRows Then
  483.      MoreButton_Click
  484.    Else
  485.      cGrid.SetFocus
  486.      SendKeys "{Down}"
  487.    End If
  488.    cGrid.Col = c
  489.    GoTo GoNextEnd
  490. GoNextError:
  491.    ShowError
  492.    Resume GoNextEnd
  493. GoNextEnd:
  494. End Sub
  495. 'needed for multi-user situations so
  496. 'new records can be viewed imediately
  497. Sub RefreshButton_Click ()
  498.    Dim numbrows As Long
  499.    On Error GoTo RefreshError
  500.    MsgBar "Reopening Dynaset", True
  501.    SetHourglass Me
  502. '   Set FDS = gCurrentDB.CreateDynaset(FDS.Name)
  503.    Set FDS = gCurrentDB.CreateSnapshot(FDS.Name)
  504.    FNumbRows = GetNumbRecsSS(FDS)
  505.    If FNumbRows = -1 Then
  506.      'error occurred but go on anyway
  507.      'because row count is non-critical
  508.      Caption = "Dynaset: " + FTblName
  509.      numbrows = gwMaxGridRows
  510.      FCurrentRow = numbrows
  511.    ElseIf FNumbRows = 0 Then
  512.      Beep
  513.      MsgBox "No Records found!", 48
  514.      Unload Me
  515.    ElseIf FNumbRows > gwMaxGridRows Then
  516.      Caption = "Dynaset: " + FTblName + " [" + CStr(FNumbRows) + " total rows]"
  517.      numbrows = gwMaxGridRows
  518.      FCurrentRow = numbrows
  519.    Else
  520.      numbrows = FNumbRows
  521.      Caption = "Dynaset: " + FTblName + " [" + CStr(FNumbRows) + " rows]"
  522.    End If
  523.    If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  524.      Unload Me
  525.      Exit Sub
  526.    End If
  527.   GoTo RefreshEnd
  528. RefreshError:
  529.   ShowError
  530.   Resume RefreshEnd
  531. RefreshEnd:
  532.   ResetMouse Me
  533.   MsgBar "", False
  534. End Sub
  535. Sub SortButton_Click ()
  536.   On Error GoTo SortErr
  537. '  Dim ds1 As dynaset, ds2 As dynaset
  538.   Dim ds1 As snapshot, ds2 As snapshot
  539.   Dim SortStr As String
  540.   Dim numbrows As Long    'local number of rows
  541.   Set ds1 = FDS            'save the dynaset
  542.   SortStr = InputBox("Enter Sort Column:")
  543.   If SortStr = "" Then Exit Sub
  544.   FDS.Sort = SortStr
  545. '  Set ds2 = FDS.CreateDynaset()            'establish the Sort
  546.   Set ds2 = FDS.CreateSnapshot()            'establish the Sort
  547.   Set FDS = ds2            'assign back to original dynaset object
  548.   'everything must be okay so redisplay form on 1st record
  549.   FNumbRows = GetNumbRecsSS(FDS)          'query numb of recs
  550.    If FNumbRows = -1 Then
  551.      'error occurred but go on anyway
  552.      'because row count is non-critical
  553.      Caption = "Dynaset: " + FTblName
  554.      numbrows = gwMaxGridRows
  555.      FCurrentRow = numbrows
  556.    ElseIf FNumbRows = 0 Then
  557.      Beep
  558.      MsgBox "No Records found!", 48
  559.      Unload Me
  560.      Exit Sub
  561.    ElseIf FNumbRows > gwMaxGridRows Then
  562.      Caption = "Dynaset: " + FTblName + " [" + CStr(FNumbRows) + " total rows]"
  563.      numbrows = gwMaxGridRows
  564.      FCurrentRow = numbrows
  565.    Else
  566.      numbrows = FNumbRows
  567.      Caption = "Dynaset: " + FTblName + " [" + CStr(FNumbRows) + " rows]"
  568.    End If
  569.   If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  570.     Unload Me
  571.     Exit Sub
  572.   End If
  573.   GoTo SortEnd
  574. SortErr:
  575.   ShowError
  576.   Set FDS = ds1            're-assign back to original
  577.   Resume SortEnd
  578. SortEnd:
  579. End Sub
  580.