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 frmObat 
   BorderStyle     =   0  'None
   Caption         =   "Obat"
   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        =   10
      TabStop         =   0   'False
      Top             =   300
      Width           =   11085
      Begin VB.TextBox txtHarga 
         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            =   6150
         MaxLength       =   10
         TabIndex        =   3
         Top             =   3600
         Width           =   1785
      End
      Begin VB.TextBox txtSatuan 
         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            =   6150
         MaxLength       =   15
         TabIndex        =   2
         Top             =   3180
         Width           =   2925
      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        =   5
         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
         TabIndex        =   4
         Top             =   6315
         Width           =   1305
      End
      Begin VB.TextBox txtNama 
         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            =   6150
         MaxLength       =   30
         TabIndex        =   1
         Top             =   2760
         Width           =   4005
      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        =   7
         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        =   6
         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        =   8
         Top             =   6315
         Width           =   1275
      End
      Begin MSDataListLib.DataCombo cboKdObat 
         Height          =   330
         Left            =   6150
         TabIndex        =   0
         Top             =   2370
         Width           =   1785
         _ExtentX        =   3149
         _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 VSFlex7Ctl.VSFlexGrid grdList 
         Height          =   5325
         Left            =   450
         TabIndex        =   9
         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    =   $"frmObat.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 VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Harga"
         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            =   4410
         TabIndex        =   15
         Top             =   3600
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Satuan"
         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            =   4410
         TabIndex        =   14
         Top             =   3180
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Nama Obat"
         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        =   13
         Top             =   2760
         Width           =   1635
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Kode Obat"
         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            =   5190
         TabIndex        =   12
         Top             =   2370
         Width           =   870
      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         =   "O b a 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        =   11
         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
   End
End
Attribute VB_Name = "frmObat"
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 rsKdObat As ADODB.Recordset
Private rsSQL As ADODB.Recordset

Private Sub cboKdObat_Change()
  With cboKdObat
    If Len(.Text) > 5 Then .Text = Left(.Text, 5)
    Call lCheckData
  End With
End Sub

Private Sub cboKdObat_Click(Area As Integer)
    Call lCheckData
End Sub

Private Sub cboKdObat_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 cboKdObat_Validate(Cancel As Boolean)
  cboKdObat.Text = UCase(Trim(cboKdObat.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()
  rsKdObat.Requery
  rsList.Requery
  DoEvents
  grdList.ColWidth(0) = 1515
End Sub

Private Sub cmdSave_Click()
  Call lSave
End Sub

Private Sub Form_Load()
  Call lSetCombo
  Call lInitObj
  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 KdObat AS [Kode Obat], NmObat AS [Nama Obat] FROM Obat ORDER BY KdObat"
  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
End Sub

Private Function lSave() As Boolean
  With grdList
    Dim csfKdObat As String, csfNama As String
    Dim csfSatuan As String, nsfHarga As Double
    csfKdObat = SafeChar(cboKdObat.Text)
    csfNama = SafeChar(txtNama.Text)
    csfSatuan = SafeChar(txtSatuan.Text)
    nsfHarga = Val(txtHarga.Text)
    
    '~ validate correct data
    If Len(csfKdObat) = 0 Then
      MsgBox "Kode Obat harus diisi.", vbInformation, "Data Tidak Lengkap"
      cboKdObat.SetFocus: Exit Function
    End If
    If Len(csfNama) = 0 Then
      MsgBox "Nama Obat harus diisi.", vbInformation, "Data Tidak Lengkap"
      txtNama.SetFocus: Exit Function
    End If
    If Len(csfSatuan) = 0 Then
      MsgBox "Satuan harus diisi.", vbInformation, "Data Tidak Lengkap"
      txtSatuan.SetFocus: Exit Function
    End If
    If nsfHarga <= 0 Then
      MsgBox "Harga harus diisi dengan benar.", vbInformation, "Data Tidak Lengkap"
      txtHarga.SetFocus: Exit Function
    End If
    '~
    
    cSQL = "SELECT * FROM Obat where KdObat = '" & csfKdObat & "'"
    If goConn.OpenRSFO(rsSQL, cSQL) Then
      cSQL = "UPDATE Obat SET NmObat = '" & csfNama & _
              "', Satuan = '" & csfSatuan & _
              "', Harga = " & nsfHarga & _
              " WHERE KdObat = '" & csfKdObat & "'"
    Else
      cSQL = "INSERT INTO Obat(KdObat, NmObat, Satuan, Harga) VALUES ( '" & _
              csfKdObat & "', '" & csfNama & "','" & _
              csfSatuan & "'," & nsfHarga & ")"
    End If
    On Error GoTo ErrorHandler
    MousePointer = vbHourglass
    cmdSave.Enabled = False
    goConn.Conn.BeginTrans
    goConn.Conn.Execute cSQL
    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(cboKdObat.Text)) > 0 Then
      If MsgBox("Hapus data ini dari database?", vbQuestion + vbYesNo, "Konfirmasi") = vbYes Then
        Dim csfKdObat As String
        csfKdObat = SafeChar(cboKdObat.Text)
        cSQL = "SELECT KdObat FROM PenyakitDetail WHERE KdObat = '" & csfKdObat & "'"
        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 Obat WHERE KdObat = '" & csfKdObat & "'"
        
        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 * FROM Obat WHERE KdObat = '" & SafeChar(cboKdObat.Text) & "'"
  goConn.OpenRS rsSQL, cSQL
  With rsSQL
    If .EOF Then
      Call lClr(False)
    Else
      MousePointer = vbHourglass
      txtNama.Text = !NmObat
      txtSatuan.Text = !Satuan
      txtHarga.Text = !Harga
      MousePointer = Default
    End If
  End With
End Sub

Private Sub lClr(pbWithPK As Boolean)
  If pbWithPK Then cboKdObat.Text = "": cboKdObat.SetFocus
  txtNama.Text = ""
  txtSatuan.Text = ""
  txtHarga.Text = ""
End Sub

Private Sub lSetCombo()
  '~ user id
  cSQL = "SELECT KdObat  FROM Obat O " & _
          "ORDER BY KdObat"
  goConn.SetCbo2 cboKdObat, rsKdObat, cSQL, "KdObat"
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 .Rows > .FixedRows Then
      cboKdObat.Text = .TextMatrix(.Row, 0)
      Call lCheckData
    End If
  End With
End Sub

Private Sub txtHarga_GotFocus()
  If Len(Trim(cboKdObat.Text)) = 0 Then cboKdObat.SetFocus
End Sub

Private Sub txtHarga_KeyPress(KeyAscii As Integer)
  If Not IsNumber(KeyAscii) Then
    KeyAscii = 0
  ElseIf KeyAscii = vbKeyReturn Then
    SendKeys "{TAB}"
  End If
End Sub

Private Sub txtNama_GotFocus()
  If Len(Trim(cboKdObat.Text)) = 0 Then cboKdObat.SetFocus
End Sub

Private Sub txtNama_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
End Sub

Private Sub lUnload()
  Set rsList = Nothing
  Set rsKdObat = Nothing
  Set rsSQL = Nothing
  Set frmObat = Nothing
End Sub

Private Sub txtSatuan_GotFocus()
  If Len(Trim(cboKdObat.Text)) = 0 Then cboKdObat.SetFocus
End Sub

Private Sub txtSatuan_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
End Sub
