VERSION 2.00
Begin Form frmMain 
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Attributes"
   ClientHeight    =   4500
   ClientLeft      =   1575
   ClientTop       =   1590
   ClientWidth     =   7470
   Height          =   4905
   Icon            =   ATTRIBS.FRX:0000
   KeyPreview      =   -1  'True
   Left            =   1515
   MaxButton       =   0   'False
   ScaleHeight     =   4500
   ScaleWidth      =   7470
   Top             =   1245
   Width           =   7590
   Begin CommonDialog ctlCommDlg 
      Left            =   6960
      Top             =   4140
   End
   Begin CommandButton cmdExport 
      Caption         =   "Ex&port"
      Height          =   375
      Left            =   6360
      TabIndex        =   5
      Top             =   1800
      Width           =   1095
   End
   Begin CommandButton cmdEdit 
      Caption         =   "&Edit"
      Height          =   375
      Left            =   6360
      TabIndex        =   2
      Top             =   780
      Width           =   1095
   End
   Begin Grid ctlGrid 
      Cols            =   5
      Height          =   4095
      Left            =   60
      TabIndex        =   0
      Top             =   360
      Width           =   6255
   End
   Begin CommandButton cmdRefresh 
      Caption         =   "&Refresh"
      Height          =   375
      Left            =   6360
      TabIndex        =   4
      Top             =   2400
      Width           =   1095
   End
   Begin CommandButton cmdQuit 
      Caption         =   "E&xit"
      Height          =   375
      Left            =   6360
      TabIndex        =   6
      Top             =   2820
      Width           =   1095
   End
   Begin CommandButton cmdDelete 
      Caption         =   "&Delete"
      Height          =   375
      Left            =   6360
      TabIndex        =   3
      Top             =   1200
      Width           =   1095
   End
   Begin CommandButton cmdAdd 
      Caption         =   "&New"
      Height          =   375
      Left            =   6360
      TabIndex        =   1
      Top             =   360
      Width           =   1095
   End
   Begin Line Line3 
      X1              =   6360
      X2              =   7440
      Y1              =   2280
      Y2              =   2280
   End
   Begin Line Line2 
      X1              =   60
      X2              =   7440
      Y1              =   300
      Y2              =   300
   End
   Begin Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Double Click to Edit Attribute"
      Height          =   195
      Left            =   60
      TabIndex        =   7
      Top             =   60
      Width           =   2775
   End
   Begin Line Line1 
      X1              =   6360
      X2              =   7440
      Y1              =   1680
      Y2              =   1680
   End
End
Option Explicit

Sub cmdAdd_Click ()
    g_fEdit = False
    SetWindowPos frmMain.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
    frmAddAttrib.Show 1
    SetWindowPos frmMain.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
End Sub

Sub cmdDelete_Click ()
    Dim I As Integer
    Dim Attribs As Object

    If AttribCount() <= 0 Then Exit Sub

    Set Attribs = m_db.Attributes

    If ctlGrid.SelStartRow <= ctlGrid.SelEndRow Then
        For I = ctlGrid.SelStartRow To ctlGrid.SelEndRow
            Attribs(m_strAttribs(IDX_NAME, I)).[Delete]
        Next I
    
        RefreshAll
    End If
End Sub

Sub cmdEdit_Click ()
    If AttribCount() <= 0 Then Exit Sub

    g_fEdit = True
    SetWindowPos frmMain.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
    frmAddAttrib.Show 1
    SetWindowPos frmMain.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
End Sub

Sub cmdExport_Click ()
    On Error GoTo lblExportFileErr

    Dim strMsg As String
    Dim strErr As String
    Dim strFileName As String

    ' First we don't want to be ontop when bringing up other forms.

    SetWindowPos frmMain.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE

    ' Next we get the export setup.  This is given back to us through the
    ' use of two globals, g_iWhere and g_iExportType

    frmExport.Show 1

    If (OUT_INVAL = g_iWhere) Or (EXPTYPE_INVAL = g_iExportType) Then
        Exit Sub
    End If

    ' If the user wants a file we use the common dialog to get its name

    If OUT_FILE = g_iWhere Then
        ctlCommDlg.CancelError = True
        ctlCommDlg.DefaultExt = "txt"
        ctlCommDlg.DialogTitle = "Save Attributes To File"
        ctlCommDlg.FilterIndex = 1
        ctlCommDlg.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        ctlCommDlg.Flags = OFN_CREATEPROMPT Or OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY
        ctlCommDlg.Action = 2
    
        strFileName = ctlCommDlg.Filename
    End If

    ' Now we try and perform the export

    Screen.MousePointer = 11

    If OpenOutputBuffer(strFileName) Then
        If Not ExportAttribs() Then
            MsgBox "Error during export.", MB_ICONSTOP, "ATTRIBS - Error"
        End If

        CloseOutputBuffer
    Else
        MsgBox "Could not open export buffers.", MB_ICONSTOP, "ATTRIBS - Error"
    End If

lblExportFileErr:
    ' Cleanup is just putting ourself back on top!

    Screen.MousePointer = 0
    
    g_iWhere = OUT_INVAL
    g_iExportType = EXPTYPE_INVAL

    SetWindowPos frmMain.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
    Exit Sub
End Sub

Sub cmdQuit_Click ()
    End
End Sub

Sub cmdRefresh_Click ()
    RefreshAll
End Sub

Sub ctlGrid_DblClick ()
    cmdEdit_Click
End Sub

Sub Form_KeyPress (KeyAscii As Integer)
    If 27 = KeyAscii Then cmdQuit_Click
End Sub

Sub Form_Load ()
    Left = (Screen.Width / 2) - (Width / 2)
    Top = (Screen.Height / 2) - (Height / 2)

    SetupColumns ctlGrid
    RefreshAll
End Sub

Sub Form_Resize ()
    SetWindowPos frmMain.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE
End Sub

