VERSION 5.00
Object = "{D76D7128-4A96-11D3-BD95-D296DC2DD072}#1.0#0"; "Vsflex7.ocx"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmPenyakit 
   BorderStyle     =   0  'None
   Caption         =   "Penyakit"
   ClientHeight    =   7500
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   11865
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MDIChild        =   -1  'True
   ScaleHeight     =   7500
   ScaleWidth      =   11865
   ShowInTaskbar   =   0   'False
   Tag             =   "mPhotographer"
   Begin VB.PictureBox picBG 
      Appearance      =   0  'Flat
      BorderStyle     =   0  'None
      ForeColor       =   &H80000008&
      Height          =   6975
      Left            =   300
      ScaleHeight     =   6975
      ScaleWidth      =   11085
      TabIndex        =   8
      TabStop         =   0   'False
      Top             =   300
      Width           =   11085
      Begin VB.CommandButton cmdClear 
         Caption         =   "&Batal"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   5250
         TabIndex        =   3
         Top             =   6315
         Width           =   1275
      End
      Begin VB.CommandButton cmdSave 
         Caption         =   "&Simpan"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3900
         MaskColor       =   &H00C0C0FF&
         TabIndex        =   2
         Top             =   6315
         Width           =   1305
      End
      Begin VB.TextBox txtNamaPenyakit 
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   6180
         MaxLength       =   30
         TabIndex        =   1
         Top             =   1500
         Width           =   4305
      End
      Begin VB.CommandButton cmdRefresh 
         Caption         =   "&Refresh"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7890
         TabIndex        =   5
         Top             =   6315
         Width           =   1275
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "&Hapus"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   6570
         TabIndex        =   4
         Top             =   6315
         Width           =   1275
      End
      Begin VB.CommandButton cmdQuit 
         Caption         =   "&Tutup Form"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   9210
         TabIndex        =   6
         Top             =   6315
         Width           =   1275
      End
      Begin MSDataListLib.DataCombo cboKdPenyakit 
         Height          =   330
         Left            =   6180
         TabIndex        =   0
         Top             =   1100
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   582
         _Version        =   393216
         Appearance      =   0
         BackColor       =   -2147483643
         Text            =   ""
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin VSFlex7Ctl.VSFlexGrid grdList 
         Height          =   5325
         Left            =   450
         TabIndex        =   7
         Top             =   630
         Width           =   3825
         _cx             =   6747
         _cy             =   9393
         _ConvInfo       =   1
         Appearance      =   0
         BorderStyle     =   1
         Enabled         =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         MousePointer    =   0
         BackColor       =   15989246
         ForeColor       =   -2147483640
         BackColorFixed  =   -2147483633
         ForeColorFixed  =   -2147483630
         BackColorSel    =   16572883
         ForeColorSel    =   0
         BackColorBkg    =   -2147483633
         BackColorAlternate=   15333630
         GridColor       =   -2147483633
         GridColorFixed  =   -2147483632
         TreeColor       =   -2147483632
         FloodColor      =   192
         SheetBorder     =   -2147483642
         FocusRect       =   1
         HighLight       =   2
         AllowSelection  =   0   'False
         AllowBigSelection=   0   'False
         AllowUserResizing=   1
         SelectionMode   =   3
         GridLines       =   1
         GridLinesFixed  =   2
         GridLineWidth   =   1
         Rows            =   22
         Cols            =   2
         FixedRows       =   1
         FixedCols       =   0
         RowHeightMin    =   0
         RowHeightMax    =   0
         ColWidthMin     =   0
         ColWidthMax     =   0
         ExtendLastCol   =   -1  'True
         FormatString    =   $"frmPenyakit.frx":0000
         ScrollTrack     =   0   'False
         ScrollBars      =   3
         ScrollTips      =   0   'False
         MergeCells      =   0
         MergeCompare    =   0
         AutoResize      =   -1  'True
         AutoSizeMode    =   0
         AutoSearch      =   2
         AutoSearchDelay =   2
         MultiTotals     =   -1  'True
         SubtotalPosition=   1
         OutlineBar      =   0
         OutlineCol      =   0
         Ellipsis        =   0
         ExplorerBar     =   5
         PicturesOver    =   0   'False
         FillStyle       =   0
         RightToLeft     =   0   'False
         PictureType     =   0
         TabBehavior     =   0
         OwnerDraw       =   0
         Editable        =   0
         ShowComboButton =   -1  'True
         WordWrap        =   0   'False
         TextStyle       =   0
         TextStyleFixed  =   0
         OleDragMode     =   0
         OleDropMode     =   0
         DataMode        =   0
         VirtualData     =   -1  'True
         DataMember      =   ""
         ComboSearch     =   3
         AutoSizeMouse   =   -1  'True
         FrozenRows      =   0
         FrozenCols      =   0
         AllowUserFreezing=   0
         BackColorFrozen =   0
         ForeColorFrozen =   0
         WallPaperAlignment=   9
      End
      Begin VSFlex7Ctl.VSFlexGrid grdObat 
         Height          =   3645
         Left            =   4530
         TabIndex        =   12
         Top             =   1980
         Width           =   5985
         _cx             =   10557
         _cy             =   6429
         _ConvInfo       =   1
         Appearance      =   0
         BorderStyle     =   1
         Enabled         =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         MousePointer    =   0
         BackColor       =   15989246
         ForeColor       =   -2147483640
         BackColorFixed  =   -2147483633
         ForeColorFixed  =   -2147483630
         BackColorSel    =   16572883
         ForeColorSel    =   -2147483640
         BackColorBkg    =   -2147483636
         BackColorAlternate=   15333630
         GridColor       =   -2147483633
         GridColorFixed  =   -2147483632
         TreeColor       =   -2147483632
         FloodColor      =   192
         SheetBorder     =   -2147483642
         FocusRect       =   1
         HighLight       =   2
         AllowSelection  =   0   'False
         AllowBigSelection=   0   'False
         AllowUserResizing=   1
         SelectionMode   =   3
         GridLines       =   1
         GridLinesFixed  =   2
         GridLineWidth   =   1
         Rows            =   15
         Cols            =   4
         FixedRows       =   1
         FixedCols       =   0
         RowHeightMin    =   0
         RowHeightMax    =   0
         ColWidthMin     =   0
         ColWidthMax     =   0
         ExtendLastCol   =   -1  'True
         FormatString    =   $"frmPenyakit.frx":005B
         ScrollTrack     =   0   'False
         ScrollBars      =   3
         ScrollTips      =   0   'False
         MergeCells      =   0
         MergeCompare    =   0
         AutoResize      =   -1  'True
         AutoSizeMode    =   0
         AutoSearch      =   0
         AutoSearchDelay =   2
         MultiTotals     =   -1  'True
         SubtotalPosition=   1
         OutlineBar      =   0
         OutlineCol      =   0
         Ellipsis        =   0
         ExplorerBar     =   0
         PicturesOver    =   0   'False
         FillStyle       =   0
         RightToLeft     =   0   'False
         PictureType     =   0
         TabBehavior     =   0
         OwnerDraw       =   0
         Editable        =   2
         ShowComboButton =   -1  'True
         WordWrap        =   0   'False
         TextStyle       =   0
         TextStyleFixed  =   0
         OleDragMode     =   0
         OleDropMode     =   0
         DataMode        =   0
         VirtualData     =   -1  'True
         DataMember      =   ""
         ComboSearch     =   3
         AutoSizeMouse   =   -1  'True
         FrozenRows      =   0
         FrozenCols      =   0
         AllowUserFreezing=   0
         BackColorFrozen =   0
         ForeColorFrozen =   0
         WallPaperAlignment=   9
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Nama Penyakit"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   195
         Index           =   4
         Left            =   4410
         TabIndex        =   11
         Top             =   1500
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Kode Penyakit"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   195
         Index           =   6
         Left            =   4845
         TabIndex        =   10
         Top             =   1100
         Width           =   1215
      End
      Begin VB.Line ln 
         BorderColor     =   &H00FFFFFF&
         Index           =   1
         Tag             =   "1"
         X1              =   425
         X2              =   10500
         Y1              =   6150
         Y2              =   6150
      End
      Begin VB.Shape shp 
         BorderColor     =   &H00C0C0C0&
         Height          =   315
         Index           =   2
         Left            =   180
         Tag             =   "2"
         Top             =   150
         Width           =   2625
      End
      Begin VB.Shape shp 
         BorderColor     =   &H00FFFFFF&
         Height          =   6765
         Index           =   1
         Left            =   150
         Tag             =   "1"
         Top             =   120
         Width           =   10785
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00E0E0E0&
         Caption         =   "P e n y a k i t"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   210
         TabIndex        =   9
         Top             =   180
         Width           =   2565
      End
      Begin VB.Line ln 
         BorderColor     =   &H00808080&
         BorderWidth     =   2
         Index           =   0
         Tag             =   "2"
         X1              =   425
         X2              =   10500
         Y1              =   6150
         Y2              =   6150
      End
      Begin VB.Shape shp 
         BorderColor     =   &H00808080&
         BorderWidth     =   2
         Height          =   6765
         Index           =   0
         Left            =   150
         Tag             =   "2"
         Top             =   120
         Width           =   10785
      End
      Begin VB.Line ln 
         BorderColor     =   &H00FFFFFF&
         Index           =   2
         Tag             =   "1"
         X1              =   4410
         X2              =   4410
         Y1              =   600
         Y2              =   5940
      End
      Begin VB.Line ln 
         BorderColor     =   &H00808080&
         BorderWidth     =   2
         Index           =   3
         Tag             =   "2"
         X1              =   4410
         X2              =   4410
         Y1              =   630
         Y2              =   5910
      End
   End
