Imports System.Data
Imports System.Data.OleDb

Imports System.IO
Public Class RegisterationForm
    
    Dim TYP, TYPV, A1, A2
    Dim dt
    Private Sub RegisterationForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        fill()
        PictureBox6.Visible = False
        PictureBox7.Visible = False
        Label10.Visible = False
        PictureBox8.Visible = False

        PictureBox1.Visible = True
        PictureBox7.Visible = False
        PictureBox9.Visible = False
    End Sub
    Sub dtp2(ByVal s As String) 'function is used to display a table
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()
        dat = New OleDb.OleDbDataAdapter(s, con)

    End Sub
    Sub fill()
        Dim dst As New DataSet  'to display table
        dtp2("select Id,Name from VehicleDetails order by Id,Name")
        dst.Clear()
        dat.Fill(dst, "VehicleDetails")
        DataGridView1.DataSource = dst
        DataGridView1.DataMember = dst.Tables(0).ToString
    End Sub

    

    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        If RadioButton4.Checked = True Then
            TYP = "STUDENT"
        End If
        If RadioButton3.Checked = True Then
            TYP = "FACULTY"
        End If
        If CheckBox1.Checked = True Then
            TYPV = "TWO WHEELER"
        End If
        If CheckBox2.Checked = True Then
            TYPV = "FOUR WHEELER"
        End If
        qry1(" insert into VehicleDetails values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TYP & "','" & TYPV & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "')")

        fill()

        PictureBox6.Visible = True
        PictureBox7.Visible = True
        PictureBox1.Visible = False
        PictureBox8.Visible = False
        PictureBox9.Visible = False
        Label10.Text = "saving"

        Label10.Visible = True
        ProgressBar1.Value = 100
        ProgressBar1.Maximum = 1000

        Timer1.Enabled = True

    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

        If RadioButton4.Checked = True Then
            TYP = "STUDENT"
        End If
        If RadioButton3.Checked = True Then
            TYP = "FACULTY"
        End If
        If CheckBox1.Checked = True Then
            TYPV = "TWO WHEELER"
        End If
        If CheckBox2.Checked = True Then
            TYPV = "FOUR WHEELER"
        End If
        qry1("update VehicleDetails set id='" & TextBox1.Text & "',Name='" & TextBox2.Text & "',Address='" & TextBox3.Text & "',TYP='" & TYP & "',TYPV='" & TYPV & "',phoneno='" & TextBox6.Text & "',mobileno='" & TextBox7.Text & "',imgt='" & TextBox8.Text & "' where id='" & dt & "'")
        PictureBox6.Visible = True
        PictureBox8.Visible = True

        PictureBox1.Visible = False
        PictureBox7.Visible = False
        PictureBox9.Visible = False
        Label10.Text = "modifying"
        Label10.Visible = True
        fill()

        ProgressBar1.Value = 100
        ProgressBar1.Maximum = 1000

        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Value = ProgressBar1.Value + 30
        If ProgressBar1.Value = 1000 Then

            Timer1.Enabled = False
            PictureBox6.Visible = False
            Label10.Visible = False
            PictureBox1.Visible = True

           
            PictureBox9.Visible = False
            PictureBox7.Visible = False
            PictureBox8.Visible = False


            MsgBox("Transaction Completed")

            clr()
        End If
    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        clr()

    End Sub

    Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick

        dt = DataGridView1.SelectedCells(0).Value.ToString

        qry("select * from VehicleDetails where id='" & dt & "'")
        If dr.Read = True Then

            TextBox1.Text = dr.Item(0).ToString
            TextBox2.Text = dr.Item(1).ToString
            TextBox3.Text = dr.Item(2).ToString
            A1 = dr.Item(3).ToString
            A2 = dr.Item(4).ToString
            TextBox6.Text = dr.Item(5).ToString
            TextBox7.Text = dr.Item(6).ToString
            TextBox8.Text = dr.Item(7).ToString
            PictureBox10.ImageLocation = impt + dr.Item(7).ToString
        End If
        dr.Close()
        If A1 = "STUDENT" Then
            RadioButton4.Checked = True
        Else
            RadioButton3.Checked = True
        End If

        If A2 = "TWO WHEELER" Then
            CheckBox1.Checked = True
        Else
            CheckBox2.Checked = True
        End If


    End Sub
    Sub clr()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        ' TextBox4.Text = ""
        'TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        ' DateTimePicker1.Value = Now
        ' DateTimePicker2.Value = Now

    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click


        qry1("delete from VehicleDetails  where id='" & dt & "'")
        fill()
        PictureBox6.Visible = True
        PictureBox9.Visible = True

        PictureBox1.Visible = False
        PictureBox7.Visible = False
        PictureBox8.Visible = False
        Label10.Text = "Sending to Recycle Bin"
        Label10.Visible = True
        ProgressBar1.Value = 100
        ProgressBar1.Maximum = 1000

        Timer1.Enabled = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try


            ' Dim fi As FileInfo

            Dim posSep, sfile

            OpenFileDialog1.ShowDialog()
            If OpenFileDialog1.FileName <> "" Then
                'fi = New FileInfo(OpenFileDialog1.FileName)
                'fi.CopyTo("G:\prfid.net\rfid\2\WindowsApplication1\WindowsApplication1\photos", True)
                posSep = OpenFileDialog1.FileName.LastIndexOf("\")
                sfile = OpenFileDialog1.FileName.Substring((posSep + 1), OpenFileDialog1.FileName.Length - (posSep + 1))
                TextBox8.Text = sfile

                System.IO.File.Copy(OpenFileDialog1.FileName, impt + sfile, False)

                PictureBox10.ImageLocation = impt + sfile
            End If

        Catch
            MsgBox("change the filename alerady exist")

        End Try
    End Sub

   
    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        If RadioButton4.Checked = True Then
            typ = "STUDENT"
        End If
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        If RadioButton3.Checked = True Then
            TYP = "FACULTY"
        End If
    End Sub

    


   

   
    Private Sub CheckBox1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TYPV = "TWO WHEELER"
        End If
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            TYPV = "FOUR WHEELER"
        End If
    End Sub
End Class