VERSION 5.00
Object = "{D76D7128-4A96-11D3-BD95-D296DC2DD072}#1.0#0"; "Vsflex7.ocx"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{5734474E-78D3-4254-99B9-C35F31BDF509}#63.0#0"; "vbskpro2.ocx"
Begin VB.Form frmKunjungan 
   BorderStyle     =   0  'None
   Caption         =   "Kunjungan"
   ClientHeight    =   7500
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   11865
   LinkTopic       =   "Form1"
   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        =   11
      TabStop         =   0   'False
      Top             =   300
      Width           =   11085
      Begin MSComCtl2.DTPicker dtpTglKunjungan 
         Height          =   345
         Left            =   6180
         TabIndex        =   1
         Top             =   1350
         Width           =   1365
         _ExtentX        =   2408
         _ExtentY        =   609
         _Version        =   393216
         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
         Format          =   19202049
         CurrentDate     =   38074
      End
      Begin VB.TextBox txtNmPasien 
         Appearance      =   0  'Flat
         BackColor       =   &H8000000F&
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   6180
         Locked          =   -1  'True
         MaxLength       =   20
         TabIndex        =   18
         TabStop         =   0   'False
         Tag             =   "?"
         Top             =   2950
         Width           =   3885
      End
      Begin VB.TextBox txtNmDokter 
         Appearance      =   0  'Flat
         BackColor       =   &H8000000F&
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   6180
         Locked          =   -1  'True
         MaxLength       =   20
         TabIndex        =   15
         TabStop         =   0   'False
         Tag             =   "?"
         Top             =   2160
         Width           =   3885
      End
      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        =   6
         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        =   5
         Top             =   6315
         Width           =   1305
      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        =   8
         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        =   7
         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        =   9
         Top             =   6315
         Width           =   1275
      End
      Begin MSDataListLib.DataCombo cboNoKunjungan 
         Height          =   330
         Left            =   6180
         TabIndex        =   0
         Top             =   930
         Width           =   2115
         _ExtentX        =   3731
         _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        =   10
         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    =   $"frmKunjungan.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 grdKunjungan 
         Height          =   2445
         Left            =   4530
         TabIndex        =   4
         Top             =   3420
         Width           =   5985
         _cx             =   10557
         _cy             =   4313
         _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            =   9
         Cols            =   8
         FixedRows       =   1
         FixedCols       =   0
         RowHeightMin    =   0
         RowHeightMax    =   0
         ColWidthMin     =   0
         ColWidthMax     =   0
         ExtendLastCol   =   -1  'True
         FormatString    =   $"frmKunjungan.frx":005A
         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 MSDataListLib.DataCombo cboKdDokter 
         Height          =   330
         Left            =   6180
         TabIndex        =   2
         Top             =   1770
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   582
         _Version        =   393216
         Appearance      =   0
         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 MSDataListLib.DataCombo cboKdPasien 
         Height          =   330
         Left            =   6180
         TabIndex        =   3
         Top             =   2550
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   582
         _Version        =   393216
         Appearance      =   0
         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 VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         BackStyle       =   0  'Transparent
         Caption         =   "Nama Pasien"
         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           =   1
         Left            =   4440
         TabIndex        =   20
         Top             =   2950
         Width           =   1635
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         BackStyle       =   0  'Transparent
         Caption         =   "Kode Pasien"
         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           =   2
         Left            =   4440
         TabIndex        =   19
         Top             =   2550
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         BackStyle       =   0  'Transparent
         Caption         =   "Nama Dokter"
         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           =   0
         Left            =   4440
         TabIndex        =   17
         Top             =   2160
         Width           =   1635
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         BackStyle       =   0  'Transparent
         Caption         =   "Kode Dokter"
         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           =   1
         Left            =   4440
         TabIndex        =   16
         Top             =   1770
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Tgl Kunjungan"
         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            =   4440
         TabIndex        =   14
         Top             =   1350
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "No Kunjungan"
         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            =   4440
         TabIndex        =   13
         Top             =   930
         Width           =   1635
      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         =   "K u n j u n g a n"
         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
         Index           =   0
         Left            =   210
         TabIndex        =   12
         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
   Begin vbskpro.Skinner Skinner 
      Left            =   0
      Top             =   0
      _ExtentX        =   1270
      _ExtentY        =   1270
      CloseButton     =   0
      MaxButton       =   0
      MinButton       =   0
      TitleBarSkin    =   3
      BodySkin        =   5
      Skin            =   98
      ChangeSkinButton=   0   'False
      SkinPicture     =   "frmKunjungan.frx":016D
      SysDisableSkinCaption=   "&Disable Skin"
   End