End
Attribute VB_Name = "frmPenyakit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private cSQL As String
Private rsList As ADODB.Recordset
Private rsPenyakit As ADODB.Recordset
Private rsObat As ADODB.Recordset
Private rsSQL As ADODB.Recordset
Private nRowAtGrid As Integer
Private nI As Integer

Private Const nColKdObat As Byte = 0
Private Const nColNmObat As Byte = 1
Private Const nColSatuan As Byte = 2
Private Const nColHarga As Byte = 3

Private Sub cboKdPenyakit_Change()
  With cboKdPenyakit
    If Len(.Text) > 5 Then .Text = Left(.Text, 5)
    Call lCheckData
  End With
End Sub

Private Sub cboKdPenyakit_Click(Area As Integer)
    Call lCheckData
End Sub

Private Sub cboKdPenyakit_KeyPress(KeyAscii As Integer)
  With Screen.ActiveControl
    Select Case KeyAscii
    Case vbKeyReturn
      KeyAscii = 0
      SendKeys "{TAB}"
    Case vbKeySpace
      KeyAscii = 0
      SendKeys "{F4}"
    Case Else
      If Len(.Text) = 5 And .SelLength = 0 And Not _
      (KeyAscii = vbKeyReturn Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeyBack) Then KeyAscii = 0
    End Select
  End With
