home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 1997 August / Personal_Computer_World_Aug_97.iso / multi / flow / abc.z / NETWORK.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-12-16  |  15.2 KB  |  473 lines

  1. VERSION 4.00
  2. Begin VB.Form NetworkDatabaseDemo 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Network Database Demo"
  7.    ClientHeight    =   1950
  8.    ClientLeft      =   1245
  9.    ClientTop       =   2190
  10.    ClientWidth     =   5265
  11.    ClipControls    =   0   'False
  12.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  13.       Name            =   "MS Sans Serif"
  14.       Size            =   8.25
  15.       Charset         =   0
  16.       Weight          =   700
  17.       Underline       =   0   'False
  18.       Italic          =   0   'False
  19.       Strikethrough   =   0   'False
  20.    EndProperty
  21.    ForeColor       =   &H80000008&
  22.    Height          =   2355
  23.    Icon            =   "NETWORK.frx":0000
  24.    Left            =   1185
  25.    LinkTopic       =   "Form1"
  26.    MaxButton       =   0   'False
  27.    ScaleHeight     =   1950
  28.    ScaleWidth      =   5265
  29.    Top             =   1845
  30.    Width           =   5385
  31.    Begin VB.CommandButton BrowseBtn 
  32.       Appearance      =   0  'Flat
  33.       BackColor       =   &H80000005&
  34.       Caption         =   "&Browse..."
  35.       Height          =   375
  36.       Left            =   3690
  37.       TabIndex        =   6
  38.       Top             =   795
  39.       Width           =   1335
  40.    End
  41.    Begin VB.PictureBox Picture1 
  42.       Appearance      =   0  'Flat
  43.       BackColor       =   &H00C0C0C0&
  44.       BorderStyle     =   0  'None
  45.       ForeColor       =   &H80000008&
  46.       Height          =   495
  47.       Left            =   4350
  48.       Picture         =   "NETWORK.frx":030A
  49.       ScaleHeight     =   495
  50.       ScaleWidth      =   495
  51.       TabIndex        =   4
  52.       Top             =   195
  53.       Width           =   495
  54.    End
  55.    Begin VB.Data Data1 
  56.       Appearance      =   0  'Flat
  57.       Caption         =   "Data1"
  58.       Connect         =   ""
  59.       DatabaseName    =   ""
  60.       Exclusive       =   0   'False
  61.       Height          =   270
  62.       Left            =   1440
  63.       Options         =   0
  64.       ReadOnly        =   0   'False
  65.       RecordsetType   =   1  'Dynaset
  66.       RecordSource    =   "Network"
  67.       Top             =   3600
  68.       Visible         =   0   'False
  69.       Width           =   1935
  70.    End
  71.    Begin VB.CommandButton cmdCancel 
  72.       Appearance      =   0  'Flat
  73.       BackColor       =   &H80000005&
  74.       Caption         =   "&Cancel"
  75.       Height          =   375
  76.       Left            =   2640
  77.       TabIndex        =   2
  78.       Top             =   1440
  79.       Width           =   1335
  80.    End
  81.    Begin VB.CommandButton cmdOK 
  82.       Appearance      =   0  'Flat
  83.       BackColor       =   &H80000005&
  84.       Caption         =   "&OK"
  85.       Default         =   -1  'True
  86.       Height          =   375
  87.       Left            =   1065
  88.       TabIndex        =   1
  89.       Top             =   1440
  90.       Width           =   1335
  91.    End
  92.    Begin VB.TextBox Text1 
  93.       Appearance      =   0  'Flat
  94.       Height          =   285
  95.       Left            =   105
  96.       TabIndex        =   0
  97.       Top             =   840
  98.       Width           =   3465
  99.    End
  100.    Begin MSComDlg.CommonDialog OpenDatabaseFile 
  101.       Left            =   120
  102.       Top             =   1440
  103.       _Version        =   65536
  104.       _ExtentX        =   847
  105.       _ExtentY        =   847
  106.       _StockProps     =   0
  107.    End
  108.    Begin AbcflowLib.ABC ABC1 
  109.       Left            =   4320
  110.       Top             =   1440
  111.       _Version        =   65536
  112.       _ExtentX        =   1085
  113.       _ExtentY        =   873
  114.       _StockProps     =   1
  115.    End
  116.    Begin VB.Label Label2 
  117.       Alignment       =   2  'Center
  118.       Appearance      =   0  'Flat
  119.       BackColor       =   &H00C0C0C0&
  120.       BackStyle       =   0  'Transparent
  121.       Caption         =   "Press ""Browse"" to choose another database."
  122.       ForeColor       =   &H80000008&
  123.       Height          =   495
  124.       Left            =   840
  125.       TabIndex        =   5
  126.       Top             =   120
  127.       Width           =   3015
  128.    End
  129.    Begin VB.Label Label1 
  130.       Appearance      =   0  'Flat
  131.       AutoSize        =   -1  'True
  132.       BackColor       =   &H00C0C0C0&
  133.       Caption         =   "Database File:"
  134.       ForeColor       =   &H80000008&
  135.       Height          =   195
  136.       Left            =   120
  137.       TabIndex        =   3
  138.       Top             =   600
  139.       Width           =   1245
  140.    End
  141.    Begin VB.Line Line1 
  142.       BorderColor     =   &H00FFFFFF&
  143.       X1              =   0
  144.       X2              =   5280
  145.       Y1              =   1320
  146.       Y2              =   1320
  147.    End
  148. Attribute VB_Name = "NetworkDatabaseDemo"
  149. Attribute VB_Creatable = False
  150. Attribute VB_Exposed = False
  151. Option Explicit
  152.     Dim ABC As Object
  153.     Dim NetSource As RECORD
  154.     Dim UserName As String
  155.     Dim DataBaseFile As String
  156.     Dim TestFileValid As String
  157.     Const DATA_ERRCONTINUE = 1
  158.     Const DATA_ERRDISPLAY = 0
  159.     Const OFN_FILEMUSTEXIST = &H1000&
  160.     Const OFN_PATHMUSTEXIST = &H800&
  161. Private Sub ABC1_AppQuitNOTIFY()
  162.     Data1.Recordset.Close
  163.     End
  164. End Sub
  165. Private Sub ABC1_DoubleClickSUBCLASS(ByVal Object As Object, ByVal Chart As Object, Override As Boolean)
  166.     Dim Obj As Object
  167.     Set Obj = ABC1.Chart.Objects.ItemFromText(".mdb")
  168.     If Obj.Valid Then
  169.         ' Get the database from the chart
  170.         Data1.DatabaseName = Obj.Text
  171.         GetDatabaseInfo (Object.Text)
  172.     Else
  173.         
  174.     End If
  175.     Override = True
  176. End Sub
  177. Private Sub BrowseBtn_Click()
  178.     'In case of error
  179.     On Error Resume Next
  180.     'Set properties here
  181.     OpenDatabaseFile.CancelError = True
  182.     OpenDatabaseFile.DefaultExt = "mdb"
  183.     OpenDatabaseFile.Filter = "Database Files(*.mdb)|*.mdb"
  184.     OpenDatabaseFile.Flags = OFN_FILEMUSTEXIST And OFN_PATHMUSTEXIST
  185.     OpenDatabaseFile.Action = 1
  186.     'Close if cancelled
  187.     If Err = 32755 Then
  188.         Exit Sub
  189.     Else
  190.         DataBaseFile = OpenDatabaseFile.filename
  191.     End If
  192.      
  193.     Text1.Text = DataBaseFile
  194. End Sub
  195. Private Sub cmdCancel_Click()
  196.      Unload NetworkDatabaseDemo
  197.      End
  198. End Sub
  199. Private Sub cmdOK_Click()
  200.     Dim DataBaseFileOne As Integer
  201.     Dim DataBaseFileTwo As Integer
  202.     Err = 0
  203.     DataBaseFile = Text1.Text
  204.     DataBaseFileOne = InStr(DataBaseFile, "NETBASE1.MDB")
  205.     DataBaseFileTwo = InStr(DataBaseFile, "NETBASE2.MDB")
  206.     If Not DataBaseFileOne > 1 And DataBaseFileTwo = 0 Then
  207.     Err = 2
  208.     ElseIf Not DataBaseFileTwo > 1 And DataBaseFileOne = 0 Then
  209.     Err = 2
  210.     End If
  211.     If Err = 1 Then
  212.         cmdOK.Enabled = False
  213.         MsgBox "File does not exist!", 48
  214.         Text1.SetFocus
  215.     End If
  216.     If Err = 2 Then
  217.         cmdOK.Enabled = False
  218.         MsgBox "This is an Invalid Database File!", 48
  219.         Text1.SetFocus
  220.     End If
  221.     If Err = 0 Then
  222.         cmdOK.Enabled = False
  223.         NetworkDatabaseDemo.WindowState = 1 ' iconize form
  224.         NetworkDatabaseDemo.Refresh
  225.         'Build the chart
  226.         Call DrawNetChart(DataBaseFile)
  227.         Call ValidateFilename
  228.     End If
  229. End Sub
  230. Private Sub DrawNetChart(DataBaseFile As String)
  231.         
  232.     Dim Shape As Object
  233.     Dim Shape1 As Object
  234.     Dim TextTitle As Object
  235.     Dim recCount As Integer
  236.     Dim PageWidth As Integer
  237.     Dim ChartCancelled As Integer
  238.     Dim CurrentRec As String
  239.     Dim FieldInfo As String
  240.     Dim ProcessorType As String
  241.     Dim Chart As Object
  242.     Dim ABCObject As Object
  243.     Dim NewLine() As Object
  244.     Dim Obj As Object
  245.     Dim DataBaseText As Object
  246.     Dim Counter As Integer
  247.     Dim TotalCount As Integer
  248.     'Get the chart
  249.     Set Chart = ABC.New
  250.     Rem Set the Chart's internal type
  251.     Chart.Type = "NETWORK"
  252.     Chart.TypeUsesEXE = True
  253.     Set ABCObject = Chart.Objects
  254.     'Prepare for chart to draw
  255.     Chart.NoRepaint = True
  256.     Chart.MasterItems.HideAll
  257.     Chart.PageLayout.Orientation = 1
  258.     Chart.View = 1
  259.     ABC.ShapePaletteVisible = False
  260.     ' Set defaults so there are no shape numbers
  261.     Set Obj = Chart.DrawShape
  262.     Obj.Shape.NumberShowN = False
  263.     Chart.SetDefaults Obj
  264.     Obj.Clear_               'This object can be seen when selected'
  265.     'Set gauge
  266.     ABC.PercentGauge NetworkDatabaseDemo.Caption, "Building Diagram", "Please Wait..."
  267.     ChartCancelled = ABC.PercentGaugeCancelled
  268.         If ChartCancelled = True Then
  269.         Call EndAppDraw
  270.         End If
  271.     'Title page
  272.     Chart.CurrentShapePalette = "Standard"
  273.     Chart.CurrentShape = "Rounded Process"
  274.     Chart.DrawPositionX = 4.5
  275.     Chart.DrawPositionY = 0.5
  276.     Set Shape = Chart.DrawShape
  277.     Shape.Height = 0.5
  278.     Shape.Width = 5.5
  279.     Shape.Text = "Network Diagram"
  280.     Shape.Font.Size = 18
  281.     Shape.Font.Bold = True
  282.     Shape.Shape.BorderWidth = 3
  283.     Shape.Shape.BorderColor = ABC.RED
  284.     Shape.Shape.FillColor = ABC.GRAY
  285.     'give feedback here
  286.     'ABC.PercentGaugeValue = 10
  287.     'cancel chart?
  288.     ChartCancelled = ABC.PercentGaugeCancelled
  289.         If ChartCancelled Then
  290.         Call EndAppDraw
  291.         End If
  292.    'Get Network palette
  293.     Chart.CurrentShapePalette = "Net - PC Workstations"
  294.     Chart.CurrentShape = "Tower"
  295.     'Set shape spacing
  296.     Chart.DrawPositionX = 4.5
  297.     Chart.DrawPositionY = 1.5
  298.     Set Shape1 = Chart.DrawShape
  299.     Shape1.Height = 1.25
  300.     Shape1.Width = 1.25
  301.     Shape1.Text = "SERVER"
  302.     Shape1.Font.Bold = True
  303.     Shape1.Font.Size = 12
  304.     ChartCancelled = ABC.PercentGaugeCancelled
  305.         If ChartCancelled Then
  306.         Call EndAppDraw
  307.         End If
  308.     'Open the Database
  309.     Data1.DatabaseName = DataBaseFile
  310.     Data1.RecordSource = "Network"
  311.     Data1.Refresh
  312.     'Get the number of records
  313.     recCount = GetRecNum(Data1.Recordset)
  314.     Data1.Refresh
  315.     PageWidth = Chart.PageLayout.Width
  316.     If recCount <= 5 Then
  317.     Chart.DrawSpacingX = PageWidth / recCount
  318.     Chart.DrawPositionX = (PageWidth / 2) / recCount
  319.     Else
  320.     Chart.DrawSpacingX = 1.5
  321.     Chart.DrawPositionX = 1
  322.     End If
  323.     Chart.DrawPositionY = 3.5
  324.     Chart.DrawDirection = 1
  325.     Do While Not Data1.Recordset.EOF
  326.         CurrentRec = GetCurrRec(Data1.Recordset)
  327.         CopyMemory NetSource, ByVal CurrentRec, Len(NetSource)
  328.         FieldInfo = Trim(NetSource.User)
  329.         ProcessorType = Trim(NetSource.Computer)
  330.     'Draw Shapes and add Usernames
  331.         Chart.CurrentShape = ProcessorType
  332.         Set Shape = Chart.DrawShape
  333.         Shape.Height = 1.25
  334.         Shape.Width = 1.25
  335.         Shape.Text = FieldInfo
  336.         Shape.Font.Size = 12
  337.         Shape.Font.Color = ABC.BLUE
  338.         TotalCount = recCount
  339.         Counter = 100 / TotalCount
  340.     'Draw Lines from server to workstation
  341.         Chart.CurrentLineRouting = 3
  342.             ReDim NewLine(recCount) As Object
  343.         Set NewLine(recCount) = Chart.DrawLine(Shape1, Shape, 2, 0)
  344.         NewLine(recCount).Line_.StemWidth = 3
  345.         recCount = recCount - 1
  346.     'Increment gauge
  347.         If Counter > 0 Then
  348.         ABC.PercentGaugeValue = Int(100 - (Counter * recCount))
  349.         End If
  350.         
  351.      Data1.Recordset.MoveNext
  352.     Loop
  353.     'Give feedback here
  354.     'ABC.PercentGaugeValue = 90
  355.     ChartCancelled = ABC.PercentGaugeCancelled
  356.         If ChartCancelled Then
  357.         Call EndAppDraw
  358.         End If
  359.     'Give double-click instructions
  360.     Chart.DrawPositionX = 1.5
  361.     Chart.DrawPositionY = 5
  362.     Set TextTitle = Chart.DrawTextBlock(UCase("To find server information, Double-click on a shape."))
  363.     TextTitle.Font.Bold = True
  364.     TextTitle.Font.Size = 16
  365.     TextTitle.CenterX = PageWidth / 2
  366.     ' Write out database name
  367.     Chart.DrawPositionX = 1.5
  368.     Chart.DrawPositionY = 5.25
  369.     Set DataBaseText = Chart.DrawTextBlock(LCase(Text1))
  370.     DataBaseText.Font.Bold = False
  371.     DataBaseText.Font.Size = 12
  372.     DataBaseText.CenterX = PageWidth / 2
  373.     'Data1.Recordset.Close
  374.     Data1.Refresh
  375.     'Give feedback here
  376.     ABC.PercentGaugeValue = 99
  377.     ABC.HidePercentGauge
  378.     'Draw chart
  379.     Chart.NoRepaint = False
  380.     Chart.Repaint
  381. End Sub
  382. Private Sub EndAppDraw()
  383.         ABC.HidePercentGauge
  384.         End
  385. End Sub
  386. Private Sub Form_Load()
  387.    'Open ABC
  388.     Set ABC = CreateObject("ABCFlow.Application")
  389.    ' ABC.Maximize
  390.     ABC.Hourglass = True
  391.     ABC.Visible = True
  392.     'Register the Events
  393.     ABC.RegisterEvent ABC1, "Network", "DoubleClickSUBCLASS"
  394.     ABC.RegisterEvent ABC1, "Network", "AppQuitNOTIFY"
  395.     'Load both forms
  396.     Load ServerInfo
  397.     NetworkDatabaseDemo.Left = (Screen.Width - Width) \ 2
  398.     NetworkDatabaseDemo.Top = (Screen.Height - Height) \ 2
  399.     Text1.Text = UCase(App.Path & "\" & "netbase1.mdb")
  400.     NetworkDatabaseDemo.Show
  401. End Sub
  402. Private Sub GetDatabaseInfo(UserName As String)
  403.     Dim CurrentRec As String
  404.     Data1.RecordSource = "Network"
  405.     Data1.Refresh
  406.     'Find this username in the database
  407.         If UserName = Data1.Recordset.Fields("User").Value Then
  408.             CurrentRec = GetCurrRec(Data1.Recordset)
  409.             CopyMemory NetSource, ByVal CurrentRec, Len(NetSource)
  410.     'Display server information
  411.     ServerInfo.txtType.Text = Trim$(NetSource.Type)
  412.     ServerInfo.txtProcess = Trim$(NetSource.Computer)
  413.     ServerInfo.txtUserID = Trim$(NetSource.UserID)
  414.     ServerInfo.txtUserName = Trim$(NetSource.User)
  415.     ServerInfo.txtServer = Trim$(NetSource.Server)
  416.     ServerInfo.Show 1
  417.           
  418.         ElseIf UserName = "" Then
  419.                     MsgBox "This Station is Unassigned.", 64
  420.         ElseIf Not UserName = Data1.Recordset.Fields("User").Value Then
  421.             Data1.Recordset.MoveFirst
  422.             Do
  423.                 Data1.Recordset.MoveNext
  424.                     On Error GoTo Error_out
  425.             Loop Until Data1.Recordset.EOF = True Or UserName = Data1.Recordset.Fields("User").Value
  426.                 CurrentRec = GetCurrRec(Data1.Recordset)
  427.                 CopyMemory NetSource, ByVal CurrentRec, Len(NetSource)
  428.     'Display server information
  429.     ServerInfo.txtType.Text = Trim$(NetSource.Type)
  430.     ServerInfo.txtProcess = Trim$(NetSource.Computer)
  431.     ServerInfo.txtUserID = Trim$(NetSource.UserID)
  432.     ServerInfo.txtUserName = Trim$(NetSource.User)
  433.     ServerInfo.txtServer = Trim$(NetSource.Server)
  434.     ServerInfo.Show 1
  435.         
  436.         End If
  437. Error_out:
  438.           Select Case Err
  439.                 Case 3021
  440.             ServerInfo.Hide
  441.             MsgBox UCase("This is not a Workstation!") + Chr(13) + Chr(13) + "  Please choose a valid name."
  442.             'DATA_ERRDISPLAY = 0
  443.             'DATA_ERRCONTINUE = 1
  444.             Data1.Refresh
  445.             Data1.Recordset.MoveFirst
  446.             Resume CloseDB
  447.                 Case Else
  448.                 Data1.Refresh
  449.                 ServerInfo.Hide
  450.           End Select
  451. CloseDB:
  452.         Data1.Refresh
  453.         Data1.Recordset.MoveFirst
  454.         
  455. End Sub
  456. Private Sub Text1_Change()
  457.     Call ValidateFilename
  458. End Sub
  459. Private Sub Text1_GotFocus()
  460.     Text1.SelStart = 0
  461.     Text1.SelLength = Len(Text1.Text)
  462. End Sub
  463. Private Sub ValidateFilename()
  464.     Dim Attr As Single
  465.     On Error Resume Next
  466.     Attr = GetAttr(Text1)
  467.     If Err Then
  468.         cmdOK.Enabled = False
  469.     Else
  470.         cmdOK.Enabled = True
  471.     End If
  472. End Sub
  473.