End
Attribute VB_Name = "frmKunjungan"
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 rsKunjungan As ADODB.Recordset
Private rsPenyakit As ADODB.Recordset
Private rsDokter As ADODB.Recordset
Private rsPasien As ADODB.Recordset
Private rsObat As ADODB.Recordset
Private rsSQL As ADODB.Recordset
Private nRowAtGrid As Integer
Private nI As Integer

Private Const nColKdPenyakit As Byte = 0
Private Const nColNmPenyakit As Byte = 1
Private Const nColKdObat As Byte = 2
Private Const nColNmObat As Byte = 3
Private Const nColSatuan As Byte = 4
Private Const nColHarga As Byte = 5
Private Const nColJlh As Byte = 6
Private Const nColTotal As Byte = 7

Private Sub cboKdDokter_Click(Area As Integer)
  cSQL = "SELECT NmDokter FROM Dokter WHERE KdDokter = '" & SafeChar(cboKdDokter.Text) & "'"
  If goConn.OpenRSFO(rsSQL, cSQL) Then
    txtNmDokter.Text = rsSQL!NmDokter
  Else
    txtNmDokter.Text = ""
  End If
End Sub

Private Sub cboKdPasien_Click(Area As Integer)
  cSQL = "SELECT NmPasien FROM Pasien WHERE KdPasien = '" & SafeChar(cboKdPasien.Text) & "'"
  If goConn.OpenRSFO(rsSQL, cSQL) Then
    txtNmPasien.Text = rsSQL!NmPasien
  Else
    txtNmPasien.Text = ""
  End If
End Sub

Private Sub cboNoKunjungan_Change()
  With cboNoKunjungan
    If Len(.Text) > 12 Then .Text = Left(.Text, 12)
    Call lCheckData
  End With
End Sub

Private Sub cboNoKunjungan_Click(Area As Integer)
    Call lCheckData
End Sub

Private Sub cboNoKunjungan_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) = 12 And .SelLength = 0 And Not _
      (KeyAscii = vbKeyReturn Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeyBack) Then KeyAscii = 0
    End Select
  End With
End Sub