End Sub

Private Sub cboKdPenyakit_Validate(Cancel As Boolean)
  cboKdPenyakit.Text = UCase(Trim(cboKdPenyakit.Text))
End Sub

Private Sub cmdClear_Click()
  Call lClr(True)
End Sub

Private Sub cmdDelete_Click()
  Call lDel
End Sub


Private Sub cmdQuit_Click()
  Unload Me
End Sub

Private Sub cmdRefresh_Click()
  rsPenyakit.Requery
  rsList.Requery
  DoEvents
  grdList.ColWidth(0) = 1515
End Sub

Private Sub cmdSave_Click()
  Call lSave
End Sub

Private Sub Form_Load()
  Call lInitObj
  Call lSetCombo
  Call lList
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  Call lUnload
End Sub

Private Sub Form_Resize()
  Center picBG
  CenterForm Me, MDI
End Sub

Private Sub lList()
  cSQL = "SELECT KdPenyakit AS [Kode Penyakit], NmPenyakit AS [Nama Penyakit] FROM Penyakit ORDER BY KdPenyakit"
  goConn.OpenRS rsList, cSQL
  With grdList
    Set .DataSource = rsList
    .ColWidth(0) = 1515
  End With
End Sub

Private Sub lInitObj()
  Screen.MousePointer = vbHourglass
  goConn.ChangeLayout (Me)
  BackColor = MDI.BackColor
  Screen.MousePointer = vbDefault
  nRowAtGrid = grdObat.Rows
