Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.41 KB | None | 0 0
  1. daUser.vb
  2.  
  3. Imports System
  4. Imports System.Collections.Generic
  5. Imports System.Text
  6. Imports System.Data
  7. Imports System.Data.OleDb
  8. Imports System.Windows.Forms
  9. Imports System.Collections
  10. Imports Pos.Pos.BLL
  11.  
  12. Namespace Pos.DAL
  13.  
  14.     Public Class daUser
  15.         Private CnnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data " + "Source= " + Application.StartupPath + "\pos.accdb;Jet OLEDB:Database Password=pos"
  16.         'Public menu As List(Of String)
  17.         'Public menu As String
  18.         Public menu As ArrayList
  19.  
  20.         Private cnn As New OleDbConnection()
  21.         Public role As String
  22.        
  23.         Public Sub New()
  24.             cnn.ConnectionString = CnnStr
  25.             cnn.Open()
  26.         End Sub
  27.  
  28.         Public Sub add(ByVal user As User)
  29.             If cnn.State = ConnectionState.Open Then
  30.                 cnn.Close()
  31.             End If
  32.  
  33.             Try
  34.                 Dim strCom As String = "Insert into tblUser(Username,Password,Jabatan) values ('" & Convert.ToString(user.Username) & "'," & Convert.ToString(user.Password) & "'," & Convert.ToString(user.Jabatan) & "')"
  35.  
  36.                 cnn.ConnectionString = CnnStr
  37.                 cnn.Open()
  38.  
  39.                 Dim Comm As New OleDbCommand(strCom, cnn)
  40.  
  41.                 Comm.Dispose()
  42.                 cnn.Close()
  43.  
  44.             Catch ex As OleDbException
  45.                 Throw ex
  46.             Catch ex As Exception
  47.                 Throw New Exception(ex.Message.ToString())
  48.             End Try
  49.  
  50.         End Sub
  51.  
  52.         Public Function Login(ByVal username As String, ByVal password As String) As String
  53.             'Dim role As String
  54.             If cnn.State = ConnectionState.Open Then
  55.                 cnn.Close()
  56.             End If
  57.             Try
  58.                 Dim strCom As String = "select Jabatan from tblUser where Username='" + username + "' and Password='" + password + "'"
  59.                 cnn.ConnectionString = CnnStr
  60.                 cnn.Open()
  61.                 Dim Comm As New OleDbCommand(strCom, cnn)
  62.                 Dim dr As OleDbDataReader = Comm.ExecuteReader
  63.                 While dr.Read
  64.                     role = dr(0).ToString
  65.                 End While
  66.                 cnn.Close()
  67.  
  68.             Catch ex As Exception
  69.                 Return ex.ToString
  70.             Finally
  71.             End Try
  72.             Return role
  73.         End Function
  74.  
  75.         Public Function getMenu(ByVal jabatan As String) As List(Of String)
  76.             'Public Function getMenu(ByVal jabatan As String) As Boolean
  77.             If cnn.State = ConnectionState.Open Then
  78.                 cnn.Close()
  79.             End If
  80.             Try
  81.                 'Dim strCommand As String = "select Menu from tblJabatan where JabatanName='" + jabatan + "'"
  82.                 Dim strCommand As String = "select Menu from tblJabatan where JabatanName='tes'"
  83.                 cnn.ConnectionString = CnnStr
  84.                 cnn.Open()
  85.                 Dim Comm As New OleDbCommand(strCommand, cnn)
  86.                 Dim dr As OleDbDataReader = Comm.ExecuteReader
  87.                 If dr.HasRows Then
  88.                     Do While dr.Read
  89.                         menu.Add(dr(0).ToString)
  90.                     Loop
  91.                 End If
  92.                 cnn.Close()
  93.  
  94.             Catch er As OleDb.OleDbException
  95.  
  96.  
  97.             Catch ex As Exception
  98.  
  99.             Finally
  100.             End Try
  101.             Return menu
  102.  
  103.         End Function
  104.  
  105.     End Class
  106.  
  107. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement