Thursday, 21 July 2011

.NET Technology


Public Class All_In_One

    Dim con As New MyConnecion()

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

        Dim ds As DataSet
        ds = con.SelectData("select max(rollno)+1 from marksheet")

        txtNo.Text = ds.Tables(0).Rows(0)(0).ToString()
        txtNo.ReadOnly = True

        txtName.Focus()

        btnAdd.Enabled = False
        btnSave.Enabled = True

    End Sub

    Private Sub ClearAll()

        txtNo.Clear()
        txtName.Clear()

        txtMaths.Clear()
        txtScience.Clear()
        txtEnglish.Clear()

        txtNo.ReadOnly = False

        btnAdd.Enabled = True
        btnSave.Enabled = False

        GroupBox2.Visible = True
        grpDelete.Visible = False
        grpUpdate.Visible = False

        txtNo.Focus()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        ClearAll()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        con.Ins_Upd_Del("insert into marksheet(rollno,studentname,maths,science,english) values(" & txtNo.Text & ",'" & txtName.Text & "'," & txtMaths.Text & "," & txtScience.Text & "," & txtEnglish.Text & ")")

        MessageBox.Show("Record successfully inserted...")

        ClearAll()

    End Sub

    Private Sub btnCancelDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelDelete.Click
        ClearAll()
    End Sub

    Private Sub btnConfirmDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirmDelete.Click
        con.Ins_Upd_Del("delete from marksheet where rollno=" & txtNo.Text & "")

        MessageBox.Show("Record successfully deleted....")

        ClearAll()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        Dim str As String
        str = "select * from marksheet where rollno=" & txtNo.Text & ""

        If con.CheckData(str) = True Then
            Dim ds As DataSet
            ds = con.SelectData(str)

            txtName.Text = ds.Tables(0).Rows(0)(2).ToString()
            txtMaths.Text = ds.Tables(0).Rows(0)(3).ToString()
            txtScience.Text = ds.Tables(0).Rows(0)(4).ToString()
            txtEnglish.Text = ds.Tables(0).Rows(0)(5).ToString()

            GroupBox2.Visible = False
            grpDelete.Visible = True

        Else
            MessageBox.Show("Record not found")
        End If

    End Sub

    Private Sub btnCancelUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelUpdate.Click
        ClearAll()
    End Sub

    Private Sub btnConfirmUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirmUpdate.Click
        con.Ins_Upd_Del("update marksheet set studentname='" & txtName.Text & "',maths=" & txtMaths.Text & ",science=" & txtScience.Text & ",english=" & txtEnglish.Text & " where rollno=" & txtNo.Text & "")

        MessageBox.Show("Record successfully updated....")

        ClearAll()
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim str As String

        str = "select * from marksheet where rollno=" & txtNo.Text & ""


        If con.CheckData(str) = True Then
            Dim ds As DataSet

            ds = con.SelectData(str)

            txtNo.ReadOnly = True

            txtName.Text = ds.Tables(0).Rows(0)(2).ToString()
            txtMaths.Text = ds.Tables(0).Rows(0)(3).ToString()
            txtScience.Text = ds.Tables(0).Rows(0)(4).ToString()
            txtEnglish.Text = ds.Tables(0).Rows(0)(5).ToString()

            GroupBox2.Visible = False
            grpUpdate.Visible = True

        Else
            MessageBox.Show("Record not found")
        End If

    End Sub
End Class