How to Create 3 Tier Vb.Net Desktop Application - Part 3 UI/UX Form Code

Sample Login Form Code

Assume that DLL & BLL refrences are Provided. If Not then Put Below Code First

" Imports BLL " - It Will Import BLL to your Application


Public Class FrmLogin
#Region "<< Variable >>"
    Dim objUserMaster As User_Master
    Dim objUserMasterProperty As User_MasterProperty
    Dim objGlb As New GlobalVariable
    Dim objCompMaster As CompanyMaster
#End Region
#Region "<< Button Click >>"
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Try
            If Me.txtUser_Name.Text <> "" Then
                Dim objMST_COMPANY As New MST_COMPANY
                Dim dt As DataTable
                dt = objMST_COMPANY.GetData("USERNAME='" + txtUser_Name.Text + "' And PASSWORD='" + txtPassword.Text + "'")
                If dt.Rows.Count > 0 Then
                    MainMdi.ToolStripStatusLabel6.Text = Me.txtUser_Name.Text
                    MainMdi.Show()
                    Me.Hide()
                Else
                    MsgBox("UserName Or Password is Invalid", MsgBoxStyle.Critical, "Login")
                    txtPassword.Text = ""
                    txtPassword.Select()
                End If
            Else
                MsgBox("Enter User Name...", MsgBoxStyle.Critical, "Login Form")
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString(), MsgBoxStyle.Critical, "Login")
        End Try
    End Sub
#End Region
#Region "<< Main Events >>"
    Private Sub FrmLogin_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.Enter Then
            System.Windows.Forms.SendKeys.Send("{TAB}")
        End If
    End Sub
    Private Sub FrmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Obj As New GlobalVariable()
        Dim DbPath As String = System.Environment.CurrentDirectory + "\Data\radhe.mdf"
        Obj.WebconfigChange(DbPath)
        objGlb.CloseAllChildWindow()
        DeleteFilesFromFolders(Application.StartupPath + "\Temp\")
        Dim objMST_COMPANY As New MST_COMPANY
        Dim dt As DataTable = objMST_COMPANY.GetData("")
        If dt.Rows.Count > 0 Then
            txtUser_Name.Text = dt.Rows(0)("USERNAME").ToString
            txtPassword.Select()
        Else
            txtUser_Name.Select()
        End If
    End Sub
    Private Sub txtUser_Name_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUser_Name.GotFocus
        txtUser_Name.SelectAll()
    End Sub
    Private Sub txtPassword_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPassword.GotFocus
        txtPassword.SelectAll()
    End Sub
    Public Sub DeleteFilesFromFolders(ByVal rootpath As String)
        Try
            If (Directory.Exists(rootpath)) Then
                For Each fName As String In Directory.GetFiles(rootpath)
                    If File.Exists(fName) Then
                        File.Delete(fName)
                    End If
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
End Class

Comments

Popular posts from this blog

Delete Confirmation for Delete ButtonField, TemplateField and CommandField in a GridView in ASP.NET

Selecting/Deselecting all CheckBoxes inside a ListView In ASP.NET

How to Create 3 Tier Vb.Net Desktop Application