home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / demo / truegrid / trubrwse / trubrwse.$ / TRUBRWSE.FRM < prev    next >
Text File  |  1994-02-08  |  13KB  |  481 lines

  1. VERSION 2.00
  2. Begin Form MainForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "True Browser"
  5.    ClientHeight    =   4020
  6.    ClientLeft      =   1065
  7.    ClientTop       =   1725
  8.    ClientWidth     =   7350
  9.    Height          =   4710
  10.    Icon            =   TRUBRWSE.FRX:0000
  11.    Left            =   1005
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4020
  14.    ScaleWidth      =   7350
  15.    Top             =   1095
  16.    Width           =   7470
  17.    Begin TrueGrid Table1 
  18.       AllowArrows     =   -1  'True
  19.       AllowTabs       =   -1  'True
  20.       BackColor       =   &H00C0C0C0&
  21.       BorderStyle     =   0  'None
  22.       DataSource      =   "Data1"
  23.       Editable        =   -1  'True
  24.       EditDropDown    =   -1  'True
  25.       ExposeCellMode  =   1  'Expose upon editing
  26.       FetchMode       =   0  'By cell
  27.       HeadingHeight   =   1
  28.       Height          =   1575
  29.       HorzLines       =   2  '3D
  30.       Layout          =   TRUBRWSE.FRX:0302
  31.       Left            =   0
  32.       LinesPerRow     =   1
  33.       MarqueeUnique   =   -1  'True
  34.       SplitPropsGlobal=   -1  'True
  35.       SplitTabMode    =   0  'Don't tab across splits
  36.       TabCapture      =   0   'False
  37.       TabIndex        =   0
  38.       Top             =   0
  39.       UseBookmarks    =   -1  'True
  40.       Visible         =   0   'False
  41.       Width           =   2475
  42.       WrapCellPointer =   0   'False
  43.    End
  44.    Begin CommonDialog CMDialog1 
  45.       CancelError     =   -1  'True
  46.       Filter          =   "Database Files | *.mdb *.dbf *.ddf *.db | Access (*.mdb) | *.mdb | dBASE (*.dbf) | *.dbf | Paradox (*.db) | *.db | Btireve (*.ddf) | *.ddf"
  47.       FilterIndex     =   1
  48.       Left            =   300
  49.       Top             =   3150
  50.    End
  51.    Begin Data Data1 
  52.       Caption         =   "Data1"
  53.       Connect         =   ""
  54.       DatabaseName    =   ""
  55.       Exclusive       =   0   'False
  56.       Height          =   465
  57.       Left            =   900
  58.       Options         =   0
  59.       ReadOnly        =   0   'False
  60.       RecordSource    =   ""
  61.       Top             =   3150
  62.       Visible         =   0   'False
  63.       Width           =   1140
  64.    End
  65.    Begin Menu mFileTitle 
  66.       Caption         =   "&File"
  67.       Begin Menu mFileOption 
  68.          Caption         =   "&Open..."
  69.          Index           =   1
  70.       End
  71.       Begin Menu mFileOption 
  72.          Caption         =   "&Close"
  73.          Enabled         =   0   'False
  74.          Index           =   2
  75.       End
  76.       Begin Menu mFileOption 
  77.          Caption         =   "-"
  78.          Index           =   3
  79.       End
  80.       Begin Menu mFileOption 
  81.          Caption         =   "E&xit"
  82.          Index           =   4
  83.       End
  84.    End
  85.    Begin Menu RecordTitle 
  86.       Caption         =   "&Record"
  87.       Visible         =   0   'False
  88.       Begin Menu mRecordOption 
  89.          Caption         =   "&Add..."
  90.          Index           =   1
  91.       End
  92.       Begin Menu mRecordOption 
  93.          Caption         =   "&Update..."
  94.          Index           =   2
  95.       End
  96.       Begin Menu mRecordOption 
  97.          Caption         =   "&Delete"
  98.          Index           =   3
  99.       End
  100.    End
  101.    Begin Menu SortTitle 
  102.       Caption         =   "&Sort"
  103.       Visible         =   0   'False
  104.       Begin Menu mSortOption 
  105.          Caption         =   "&UnSorted"
  106.          Checked         =   -1  'True
  107.          Index           =   0
  108.       End
  109.       Begin Menu mSortOption 
  110.          Caption         =   "-"
  111.          Index           =   1
  112.       End
  113.       Begin Menu mSortOption 
  114.          Index           =   2
  115.          Visible         =   0   'False
  116.       End
  117.       Begin Menu mSortOption 
  118.          Index           =   3
  119.          Visible         =   0   'False
  120.       End
  121.       Begin Menu mSortOption 
  122.          Index           =   4
  123.          Visible         =   0   'False
  124.       End
  125.       Begin Menu mSortOption 
  126.          Index           =   5
  127.          Visible         =   0   'False
  128.       End
  129.       Begin Menu mSortOption 
  130.          Index           =   6
  131.          Visible         =   0   'False
  132.       End
  133.       Begin Menu mSortOption 
  134.          Index           =   7
  135.          Visible         =   0   'False
  136.       End
  137.       Begin Menu mSortOption 
  138.          Index           =   8
  139.          Visible         =   0   'False
  140.       End
  141.       Begin Menu mSortOption 
  142.          Index           =   9
  143.       End
  144.       Begin Menu mSortOption 
  145.          Caption         =   "-"
  146.          Index           =   10
  147.       End
  148.       Begin Menu mSortOption 
  149.          Caption         =   "More Fields..."
  150.          Index           =   11
  151.          Visible         =   0   'False
  152.       End
  153.    End
  154.    Begin Menu QueryTitle 
  155.       Caption         =   "&Query"
  156.       Visible         =   0   'False
  157.       Begin Menu mQueryOption 
  158.          Caption         =   "&Find..."
  159.          Index           =   0
  160.       End
  161.       Begin Menu mQueryOption 
  162.          Caption         =   "-"
  163.          Index           =   1
  164.       End
  165.       Begin Menu mQueryOption 
  166.          Caption         =   "Find &All"
  167.          Index           =   2
  168.       End
  169.    End
  170.    Begin Menu HelpTitle 
  171.       Caption         =   "&Help"
  172.       Begin Menu mHelpOption 
  173.          Caption         =   "&Index"
  174.          Index           =   1
  175.       End
  176.       Begin Menu mHelpOption 
  177.          Caption         =   "&Using Help"
  178.          Index           =   2
  179.       End
  180.       Begin Menu mHelpOption 
  181.          Caption         =   "-"
  182.          Index           =   3
  183.       End
  184.       Begin Menu mHelpOption 
  185.          Caption         =   "&About True Browser..."
  186.          Index           =   4
  187.       End
  188.    End
  189. End
  190. ' ---------------------------------------------------------
  191. '       Copyright (C) 1993 Apex Software Corporation
  192. '
  193. ' You have a royalty-free right to use, modify, reproduce,
  194. ' and distribute the True Grid sample application files
  195. ' (and/or any modified version) in any way you find useful,
  196. ' provided that you agree that Apex Software Corporation
  197. ' has no warranty, obligations, or liability for any sample
  198. ' application files.
  199. ' ---------------------------------------------------------
  200.  
  201. Sub ClearCheck ()
  202.  
  203.     'Clears the previous Sort checkmark
  204.     For ct% = 0 To 10
  205.     mSortOption(ct%).Checked = False
  206.     Next ct%
  207.  
  208. End Sub
  209.  
  210. Sub Data1_Error (DataErr As Integer, Response As Integer)
  211.     
  212. 'If the data control generates an error it passes through this event
  213. 'You can either choose to display or ignore the error using the response parameter
  214. 'In this case I simply set the DbOpen flag to false and allow the message to be displayed
  215.  
  216.     DbOpen = False
  217.  
  218. End Sub
  219.  
  220. Sub DisplayGrid (Status As Integer, File As String)
  221.         
  222.     mFileOption(2).Enabled = Status
  223.     RecordTitle.Visible = Status
  224.     SortTitle.Visible = Status
  225.     QueryTitle.Visible = Status
  226.     Table1.Visible = Status
  227.     If Status Then
  228.         MainForm.Caption = "True Browser - " + File
  229.     Else
  230.         MainForm.Caption = "True Browser"
  231.     End If
  232.     
  233.     Screen.MousePointer = DEFAULT
  234.         
  235. End Sub
  236.  
  237. Sub Form_Load ()
  238.     
  239.     'Center the Form on the screen
  240.     CenterForm MainForm
  241.  
  242.     'Load in database if one is present on the Command Line
  243.     If Command <> "" Then
  244.     DbOpen = True
  245.     OpenFile (Command$)
  246.     If DbOpen = True Then
  247.         Call DisplayGrid(True, Command$)
  248.     End If
  249.     End If
  250.     
  251.     ' Go with a default color for updated cells, but
  252.     ' make the cell italic.
  253.  
  254.     ' Use white text, italic for non-selected updated cells
  255.  
  256.     Table1.ParamForeColor = WHITE
  257.     Table1.ParamBackColor = INHERIT_COLOR
  258.     Table1.ParamFontStyle = GRF_ITALIC
  259.  
  260.     Table1.SetStatusAttr = GFS_CURCELL Or GFS_HIGHROW Or GFS_CHANGED
  261.     Table1.SetStatusAttr = GFS_HIGHROW Or GFS_CHANGED
  262.     
  263.     ' Use the selection color for selected updated cells
  264.  
  265.     Table1.ParamForeColor = Table1.SelectedForeColor
  266.     Table1.SetStatusAttr = GFS_CURCELL Or GFS_HIGHROW Or GFS_CHANGED Or GFS_SELECTED
  267.     Table1.SetStatusAttr = GFS_HIGHROW Or GFS_CHANGED Or GFS_SELECTED
  268.  
  269. End Sub
  270.  
  271. Sub Form_Resize ()
  272.  
  273.     'Make the grid to the size of the form
  274.     Table1.Move 0, 0, ScaleWidth, ScaleHeight
  275.  
  276. End Sub
  277.  
  278. Sub Form_Unload (Cancel As Integer)
  279.  
  280.     'Unload the Help file, and the pick form if left open
  281.     HelpQuit MainForm
  282.     Unload PickTable
  283.     End
  284.  
  285. End Sub
  286.  
  287. Sub mFileOption_Click (index As Integer)
  288.  
  289.  
  290. 'User hits cancel button on Common dialog
  291. On Error GoTo ErrHandler
  292.     Select Case index
  293.     Case 1
  294.         If DbOpen Then
  295.         Data1.Recordset.Close
  296.         Table1.Layout = ""
  297.         End If
  298.  
  299.         'Set the database open flag to true
  300.         DbOpen = True
  301.     
  302.         'Call common dialog
  303.         CMDialog1.Filename = ""
  304.         CMDialog1.Action = DLGOPEN
  305.     
  306.         Screen.MousePointer = HOURGLASS
  307.     
  308.         'Procedure that opens the database
  309.         OpenFile (CMDialog1.Filename)
  310.         
  311.         'Check for read-only
  312.         If (CMDialog1.Flags And ofn_readonly) <> 0 Then
  313.         Data1.ReadOnly = True
  314.         RecordTitle.Visible = False
  315.         End If
  316.         
  317.         File$ = CMDialog1.Filename
  318.         Call DisplayGrid(DbOpen, File$)
  319.  
  320.  
  321.     'If close is selected
  322.     Case 2
  323.         If DbOpen = True Then
  324.         Data1.Recordset.Close
  325.         Table1.Layout = ""
  326.         Call DisplayGrid(False, "")
  327.         End If
  328.         DbOpen = False
  329.     'If Exit is Chosen
  330.     Case 4
  331.         Unload MainForm
  332.         End
  333.     
  334.     End Select
  335.  
  336. Exit Sub
  337.  
  338. ErrHandler:
  339.     Screen.MousePointer = DEFAULT
  340.     Select Case Err
  341.     Case 19
  342.         Resume Next
  343.     Case 32755
  344.         Exit Sub
  345.     Case 91
  346.         Resume Next
  347.     Case Else
  348.         MsgBox Str$(Err) + " " + Error, MB_ICONEXCLAMATION
  349.         Resume Next
  350.     End Select
  351.  
  352. End Sub
  353.  
  354. Sub mHelpOption_Click (index As Integer)
  355.  
  356.     'This event calls the WinHelp EXE and a location to goto based on which selection the user has chosen
  357.     'Case 4 shows the about box for True Browser
  358.     Select Case index
  359.     Case 1
  360.         HelpContext MainForm, HELP_TRUEBROWSER
  361.     Case 2
  362.         HelpOnHelp MainForm
  363.     Case 4
  364.         About.Show 1
  365.     End Select
  366.  
  367. End Sub
  368.  
  369. Sub mQueryOption_Click (index As Integer)
  370.  
  371. 'Event calls SchemaForm and set the caption property of the form
  372. 'to "Find..." which is what the SchemaForm uses to determine that its setup
  373. 'will be for doing a Find
  374.     Select Case index
  375.     Case 0
  376.         SchemaForm.Caption = "Find..."
  377.         SchemaForm.Show 1
  378.     Case 2
  379.         'If case 2 is chosen the database simply reverts to it status before the find
  380.         curFind = ""
  381.         Data1.RecordSource = "Select * From " + "[" + curTable + "]" + curSort
  382.         Data1.Refresh
  383.     End Select
  384.  
  385. End Sub
  386.  
  387. Sub mRecordOption_Click (index As Integer)
  388.  
  389. 'Event calls SchemaForm and set the caption property of the form,
  390. 'this is what the SchemaForm uses to determine its setup
  391. 'In this case the Add and Update sections of Schema form are used
  392.     Select Case index
  393.     Case 1
  394.         SchemaForm.Caption = "Add..."
  395.         SchemaForm.Show 1
  396.     Case 2
  397.         SchemaForm.Caption = "Update..."
  398.         SchemaForm.Show 1
  399.     Case 3
  400.         'If case 3 is chosen the current record is deleted
  401.         Data1.Recordset.Delete
  402.     End Select
  403.  
  404. End Sub
  405.  
  406. Sub mSortOption_Click (index As Integer)
  407.     
  408. 'This event sorts the database based on the option the user has checked
  409. 'If there are more than 8 fields for a given database then a table is
  410. 'brought up so that user can scroll through the rest of the fields
  411.  
  412.     Dim selField As String
  413.  
  414. 'In most cases an error here is becuase the user hit cancel on the More Fields form
  415. On Error GoTo errhandler2
  416.     
  417.     ' If the user selected the same option exit sub
  418.     If mSortOption(index).Checked Then Exit Sub
  419.  
  420.     Select Case index
  421.     
  422.     'UnSorted
  423.     Case 0
  424.         selField = ""
  425.         ClearCheck
  426.         mSortOption(index).Checked = True
  427.     
  428.     'More Fields...
  429.     Case 11
  430.         Call ShowTable("Choose Sort Field", Int(Table1.Columns), selField, dbFields())
  431.         ClearCheck
  432.     
  433.     'Any field displayed in the drop down menu list
  434.     Case Else
  435.         selField = mSortOption(index).Caption
  436.         ClearCheck
  437.         mSortOption(index).Checked = True
  438.  
  439.     End Select
  440.     If selField <> "" Then
  441.     curSort = " Order by [" + selField + "]"
  442.     Else
  443.     curSort = ""
  444.     End If
  445.  
  446.     'Rebuild the Table
  447.     Data1.RecordSource = "Select * From " + "[" + curTable + "]" + curFind + curSort
  448.     Data1.Refresh
  449.     Screen.MousePointer = DEFAULT
  450.  
  451. Exit Sub
  452. errhandler2:
  453.     'If error occurs remove any sort criteria from db
  454.     Screen.MousePointer = DEFAULT
  455.     
  456.     'Check UnSort on Menu bar
  457.     ClearCheck
  458.     mSortOption(0).Checked = True
  459.  
  460.     'Clear sort criteria and refresh recordsource
  461.     curSort = ""
  462.     Data1.RecordSource = "Select * From " + "[" + curTable + "]" + curFind
  463.     Data1.Refresh
  464.     If Err = TableCancel Then
  465.     Exit Sub
  466.     Else
  467.     MsgBox Str$(Err) + " " + Error, MB_ICONEXCLAMATION
  468.     Exit Sub
  469.     End If
  470.     
  471. End Sub
  472.  
  473. Sub Table1_Append ()
  474.  
  475.     'Same effect as choosing Add from the Menu list
  476.     SchemaForm.Caption = "Add..."
  477.     SchemaForm.Show 1
  478.  
  479. End Sub
  480.  
  481.