Private Sub cboNoKunjungan_Validate(Cancel As Boolean)
  cboNoKunjungan.Text = UCase(Trim(cboNoKunjungan.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()
  rsKunjungan.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 NoKunjungan AS [No Kunjungan], TglKunjungan AS [Tgl Kunjungan] FROM Kunjungan ORDER BY NoKunjungan"
  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 = grdKunjungan.Rows
  dtpTglKunjungan.Value = Date
End Sub

Private Function lSave() As Boolean
  With grdKunjungan
    Dim csfNoKunjungan As String, csfKdDokter As String
    Dim csfKdPasien As String
    
    csfNoKunjungan = SafeChar(cboNoKunjungan.Text)
    csfKdDokter = SafeChar(cboKdDokter.Text)
    csfKdPasien = SafeChar(cboKdPasien.Text)
    
    '~ validate correct data
    If Len(csfNoKunjungan) = 0 Then
      MsgBox "Nomor Kunjungan harus diisi.", vbInformation, "Data Tidak Lengkap"
      cboNoKunjungan.SetFocus: Exit Function
    End If
    If Len(csfKdDokter) = 0 Then
      MsgBox "Kode Dokter harus diisi.", vbInformation, "Data Tidak Lengkap"
      cboKdDokter.SetFocus: Exit Function
    End If
    
    cSQL = "SELECT KdDokter FROM Dokter WHERE KdDokter = '" & csfKdDokter & "'"
    If Not goConn.OpenRSFO(rsSQL, cSQL) Then
      MsgBox "Tidak ada Kode Dokter " & cboKdDokter.Text & " pada Database.", vbCritical, "Kesalahan Entri"
      cboKdDokter.SetFocus: Exit Function
    End If
    
    If Len(csfKdPasien) = 0 Then
      MsgBox "Kode Pasien harus diisi.", vbInformation, "Data Tidak Lengkap"
      cboKdPasien.SetFocus: Exit Function
    End If
    
    cSQL = "SELECT KdPasien FROM Pasien WHERE KdPasien = '" & csfKdPasien & "'"
    If Not goConn.OpenRSFO(rsSQL, cSQL) Then
      MsgBox "Tidak ada Kode Pasien " & cboKdPasien.Text & " pada Database.", vbCritical, "Kesalahan Entri"
      cboKdPasien.SetFocus: Exit Function
    End If
    
    If Not IsTextInGrid(grdKunjungan, 0) Then
      MsgBox "Belum ada Penyakit untuk Kunjungan ini.", vbInformation, "Data Tidak Lengkap"
      grdKunjungan.SetFocus: Exit Function
    End If
    
    With grdKunjungan
      For nI = .FixedRows To .Rows - 1
        If Len(.TextMatrix(nI, nColKdPenyakit)) > 0 Then
          cSQL = "SELECT KdPenyakit FROM Penyakit WHERE KdPenyakit = '" & SafeChar(.TextMatrix(nI, nColKdPenyakit)) & "'"
          If Not goConn.OpenRSFO(rsSQL, cSQL) Then
            MsgBox "Tidak ada Kode Penyakit " & .TextMatrix(nI, nColKdPenyakit) & " pada Database.", vbCritical, "Kesalahan Entri"
            .SetFocus: .Row = nI: Exit Function
          End If
                              
          If Len(.TextMatrix(nI, nColKdObat)) = 0 Or .ValueMatrix(nI, nColHarga) = 0 Or .ValueMatrix(nI, nColJlh) = 0 Then
            MsgBox "Data pada grid belum lengkap", vbInformation, "Data tidak lengkap"
            .SetFocus: .Row = nI: Exit Function
          Else
            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
        End If
      Next nI
    End With
    '~
    
    cSQL = "SELECT NoKunjungan FROM Kunjungan where NoKunjungan = '" & csfNoKunjungan & "'"
    If goConn.OpenRSFO(rsSQL, cSQL) Then
      cSQL = "UPDATE Kunjungan SET KdDokter = '" & csfKdDokter & _
              "', KdPasien = '" & csfKdPasien & _
              "', TglKunjungan = '" & Format(dtpTglKunjungan.Value, "mm/dd/yyyy") & _
              "' WHERE NoKunjungan = '" & csfNoKunjungan & "'"
    Else
      cSQL = "INSERT INTO Kunjungan(NoKunjungan, TglKunjungan, KdDokter, KdPasien) VALUES ( '" & _
              csfNoKunjungan & "', '" & Format(dtpTglKunjungan.Value, "mm/dd/yyyy") & _
              "', '" & csfKdDokter & "', '" & csfKdPasien & "')"
    End If
    
    On Error GoTo ErrorHandler
    MousePointer = vbHourglass
    cmdSave.Enabled = False
    goConn.Conn.BeginTrans
    goConn.Conn.Execute cSQL
       
    cSQL = "DELETE FROM KunjunganDetail Where NoKunjungan = '" & csfNoKunjungan & "'"
    goConn.Conn.Execute cSQL
    
    Dim csfKdPenyakit As String, csfKdObat As String, nsfHarga As Double
    Dim nsfJlh As Integer, nsfTotal As Double
    For nI = .FixedRows To .Rows - 1
      If Len(Trim(.TextMatrix(nI, 0))) > 0 Then
        csfKdPenyakit = SafeChar(.TextMatrix(nI, nColKdPenyakit))
        csfKdObat = SafeChar(.TextMatrix(nI, nColKdObat))
        nsfHarga = .ValueMatrix(nI, nColHarga)
        nsfJlh = .ValueMatrix(nI, nColJlh)
        nsfTotal = .ValueMatrix(nI, nColTotal)
        cSQL = "INSERT INTO KunjunganDetail(NoKunjungan, KdPenyakit, KdObat, Harga, Jlh, Total) ValUES ('" & _
                csfNoKunjungan & "', '" & csfKdPenyakit & "', '" & _
                csfKdObat & "'," & nsfHarga & "," & nsfJlh & "," & nsfTotal & ")"
        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(cboNoKunjungan.Text)) > 0 Then
      If MsgBox("Hapus data ini dari database?", vbQuestion + vbYesNo, "Konfirmasi") = vbYes Then
        Dim csfNoKunjungan As String
        csfNoKunjungan = SafeChar(cboNoKunjungan.Text)
        cSQL = "DELETE FROM Kunjungan WHERE NoKunjungan = '" & csfNoKunjungan & "'"
        
        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 K.*, Pa.NmPasien, D.NmDokter " & _
        "FROM Kunjungan K " & _
        "INNER JOIN Pasien Pa ON K.KdPasien = Pa.KdPasien " & _
        "INNER JOIN Dokter D ON K.KdDokter = D.KdDokter " & _
        "WHERE K.NoKunjungan = '" & SafeChar(cboNoKunjungan.Text) & "'"
  
  goConn.OpenRS rsSQL, cSQL
  If rsSQL.EOF Then
    Call lClr(False)
  Else
    MousePointer = vbHourglass
    dtpTglKunjungan.Value = rsSQL!TglKunjungan
    cboKdDokter.Text = rsSQL!KdDokter
    txtNmDokter.Text = rsSQL!NmDokter
    cboKdPasien.Text = rsSQL!KdPasien
    txtNmPasien.Text = rsSQL!NmPasien
    
    cSQL = "SELECT K.KdPenyakit, P.NmPenyakit, K.KdObat, O.NmObat, " & _
            "O.Satuan , K.Jlh, K.Harga, K.Total " & _
            "FROM KunjunganDetail K " & _
            "INNER JOIN Penyakit P ON K.KdPenyakit = P.KdPenyakit " & _
            "INNER JOIN Obat O ON K.KdObat = O.KdObat " & _
          "WHERE K.NoKunjungan = '" & SafeChar(cboNoKunjungan.Text) & "'"
    goConn.OpenRS rsSQL, cSQL
    
    With grdKunjungan
      .Clear 1, 1
      .Rows = IIf(rsSQL.RecordCount < nRowAtGrid - .FixedRows, nRowAtGrid, rsSQL.RecordCount + .FixedRows)
      For nI = 1 To rsSQL.RecordCount
        .TextMatrix(nI, nColKdPenyakit) = rsSQL!KdPenyakit
        .TextMatrix(nI, nColNmPenyakit) = rsSQL!NmPenyakit
        .TextMatrix(nI, nColKdObat) = rsSQL!KdObat
        .TextMatrix(nI, nColNmObat) = rsSQL!NmObat
        .TextMatrix(nI, nColSatuan) = rsSQL!Satuan
        .TextMatrix(nI, nColHarga) = rsSQL!Harga
        .TextMatrix(nI, nColJlh) = rsSQL!Jlh
        .TextMatrix(nI, nColTotal) = rsSQL!Total
        rsSQL.MoveNext
      Next nI
    End With
    
    MousePointer = Default
  End If
End Sub

Private Sub lClr(pbWithPK As Boolean)
  If pbWithPK Then cboNoKunjungan.Text = "": cboNoKunjungan.SetFocus
  cboKdDokter.Text = ""
  txtNmDokter.Text = ""
  cboKdPasien.Text = ""
  txtNmPasien.Text = ""
  dtpTglKunjungan.Value = Date

  grdKunjungan.Clear 1, 1
  grdKunjungan.Rows = nRowAtGrid
End Sub

Private Sub lSetCombo()
  '~ set combo
  cSQL = "SELECT NoKunjungan FROM Kunjungan " & _
          "ORDER BY NoKunjungan"
  goConn.SetCbo2 cboNoKunjungan, rsKunjungan, cSQL, "NoKunjungan"

  cSQL = "SELECT KdDokter FROM Dokter " & _
          "ORDER BY KdDokter"
  goConn.SetCbo2 cboKdDokter, rsDokter, cSQL, "KdDokter"

  cSQL = "SELECT KdPasien FROM Pasien " & _
          "ORDER BY KdPasien"
  goConn.SetCbo2 cboKdPasien, rsPasien, cSQL, "KdPasien"
End Sub

Private Sub grdKunjungan_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
  Cancel = Not cmdSave.Enabled
  If Cancel Then Exit Sub
  With grdKunjungan
    Select Case Col
    Case nColKdPenyakit
      Cancel = Not lSetKdPenyakit
    Case nColKdObat
      Cancel = Not lSetKdObat(.TextMatrix(Row, nColKdPenyakit))
    Case nColHarga
      .EditMaxLength = 10
    Case nColJlh
      .EditMaxLength = 4
    Case Else
      Cancel = True
    End Select
  End With
End Sub

Private Sub grdKunjungan_GotFocus()
  If Len(Trim(cboNoKunjungan.Text)) = 0 Then cboNoKunjungan.SetFocus
End Sub

Private Sub grdKunjungan_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii As Integer)
  Select Case Col
    Case nColHarga, nColJlh
      If Not IsNumber(KeyAscii) Then KeyAscii = 0
  End Select
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
      cboNoKunjungan.Text = .TextMatrix(.Row, 0)
