Advertisement
Guest User

Untitled

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