End Sub

Private Function lSave() As Boolean
  With grdObat
    Dim csfKdPenyakit As String, csfNmPenyakit As String
    csfKdPenyakit = SafeChar(cboKdPenyakit.Text)
    csfNmPenyakit = SafeChar(txtNamaPenyakit.Text)
    
    '~ validate correct data
    If Len(csfKdPenyakit) = 0 Then
      MsgBox "Kode Penyakit harus diisi.", vbInformation, "Data Tidak Lengkap"
      cboKdPenyakit.SetFocus: Exit Function
    End If
    If Len(csfNmPenyakit) = 0 Then
      MsgBox "Nama Penyakit harus diisi.", vbInformation, "Data Tidak Lengkap"
      txtNamaPenyakit.SetFocus: Exit Function
    End If
    If Not IsTextInGrid(grdObat, 0) Then
      MsgBox "Belum ada Obat untuk Penyakit ini.", vbInformation, "Data Tidak Lengkap"
      grdObat.SetFocus: Exit Function
    End If
    
    With grdObat
      For nI = .FixedRows To .Rows - 1
        If Len(.TextMatrix(nI, nColKdObat)) > 0 Then
          cSQL = "SELECT KdObat FROM Obat WHERE KdObat = '" & SafeChar(.TextMatrix(nI, nColKdObat)) & "'"
          If Not goConn.OpenRSFO(rsSQL, cSQL) Then
            MsgBox "Tidak ada Kode Obat " & .TextMatrix(nI, nColKdObat) & " pada Database.", vbCritical, "Kesalahan Entri"
            .SetFocus: .Row = nI: Exit Function
          End If
        End If
      Next nI
    End With
    '~
    
    cSQL = "SELECT KdPenyakit FROM Penyakit where KdPenyakit = '" & csfKdPenyakit & "'"
    If goConn.OpenRSFO(rsSQL, cSQL) Then
      cSQL = "UPDATE Penyakit SET NmPenyakit = '" & csfNmPenyakit & _
              "' WHERE KdPenyakit = '" & csfKdPenyakit & "'"
    Else
      cSQL = "INSERT INTO Penyakit(KdPenyakit, NmPenyakit) VALUES ( '" & _
              csfKdPenyakit & "', '" & csfNmPenyakit & "')"
    End If
    
    On Error GoTo ErrorHandler
    MousePointer = vbHourglass
    cmdSave.Enabled = False
    goConn.Conn.BeginTrans
    goConn.Conn.Execute cSQL
       
    cSQL = "DELETE FROM PenyakitDetail Where KdPenyakit = '" & csfKdPenyakit & "'"
    goConn.Conn.Execute cSQL
    
    Dim csfKdObat As String
    For nI = .FixedRows To .Rows - 1
      If Len(Trim(.TextMatrix(nI, 0))) > 0 Then
        csfKdObat = SafeChar(.TextMatrix(nI, nColKdObat))
        cSQL = "INSERT INTO PenyakitDetail(KdPenyakit, KdObat) ValUES ('" & _
                csfKdPenyakit & "', '" & csfKdObat & "')"
        goConn.Conn.Execute cSQL
      End If
    Next nI
    goConn.Conn.CommitTrans
    MousePointer = vbDefault
  
    Call lClr(True)
    Call cmdRefresh_Click
    cmdSave.Enabled = True
  End With
  lSave = True
