VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmBidang 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Bidang Studi - [SMP Negeri 2] Medan"
   ClientHeight    =   4425
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7035
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4425
   ScaleWidth      =   7035
   Begin MSComctlLib.ListView Lv1 
      Height          =   1575
      Left            =   120
      TabIndex        =   20
      Top             =   1800
      Width           =   6855
      _ExtentX        =   12091
      _ExtentY        =   2778
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   1
      NumItems        =   6
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "No."
         Object.Width           =   882
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Kode Studi"
         Object.Width           =   1764
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "Bidang Studi"
         Object.Width           =   2646
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "NIP"
         Object.Width           =   1764
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Text            =   "Kode Pelajaran"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   5
         Text            =   "Pelajaran"
         Object.Width           =   2540
      EndProperty
   End
   Begin VB.TextBox txtPelajaran 
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   1890
      MaxLength       =   35
      TabIndex        =   18
      Top             =   1320
      Width           =   5055
   End
   Begin VB.TextBox txtKodePelajaran 
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   1890
      MaxLength       =   4
      TabIndex        =   16
      Top             =   960
      Width           =   1095
   End
   Begin VB.ComboBox CmbNIP 
      Enabled         =   0   'False
      Height          =   315
      Left            =   3570
      TabIndex        =   15
      Top             =   240
      Width           =   1335
   End
   Begin VB.TextBox txtCari 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   240
      TabIndex        =   12
      Top             =   3960
      Width           =   1455
   End
   Begin VB.CommandButton cmdTambah 
      BackColor       =   &H00D8E9EC&
      Caption         =   "&Tambah"
      Height          =   405
      Left            =   2040
      TabIndex        =   9
      Top             =   3840
      Width           =   945
   End
   Begin VB.CommandButton cmdSimpan 
      BackColor       =   &H00D8E9EC&
      Caption         =   "&Simpan"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   3000
      TabIndex        =   8
      Top             =   3840
      Width           =   945
   End
   Begin VB.CommandButton cmdEdit 
      BackColor       =   &H00D8E9EC&
      Caption         =   "&Edit"
      Enabled         =   0   'False
      Height          =   405
      Left            =   3960
      TabIndex        =   7
      Top             =   3840
      Width           =   945
   End
   Begin VB.CommandButton cmdTutup 
      BackColor       =   &H00D8E9EC&
      Caption         =   "&Tutup"
      Height          =   405
      Left            =   5880
      TabIndex        =   6
      Top             =   3840
      Width           =   945
   End
   Begin VB.CommandButton cmdHapus 
      BackColor       =   &H00D8E9EC&
      Caption         =   "&Hapus"
      Enabled         =   0   'False
      Height          =   405
      Left            =   4920
      TabIndex        =   5
      Top             =   3840
      Width           =   945
   End
   Begin VB.TextBox txtKOde 
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   1890
      TabIndex        =   1
      Top             =   240
      Width           =   1095
   End
   Begin VB.TextBox txtNama 
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   1890
      MaxLength       =   35
      TabIndex        =   0
      Top             =   600
      Width           =   5055
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Pelajaran:"
      Height          =   195
      Index           =   5
      Left            =   1080
      TabIndex        =   19
      Top             =   1320
      Width           =   735
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Kode Pelajaran:"
      Height          =   195
      Index           =   4
      Left            =   675
      TabIndex        =   17
      Top             =   960
      Width           =   1140
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "NIP:"
      Height          =   195
      Index           =   3
      Left            =   3180
      TabIndex        =   14
      Top             =   240
      Width           =   315
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Kode Bidang Studi::"
      Height          =   195
      Index           =   2
      Left            =   240
      TabIndex        =   13
      Top             =   3720
      Width           =   1410
   End
   Begin VB.Shape Shape1 
      BorderColor     =   &H00FF8080&
      Height          =   855
      Index           =   0
      Left            =   120
      Top             =   3480
      Width           =   1695
   End
   Begin VB.Line Line1 
      BorderColor     =   &H80000002&
      X1              =   120
      X2              =   1800
      Y1              =   3720
      Y2              =   3720
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BackColor       =   &H80000018&
      Caption         =   "C a r i"
      ForeColor       =   &H00004000&
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   11
      Top             =   3480
      Width           =   1695
   End
   Begin VB.Line Line2 
      BorderColor     =   &H8000000D&
      X1              =   1920
      X2              =   6960
      Y1              =   3720
      Y2              =   3720
   End
   Begin VB.Shape Shape1 
      BorderColor     =   &H00FF8080&
      Height          =   855
      Index           =   1
      Left            =   1920
      Top             =   3480
      Width           =   5055
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BackColor       =   &H80000018&
      Caption         =   "P r o s e s"
      ForeColor       =   &H00004000&
      Height          =   255
      Index           =   1
      Left            =   1920
      TabIndex        =   10
      Top             =   3480
      Width           =   5055
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Kode Bidang Studi::"
      Height          =   195
      Index           =   0
      Left            =   405
      TabIndex        =   4
      Top             =   240
      Width           =   1410
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Nama Bidang Studi"
      Height          =   195
      Index           =   1
      Left            =   480
      TabIndex        =   3
      Top             =   600
      Width           =   1335
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   435
      Index           =   1
      Left            =   120
      TabIndex        =   2
      Top             =   0
      Width           =   105
   End
