home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / relation.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  16.8 KB  |  528 lines

  1. VERSION 4.00
  2. Begin VB.Form frmRelations 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Relations"
  5.    ClientHeight    =   4545
  6.    ClientLeft      =   1080
  7.    ClientTop       =   1515
  8.    ClientWidth     =   8055
  9.    Height          =   4950
  10.    HelpContextID   =   2016087
  11.    Icon            =   "RELATION.frx":0000
  12.    Left            =   1020
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MDIChild        =   -1  'True
  16.    ScaleHeight     =   4545
  17.    ScaleWidth      =   8055
  18.    Top             =   1170
  19.    Width           =   8175
  20.    Begin VB.CommandButton cmdClose 
  21.       Caption         =   "&Close"
  22.       Height          =   375
  23.       Left            =   5280
  24.       TabIndex        =   17
  25.       Top             =   4080
  26.       Width           =   2175
  27.    End
  28.    Begin VB.CommandButton cmdDelete 
  29.       Caption         =   "&Delete Relation"
  30.       Height          =   375
  31.       Left            =   2880
  32.       TabIndex        =   16
  33.       Top             =   4080
  34.       Width           =   2175
  35.    End
  36.    Begin VB.CommandButton cmdAdd 
  37.       Caption         =   "&New Relation"
  38.       Height          =   375
  39.       Left            =   480
  40.       TabIndex        =   15
  41.       Top             =   4080
  42.       Width           =   2175
  43.    End
  44.    Begin VB.PictureBox picJoinType 
  45.       BorderStyle     =   0  'None
  46.       Enabled         =   0   'False
  47.       Height          =   855
  48.       Left            =   120
  49.       ScaleHeight     =   855
  50.       ScaleWidth      =   7815
  51.       TabIndex        =   21
  52.       TabStop         =   0   'False
  53.       Top             =   3120
  54.       Width           =   7815
  55.       Begin VB.OptionButton optJoinType 
  56.          Caption         =   "All records from foreign and only those from base where joined fields are equal."
  57.          Height          =   255
  58.          Index           =   2
  59.          Left            =   120
  60.          TabIndex        =   14
  61.          Top             =   560
  62.          Width           =   6255
  63.       End
  64.       Begin VB.OptionButton optJoinType 
  65.          Caption         =   "All records from base and only those from foreign where joined fields are equal."
  66.          Height          =   255
  67.          Index           =   1
  68.          Left            =   120
  69.          TabIndex        =   13
  70.          Top             =   300
  71.          Width           =   6375
  72.       End
  73.       Begin VB.OptionButton optJoinType 
  74.          Caption         =   "Only rows where joined fields from both tables are equal."
  75.          Height          =   255
  76.          Index           =   0
  77.          Left            =   120
  78.          TabIndex        =   12
  79.          Top             =   40
  80.          Width           =   6255
  81.       End
  82.    End
  83.    Begin VB.PictureBox picProperties 
  84.       Appearance      =   0  'Flat
  85.       BorderStyle     =   0  'None
  86.       Enabled         =   0   'False
  87.       ForeColor       =   &H80000008&
  88.       Height          =   2895
  89.       Left            =   2640
  90.       ScaleHeight     =   2895
  91.       ScaleWidth      =   5295
  92.       TabIndex        =   19
  93.       TabStop         =   0   'False
  94.       Top             =   0
  95.       Width           =   5295
  96.       Begin VB.ComboBox cboBaseField 
  97.          Height          =   300
  98.          ItemData        =   "RELATION.frx":030A
  99.          Left            =   3240
  100.          List            =   "RELATION.frx":0311
  101.          Style           =   2  'Dropdown List
  102.          TabIndex        =   3
  103.          Top             =   720
  104.          Width           =   2055
  105.       End
  106.       Begin VB.ComboBox cboForeignField 
  107.          Height          =   300
  108.          ItemData        =   "RELATION.frx":0323
  109.          Left            =   3240
  110.          List            =   "RELATION.frx":032A
  111.          Style           =   2  'Dropdown List
  112.          TabIndex        =   5
  113.          Top             =   1080
  114.          Width           =   2055
  115.       End
  116.       Begin VB.ComboBox cboForeignTable 
  117.          Height          =   300
  118.          Left            =   840
  119.          Sorted          =   -1  'True
  120.          Style           =   2  'Dropdown List
  121.          TabIndex        =   4
  122.          Top             =   1080
  123.          Width           =   2295
  124.       End
  125.       Begin VB.ComboBox cboBaseTable 
  126.          Height          =   300
  127.          Left            =   840
  128.          Sorted          =   -1  'True
  129.          Style           =   2  'Dropdown List
  130.          TabIndex        =   2
  131.          Top             =   720
  132.          Width           =   2295
  133.       End
  134.       Begin VB.TextBox txtRelationName 
  135.          Height          =   285
  136.          Left            =   840
  137.          TabIndex        =   1
  138.          Top             =   120
  139.          Width           =   4455
  140.       End
  141.       Begin VB.CheckBox chkInherited 
  142.          Caption         =   "Inherited"
  143.          Height          =   255
  144.          Left            =   120
  145.          TabIndex        =   6
  146.          Top             =   1560
  147.          Width           =   3015
  148.       End
  149.       Begin VB.CheckBox chkReferentialIntegrity 
  150.          Caption         =   "Enforce Referential Integrity"
  151.          Height          =   255
  152.          Left            =   120
  153.          TabIndex        =   7
  154.          Top             =   1920
  155.          Width           =   3015
  156.       End
  157.       Begin VB.CheckBox chkCascadeUpdate 
  158.          Caption         =   "UpdateCascade"
  159.          Enabled         =   0   'False
  160.          Height          =   255
  161.          Left            =   2760
  162.          TabIndex        =   10
  163.          Top             =   2280
  164.          Width           =   1935
  165.       End
  166.       Begin VB.CheckBox chkCascadeDelete 
  167.          Caption         =   "DeleteCascade"
  168.          Enabled         =   0   'False
  169.          Height          =   255
  170.          Left            =   2760
  171.          TabIndex        =   11
  172.          Top             =   2640
  173.          Width           =   1935
  174.       End
  175.       Begin VB.OptionButton optOneToMany 
  176.          Caption         =   "One-To-Many"
  177.          Enabled         =   0   'False
  178.          Height          =   255
  179.          Left            =   165
  180.          TabIndex        =   9
  181.          Top             =   2565
  182.          Width           =   1455
  183.       End
  184.       Begin VB.OptionButton optOneToOne 
  185.          Caption         =   "One-To-One"
  186.          Enabled         =   0   'False
  187.          Height          =   255
  188.          Left            =   165
  189.          TabIndex        =   8
  190.          Top             =   2310
  191.          Width           =   1455
  192.       End
  193.       Begin VB.Label lblLabels 
  194.          AutoSize        =   -1  'True
  195.          Caption         =   "Table Name: "
  196.          Height          =   195
  197.          Index           =   3
  198.          Left            =   840
  199.          TabIndex        =   26
  200.          Top             =   480
  201.          Width           =   960
  202.       End
  203.       Begin VB.Label lblLabels 
  204.          AutoSize        =   -1  'True
  205.          Caption         =   " Foreign: "
  206.          Height          =   195
  207.          Index           =   4
  208.          Left            =   0
  209.          TabIndex        =   25
  210.          Top             =   1125
  211.          Width           =   660
  212.       End
  213.       Begin VB.Label lblLabels 
  214.          AutoSize        =   -1  'True
  215.          Caption         =   " Field Name:  "
  216.          Height          =   195
  217.          Index           =   6
  218.          Left            =   3240
  219.          TabIndex        =   24
  220.          Top             =   480
  221.          Width           =   975
  222.       End
  223.       Begin VB.Label lblLabels 
  224.          AutoSize        =   -1  'True
  225.          Caption         =   " Base: "
  226.          Height          =   195
  227.          Index           =   7
  228.          Left            =   0
  229.          TabIndex        =   23
  230.          Top             =   765
  231.          Width           =   495
  232.       End
  233.       Begin VB.Label lblLabels 
  234.          AutoSize        =   -1  'True
  235.          Caption         =   " Name: "
  236.          Height          =   195
  237.          Index           =   2
  238.          Left            =   0
  239.          TabIndex        =   22
  240.          Top             =   165
  241.          Width           =   555
  242.       End
  243.    End
  244.    Begin VB.ListBox lstRelations 
  245.       Height          =   2205
  246.       Left            =   120
  247.       TabIndex        =   0
  248.       Top             =   360
  249.       Width           =   2415
  250.    End
  251.    Begin VB.Label lblLabels 
  252.       AutoSize        =   -1  'True
  253.       Caption         =   " Join Type: "
  254.       Height          =   195
  255.       Index           =   5
  256.       Left            =   120
  257.       TabIndex        =   20
  258.       Top             =   2880
  259.       Width           =   825
  260.    End
  261.    Begin VB.Label lblLabels 
  262.       AutoSize        =   -1  'True
  263.       Caption         =   " Relations: "
  264.       Height          =   195
  265.       Index           =   0
  266.       Left            =   120
  267.       TabIndex        =   18
  268.       Top             =   120
  269.       Width           =   795
  270.    End
  271. Attribute VB_Name = "frmRelations"
  272. Attribute VB_Creatable = False
  273. Attribute VB_Exposed = False
  274. Option Explicit
  275. Dim mrelFrmRel As Relation
  276. Sub cboBaseTable_Click()
  277.   On Error GoTo BTErr
  278.   If cboBaseTable.ItemData(cboBaseTable.ListIndex) = 0 Then
  279.     'its a table
  280.     ListItemNames gdbCurrentDB.TableDefs(cboBaseTable.Text).Fields, cboBaseField, True
  281.   Else
  282.     'its a querydef
  283.     ListItemNames gdbCurrentDB.QueryDefs(cboBaseTable.Text).Fields, cboBaseField, True
  284.   End If
  285.   Exit Sub
  286. BTErr:
  287.   ShowError
  288.   Exit Sub
  289. End Sub
  290. Sub cboForeignTable_Click()
  291.   On Error GoTo FTErr
  292.   If cboForeignTable.ItemData(cboForeignTable.ListIndex) = 0 Then
  293.     'its a table
  294.     ListItemNames gdbCurrentDB.TableDefs(cboForeignTable.Text).Fields, cboForeignField, True
  295.   Else
  296.     'its a querydef
  297.     ListItemNames gdbCurrentDB.QueryDefs(cboForeignTable.Text).Fields, cboForeignField, True
  298.   End If
  299.   Exit Sub
  300. FTErr:
  301.   ShowError
  302.   Exit Sub
  303. End Sub
  304. Sub chkReferentialIntegrity_Click()
  305.   If chkReferentialIntegrity.Value = 1 Then
  306.     optOneToOne.Enabled = True
  307.     optOneToMany.Enabled = True
  308.     chkCascadeUpdate.Enabled = True
  309.     chkCascadeDelete.Enabled = True
  310.   Else
  311.     optOneToOne.Enabled = False
  312.     optOneToMany.Enabled = False
  313.     chkCascadeUpdate.Enabled = False
  314.     chkCascadeDelete.Enabled = False
  315.   End If
  316. End Sub
  317. Private Sub cmdAdd_Click()
  318.   On Error GoTo AddErr
  319.   Dim rel As Relation
  320.   Dim fld As Field
  321.   If cmdAdd.Caption = "&New Relation" Then
  322.     'enable the controls  to add a new relation
  323.     txtRelationName.Text = gsNULL_STR
  324.     lstRelations.Enabled = False
  325.     picProperties.Enabled = True
  326.     picJoinType.Enabled = True
  327.     cmdDelete.Caption = "&Don't Add Relation"
  328.     cmdAdd.Caption = "&Add Relation"
  329.     Me.Caption = "New Relation"
  330.     txtRelationName.SetFocus
  331.   Else
  332.     'add the new relation
  333.     If Len(txtRelationName.Text) = 0 Or _
  334.        Len(cboBaseTable.Text) = 0 Or _
  335.        Len(cboBaseField.Text) = 0 Or _
  336.        Len(cboForeignTable.Text) = 0 Or _
  337.        Len(cboForeignField.Text) = 0 Then
  338.       MsgBox "Some info was not filled in!", 48
  339.       txtRelationName.SetFocus
  340.       Exit Sub
  341.     End If
  342.     Set rel = gdbCurrentDB.CreateRelation(txtRelationName.Text)
  343.     With rel
  344.       .TABLE = cboBaseTable.Text
  345.       .ForeignTable = cboForeignTable.Text
  346.       'set the attributes
  347.       If chkInherited.Value = 1 Then
  348.         .Attributes = .Attributes Or dbRelationInherited
  349.       End If
  350.       If chkReferentialIntegrity.Value = 1 Then
  351.         If optOneToOne.Value = True Then
  352.           .Attributes = .Attributes Or dbRelationUnique
  353.         End If
  354.         If chkCascadeUpdate.Value = 1 Then
  355.           .Attributes = .Attributes Or dbRelationUpdateCascade
  356.         End If
  357.         If chkCascadeDelete.Value = 1 Then
  358.           .Attributes = .Attributes Or dbRelationDeleteCascade
  359.         End If
  360.       Else
  361.         .Attributes = .Attributes Or dbRelationDontEnforce
  362.       End If
  363.       If optJoinType(2).Value = True Then
  364.         .Attributes = .Attributes Or dbRelationRight
  365.       ElseIf optJoinType(1).Value = True Then
  366.         .Attributes = .Attributes Or dbRelationLeft
  367.       End If
  368.     End With
  369.     'add the fields
  370.     Set fld = rel.CreateField(cboBaseField.Text)
  371.     fld.ForeignName = cboForeignField.Text
  372.     rel.Fields.Append fld
  373.     'add the relation to the database
  374.     gdbCurrentDB.Relations.Append rel
  375.     'must have been successful so add it to the list
  376.     lstRelations.AddItem txtRelationName.Text
  377.     'make the new one active
  378.     lstRelations.ListIndex = lstRelations.NewIndex
  379.     'reset the controls
  380.     lstRelations.Enabled = True
  381.     picProperties.Enabled = False
  382.     picJoinType.Enabled = False
  383.     cmdDelete.Caption = "&Delete Relation"
  384.     cmdAdd.Caption = "&New Relation"
  385.     Me.Caption = "Relations"
  386.   End If
  387.   Exit Sub
  388. AddErr:
  389.   ShowError
  390.   Exit Sub
  391. End Sub
  392. Sub cmdClose_Click()
  393.   Unload Me
  394. End Sub
  395. Private Sub cmdDelete_Click()
  396.   On Error GoTo DELErr
  397.   If cmdDelete.Caption = "&Delete Relation" Then
  398.     If MsgBox("Delete '" & lstRelations.Text & "' Relation?", gnMSGBOX_TYPE) = gnMSGBOX_YES Then
  399.       gdbCurrentDB.Relations.Delete lstRelations.Text
  400.       lstRelations.RemoveItem lstRelations.ListIndex
  401.       If lstRelations.ListCount > 0 Then
  402.         lstRelations.ListIndex = 0
  403.       End If
  404.     End If
  405.   Else
  406.     'reset the controls
  407.     lstRelations.Enabled = True
  408.     picProperties.Enabled = False
  409.     picJoinType.Enabled = False
  410.     cmdDelete.Caption = "&Delete Relation"
  411.     cmdAdd.Caption = "&New Relation"
  412.     Me.Caption = "Relations"
  413.     'make the last active one active again
  414.     'this is needed on failures
  415.     If lstRelations.ListCount > 0 Then
  416.       lstRelations_Click
  417.     End If
  418.   End If
  419.   Exit Sub
  420. DELErr:
  421.   ShowError
  422.   Exit Sub
  423. End Sub
  424. Sub Form_Load()
  425.   On Error GoTo FLErr
  426.   Dim i As Integer
  427.   Dim tdf As TableDef
  428.   Dim qdf As QueryDef
  429.   Dim rln As Relation
  430.   CenterMe Me, gnMDIFORM
  431.   'load tables and querydefs
  432.   GetTableList cboBaseTable, True, False, True
  433.   GetTableList cboForeignTable, True, False, True
  434.   'load relations
  435.   ListItemNames gdbCurrentDB.Relations, lstRelations, False
  436.   If lstRelations.ListCount > 0 Then
  437.     lstRelations.ListIndex = 0
  438.   End If
  439.   Screen.MousePointer = vbDefault
  440.   Exit Sub
  441. FLErr:
  442.   ShowError
  443.   Exit Sub
  444. End Sub
  445. Sub lstRelations_Click()
  446.   On Error GoTo LRErr
  447.   Dim i As Integer
  448.   Dim fld As Field
  449.   Set mrelFrmRel = gdbCurrentDB.Relations(lstRelations.Text)
  450.   'set all the properties
  451.   txtRelationName.Text = mrelFrmRel.Name
  452.   'clear out the lists
  453.   cboBaseField.Clear
  454.   cboForeignField.Clear
  455.   For i = 0 To cboBaseTable.ListCount - 1
  456.     If mrelFrmRel.TABLE = cboBaseTable.List(i) Then
  457.       cboBaseTable.ListIndex = i
  458.       Exit For
  459.     End If
  460.   Next
  461.   ListItemNames gdbCurrentDB.TableDefs(cboBaseTable.Text).Fields, cboBaseField, True
  462.   'set the list to the correct field
  463.   For i = 0 To cboBaseField.ListCount - 1
  464.     If mrelFrmRel.Fields(0).Name = cboBaseField.List(i) Then
  465.       cboBaseField.ListIndex = i
  466.       Exit For
  467.     End If
  468.   Next
  469.   For i = 0 To cboForeignTable.ListCount - 1
  470.     If mrelFrmRel.ForeignTable = cboForeignTable.List(i) Then
  471.       cboForeignTable.ListIndex = i
  472.       Exit For
  473.     End If
  474.   Next
  475.   ListItemNames gdbCurrentDB.TableDefs(cboForeignTable.Text).Fields, cboForeignField, True
  476.   'set the list to the correct field
  477.   For i = 0 To cboForeignField.ListCount - 1
  478.     If mrelFrmRel.Fields(0).ForeignName = cboForeignField.List(i) Then
  479.       cboForeignField.ListIndex = i
  480.       Exit For
  481.     End If
  482.   Next
  483.   If (mrelFrmRel.Attributes And dbRelationInherited) = 0 Then
  484.     chkInherited.Value = 0
  485.   Else
  486.     chkInherited.Value = 1
  487.   End If
  488.   If (mrelFrmRel.Attributes And dbRelationDontEnforce) = 0 Then
  489.     chkReferentialIntegrity.Value = 1
  490.   Else
  491.     chkReferentialIntegrity.Value = 0
  492.   End If
  493.   If (mrelFrmRel.Attributes And dbRelationUnique) = 0 Then
  494.     optOneToMany.Value = True
  495.   Else
  496.     optOneToOne.Value = True
  497.   End If
  498.   If (mrelFrmRel.Attributes And dbRelationUpdateCascade) = 0 Then
  499.     chkCascadeUpdate.Value = 0
  500.   Else
  501.     chkCascadeUpdate.Value = 1
  502.   End If
  503.       
  504.   If (mrelFrmRel.Attributes And dbRelationDeleteCascade) = 0 Then
  505.     chkCascadeDelete.Value = 0
  506.   Else
  507.     chkCascadeDelete.Value = 1
  508.   End If
  509.             
  510.   If (mrelFrmRel.Attributes And dbRelationRight) = dbRelationRight Then
  511.     optJoinType(2).Value = True
  512.   ElseIf (mrelFrmRel.Attributes And dbRelationLeft) = dbRelationLeft Then
  513.     optJoinType(1).Value = True
  514.   Else  'must be an inner join
  515.     optJoinType(0).Value = True
  516.   End If
  517.                 
  518.   Exit Sub
  519. LRErr:
  520.   ShowError
  521.   Exit Sub
  522. End Sub
  523. Sub lstRelations_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
  524.   If Button <> 2 Then Exit Sub
  525.   If SetPropItem(lstRelations, Y) = False Then Exit Sub
  526.   ShowProperties "Relation", gdbCurrentDB.Relations(lstRelations.Text)
  527. End Sub
  528.