Exit Function

ErrorHandler:
  goConn.Conn.RollbackTrans
  MousePointer = vbDefault
  MsgBox "No Kesalahan : " & Err.Number & vbCrLf & "Deskripsi Kesalahan : " & Err.Description, vbOKOnly, "Save Error"
  lSave = False
  cmdSave.Enabled = True
  Call lList
End Function

Private Function lDel() As Boolean
  With grdList
    If Len(Trim(cboKdPenyakit.Text)) > 0 Then
      If MsgBox("Hapus data ini dari database?", vbQuestion + vbYesNo, "Konfirmasi") = vbYes Then
        Dim csfKdPenyakit As String
        csfKdPenyakit = SafeChar(cboKdPenyakit.Text)
        cSQL = "SELECT KdPenyakit FROM KunjunganDetail WHERE KdPenyakit = '" & csfKdPenyakit & "'"
        If goConn.OpenRSFO(rsSQL, cSQL) Then
          MsgBox "Data tidak dapat dihapus karena telah dipakai!", vbExclamation, "Data telah dipakai"
          Exit Function
        End If
        cSQL = "DELETE FROM Penyakit WHERE KdPenyakit = '" & csfKdPenyakit & "'"
        
        On Error GoTo ErrorHandler
        MousePointer = vbHourglass
        cmdDelete.Enabled = False
        goConn.Conn.BeginTrans
        goConn.Conn.Execute cSQL
        goConn.Conn.CommitTrans
        MousePointer = vbDefault
        Call lClr(True)
        Call cmdRefresh_Click
        cmdDelete.Enabled = True
      End If
    End If
  End With
  lDel = True
  Exit Function
    
ErrorHandler:
  goConn.Conn.RollbackTrans
  MousePointer = vbDefault
  MsgBox "No Kesalahan : " & Err.Number & vbCrLf & "Deskripsi Kesalahan : Data tidak dapat dihapus karena telah dipakai!", vbOKOnly, "Delete Error"
  lDel = False
  cmdDelete.Enabled = True
  Call lList: grdList.SetFocus
End Function

Public Sub lCheckData()
  cSQL = "SELECT P.NmPenyakit FROM Penyakit P " & _
        "WHERE P.KdPenyakit = '" & SafeChar(cboKdPenyakit.Text) & "'"
  
  goConn.OpenRS rsSQL, cSQL
  If rsSQL.EOF Then
    Call lClr(False)
  Else
    MousePointer = vbHourglass
    txtNamaPenyakit.Text = rsSQL!NmPenyakit
    
    cSQL = "SELECT PD.KdObat, O.NmObat, O.Satuan, O.Harga FROM PenyakitDetail PD " & _
          "INNER JOIN Obat O ON PD.KdObat = O.KdObat " & _
          "WHERE PD.KdPenyakit = '" & SafeChar(cboKdPenyakit.Text) & "'"
    goConn.OpenRS rsSQL, cSQL
    
    With grdObat
      .Clear 1, 1
      .Rows = IIf(rsSQL.RecordCount < nRowAtGrid - .FixedRows, nRowAtGrid, rsSQL.RecordCount + .FixedRows)
      For nI = 1 To rsSQL.RecordCount
        .TextMatrix(nI, nColKdObat) = rsSQL!KdObat
        .TextMatrix(nI, nColNmObat) = rsSQL!NmObat
        .TextMatrix(nI, nColSatuan) = rsSQL!Satuan
        .TextMatrix(nI, nColHarga) = rsSQL!Harga
        rsSQL.MoveNext
      Next nI
    End With
    
    MousePointer = Default
  End If