End
Attribute VB_Name = "frmBidang"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Sub Bersih()
Dim Control
For Each Control In Me.Controls
    If TypeOf Control Is TextBox Then
        Control.Text = ""
    End If
Next Control
End Sub

Sub Semula()
    cmdSimpan.Enabled = False
    cmdEdit.Enabled = False
    cmdHapus.Enabled = False
    cmdTambah.Caption = "&Tambah"
    Bersih
    vEdit = False
    vTrans = False
    NotAktif
    txtCari.Enabled = True
    Lv1.ListItems.Clear
End Sub

Sub NotAktif()
Dim Control
For Each Control In Me.Controls
    If TypeOf Control Is TextBox Then
        Control.Enabled = False
    End If
    If TypeOf Control Is ComboBox Then
        Control.Enabled = False
    End If
Next Control
End Sub


Private Sub cmbNIP_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    If cmbNIP.Text <> "" Then
        Me.MousePointer = 11
        Kata = "Select * from guru where NIP='" & cmbNIP.Text & "'"
        Set TGuru = New ADODB.Recordset
            TGuru.Open Kata, Datasiswa, adOpenDynamic, adLockPessimistic
            If TGuru.EOF Then
                TGuru.Close
                Set TGuru = Nothing
                Me.MousePointer = 1
                MsgBox "NIP = " & cmbNIP.Text & " tidak terdaftar...", vbExclamation
                cmbNIP.SetFocus
                Exit Sub
            End If
            TGuru.Close
            Set TGuru = Nothing
            txtKodePelajaran.Text = Left(txtNama.Text, 1) & "-"
            txtKodePelajaran.Enabled = True
            txtKodePelajaran.SelStart = 2
            txtKodePelajaran.SetFocus
            Me.MousePointer = 1
        End If
    End If
End Sub

Private Sub CmbNIP_KeyPress(KeyAscii As Integer)
KeyAscii = AutoComplete(cmbNIP, KeyAscii, True, Ubah)

End Sub

Private Sub Form_Load()
Ketengah Me
End Sub

Private Sub cmdTambah_Click()
    Me.MousePointer = 11
    If cmdTambah.Caption = "&Tambah" Then
        cmdTambah.Caption = "&Batal"
       Fokus txtKode
       Bersih
       txtCari.Enabled = False
    Else
        Semula
    End If
    Me.MousePointer = 1
End Sub

Private Sub cmdTutup_Click()
Unload Me
End Sub

Private Sub cmdEdit_Click()
    Me.MousePointer = 11
    vEdit = True
    vTrans = True
    Fokus txtPelajaran
    cmdEdit.Enabled = False
    cmdHapus.Enabled = False
    cmdTambah.Caption = "&Batal"
    cmdSimpan.Enabled = True
    Me.MousePointer = 1
End Sub

Private Sub cmdHapus_Click()
    Kata = MsgBox("Data Bidang : " & txtNama & " : Mau dihapus...", vbInformation + vbYesNo, "Warning....")
    If Kata = vbYes Then
        Me.MousePointer = 11
        Datasiswa.Execute "Delete From Bidang Where [kode Bidang]='" & txtKode.Text & "'"
        Semula
        Me.MousePointer = 1
    End If
End Sub

