VERSION 5.00
Begin VB.Form frmRegCustomer 
   Caption         =   "Register Customer"
   ClientHeight    =   4065
   ClientLeft      =   240
   ClientTop       =   345
   ClientWidth     =   4800
   LinkTopic       =   "Form1"
   ScaleHeight     =   4065
   ScaleWidth      =   4800
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtTelefon 
      Height          =   285
      Left            =   1200
      TabIndex        =   8
      Top             =   2040
      Width           =   1935
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   375
      Left            =   960
      TabIndex        =   14
      Top             =   3600
      Width           =   1695
   End
   Begin VB.CommandButton cmdUpdate 
      Caption         =   "&Register Customer"
      Height          =   375
      Left            =   2760
      TabIndex        =   13
      Top             =   3600
      Width           =   1695
   End
   Begin VB.TextBox txtPostanskibroj 
      Height          =   285
      Left            =   1200
      TabIndex        =   12
      Top             =   2760
      Width           =   855
   End
   Begin VB.TextBox txtGrad 
      Height          =   285
      Left            =   1200
      TabIndex        =   10
      Top             =   2400
      Width           =   1935
   End
   Begin VB.TextBox txtAdresa 
      Height          =   285
      Left            =   1200
      TabIndex        =   7
      Top             =   1680
      Width           =   3135
   End
   Begin VB.TextBox txtPrezime 
      Height          =   285
      Left            =   1200
      TabIndex        =   5
      Top             =   1320
      Width           =   3135
   End
   Begin VB.TextBox txtIme 
      Height          =   285
      Left            =   1200
      TabIndex        =   3
      Top             =   960
      Width           =   1935
   End
   Begin VB.TextBox txtID 
      BackColor       =   &H80000004&
      Height          =   285
      Left            =   1200
      TabIndex        =   1
      Top             =   240
      Width           =   1215
   End
   Begin VB.Label lblTelefon 
      Alignment       =   1  'Right Justify
      Caption         =   "Telefon"
      Height          =   255
      Left            =   120
      TabIndex        =   15
      Top             =   2040
      Width           =   975
   End
   Begin VB.Label lblPostanskibroj 
      Alignment       =   1  'Right Justify
      Caption         =   "Postanski broj"
      Height          =   255
      Left            =   0
      TabIndex        =   11
      Top             =   2760
      Width           =   1095
   End
   Begin VB.Label lblGrad 
      Alignment       =   1  'Right Justify
      Caption         =   "Grad"
      Height          =   255
      Left            =   120
      TabIndex        =   9
      Top             =   2400
      Width           =   975
   End
   Begin VB.Label lblAdresa 
      Alignment       =   1  'Right Justify
      Caption         =   "Adresa"
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   1680
      Width           =   975
   End
   Begin VB.Label lblPrezime 
      Alignment       =   1  'Right Justify
      Caption         =   "Prezime"
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   1320
      Width           =   975
   End
   Begin VB.Label lblIme 
      Alignment       =   1  'Right Justify
      Caption         =   "Ime"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   960
      Width           =   975
   End
   Begin VB.Label lblID 
      Alignment       =   1  'Right Justify
      Caption         =   "Korisnicki ID"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   975
   End
End
Attribute VB_Name = "frmRegCustomer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cn As Connection
Dim adoRS As ADODB.Recordset
Dim update As Boolean

Function closeConnection()

    If (cn <> Null) Then
        cn.Close
        Set cn = Nothing
    End If
    
End Function

Private Sub cmdCancel_Click()
    
    ' clears all fields and returns to main menu
    Call clearFields
    Call clearForm
    Call showCID
    Unload Me
    
End Sub

Private Sub cmdUpdate_Click()
    
    Call closeConnection
    Call connDB
    
    
    ' test if all fields all corect
    'update DB
    If Not (update) Then
        adoRS.ActiveConnection = cn
        adoRS.Source = "INSERT INTO tblCustomer (Korisnicki ID, Ime, Prezime, Adresa, Telefon, Grad, Postanskibroj) Values('" _
                    & Val(txtID.Text) & "','" & txtIme.Text & "','" _
                    & txtPrezime.Text & "','" & txtAdresa.Text & "','" _
                    & txtTelefon.Text & "','" _
                    & txtGrad.Text & "','" & txtPostanskibroj.Text & "')"
    
    Call clearFields
    Unload Me
    Else
        adoRS.ActiveConnection = cn
        adoRS.Source = "UPDATE tblCustomer SET Name ='" & txtIme.Text _
                    & "', Prezime ='" & txtPrezime.Text & "', Adresa ='" & txtAdresa.Text _
                    & "', Telefon ='" & txtTelefon.Text & "', Grad ='" & txtGrad.Text _
                    & "', Postanskibroj ='" & txtPostanskibroj.Text & "' WHERE Korisnicki ID =" & Val(txtID.Text)
                        
                    

        adoRS.Open
    Call clearFields
    Unload Me
    End If
End Sub

Private Sub Form_Load()
    Call connDB
End Sub

Function clearFields()

    txtIme.Text = ""
    txtPrezime.Text = ""
    txtAdresa.Text = ""
    txtTelefon.Text = ""
    txtGrad.Text = ""
    txtPostanskibroj.Text = ""

End Function

Private Sub txtAdresa_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        txtTelefon.SetFocus
    End If
End Sub

Private Sub txtGrad_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        txtPostanskibroj.SetFocus
    End If
End Sub

Private Sub txtID_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        If (txtID <> "") Then
            Call txtID_LostFocus
            txtIme.SetFocus
        Else
            Call closeConnection
            Call clearFields
            Unload Me
        End If
    End If
End Sub

Private Sub txtID_LostFocus()
    Call closeConnection
    Call connDB
    
    adoRS.ActiveConnection = cn
    adoRS.Source = "Select * From tblCustomer WHERE CustomerID=" _
                    & Val(txtID.Text)
    adoRS.Open
    If Not (adoRS.EOF And adoRS.BOF) Then
        txtIme.Text = adoRS.Fields("Name").Value
        txtPrezime.Text = adoRS.Fields("LastName").Value
        txtAdresa.Text = adoRS.Fields("Address").Value
        txtTelefon.Text = adoRS.Fields("Telefon").Value
        txtGrad.Text = adoRS.Fields("City").Value
        txtPostanskibroj.Text = adoRS.Fields("Zip").Value
        update = True
    Else
        update = False
    End If
End Sub


Function connDB()
   
    Dim strConnect As String
    Dim strProvider As String
    Dim strDataSource As String
    Dim strDataBaseName As String
    
    strProvider = "Provider= Microsoft.Jet.OLEDB.3.51;"
    strDataSource = App.Path
    strDataBaseName = "\video.mdb;"
    strDataSource = "Data Source=" & strDataSource & strDataBaseName
    strConnect = strProvider & strDataSource
    
    Set cn = New ADODB.Connection
    cn.Open strConnect
    
    Set adoRS = New ADODB.Recordset
    
    adoRS.CursorType = adOpenStatic
    adoRS.CursorLocation = adUseClient
    adoRS.LockType = adLockPessimistic
    
End Function

Private Sub txtPrezime_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        txtAdresa.SetFocus
    End If
End Sub

Private Sub txtIme_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        txtPrezime.SetFocus
    End If
End Sub

Private Sub txtTelefon_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        txtGrad.SetFocus
    End If
End Sub

Private Sub txtPostanskibroj_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        cmdUpdate.SetFocus
    End If
End Sub
