none
[Tanya] Cara buat sistem login dan log out Di VB 2008 RRS feed

  • Pertanyaan

  • selamat malam rekan rekan semua...

    saya mau nanya nih, gimana cara / code untuk membuat login dan log out di form Mainmenu (Sebagai MDI Parent).

    jadi kasus nya seperti ini :

    1. Saya membuat suatu form dengan nama "MainMenu" dan saya seting menjadi  "MDIParent" 


    2. kemudian , di form tersebut, saya tambahkan Menustrip, dan saya tambahkan sub menu di menustrip tersebut seperti gambar berikut :

    3. saat pertama kali program dijalankan, akan muncul form login, dan saya lakukan login, setelah login Sukses, maka menu akan Tampil Seperti Gambar Di Atas.

    4. Kemudian Saya Tekan "Log Out" Dan Daftar Menu berubah menjadi seperti ini :

    5. Setelah "Log Out", Saya Coba Kembali Untuk Login dengaN menekan "Log In", Nah, Permasalahannya disini,,,
        pas sudah "Login Sukses", daftar menu TIDAK Kembali seperti semula, Namun, Masih Tetap Seperti Pada Kondisi "Gambar B."

    Untuk Code Yang Saya Gunakan Seperti Ini :

    Class Koneksi dan GetData login from Mysql Database

    Imports MySql.Data
    Imports MySql.Data.MySqlClient
    Imports System.IO
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Public Class MSQLQuery

    dim m_QueryString As String = "String Koneksi Kedatabase....." Property QueryString() As String Get Return m_QueryString End Get Set(ByVal value As String) m_QueryString = value ds = New DataSet ds.Clear() da = New MySqlClient.MySqlDataAdapter(m_QueryString, Mkonek) da.Fill(ds) End Set End Property ReadOnly Property RecordCount() As Long Get Return ds.Tables(0).Rows.Count End Get End Property ReadOnly Property GetRecords() As DataTable Get Return ds.Tables(0) End Get End Property

    End Class


    Code Pada Form Login :

            

    Dim DQ As New MSQLQuery 'Class MSQLquery..

    With DQ .BukaKoneksi() Select Case Sts 'Parameter status, Jika di jalankan pertama Kali, Maka Sts = "Start", jika form login dipanggil dari Form MainMenu, Maka Sts = "MainMenu" Case "MainMenu" If MainMenu.HasChildren Then For Each f As Form In MainMenu.MdiChildren If f.Name = "MainMenu" Then With DQ .QueryString = "Select " & Coluserlogin & " FROM " & userlogin & " WHERE User ='" & UsernameTextBox.Text.Trim & "' And Pass ='" & PasswordTextBox.Text.Trim & "' Limit 1" If .RecordCount > 0 Then With CType(f, MainMenu) Select Case CStr(DQ.GetRecords.Rows(0)("level")) Case "Admin" .PEMESANANToolStripMenuItem1.Visible = True .PEMBELIANToolStripMenuItem1.Visible = True .LOGINToolStripMenuItem.Enabled = True .LOGINToolStripMenuItem.Visible = True .LOGOUTToolStripMenuItem.Visible = True .FILEToolStripMenuItem.Visible = True .MEMBERToolStripMenuItem.Visible = True .PRODUKToolStripMenuItem.Visible = True .MEMBERToolStripMenuItem1.Visible = True .CekLevel = CStr(DQ.GetRecords.Rows(0)("level")) .ToolStripStatusLabel1.ForeColor = Color.FloralWhite .ToolStripStatusLabel1.Text = "Welcome : " & CStr(DQ.GetRecords.Rows(0)("Nama")) & " [ Login As : " & CStr(DQ.GetRecords.Rows(0)("level")) & " ]" Me.Close() Exit Select Exit Sub Case "Operator" .PEMESANANToolStripMenuItem1.Visible = False .PEMBELIANToolStripMenuItem1.Visible = False .LOGINToolStripMenuItem.Visible = True .LOGOUTToolStripMenuItem.Visible = True .FILEToolStripMenuItem.Visible = True .MEMBERToolStripMenuItem.Visible = True .PRODUKToolStripMenuItem.Visible = True .MEMBERToolStripMenuItem1.Visible = True .ToolStripStatusLabel1.ForeColor = Color.FloralWhite .ToolStripStatusLabel1.Text = "Welcome : " & CStr(DQ.GetRecords.Rows(0)("Nama")) & " [ Login As : " & CStr(DQ.GetRecords.Rows(0)("level")) & " ]" Me.Close() Exit Select Exit Sub Case Else .ToolStripStatusLabel1.ForeColor = Color.FloralWhite .ToolStripStatusLabel1.Text = "Welcome : " & CStr(DQ.GetRecords.Rows(0)("Nama")) & " [ Login As : " & CStr(DQ.GetRecords.Rows(0)("level")) & " ]" .LOGINToolStripMenuItem.Visible = False .LOGOUTToolStripMenuItem.Visible = False .FILEToolStripMenuItem.Visible = False .MEMBERToolStripMenuItem.Visible = False .PRODUKToolStripMenuItem.Visible = False .MEMBERToolStripMenuItem1.Visible = False .PEMESANANToolStripMenuItem1.Visible = False .PEMBELIANToolStripMenuItem1.Visible = False .REPORTToolStripMenuItem.Visible = False .SETTINGToolStripMenuItem.Visible = False Me.Close() Exit Select Exit Sub End Select .LOGINToolStripMenuItem.Enabled = False End With Else .NullData("Dengan Username : " & UsernameTextBox.Text & " Dan Password : " & PasswordTextBox.Text) UsernameTextBox.Text = "" PasswordTextBox.Text = "" UsernameTextBox.Focus() Exit Sub End If End With End If Next End If Case "Start" CekLogin() End Select End With End Sub

     

    code "Log Out Pada Form "MainMenu" :

            With Me
                .FILEToolStripMenuItem.Visible = False
                .TRANSAKSIToolStripMenuItem.Visible = False
                .DATAVIEWToolStripMenuItem.Visible = False
                .REPORTToolStripMenuItem.Visible = False
                .SETTINGToolStripMenuItem.Visible = False
                LOGOUTToolStripMenuItem.Enabled = False
                MENUToolStripMenuItem.Enabled = True
                LOGINToolStripMenuItem.Enabled = True
                .ToolStripStatusLabel1.ForeColor = Color.Red
                .ToolStripStatusLabel1.Text = "Anda Sudah Log Out. Silahkan Login Kembali Untuk Menggunakan Aplikasi Ini.!"
            End With

    Mohon Pencerahaannya ya..

    terima kasih..

    By : Tafarie


    Kamis, 19 September 2013 20.56

