Friday, February 15, 2013

VB CODE FOR DESKTOP APPLICATION (ISNUMERIC = TRUE / FALSE CHECK)


ISNUMERIC USAGE IN THIS CODE

Imports System.Data.SqlClient
Imports System.Data

Public Class frmJobCard
    Dim con As SqlConnection
    Dim dr As SqlDataReader
    Dim da As SqlDataAdapter
    Dim da1 As SqlDataAdapter
    Dim ds As DataSet
    Dim ds1 As DataSet
    Dim s1 As String
    Dim cmd As SqlCommand
    Dim s As String
    Dim objcon As New ConnectionString

    Private Sub frmJobCard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnEdit.Visible = False
        DtpDate.CustomFormat = DateTimePickerFormat.Custom
        DtpDate.CustomFormat = "d-MMM-yyyy"
        Me.Size = New Size(595, 181)
        Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
        Me.Top = 10
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim con As SqlConnection = New SqlConnection("Data Source=KAUSHAL-6DC0C02\KAUSHAL; Initial Catalog=MotoSoftDB; Integrated Security=True; MultipleActiveResultSets=True")
        Dim intMaxPartiID As Integer = MaxParticularID() + 1
        If RequiredFieldValidator() = False Then
            Exit Sub
        End If
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        s = "Insert into tblJobparticular (ParticularID, Particular, Qty, Rate, Amount, Job_No) Values (@ParticularID, @Particular, @Qty, @Rate, @Amount, @Job_No)"
        cmd = New SqlCommand(s, con)

        With cmd
            .Parameters.AddWithValue("@ParticularID", intMaxPartiID)
            .Parameters.AddWithValue("@Particular", Trim(txtParticular.Text))
            .Parameters.AddWithValue("@Qty", Trim(txtQty.Text))
            .Parameters.AddWithValue("@Rate", CDbl(Trim(txtRate.Text)))
            .Parameters.AddWithValue("@Amount", CDbl(Trim(txtAmount.Text)))
            .Parameters.AddWithValue("@Job_No", CInt(Trim(lblJobNo.Text)))
        End With
        cmd.ExecuteNonQuery()
        con.Close()

        Load_DataGridview()
        lblEstimateCost.Text = TotalCost()

        txtParticular.Text = ""
        txtAmount.Text = ""
        txtQty.Text = ""
        txtRate.Text = ""
        txtParticular.Focus()

    End Sub
    Public Function RequiredFieldValidator() As Boolean
        If txtJobName.Text = "" Then
            MsgBox("Fill Required fields")
            txtJobName.BackColor = Color.Gold
            txtParticular.BackColor = Color.Gold
            Return False
        Else
            Return True
        End If


    End Function
    Public Function TotalCost() As Double
        Dim dblTotalcost As Double = 0
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()

        s = "Select sum(Amount) from tblJobParticular where Job_No = " & CInt(lblJobNo.Text)
        cmd = New SqlCommand(s, con)
        dr = cmd.ExecuteReader
        If dr.HasRows Then
            dr.Read()
            dblTotalcost = dr.GetDouble(0)
            Return dblTotalcost
        Else
            Return 0.0
        End If

    End Function
    Public Sub Load_DataGridview()

        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s1 = "Select * from tblJobParticular where Job_No = " & CInt(lblJobNo.Text)
        da1 = New SqlDataAdapter(s1, con)
        ds1 = New DataSet
        da1.Fill(ds1, "tblJobParticular")
        DataGridView1.DataSource = ds1
        DataGridView1.DataMember = "tblJobParticular"
        con.Close()
    End Sub

 
    Private Sub txtAddRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAddRec.Click
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        If RequiredFieldValidator() = False Then
            Exit Sub
        End If
        con.Open()
        lblJobNo.Text = MaxJobNo() + 1
        s = "Insert into tblJob (Job_No, Name, Job_Date, Job_Name) values (@Job_No, @Name, @Job_Date, @Job_Name)"
        cmd = New SqlCommand(s, con)
        With cmd
            .Parameters.AddWithValue("@Job_No", CInt(Trim(lblJobNo.Text)))
            .Parameters.AddWithValue("@Name", Trim(txtName.Text))
            .Parameters.AddWithValue("@Job_Date", CDate(Trim(DtpDate.Text)))
            .Parameters.AddWithValue("@Job_Name", Trim(txtJobName.Text))

        End With
        cmd.ExecuteNonQuery()

        txtParticular.Focus()

        Me.Size = New Size(595, 634)
        con.Close()
        btnEdit.Visible = True

    End Sub

    Public Function MaxParticularID() As Integer
        Dim intParticularID As Integer
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        Try

            con.Open()
            s = "Select max(ParticularID) from tblJobParticular where job_No = " & CInt(lblJobNo.Text)
            cmd = New SqlCommand(s, con)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                dr.Read()
                intParticularID = dr.GetInt32(0)

                Return intParticularID
                con.Close()
            Else
                MsgBox("There is no particular yet Added")
                cmd.Dispose()
                Return intParticularID = 1
            End If

        Catch ex As Exception
            ' MsgBox("First record")
            con.Close()
            Return intParticularID = 1

        End Try


    End Function

    Public Function MaxJobNo() As Integer
        Dim intJobNo As Integer
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select max(Job_No) from tblJob"
        cmd = New SqlCommand(s, con)
        dr = cmd.ExecuteReader
        If dr.HasRows Then
            dr.Read()
            intJobNo = dr.GetInt32(0)
            Return intJobNo
        Else
            'MsgBox("This is your first record")
            Return intJobNo = 1

        End If

    End Function

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        'refer the diary to delete the selected cell from Datagridview and fill the gridview again.
        ' s = "Delete from tblJobParticular where ParticularID = '" & DataGridView1.SelectedColumns.Item("SrNo") & "'"
        For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells("Choose").Value Then
                If MsgBox("Do you really don't want " & row.Cells("Particular").Value, MsgBoxStyle.YesNo, "Delete Record") = MsgBoxResult.Yes Then
                    s = "Delete from tblJobParticular where ParticularID = " & row.Cells("ParticularID").Value
                    cmd = New SqlCommand(s, con)
                    cmd.ExecuteNonQuery()
                    DataGridView1.Rows.Remove(row)

                End If
            End If
        Next
        lblEstimateCost.Text = TotalCost()
        MsgBox("Record Deleted successfully", MsgBoxStyle.Information)
        'code for deleting the record from the datagrid


    End Sub


    Private Sub txtRate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRate.Leave
        If Not IsNumeric(txtRate.Text) Then
            MsgBox("Rate must be in numeric", MsgBoxStyle.Critical)
            txtRate.Focus()
            txtRate.SelectAll()
        End If
    End Sub

    Private Sub txtAmount_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAmount.Leave
        If Not IsNumeric(txtAmount.Text) Then
            MsgBox("Amount must be in numeric", MsgBoxStyle.Critical)
        End If
    End Sub


    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        'code to update the jobparticulat table
        Try
            Dim con As SqlConnection = New SqlConnection(objCon.constr)
            con.Open()

            Dim intRowCount As Integer = DataGridView1.Rows.Count - 2

            For i = 0 To intRowCount
                'MsgBox("updating row no. :" & DataGridView1.Rows(i).Cells("ParticularID").Value)
                'checking updated Rate and Amount are numeric or not
                If Not IsNumeric(DataGridView1.Rows(i).Cells("Rate").Value) Or IsNumeric(DataGridView1.Rows(i).Cells("Amount").Value) Then
                    MsgBox("Rate / Amount must be numeric in nature", MsgBoxStyle.Exclamation)
                End If
                s = "Update tblJobParticular set Particular = '" & DataGridView1.Rows(i).Cells("Particular").Value & "', Qty = '" & DataGridView1.Rows(i).Cells("Qty").Value & "', Rate = '" & DataGridView1.Rows(i).Cells("Rate").Value & "' , Amount = '" & DataGridView1.Rows(i).Cells("Amount").Value & "' where Job_No = " & CInt(lblJobNo.Text) & " and ParticularID = " & DataGridView1.Rows(i).Cells("ParticularID").Value
                cmd = New SqlCommand(s, con)
                cmd.ExecuteNonQuery()

            Next
            MsgBox("Record Updated Successfully", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox("Problem in last row performation")
        End Try
       
    End Sub
    Public Sub Update_tblJobParticular()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select * from tblJobParticular"
        da = New SqlDataAdapter(s, con)
        ds = New DataSet
        da.Fill(ds)
        DataGridView1.DataSource = ds.Tables(0)

        'DataGridView1.DataMember = "tblJobParticular"
        da.Update(ds)

    End Sub

 
    Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
        Me.Close() '' Update_tblJobParticular()
        'Dim sqlcmdbld As New SqlCommandBuilder
        'sqlcmdbld.GetUpdateCommand()
        'da1.UpdateCommand = sqlcmdbld.GetUpdateCommand()

        'da1.Update(ds1, "tblJobParticular")

    End Sub

    'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '    Dim rowdelete As Integer = DataGridView1.RowCount
    '    DataGridView1.Rows.RemoveAt(rowdelete)
    'End Sub

 
   
    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Try
            Dim con As SqlConnection = New SqlConnection(objCon.constr)
            con.Open()
            s = "Update tblJob set Name = '" & Trim(txtName.Text) & "', job_Date = '" & CDate(Trim(DtpDate.Value)) & "', Job_Name = '" & txtJobName.Text & "' where job_No = " & CInt(lblJobNo.Text)
            cmd = New SqlCommand(s, con)
            cmd.ExecuteNonQuery()
            MsgBox("Record Updated Successfully", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
       
    End Sub
End Class

VB CODE FOR DESKTOP APPLICATION (NAVIGATE FORM WITH VALUE)


NAVIGATING FORM TO FORM. FETCHING OTHER FORM'S VALUE.

Imports System.Data.SqlClient
Imports System.Data
Public Class frmBill
    Dim s As String
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim dr As SqlDataReader
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim objcon As New ConnectionString

    Private Sub frmBilling_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2
        If frmSearchRecord.DialogResult = Windows.Forms.DialogResult.OK Then
            GetJobDetails()
            dgvLoadJobParticular()
        End If
    End Sub

    Public Sub dgvLoadJobParticular()
        con = New SqlConnection(objcon.constr)
        s = "Select Particular, Qty, Amount, Job_No from tblJobParticular where Job_No = " & lblJobNo.Text
        da = New SqlDataAdapter(s, con)
        ds = New DataSet
        da.Fill(ds, "tblJobParticular")
        dgvJobParticular.DataSource = ds
        dgvJobParticular.DataMember = "tblJobParticular"
        dgvJobParticular.Columns(0).Width = 150
        dgvJobParticular.Columns(1).Width = 50
        dgvJobParticular.Columns(2).Width = 70
        dgvJobParticular.Columns(3).Width = 1

    End Sub

    Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click

        con = New SqlConnection(objcon.constr)
        s = "Insert into tblBill (BillNo, Job_No, Job_Name, Bill_Date, payment_Type, Amount, Remarks)values (@BillNo, @Job_No, @Job_Name, @Bill_Date, @payment_Type, @Amount, @Remarks)"
        cmd = New SqlCommand(s, con)
        lblBillNo.Text = MaxBillNo()
        With cmd
            .Parameters.AddWithValue("@BillNo", MaxBillNo())
            .Parameters.AddWithValue("@Job_No", CInt(Trim(lblJobNo.Text)))
            .Parameters.AddWithValue("@Job_Name", Trim(txtJobName.Text))
            .Parameters.AddWithValue("@Bill_Date", CDate(dtpBillDate.Value.Date))
            .Parameters.AddWithValue("@payment_Type", cmbPaymentType.SelectedText)
            .Parameters.AddWithValue("@Amount", CDbl(Trim(txtAmount.Text)))
            .Parameters.AddWithValue("@Remarks", Trim(txtRemarks.Text))
        End With
        cmd.ExecuteNonQuery()
        'LoadJobparticular()
        txtAmount.Text = Total_BillAmount() '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Change its position for Trigger its event
    End Sub
    Public Function Total_BillAmount() As Double
        Dim dblTotalAmt As Double = 0
        con = New SqlConnection(objcon.constr)
        con.Open()

        s = "Select sum(Amount) from tblBillParticular where Bill_No = " & lblBillNo.Text
        cmd = New SqlCommand(s, con)
        dr = cmd.ExecuteReader
        If dr.HasRows Then
            dr.Read()
            dblTotalAmt = dr.GetDouble(0)
            Return dblTotalAmt
        Else
            Return dblTotalAmt = 0.0
        End If
    End Function
    Public Sub LoadBillParticular()

        con = New SqlConnection(objcon.constr)
        con.Open()

        s = "Insert into tblBillParticular(BillParticularNo, BillParticular, BillQty, BillAmount, BillNo) Values (@BillParticularNo, @BillParticular, @BillQty, @BillAmount, @BillNo)"
        cmd = New SqlCommand(s, con)
        With cmd
            .Parameters.AddWithValue("@BillParticularNO", MaxBillParticularID)
            .Parameters.AddWithValue("@BillParticular",

        End With
    End Sub
    Public Function MaxBillParticularID() As Integer
        Dim intMaxbillParticular As Integer
        con = New SqlConnection(objcon.constr)
        s = "Select max(BillParticularNo) from tblBillParticular where BillNo = " & lblBillNo.Text
        cmd = New SqlCommand(s, con)
        dr = cmd.ExecuteReader
        If dr.HasRows Then
            dr.Read()
            intMaxbillParticular = dr.GetInt32(0)
            Return intMaxbillParticular + 1
        Else
            MsgBox("First Record")
            Return intMaxbillParticular = 1
        End If
    End Function
    Public Function MaxBillNo() As Integer
        Dim intMaxBillNo As Integer = 0
        con = New SqlConnection(objcon.constr)
        con.Open()
        s = "Select Max(Bill_No) from tblBill"
        cmd = New SqlCommand(s, con)
        dr = cmd.ExecuteReader
        If dr.HasRows Then
            dr.Read()
            intMaxBillNo = dr.GetInt32(0)
            Return intMaxBillNo + 1
        Else
            Return intMaxBillNo = 1001
        End If
        con.Close()

    End Function

    Public Sub GetJobDetails()
        con = New SqlConnection(objcon.constr)
        con.Open()
        s = "Select * from tbljob where job_No = '" & frmSearchRecord.lblJobNo.Text & "'"
        cmd = New SqlCommand(s, con)

        dr = cmd.ExecuteReader
        If dr.HasRows Then
            dr.Read()
            lblJobNo.Text = dr.GetInt32(0)
            txtName.Text = dr.GetString(1)
            txtJobName.Text = dr.GetString(3)
        Else
            MsgBox("This job is not in the Record")
        End If
        con.Close()
    End Sub


    'subroutine for loading the JObparticular accroding to JobNo fetched to the other textboxes
End Class

VB DESKTOP APPLICATION (DATAGRIDVIEW BINDING)


CONSIST OF DATAGRIDVIEW BINDING AND FORM PLACING IN MASTER FORM
Imports System.Data.SqlClient
Imports System.Data


Public Class frmSearchRecord
    Dim s As String
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim dr As SqlDataReader
    Dim objCon As New ConnectionString


    Private Sub frmSearchRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2
        cmbSearchBy.SelectedItem = "Job Name"
        dgvJobParticular.Enabled = False
        If cmbSearchBy.SelectedText = "Date" Then
            DateTimePicker1.Visible = True
        Else
            DateTimePicker1.Visible = False
        End If
        DataGridView1.Enabled = False
        txtEnterSearch.Text = "GJ"

        'Loading Gridview for first time
        Load_JobGridview()

    End Sub
    Public Sub Load_JobGridview()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select Job_Name, Job_Date, Name,Job_No from tblJob "
        Common_Search(s, con)
        con.Close()
    End Sub
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        If cmbSearchBy.SelectedItem = "Date" Then
            SerachBy_Date()
        ElseIf cmbSearchBy.SelectedItem = "Cust. Name" Then
            SearchBy_CustName()
        ElseIf cmbSearchBy.SelectedItem = "Job Name" Then
            SearchBy_JobName()
        Else
            MsgBox("select any one of 'Search by Item'", MsgBoxStyle.Exclamation)
        End If
    End Sub
    Public Sub SearchBy_JobName()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select Job_Name, Job_Date, Name,Job_No from tblJob where Job_Name like '" & txtEnterSearch.Text & "%'"
        Common_Search(s, con)
        con.Close()
    End Sub

    Public Sub SerachBy_Date()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select Job_Name, Job_Date, Name,Job_No from tblJob where Job_Date = '" & CDate(DateTimePicker1.Value.Date) & "'"
        Common_Search(s, con)
        con.Close()
    End Sub
    Public Sub SearchBy_CustName()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select Job_Name, Job_Date, Name, Job_No from tblJob where Name like '" & txtEnterSearch.Text & "%'"
        Common_Search(s, con)
        con.Close()
    End Sub

    Private Sub cmbSearchBy_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSearchBy.SelectedIndexChanged
        If cmbSearchBy.SelectedItem = "Date" Then
            DateTimePicker1.Visible = True
        Else
            DateTimePicker1.Visible = False
        End If
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim CurrentRow As DataGridViewRow = DataGridView1.CurrentRow
        lblJobNo.Text = CurrentRow.Cells(3).Value
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()

        s = "Select Particular, Qty, Rate, Amount from tblJobParticular where Job_No = " & CInt(lblJobNo.Text)
        DGVJobParticular_Common_Load(s, con)
        con.Close()
    End Sub
    Public Sub DGVJobParticular_Common_Load(ByVal s As String, ByVal con As SqlConnection)
        da = New SqlDataAdapter(s, con)
        ds = New DataSet
        da.Fill(ds, "tblJobParticular")
        dgvJobParticular.DataSource = ds
        dgvJobParticular.DataMember = "tblJobParticular"
        dgvJobParticular.Columns(0).Width = 120
        dgvJobParticular.Columns(1).Width = 140
        dgvJobParticular.Columns(2).Width = 40
        dgvJobParticular.Columns(3).Width = 120
        dgvJobParticular.Enabled = True

    End Sub


    Public Sub Common_Search(ByVal s As String, ByVal con As SqlConnection)

        da = New SqlDataAdapter(s, con)
        ds = New DataSet
        da.Fill(ds, "tblJob")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "tblJob"
        DataGridView1.Columns(0).Width = 160
        DataGridView1.Columns(1).Width = 150
        DataGridView1.Columns(2).Width = 160
        'DataGridView1.Columns(3).Width = 120

        DataGridView1.Enabled = True

    End Sub

 
    Private Sub btnDeleteJOb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteJOb.Click
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        If MsgBox("Do you really want to delete Selected Job? ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Delete Job") = MsgBoxResult.Yes Then
            s = "Delete from tblJobParticular where Job_No = " & CInt(lblJobNo.Text)
            cmd = New SqlCommand(s, con)
            cmd.ExecuteNonQuery()

            DeleteJob()
            Load_JobGridview()
            Load_DGVJobParticular()
            con.Close()
        End If
    End Sub
    Public Sub Load_DGVJobParticular()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Select Particular, Qty, Rate, Amount from tblJobParticular where Job_No = " & 0
        DGVJobParticular_Common_Load(s, con)
        con.Close()
    End Sub
    Public Sub DeleteJob()
        Dim con As SqlConnection = New SqlConnection(objCon.constr)
        con.Open()
        s = "Delete from tbljob where Job_No = " & CInt(lblJobNo.Text)
        cmd = New SqlCommand(s, con)
        cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("Record Deleted successfully", MsgBoxStyle.Information, "Job Deleted")
    End Sub

    Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK
        frmBill.MdiParent = frmMaster
        frmBill.WindowState = FormWindowState.Normal
        frmBill.Show()

    End Sub
End Class

VB CODE FOR DESKTOP APPLICATION (MASTER FORM)


IN MASTER FORM :
Public Class frmMaster

    Private Sub frmMaster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If frmLogin.ShowDialog <> DialogResult.OK Then
            Me.Close()
        Else
            Me.Show()
        End If

       
    End Sub

    Private Sub JobCardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JobCardToolStripMenuItem.Click
        frmJobCard.MdiParent = Me
        frmJobCard.WindowState = FormWindowState.Normal
        frmJobCard.StartPosition = FormStartPosition.CenterParent
        frmJobCard.Show()

    End Sub

    Private Sub SerchRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SerchRecordToolStripMenuItem.Click
        frmSearchRecord.MdiParent = Me
        frmSearchRecord.WindowState = FormWindowState.Normal
        frmSearchRecord.StartPosition = FormStartPosition.CenterParent
        frmSearchRecord.Show()
    End Sub

    Private Sub BillingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BillingToolStripMenuItem.Click
        frmBill.MdiParent = Me
        frmBill.StartPosition = FormStartPosition.CenterParent
        frmBill.WindowState = FormWindowState.Normal
        frmBill.Show()
    End Sub
End Class

VB CODE FOR DESKTOP APPLICATION

IN LOGIN FORM


Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Public Class frmLogin

    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim s As String
    Dim dr As SqlDataReader
    Dim objcon As New ConnectionString


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Application.Exit()
        Me.DialogResult = DialogResult.Cancel
    End Sub

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Static count As Integer
        If count >= 2 Then
            MsgBox("Unauthorized Login!")
            Me.DialogResult = DialogResult.Cancel
        Else
            con = New SqlConnection(objCon.constr)
            If con.State = ConnectionState.Closed Then
                con.Open()
            End If

            Dim strpassword As String = Nothing

            s = "Select * from tblLogin where LoginID = '" & txtLoginID.Text & "'"
            cmd = New SqlCommand(s, con)
            dr = cmd.ExecuteReader()
            If dr.HasRows() Then
                dr.Read()
                'txtLoginID.Text = dr.GetString(0)
                strpassword = dr.GetString(1)


            Else
                MsgBox("Invalid Login ID/ Password")
                count = count + 1
                Exit Sub
                ' Me.DialogResult = DialogResult.Cancel

            End If
            If txtPassword.Text <> strpassword Then
                MsgBox("Invalid Login ID / Password")
                count = count + 1
                'Me.DialogResult = DialogResult.Cancel
                'Got login
            Else
                Me.DialogResult = DialogResult.OK
                Me.Close()

            End If

            con.Close()
        End If
       


    End Sub

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtLoginID.Text = "admin"
        txtPassword.Text = "1234"
    End Sub
End Class