Private Sub cmdSimpan_Click()
Me.MousePointer = 1
   If Not vEdit Then
        Simpan
    Else
        Edit
    End If
Semula
Me.MousePointer = 1
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set frmBidang = Nothing
Unload Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Not vTrans Then
    Unload Me
Else
    Kata = MsgBox("Data Bidang studi mau di simpan...", vbInformation + vbYesNo, "konfirmasi")
    If Kata = vbYes Then
        cmdSimpan.Enabled = True
        cmdSimpan_Click
        Unload Me
    Else
        Unload Me
    End If
End If
End Sub

Private Sub Lv1_Click()
If Lv1.ListItems.Count = 0 Then Exit Sub
    txtKodePelajaran.Text = Lv1.SelectedItem.SubItems(4)
    txtPelajaran.Text = Lv1.SelectedItem.SubItems(5)
End Sub

Private Sub Lv1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Lv1_Click
End Sub

Private Sub txtCari_Change()
If Len(txtCari) = 5 Then
    Me.MousePointer = 11
    Kata = "Select * from QStudi Where [kode Bidang]='" & txtCari.Text & "'"
    Set TBidang = New ADODB.Recordset
        TBidang.Open Kata, Datasiswa, adOpenDynamic, adLockPessimistic
        If TBidang.EOF Then
            TBidang.Close
            Set TBidang = Nothing
            Me.MousePointer = 1
            MsgBox "Kode Bidang tidak ditemukan dalam database...", vbInformation, "kode Bidang Invalid.."
            Fokus txtCari
            Exit Sub
        End If
        DaftarBidang
        cmdHapus.Enabled = True
        cmdEdit.Enabled = True
        cmdTambah.Caption = "&Batal"
        TBidang.Close
        Set TBidang = Nothing
        Me.MousePointer = 1
End If
End Sub

Private Sub txtKode_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If txtKode <> "" Then
        If Len(txtKode) <> 2 Then
            MsgBox "kode harus di input sebanyak 2 digit..."
            Fokus txtKode
            Exit Sub
        End If
        
        Me.MousePointer = 11
        Kata = "Select * from QStudi where [kode Bidang] ='" & txtKode.Text & "'"
        Set TBidang = New ADODB.Recordset
            TBidang.Open Kata, Datasiswa, adOpenDynamic, adLockPessimistic
            If TBidang.EOF Then
                TBidang.Close
                Set TBidang = Nothing
                Me.MousePointer = 1
                Fokus txtNama
                Exit Sub
            End If
            DaftarBidang
            cmdEdit.Enabled = True
            cmdHapus.Enabled = True
            cmdTambah.Caption = "&Batal"
            cmdEdit.Enabled = True
            Fokus txtNama
            TBidang.Close
            Set TBidang = Nothing
            Me.MousePointer = 1
    End If
End If
End Sub

Private Sub txtKodePelajaran_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If txtKode <> "" Then
        If Len(txtKodePelajaran) <> 4 Then
            MsgBox "kode pelajaran harus di input sebanyak 4 digit..."
            txtKodePelajaran.SetFocus
            txtKodePelajaran.SelStart = 2
            Exit Sub
        End If
        
        For i = 1 To Lv1.ListItems.Count
            If txtKodePelajaran.Text = Lv1.ListItems(i).SubItems(1) Then
                MsgBox "Kode Pelajaran Sudah Ada pada daftar....", vbExclamation, "Ooops..."
                txtKodePelajaran.SetFocus
                Fokus txtKodePelajaran
                Exit Sub
            End If
        Next
        
        Me.MousePointer = 11
        Kata = "Select * from pelajaran where [kode pelajaran] ='" & txtKodePelajaran.Text & "'"
        Set TBidang = New ADODB.Recordset
            TBidang.Open Kata, Datasiswa, adOpenDynamic, adLockPessimistic
            If TBidang.EOF Then
                TBidang.Close
                Set TBidang = Nothing
                Me.MousePointer = 1
                Fokus txtPelajaran
                Exit Sub
            End If
            TBidang.Close
            Set TBidang = Nothing
            Me.MousePointer = 1
            MsgBox "Kode Pelajaran Sudah Di Input.." & vbCrLf & _
                   "Coba input dengan kode pelajaran yang lain...", vbInformation
            txtKodePelajaran.Text = Left(txtNama.Text, 1) & "-"
            txtKodePelajaran.Enabled = True
            txtKodePelajaran.SelStart = 2
            txtKodePelajaran.SetFocus
    End If