'      txtNamaPenyakit.Text = .TextMatrix(.Row, 1)
    End If
  End With
End Sub


Private Sub txtNmDokter_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
End Sub

Private Sub grdKunjungan_KeyPress(KeyAscii As Integer)
  With grdKunjungan
    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 grdKunjungan_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
  With grdKunjungan
    Select Case Col
    Case nColKdPenyakit
      If Len(Trim(.EditText)) = 0 Then
        Call ClearRow(grdKunjungan, Row)
      ElseIf .EditText <> .ComboData Then
        Cancel = True
      Else
        Call lPenyakitDetail(Row, SafeChar(.EditText))
      End If
    Case nColKdObat
      If Len(Trim(.EditText)) = 0 Then
        .Cell(flexcpText, Row, nColKdObat, Row, .Cols - 1) = ""
      ElseIf IsMultiExist(grdKunjungan, .EditText & "|" & .TextMatrix(Row, nColKdPenyakit), Col & "|" & Col - 2, 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
    Case nColJlh
      .EditText = Val(.EditText)
      .TextMatrix(Row, nColTotal) = .EditText * .ValueMatrix(Row, nColHarga)
    Case nColHarga
      .EditText = Val(.EditText)
      .TextMatrix(Row, nColTotal) = Val(.EditText) * .ValueMatrix(Row, nColJlh)
    Case Else
      Cancel = True
    End Select
  End With
End Sub

Private Sub lPenyakitDetail(ByVal pnRow As Integer, pcKdPenyakit As String)
  With grdKunjungan
    cSQL = "SELECT NmPenyakit FROM Penyakit " & _
          "WHERE KdPenyakit = '" & pcKdPenyakit & "'"
    If goConn.OpenRS(rsSQL, cSQL) Then
      .TextMatrix(pnRow, nColNmPenyakit) = rsSQL!NmPenyakit
    End If
  End With
End Sub

Private Sub lObatDetail(ByVal pnRow As Integer, pcKdObat As String)
  With grdKunjungan
    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 lSetKdPenyakit() As Boolean
  cSQL = "SELECT * FROM Penyakit"
  lSetKdPenyakit = goConn.OpenRS(rsPenyakit, cSQL)
  SetCboList grdKunjungan, nColKdPenyakit, rsPenyakit, "KdPenyakit, NmPenyakit", "KdPenyakit", False
End Function

Private Function lSetKdObat(pcKdPenyakit As String) As Boolean
  cSQL = "SELECT * FROM Obat WHERE KdObat IN " & _
          "(SELECT KdObat FROM PenyakitDetail WHERE KdPenyakit = '" & pcKdPenyakit & "')"
  lSetKdObat = goConn.OpenRS(rsObat, cSQL)
  SetCboList grdKunjungan, nColKdObat, rsObat, "KdObat, NmObat, Satuan, Harga", "KdObat", False
End Function

Private Sub lUnload()
  Set rsList = Nothing
  Set rsKunjungan = Nothing
  Set rsObat = Nothing
  Set rsSQL = Nothing
  Set frmPenyakit = Nothing
End Sub