Jawaban

  • Hi Tafarie

    Mohon maaf atas keterlambatan membalas forum ini

    Kamu bisa menggunakan kode dibawah

    Dim DQ As New MSQLQuery   'Class MSQLquery..
    
           With DQ
                .BukaKoneksi()
                Select Case Sts 'Parameter status, Jika di jalankan pertama Kali, Maka Sts = "Start", jika form login dipanggil dari Form MainMenu, Maka Sts = "MainMenu"
                    Case "MainMenu"
                        If MainMenu.HasChildren Then
                            For Each f As Form In MainMenu.MdiChildren
                                If f.Name = "MainMenu" Then
                                    With DQ
                                        .QueryString = "Select " & Coluserlogin & " FROM " & userlogin & " WHERE User ='" & UsernameTextBox.Text.Trim & "' And Pass ='" & PasswordTextBox.Text.Trim & "' Limit 1"
                                        If .RecordCount > 0 Then
                                            With CType(f, MainMenu)
                                                Select Case CStr(DQ.GetRecords.Rows(0)("level"))
                                                    Case "Admin"
                                                        .PEMESANANToolStripMenuItem1.Visible = True
                                                        .PEMBELIANToolStripMenuItem1.Visible = True
                                                        .LOGINToolStripMenuItem.Enabled = True
                                                        .LOGINToolStripMenuItem.Visible = True
                                                        .LOGOUTToolStripMenuItem.Visible = True
                                                        .FILEToolStripMenuItem.Visible = True
                                                        .MEMBERToolStripMenuItem.Visible = True
                                                        .PRODUKToolStripMenuItem.Visible = True
                                                        .MEMBERToolStripMenuItem1.Visible = True
                                                        .CekLevel = CStr(DQ.GetRecords.Rows(0)("level"))
                                                        .ToolStripStatusLabel1.ForeColor = Color.FloralWhite
                                                        .ToolStripStatusLabel1.Text = "Welcome : " & CStr(DQ.GetRecords.Rows(0)("Nama")) & " [ Login As : " & CStr(DQ.GetRecords.Rows(0)("level")) & " ]"
                                                        Me.Close()
                                                        Exit Select
                                                        Exit Sub
                                                    Case "Operator"
                                                        .PEMESANANToolStripMenuItem1.Visible = False
                                                        .PEMBELIANToolStripMenuItem1.Visible = False
                                                        .LOGINToolStripMenuItem.Visible = True
                                                        .LOGOUTToolStripMenuItem.Visible = True
                                                        .FILEToolStripMenuItem.Visible = True
                                                        .MEMBERToolStripMenuItem.Visible = True
                                                        .PRODUKToolStripMenuItem.Visible = True
                                                        .MEMBERToolStripMenuItem1.Visible = True
                                                        .ToolStripStatusLabel1.ForeColor = Color.FloralWhite
                                                        .ToolStripStatusLabel1.Text = "Welcome : " & CStr(DQ.GetRecords.Rows(0)("Nama")) & " [ Login As : " & CStr(DQ.GetRecords.Rows(0)("level")) & " ]"
                                                        Me.Close()
                                                        Exit Select
                                                        Exit Sub
                                                    Case Else
                                                        .ToolStripStatusLabel1.ForeColor = Color.FloralWhite
                                                        .ToolStripStatusLabel1.Text = "Welcome : " & CStr(DQ.GetRecords.Rows(0)("Nama")) & " [ Login As : " & CStr(DQ.GetRecords.Rows(0)("level")) & " ]"
                                                        .LOGINToolStripMenuItem.Visible = False
                                                        .LOGOUTToolStripMenuItem.Visible = False
                                                        .FILEToolStripMenuItem.Visible = False
                                                        .MEMBERToolStripMenuItem.Visible = False
                                                        .PRODUKToolStripMenuItem.Visible = False
                                                        .MEMBERToolStripMenuItem1.Visible = False
                                                        .PEMESANANToolStripMenuItem1.Visible = False
                                                        .PEMBELIANToolStripMenuItem1.Visible = False
                                                        .REPORTToolStripMenuItem.Visible = False
                                                        .SETTINGToolStripMenuItem.Visible = False
                                                        Me.Close()
                                                        Exit Select
                                                        Exit Sub
                                                End Select
                                                .LOGINToolStripMenuItem.Enabled = False
                                                .LOGOUTToolStripMenuItem.Enabled = True
                                            End With
                                        Else
                                            .NullData("Dengan Username : " & UsernameTextBox.Text & " Dan Password : " & PasswordTextBox.Text)
                                            UsernameTextBox.Text = ""
                                            PasswordTextBox.Text = ""
                                            UsernameTextBox.Focus()
                                            Exit Sub
                                        End If
                                    End With
                                End If
                            Next
                        End If
                    Case "Start"
                        CekLogin()
                End Select
            End With
        End Sub
    
    Terima kasih

    Andy Nugraha

    TechNet Community Support

    Senin, 23 September 2013 06.26
    Moderator