End If
End Sub

Private Sub txtNama_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
        If txtNama = "" Then
            MsgBox "Nama Bidang harus di isi....", vbExclamation
            Fokus txtNama
            Exit Sub
        End If
        Me.MousePointer = 11
        Daftar
        cmbNIP.Enabled = True
        cmbNIP.SetFocus
        Me.MousePointer = 1
    End If
End Sub




Sub DaftarBidang()
    With TBidang
        cmbNIP = !NIP
        txtNama = ![Bidang Studi]
        txtKode = ![kode Bidang]
        While Not TBidang.EOF
            Set Vbutir = Lv1.ListItems.Add(, , Lv1.ListItems.Count + 1 & ".")
            Vbutir.SubItems(1) = TBidang![kode Bidang]
            Vbutir.SubItems(2) = TBidang![Bidang Studi]
            Vbutir.SubItems(3) = TBidang![NIP]
            Vbutir.SubItems(5) = TBidang![Pelajaran]
            Vbutir.SubItems(4) = TBidang![Kode Pelajaran]
            
            TBidang.MoveNext
        Wend
    End With

End Sub

Sub Simpan()
'On Error GoTo Salah
    Me.MousePointer = 11
    
    Datasiswa.BeginTrans
    
    Datasiswa.Execute "Insert Into Bidang values ('" & txtKode.Text & "'," & _
    "'" & txtNama.Text & "','" & cmbNIP.Text & "')"
    Datasiswa.CommitTrans
    
    
    Datasiswa.BeginTrans
    For i = 1 To Lv1.ListItems.Count
        Datasiswa.Execute "Insert Into Pelajaran Values ( '" & txtKode.Text & "','" & Lv1.ListItems(i).SubItems(4) & "','" & Lv1.ListItems(i).SubItems(5) & "')"
    Next i
    Datasiswa.CommitTrans
    
    Me.MousePointer = 1
   ' Exit Sub
'Salah:
   ' MsgBox "Data Bidang tidak bisa di simpan...", vbInformation, "Data Error..."
End Sub

Sub Edit()
    On Error GoTo Salah
    Me.MousePointer = 11
    
    Datasiswa.BeginTrans
    Datasiswa.Execute "Update Pelajaran Set [Nama Pelajaran]='" & txtPelajaran.Text & "' where [kode Pelajaran]='" & Lv1.ListItems(i).SubItems(4) & "'"
    Datasiswa.CommitTrans
    Me.MousePointer = 1
    Exit Sub
Salah:
    MsgBox Err.Description
End Sub


Sub Daftar()
Me.MousePointer = 11
    Set TGuru = New ADODB.Recordset
        Kata = "Select * from Guru Order By [NIP]"
        TGuru.Open Kata, Datasiswa, adOpenDynamic, adLockPessimistic
        cmbNIP.Clear
        If Not TGuru.EOF Then
           TGuru.MoveFirst
           While Not TGuru.EOF
                cmbNIP.AddItem TGuru![NIP]
                TGuru.MoveNext
            Wend
        End If
        TGuru.Close
        Set TGuru = Nothing

    Me.MousePointer = 1

End Sub
    

Private Sub txtPelajaran_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If txtPelajaran <> "" Then
        Set Vbutir = Lv1.ListItems.Add(, , Lv1.ListItems.Count + 1 & ".")
                     Vbutir.SubItems(1) = txtKode
                    Vbutir.SubItems(2) = txtNama
                    Vbutir.SubItems(3) = cmbNIP
                    Vbutir.SubItems(4) = txtKodePelajaran
                    Vbutir.SubItems(5) = txtPelajaran
                    vTrans = True
                    Kata = MsgBox("Masih Ada Pelajaran yang mau di entry ....", vbInformation + vbYesNo, "Informasi")
                    If Kata = vbYes Then
                        txtKodePelajaran.Text = Left(txtNama.Text, 1) & "-"
                        txtKodePelajaran.Enabled = True
                        txtKodePelajaran.SelStart = 2
                        txtKodePelajaran.SetFocus
                        Exit Sub
                    End If
                    cmdSimpan.Enabled = True
                    cmdSimpan.SetFocus
    End If
End If
End Sub


