Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.53 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 List(Of String)
  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.                 Dim strCom As String = "select Jabatan from tblUser where Username='tes' and Password='" + password + "'"
  58.                 cnn.ConnectionString = CnnStr
  59.                 cnn.Open()
  60.                 Dim Comm As New OleDbCommand(strCom, cnn)
  61.                 Dim dr As OleDbDataReader = Comm.ExecuteReader
  62.                 While dr.Read
  63.                     role = dr(0).ToString
  64.                 End While
  65.                 cnn.Close()
  66.  
  67.             Catch ex As Exception
  68.                 Return ex.ToString
  69.             Finally
  70.             End Try
  71.             Return role
  72.         End Function
  73.  
  74.         Public Function getMenu(ByVal jabatan As String) As List(Of String)
  75.             'Public Function getMenu(ByVal jabatan As String) As Boolean
  76.             If cnn.State = ConnectionState.Open Then
  77.                 cnn.Close()
  78.             End If
  79.             Try
  80.                 Dim strCommand As String = "select Menu from tblJabatan where JabatanName='" + jabatan + "'"
  81.                 'Dim strCommand As String = "select Menu from tblJabatan where JabatanName='tes'"
  82.                 cnn.ConnectionString = CnnStr
  83.                 cnn.Open()
  84.                 Dim Comm As New OleDbCommand(strCommand, cnn)
  85.                 Dim dr As OleDbDataReader = Comm.ExecuteReader
  86.                 If dr.HasRows Then
  87.                     Do While dr.Read
  88.                         menu.Add(dr(0).ToString)
  89.                     Loop
  90.                 End If
  91.                 cnn.Close()
  92.  
  93.             Catch er As OleDb.OleDbException
  94.  
  95.  
  96.             Catch ex As Exception
  97.  
  98.             Finally
  99.             End Try
  100.             Return menu
  101.  
  102.         End Function
  103.  
  104.     End Class
  105.  
  106. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement