home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / DAT_MGR / DATAFORM.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1993-04-21  |  18.5 KB  |  636 lines

  1. VERSION 2.00
  2. Begin Form DataForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   3960
  5.    ClientLeft      =   630
  6.    ClientTop       =   1755
  7.    ClientWidth     =   8475
  8.    Height          =   4365
  9.    Icon            =   DATAFORM.FRX:0000
  10.    Left            =   570
  11.    LinkTopic       =   "Form2"
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   3960
  14.    ScaleWidth      =   8475
  15.    Top             =   1410
  16.    Width           =   8595
  17.    Begin PictureBox StatBox 
  18.       Align           =   2  'Align Bottom
  19.       BackColor       =   &H00C0C0C0&
  20.       BorderStyle     =   0  'None
  21.       Height          =   270
  22.       Left            =   0
  23.       ScaleHeight     =   282.462
  24.       ScaleMode       =   0  'User
  25.       ScaleWidth      =   8490.27
  26.       TabIndex        =   5
  27.       Top             =   3690
  28.       Width           =   8475
  29.       Begin Data Data1 
  30.          Connect         =   ""
  31.          DatabaseName    =   ""
  32.          Exclusive       =   0   'False
  33.          Height          =   270
  34.          Left            =   0
  35.          Options         =   0
  36.          ReadOnly        =   0   'False
  37.          RecordSource    =   ""
  38.          Top             =   0
  39.          Width           =   5475
  40.       End
  41.    End
  42.    Begin VScrollBar cScrollBar 
  43.       Height          =   2085
  44.       LargeChange     =   3500
  45.       Left            =   7665
  46.       SmallChange     =   350
  47.       TabIndex        =   14
  48.       Top             =   630
  49.       Visible         =   0   'False
  50.       Width           =   255
  51.    End
  52.    Begin PictureBox cFields 
  53.       BackColor       =   &H00C0C0C0&
  54.       BorderStyle     =   0  'None
  55.       Height          =   1065
  56.       Left            =   0
  57.       ScaleHeight     =   1056.48
  58.       ScaleMode       =   0  'User
  59.       ScaleWidth      =   7600.262
  60.       TabIndex        =   9
  61.       TabStop         =   0   'False
  62.       Top             =   630
  63.       Width           =   7605
  64.       Begin TextBox cFieldData 
  65.          BackColor       =   &H00FFFFFF&
  66.          DataSource      =   "Data1"
  67.          ForeColor       =   &H00000000&
  68.          Height          =   285
  69.          Index           =   0
  70.          Left            =   1679
  71.          TabIndex        =   12
  72.          Top             =   0
  73.          Visible         =   0   'False
  74.          Width           =   3255
  75.       End
  76.       Begin CheckBox cFieldCheck 
  77.          BackColor       =   &H00C0C0C0&
  78.          DataSource      =   "Data1"
  79.          Height          =   330
  80.          Index           =   0
  81.          Left            =   1679
  82.          TabIndex        =   11
  83.          Top             =   735
  84.          Visible         =   0   'False
  85.          Width           =   3270
  86.       End
  87.       Begin PictureBox cFieldPicture 
  88.          DataSource      =   "Data1"
  89.          Height          =   282
  90.          Index           =   0
  91.          Left            =   1679
  92.          ScaleHeight     =   255
  93.          ScaleWidth      =   3240
  94.          TabIndex        =   10
  95.          Top             =   315
  96.          Visible         =   0   'False
  97.          Width           =   3270
  98.       End
  99.       Begin Label cFieldName 
  100.          BackColor       =   &H00C0C0C0&
  101.          ForeColor       =   &H00000000&
  102.          Height          =   225
  103.          Index           =   0
  104.          Left            =   105
  105.          TabIndex        =   13
  106.          Top             =   0
  107.          Visible         =   0   'False
  108.          Width           =   1515
  109.       End
  110.    End
  111.    Begin PictureBox FieldHeader 
  112.       Align           =   1  'Align Top
  113.       BackColor       =   &H00C0C0C0&
  114.       BorderStyle     =   0  'None
  115.       Height          =   300
  116.       Left            =   0
  117.       ScaleHeight     =   300
  118.       ScaleMode       =   0  'User
  119.       ScaleWidth      =   8480.059
  120.       TabIndex        =   6
  121.       Top             =   330
  122.       Width           =   8475
  123.       Begin Label FieldValueLabel 
  124.          BackColor       =   &H00C0C0C0&
  125.          Caption         =   " Value:"
  126.          Height          =   252
  127.          Left            =   1680
  128.          TabIndex        =   8
  129.          Top             =   30
  130.          Width           =   2652
  131.       End
  132.       Begin Label FieldHdrLabel 
  133.          BackColor       =   &H00C0C0C0&
  134.          Caption         =   "Field Name:"
  135.          Height          =   252
  136.          Left            =   120
  137.          TabIndex        =   7
  138.          Top             =   30
  139.          Width           =   1212
  140.       End
  141.    End
  142.    Begin PictureBox TopPic 
  143.       Align           =   1  'Align Top
  144.       BackColor       =   &H00C0C0C0&
  145.       BorderStyle     =   0  'None
  146.       Height          =   330
  147.       Left            =   0
  148.       ScaleHeight     =   330
  149.       ScaleWidth      =   8475
  150.       TabIndex        =   0
  151.       Top             =   0
  152.       Width           =   8475
  153.       Begin CommandButton RefreshBtn 
  154.          Caption         =   "&Refresh"
  155.          Height          =   260
  156.          Left            =   4680
  157.          TabIndex        =   15
  158.          Top             =   0
  159.          Width           =   1215
  160.       End
  161.       Begin CommandButton FindBtn 
  162.          Caption         =   "&Find"
  163.          Height          =   260
  164.          Left            =   3480
  165.          TabIndex        =   4
  166.          Top             =   0
  167.          Width           =   1215
  168.       End
  169.       Begin CommandButton DeleteBtn 
  170.          Caption         =   "&Delete"
  171.          Height          =   260
  172.          Left            =   2280
  173.          TabIndex        =   3
  174.          Top             =   0
  175.          Width           =   1215
  176.       End
  177.       Begin CommandButton AddBtn 
  178.          Caption         =   "&Add"
  179.          Height          =   260
  180.          Left            =   0
  181.          TabIndex        =   2
  182.          Top             =   0
  183.          Width           =   1215
  184.       End
  185.       Begin CommandButton UpdateBtn 
  186.          Caption         =   "&Update"
  187.          Height          =   260
  188.          Left            =   1200
  189.          TabIndex        =   1
  190.          Top             =   0
  191.          Width           =   1095
  192.       End
  193.    End
  194. Dim FldArr() As control
  195. Dim FDS As Dynaset
  196. Dim numFlds As Integer
  197. Dim CurrField As Integer
  198. Dim JustUsedFind As Integer        'flag for find function
  199. Dim fResizing As Integer           'flag to avoid resize recursion
  200. Dim FldTop As Integer
  201. Const EM_NOTHING = 0
  202. Const EM_EDIT = 1
  203. Const EM_ADDNEW = 2
  204. Const FT_TRUEFALSE = 1
  205. Const FT_BYTE = 2
  206. Const FT_INTEGER = 3
  207. Const FT_LONG = 4
  208. Const FT_CURRENCY = 5
  209. Const FT_SINGLE = 6
  210. Const FT_DOUBLE = 7
  211. Const FT_DATETIME = 8
  212. Const FT_STRING = 10
  213. Const FT_BINARY = 11
  214. Const FT_MEMO = 12
  215. Const YES = 6
  216. Const MSGBOX_TYPE = 4 + 48
  217. Sub AddBtn_Click ()
  218.   On Error GoTo AddErr
  219.     data1.Caption = "Entering New Record"
  220.   If AddBtn.Tag = "Disabled" Then
  221.     EnableAllControls
  222.   End If
  223.   data1.Recordset.AddNew
  224.   FldArr(0).SetFocus
  225.   Exit Sub
  226. AddErr:
  227.   MsgBox Error$
  228.   Resume AddEnd
  229. AddEnd:
  230. End Sub
  231. Sub cFieldPicture_Click (Index As Integer)
  232.   'this toggles the size of a picture control
  233.   'so it mat be viewed or compressed
  234.   If cFieldPicture(Index).Height <= 280 Then
  235.     cFieldPicture(Index).AutoSize = True
  236.   Else
  237.     cFieldPicture(Index).AutoSize = False
  238.     cFieldPicture(Index).Height = 280
  239.   End If
  240. End Sub
  241. Sub cFieldPicture_DblClick (Index As Integer)
  242.   On Error GoTo PicErr
  243.   st = InputBox("Enter Picture FilName:")
  244.   If st <> "" Then
  245.     cFieldPicture(Index).Picture = LoadPicture(st)
  246.   End If
  247.   GoTo PicEnd
  248. PicErr:
  249.   MsgBox Error$
  250.   Resume PicEnd
  251. PicEnd:
  252. End Sub
  253. Sub cScrollBar_Change ()
  254.   Dim t As Integer
  255.   t = cScrollBar
  256.   If (t - FldTop) Mod 350 = 0 Then
  257.     cFields.Top = t
  258.   Else
  259.     cFields.Top = ((t - FldTop) \ 350) * 350 + FldTop
  260.   End If
  261. End Sub
  262. Sub Data1_Error (dataerr As Integer, response As Integer)
  263.   If dataerr = 3021 Then
  264.     response = 0
  265.   ElseIf dataerr = 481 Or dataerr = 321 Then 'Invalid picture
  266.     response = 0
  267.   Else
  268.     MsgBox "Error:  " + Error$(dataerr)
  269.     response = 0
  270.   End If
  271. End Sub
  272. Sub data1_Reposition ()
  273.     'if not valid record and not in addnew mode
  274.     If (data1.Recordset.BOF Or data1.Recordset.EOF) And data1.Caption <> "Entering New Record" Then
  275.         DisableAllControls
  276.     'otherwise, if form is disabled, then enable it
  277.     ElseIf AddBtn.Tag = "Disabled" Then
  278.         EnableAllControls
  279.     Else
  280.        If data1.Caption <> "Entering New Record" Then data1.Caption = "Editing Record"
  281.     End If
  282. End Sub
  283. Sub Data1_Validate (Action As Integer, save As Integer)
  284. On Error Resume Next
  285.   'first check for a move from an addnew or edit record
  286.   If Action < 5 Then
  287.     If save = True Then      'data changed
  288.       If data1.EditMode = EM_ADDNEW Then
  289.         If MsgBox("Save New Record?", MSGBOX_TYPE) = YES Then
  290.           data1.UpdateRecord
  291.           If Err <> 0 Then
  292.             MsgBox Error$, 0, "Data Manager"
  293.             Action = 0: save = 0
  294.           End If
  295.           save = 0
  296.         Else
  297.             save = 0
  298.         End If
  299.       ElseIf MsgBox("Commit Changes?", MSGBOX_TYPE) <> YES Then
  300.          save = False        'loose changes
  301.       End If
  302.     End If
  303.   data1.Caption = "Editing Record"
  304.   End If
  305.   Select Case Action
  306.     Case 1          'First
  307.     Case 6          'Update
  308.       If save = True Then
  309.         If data1.EditMode = EM_ADDNEW Then
  310.           If MsgBox("Save New Record?", MSGBOX_TYPE) = YES Then
  311.             data1.UpdateRecord
  312.             data1.Caption = "Editing Record"
  313.           Else
  314.             save = 0: Action = 0
  315.           End If
  316.         ElseIf MsgBox("Commit Changes?", MSGBOX_TYPE) = YES Then
  317.           data1.UpdateRecord
  318.         End If
  319.       End If
  320.     Case 10          'Close
  321.       If save = True Then
  322.         If MsgBox("Commit Changes before Closing?", MSGBOX_TYPE) = YES Then
  323.         Else
  324.           Cancel = True
  325.         End If
  326.       End If
  327.   End Select
  328. End Sub
  329. Sub DeleteBtn_Click ()
  330.   On Error GoTo DelErr
  331.   If MsgBox("Delete Current Record?", MSGBOX_TYPE) = YES Then
  332.     data1.Recordset.Delete
  333.     data1.Recordset.MoveNext
  334.     If AddBtn.Tag <> "Disabled" Then FldArr(0).SetFocus
  335.   End If
  336.   GoTo DelEnd
  337. DelErr:
  338.     If Err = 444 Then
  339.         MsgBox "Can't delete this record.", 64, "Data Manager"
  340.     ElseIf Err = 3021 Then
  341.         DisableAllControls
  342.     Else
  343.         MsgBox Error$, 64, "Data Manager"
  344.     End If
  345.     If AddBtn.Tag <> "Disabled" Then FldArr(0).SetFocus
  346.   Resume DelEnd
  347. DelEnd:
  348. End Sub
  349. Sub DisableAllControls ()
  350.     On Error GoTo disableerror
  351.     'This handles the case of calls with empty tables before
  352.     'call of loadfields.  Otherwise, you get subscript out of range.
  353.    Dim i As Integer
  354.    DeleteBtn.Enabled = False
  355.    UpdateBtn.Enabled = False
  356. '   FindBtn.Enabled = False
  357.    For i = 0 To data1.Recordset.Fields.Count - 1
  358.      FldArr(i).Visible = False
  359.    Next i
  360.     GoTo disableend
  361. disableerror:
  362.     Resume disableend
  363. disableend:
  364.    AddBtn.Tag = "Disabled"
  365.    data1.Caption = "No Current Record"
  366. End Sub
  367. Sub EnableAllControls ()
  368.    Dim i As Integer
  369.    DeleteBtn.Enabled = True
  370.    UpdateBtn.Enabled = True
  371. '   FindBtn.Enabled = True
  372.    For i = 0 To data1.Recordset.Fields.Count - 1
  373.      FldArr(i).Visible = True
  374.    Next i
  375.    AddBtn.Tag = "Enabled"
  376.    If data1.Caption <> "Entering New Record" Then
  377.     data1.Caption = "Editing Record"
  378.    End If
  379. End Sub
  380. Sub FindBtn_Click ()
  381.   On Error GoTo FindErr
  382.   Dim bm As String, findstr As String
  383.   findstr = InputBox("Enter Search Expression:")
  384.   If findstr = "" Then Exit Sub
  385.   If Not data1.Recordset.BOF And Not data1.Recordset.EOF Then
  386.     bm = data1.Recordset.Bookmark
  387.   End If
  388.   data1.Recordset.FindFirst findstr
  389.   'return to old record if no match was found
  390.   If data1.Recordset.NoMatch And bm <> "" Then
  391.     data1.Recordset.Bookmark = bm
  392.   End If
  393.   GoTo FindEnd
  394. FindErr:
  395.   MsgBox Error$
  396.   Resume FindEnd
  397. FindEnd:
  398.   If FldArr(0).Visible = True Then FldArr(0).SetFocus
  399. End Sub
  400. Sub Form_Load ()
  401.   Dim ds2 As Dynaset
  402.   On Error GoTo LoadErr
  403.   '-------------------------------------------------------
  404.   'this is where the data control properties get
  405.   'set from whatever source they are coming from
  406.   'in this case, it is mainform controls
  407.   '-------------------------------------------------------
  408.   Screen.MousePointer = 11 'wait cursor
  409.   data1.DatabaseName = gDatabaseName
  410.   data1.Connect = gDatabase.Connect
  411.   Me.Caption = UCase(gDatabaseName) + " : " + UCase(mainForm.TableName)
  412.   data1.RecordSource = mainForm.TableName
  413.   '-------------------------------------------------------
  414.   data1.Refresh
  415.   LoadFields data1.Recordset, mainForm.TableName
  416.   data1_Reposition 'This ensures that we enable the controls
  417.   Me.Show
  418.   If AddBtn.Tag = "Enabled" Then
  419.     FldArr(0).SetFocus
  420.   End If
  421.   GoTo loadend
  422. LoadErr:
  423.   MsgBox Error$
  424.   Unload Me
  425.   Resume loadend
  426. loadend:
  427.   Screen.MousePointer = 0
  428. End Sub
  429. Sub Form_Resize ()
  430.   On Error Resume Next
  431.   If fResizing = True Then Exit Sub
  432.   Dim h As Integer, i As Integer
  433.   Dim totw As Integer
  434.   fResizing = True
  435.   If WindowState <> 1 And cFieldName(0).Visible = True Then 'not minimized
  436.     'make sure the form is lined up on a field
  437.     h = Height
  438.     If (h - 1340) Mod 350 <> 0 Then
  439.       Height = ((h - 1340) \ 350) * 350 + 1340
  440.     End If
  441.     'reset scroll
  442.     If Height - 1340 >= cFields.Height - 1065 + 350 Then
  443.         cScrollBar.Visible = False
  444.     Else
  445.         cScrollBar.Max = cScrollBar.Min + 350 * ((Height - 1340) \ 350) - (cFields.Height - 1065 + 350)
  446.         cScrollBar.Visible = True
  447.     End If
  448.     'resize the status bar
  449.     StatBox.Top = Height - 650
  450.     'resize the scrollbar
  451.     cScrollBar.Height = StatBox.Top - (FieldHeader.Top - FieldHeader.Height) - 600
  452.     cScrollBar.Left = Width - 360
  453.     If FDS.Fields.Count > 10 Then
  454.       cFields.Width = Width - 260
  455.       totw = cScrollBar.Left - 20
  456.     Else
  457.       cFields.Width = Width - 20
  458.       totw = Width - 50
  459.     End If
  460.     FieldHeader.Width = Width - 20
  461.     'widen the fields if possible
  462. '    data1.Database.TableDefs(TableName).Fields.Refresh
  463. '    For i = 0 To data1.Recordset.Fields.Count - 1
  464. '      cFieldName(i).Width = .3 * totw
  465. '       FldArr(i).Left = cFieldName(i).Width + 20
  466. '      If data1.Recordset.Fields(i).Type > 9 Then
  467. '        FldArr(i).Width = .7 * totw - 270
  468. '      End If
  469. '    Next
  470.     FieldValueLabel.Left = FldArr(0).Left
  471.   End If
  472.   data1.Width = StatBox.Width
  473.   fResizing = False
  474. End Sub
  475. Function GetFieldWidth (t As Integer)
  476.   'determines the form control width
  477.   'based on the field type
  478.   Select Case t
  479.     Case FT_TRUEFALSE
  480.       GetFieldWidth = 850
  481.     Case FT_BYTE
  482.       GetFieldWidth = 650
  483.     Case FT_INTEGER
  484.       GetFieldWidth = 900
  485.     Case FT_LONG
  486.       GetFieldWidth = 1100
  487.     Case FT_CURRENCY
  488.       GetFieldWidth = 1800
  489.     Case FT_SINGLE
  490.       GetFieldWidth = 1800
  491.     Case FT_DOUBLE
  492.       GetFieldWidth = 2200
  493.     Case FT_DATETIME
  494.       GetFieldWidth = 2000
  495.     Case FT_STRING
  496.       GetFieldWidth = 3250
  497.     Case FT_MEMO
  498.       GetFieldWidth = 3250
  499.     Case Else
  500.       GetFieldWidth = 3250
  501.   End Select
  502. End Function
  503. Sub LoadFields (t As Dynaset, tName)
  504. '   Dim t As table
  505.    Dim ft As Integer
  506.    Dim i As Integer
  507.    On Error GoTo LoadFieldsErr
  508. '   Set t = db.OpenTable(tName)
  509.    'load the controls on the dynaset form
  510.    numFlds = t.Fields.Count
  511.     If numFlds = 0 Then
  512.         MsgBox "There are no fields in this table.  Cannot Edit Table Data", 64, "Data Manager"
  513.         Unload Me
  514.     End If
  515.    ReDim FldArr(numFlds) As control
  516.    cFieldName(0).Visible = True
  517.    ft = t.Fields(0).Type
  518.    If ft = FT_TRUEFALSE Then
  519.      Set FldArr(0) = cFieldCheck(0)
  520.    ElseIf ft = FT_BINARY Then
  521.      Set FldArr(0) = cFieldPicture(0)
  522.    Else
  523.      Set FldArr(0) = cFieldData(0)
  524.    End If
  525.    FldArr(0).Visible = True
  526.    FldArr(0).Top = 0
  527.    FldArr(0).Width = GetFieldWidth(ft)
  528.    FldArr(0).TabIndex = 0
  529.    On Error Resume Next
  530.    For i = 1 To t.Fields.Count - 1
  531.      cFields.Height = cFields.Height + 350
  532.      Load cFieldName(i)
  533.      cFieldName(i).Top = cFieldName(i - 1).Top + 350
  534.      cFieldName(i).Visible = True
  535.      ft = t.Fields(i).Type
  536.      If ft = FT_TRUEFALSE Then
  537.        Load cFieldCheck(i)
  538.        Set FldArr(i) = cFieldCheck(i)
  539.      ElseIf ft = FT_BINARY Then
  540.        Load cFieldPicture(i)
  541.        Set FldArr(i) = cFieldPicture(i)
  542.      Else
  543.        Load cFieldData(i)
  544.        Set FldArr(i) = cFieldData(i)
  545.      End If
  546.      FldArr(i).Top = FldArr(i - 1).Top + 350
  547.      FldArr(i).Width = GetFieldWidth(ft)
  548.      FldArr(i).TabIndex = i
  549.    Next
  550.    AddBtn.Tag = "Disabled"
  551.    On Error GoTo LoadFieldsErr
  552.    'resize main window
  553.    cFields.Top = FieldHeader.Top + FieldHeader.Height
  554.    FldTop = cFields.Top
  555.    cScrollBar.Min = FldTop
  556.    If i <= 10 Then
  557.      Height = i * 350 + 1500
  558.      cScrollBar.Visible = False
  559.    Else
  560.      Height = 5000
  561.      Width = Width + 260
  562.      cScrollBar.Visible = True
  563.      cScrollBar.Max = FldTop - (i * 350) + 3500
  564.      cScrollBar = FldTop
  565.    End If
  566.    'display the field names
  567.    For i = 0 To t.Fields.Count - 1
  568.      cFieldName(i) = UCase(t.Fields(i).Name) + ":"
  569.    Next
  570.    'bind the controls
  571.    On Error Resume Next   'bind even if table is empty
  572.    For i = 0 To t.Fields.Count - 1
  573.      FldArr(i).DataField = t.Fields(i).Name
  574.    Next
  575.    GoTo LoadFieldsEnd
  576. LoadFieldsErr:
  577.    MsgBox Error$
  578.    Resume LoadFieldsEnd
  579. LoadFieldsEnd:
  580. End Sub
  581. Sub MoveBtn_Click (Index As Integer)
  582.   On Error GoTo moveerr
  583.   Dim bm As String
  584.   If Not data1.Recordset.BOF And Not data1.Recordset.EOF Then
  585.     bm = data1.Recordset.Bookmark
  586.   End If
  587.   Select Case Index
  588.     Case 0
  589.       If findval <> "" Then
  590.         data1.Recordset.FindFirst findval
  591.       Else
  592.         data1.Recordset.MoveFirst
  593.       End If
  594.     Case 1
  595.       If findval <> "" Then
  596.         data1.Recordset.FindPrevious findval
  597.       Else
  598.         data1.Recordset.MovePrevious
  599.       End If
  600.     Case 2
  601.       If findval <> "" Then
  602.         data1.Recordset.FindNext findval
  603.       Else
  604.         data1.Recordset.MoveNext
  605.       End If
  606.     Case 3
  607.       If findval <> "" Then
  608.         data1.Recordset.FindLast findval
  609.       Else
  610.         data1.Recordset.MoveLast
  611.       End If
  612.   End Select
  613.   'return to old record if no match was found
  614.   If data1.Recordset.NoMatch And bm <> "" Then
  615.     data1.Recordset.Bookmark = bm
  616.   End If
  617.   GoTo moveend
  618. moveerr:
  619.   MsgBox Error$
  620.   Resume moveend
  621. moveend:
  622.   FldArr(0).SetFocus
  623. End Sub
  624. Sub RefreshBtn_Click ()
  625.   data1.Refresh
  626. End Sub
  627. Sub UpdateBtn_Click ()
  628.   On Error GoTo UpdErr
  629.   data1.Recordset.Update
  630.   GoTo UpdEnd
  631. UpdErr:
  632.   MsgBox Error$
  633.   Resume UpdEnd
  634. UpdEnd:
  635. End Sub
  636.