End Sub

Private Sub lClr(pbWithPK As Boolean)
  If pbWithPK Then cboKdPenyakit.Text = "": cboKdPenyakit.SetFocus
  txtNamaPenyakit.Text = ""
  grdObat.Clear 1, 1
  grdObat.Rows = nRowAtGrid
End Sub

Private Sub lSetCombo()
  '~ user id
  cSQL = "SELECT KdPenyakit FROM Penyakit P " & _
          "ORDER BY KdPenyakit"
  goConn.SetCbo2 cboKdPenyakit, rsPenyakit, cSQL, "KdPenyakit"
End Sub

Private Sub grdObat_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
  Cancel = Not cmdSave.Enabled
  If Cancel Then Exit Sub
  With grdObat
    Select Case Col
    Case nColKdObat
      Cancel = Not lSetKdObat
    Case Else
      Cancel = True
    End Select
  End With
End Sub

Private Sub grdObat_GotFocus()
  If Len(Trim(cboKdPenyakit.Text)) = 0 Then cboKdPenyakit.SetFocus
End Sub

Private Sub grdList_AfterRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, ByVal NewRow As Long, ByVal NewCol As Long)
  Call grdList_Click
End Sub

Private Sub grdList_Click()
  With grdList
    If .Row > 0 Then
      cboKdPenyakit.Text = .TextMatrix(.Row, 0)
'      txtNamaPenyakit.Text = .TextMatrix(.Row, 1)
    End If
  End With
End Sub

Private Sub txtNamaPenyakit_GotFocus()
  If Len(Trim(cboKdPenyakit.Text)) = 0 Then cboKdPenyakit.SetFocus
End Sub

Private Sub txtNamaPenyakit_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
End Sub

Private Sub grdObat_KeyPress(KeyAscii As Integer)
  With grdObat
    If KeyAscii = vbKeyReturn Then
      KeyAscii = 0
      If .Col = 0 Or .Col = .Cols - 1 Then
        If .Row = .Rows - 1 Then .Rows = .Rows + 1
        .Select .Row + 1, 0
      Else
        .Select .Row, .Col + 1
      End If
      .ShowCell .Row, .Col
    End If
  End With
End Sub

Private Sub grdObat_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
  With grdObat
    Select Case Col
    Case nColKdObat
      If Len(Trim(.EditText)) = 0 Then
        Call ClearRow(grdObat, Row)
      ElseIf IsExist(grdObat, .EditText, Col, Row) <> -1 Then
        MsgBox "Kode Obat tersebut sudah ada. Harap isikan Kode Obat yang lain.", vbExclamation, "Data sudah ada"
        Cancel = True
      ElseIf .EditText <> .ComboData Then
        Cancel = True
      Else
        Call lObatDetail(Row, SafeChar(.EditText))
      End If
    End Select
  End With
End Sub

Private Sub lObatDetail(ByVal pnRow As Integer, pcKdObat As String)
  With grdObat
    cSQL = "SELECT * FROM Obat " & _
          "WHERE KdObat = '" & pcKdObat & "'"
    If goConn.OpenRS(rsSQL, cSQL) Then
      .TextMatrix(pnRow, nColNmObat) = rsSQL!NmObat
      .TextMatrix(pnRow, nColSatuan) = rsSQL!Satuan
      .TextMatrix(pnRow, nColHarga) = rsSQL!Harga
    End If
  End With
End Sub

Private Function lSetKdObat() As Boolean
  cSQL = "SELECT * FROM Obat"
  lSetKdObat = goConn.OpenRS(rsObat, cSQL)
  SetCboList grdObat, nColKdObat, rsObat, "KdObat, NmObat, Satuan, Harga", "KdObat", False
End Function

Private Sub lUnload()
  Set rsList = Nothing
  Set rsPenyakit = Nothing
  Set rsObat = Nothing
  Set rsSQL = Nothing
  Set frmPenyakit = Nothing
End Sub
