VERSION 5.00
Object = "{5734474E-78D3-4254-99B9-C35F31BDF509}#63.0#0"; "vbskpro2.ocx"
Begin VB.Form frmLogin 
   Caption         =   "Login Database"
   ClientHeight    =   3165
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4740
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   3165
   ScaleWidth      =   4740
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame frLoginDB 
      Appearance      =   0  'Flat
      ForeColor       =   &H80000008&
      Height          =   2715
      Left            =   180
      TabIndex        =   6
      Top             =   180
      Width           =   4365
      Begin VB.Frame Frame1 
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1035
         Left            =   120
         TabIndex        =   7
         Top             =   1050
         Width           =   4155
         Begin VB.TextBox txtPasswd 
            Appearance      =   0  'Flat
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            IMEMode         =   3  'DISABLE
            Left            =   1620
            PasswordChar    =   "*"
            TabIndex        =   5
            Top             =   600
            Width           =   2355
         End
         Begin VB.TextBox txtUsername 
            Appearance      =   0  'Flat
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   1620
            TabIndex        =   4
            Top             =   240
            Width           =   2355
         End
         Begin VB.Label Label1 
            Alignment       =   1  'Right Justify
            Caption         =   "Nama User"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   480
            TabIndex        =   9
            Top             =   300
            Width           =   1035
         End
         Begin VB.Label Label2 
            Alignment       =   1  'Right Justify
            Caption         =   "Password"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   480
            TabIndex        =   8
            Top             =   690
            Width           =   1035
         End
      End
      Begin VB.CheckBox chkAuthentication 
         Caption         =   "Autentikasi NT"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1740
         TabIndex        =   3
         Top             =   630
         Width           =   2295
      End
      Begin VB.ComboBox cboServer 
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   1740
         TabIndex        =   2
         Top             =   270
         Width           =   2295
      End
      Begin VB.CommandButton cmdCancel 
         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            =   2280
         TabIndex        =   1
         Top             =   2190
         Width           =   1275
      End
      Begin VB.CommandButton cmdOK 
         Caption         =   "&OK"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   900
         TabIndex        =   0
         Top             =   2190
         Width           =   1275
      End
      Begin VB.Label Label3 
         Alignment       =   1  'Right Justify
         Caption         =   "Nama Server SQL"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   10
         Top             =   360
         Width           =   1395
      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     =   "frmLogin.frx":0000
      SysDisableSkinCaption=   "&Disable Skin"
   End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private nI As Integer

Private Sub cboServer_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}": KeyAscii = 0
End Sub

Private Sub chkAuthentication_Click()
  If chkAuthentication.Value = vbChecked Then
    Frame1.Enabled = False
    Label1.Enabled = False
    Label2.Enabled = False
  Else
    Frame1.Enabled = True
    Label1.Enabled = True
    Label2.Enabled = True
  End If
End Sub

Private Sub chkAuthentication_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}": KeyAscii = 0
End Sub

Private Sub cmdCancel_Click()
  Unload Me
End Sub

Private Sub cmdOK_Click()
  If lLoginDB Then
    On Error Resume Next
    With gcDBLogin
      WriteINI "StartUp", "ServerName", .ServerName, ProgPath & "StartUp.ini"
      WriteINI "StartUp", "Authentic", .Authentic, ProgPath & "StartUp.ini"
      WriteINI "StartUp", "UserName", IIf(.UserName = "", " ", .UserName), ProgPath & "StartUp.ini"
      WriteINI "StartUp", "Pass", IIf(.Pass = "", " ", .Pass), ProgPath & "StartUp.ini"
    End With
    Unload Me
    MDI.Show
  End If
End Sub

Private Sub Form_Load()
  Call lInitObj
  Call lSetCombo
  Call lReadConf
End Sub

Private Function lLoginDB() As Boolean
  With gcDBLogin
    '~ save info
    .Authentic = chkAuthentication.Value
    .ServerName = cboServer.Text
    .DBName = kcDBName
    .UserName = txtUsername.Text
    .Pass = txtPasswd.Text
    
    '~ connect 2 server
    If Not goConnDB.ConnectToServer(.Authentic, .ServerName, .UserName, .Pass) Then Exit Function
    
    '~ connect 2 database
Connect2DB:
    Set goConn = New dllUtil.clsRs
    If goConn.OpenConn(.Authentic, .ServerName, .DBName, .UserName, .Pass, False) Then
      goConn.Conn.CursorLocation = adUseClient
      lLoginDB = True
    Else
      If MsgBox("Database tidak ditemukan pada server. Buat database baru?", vbQuestion + vbYesNo, "Database Baru") = vbYes Then
        If DoDecrypt(QueryPath, kcEncryptPass) Then
          If goConnDB.RunQuery(goConnDB.ReadQuery(QueryPath)) Then
            MsgBox "Database baru telah dibuat!", vbInformation, "Informasi"
            Call DoEncrypt(QueryPath, kcEncryptPass)
            GoTo Connect2DB
          Else
            goConnDB.RemoveDB kcDBName
            MsgBox "File Database tidak dapat di-restore!", vbCritical, "Fatal Error"
            Exit Function
          End If
        End If
      End If
     End If
  End With
Exit Function

ErrorHandler:
    MsgBox "Error: " & Err.Number & " " & Err.Description, vbOKOnly, "Login Error"
    lLoginDB = False
End Function


Private Sub lInitObj()
  Set goConnDB = New dllUtil.clsSQLDmo
End Sub

Private Sub lSetCombo()
  goConnDB.GetAvailServer
  For nI = 1 To goConnDB.TotAvailServer
    cboServer.AddItem goConnDB.colServer(nI)
  Next nI
  If cboServer.ListCount > 0 Then cboServer.ListIndex = 0
End Sub

Private Sub txtPasswd_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then Call cmdOK_Click
End Sub

Private Sub txtUserID_KeyPress(KeyAscii As Integer)
  KeyAscii = Asc(UCase(Chr(KeyAscii)))
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}": KeyAscii = 0
End Sub

Private Sub txtUserName_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then SendKeys "{TAB}": KeyAscii = 0
End Sub

Private Function lReadConf() As Boolean
  lReadConf = False
  On Error GoTo ErrHandler
  chkAuthentication.Value = IIf(ReadINI("StartUp", "Authentic", ProgPath & "StartUp.ini") = False, 0, 1)
  cboServer.Text = ReadINI("StartUp", "ServerName", ProgPath & "StartUp.ini")
  txtUsername.Text = ReadINI("StartUp", "UserName", ProgPath & "StartUp.ini")
  txtPasswd.Text = ReadINI("StartUp", "Pass", ProgPath & "StartUp.ini")
  lReadConf = True
  Exit Function
ErrHandler:
End Function
