Description:
Data to be stored into database through controls
Imports System.Data.OleDb
Public Class transmas
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Dim OldTransCode As String = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call database_connection()
textenable()
cmbTransName.Visible = False
cmdcancel.Enabled = Not cmdcancel.Enabled
cmdsave.Enabled = False
cmdupdate.Enabled = Not cmdupdate.Enabled
cmddelok.Enabled = Not cmddelok.Enabled
cmdadd.Focus()
End Sub
Private Sub cmbload()
Try
cmbTransName.Items.Clear()
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
con.Open()
cmd = New OleDbCommand("select transname from transmaster", con)
dr = cmd.ExecuteReader
While dr.Read
cmbTransName.Items.Add(dr("transname"))
End While
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Private Sub cmdenable()
cmdadd.Enabled = Not cmdadd.Enabled
cmdedit.Enabled = Not cmdedit.Enabled
cmddelete.Enabled = Not cmddelete.Enabled
cmdend.Enabled = Not cmdend.Enabled
cmdview.Enabled = Not cmdview.Enabled
End Sub
Private Sub textenable()
txttranscode.Enabled = Not txttranscode.Enabled
txttransname.Enabled = Not txttransname.Enabled
txttransownname.Enabled = Not txttransownname.Enabled
txtaddress1.Enabled = Not txtaddress1.Enabled
txtaddress2.Enabled = Not txtaddress2.Enabled
txtaddress3.Enabled = Not txtaddress3.Enabled
txtcontactno.Enabled = Not txtcontactno.Enabled
txtfax.Enabled = Not txtfax.Enabled
txtemail.Enabled = Not txtemail.Enabled
cmbTransName.Enabled = Not cmbTransName.Enabled
End Sub
Private Sub textclear()
txttranscode.Text = ""
txttransname.Text = ""
txttransownname.Text = ""
txtaddress1.Text = ""
txtaddress2.Text = ""
txtaddress3.Text = ""
txtcontactno.Text = ""
txtfax.Text = ""
txtemail.Text = ""
cmbTransName.Text = ""
End Sub
Private Sub cmdadd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdadd.Click
textenable()
cmdenable()
textclear()
If cmbTransName.Visible Then
cmbTransName.Visible = Not cmbTransName.Visible
End If
cmdsave.Enabled = True
cmdsave.Visible = True
cmdcancel.Enabled = Not cmdcancel.Enabled
If cmdupdate.Visible Then
cmdupdate.Visible = Not cmdupdate.Visible
ElseIf cmddelok.Visible Then
cmddelok.Visible = Not cmddelok.Visible
End If
txttranscode.Focus()
End Sub
Private Sub cmdcancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdcancel.Click
textclear()
textenable()
cmdenable()
cmdcancel.Visible = True
cmdcancel.Enabled = Not cmdcancel.Enabled
cmdsave.Visible = False
cmdsave.Enabled = Not cmdsave.Enabled
If cmbTransName.Enabled Then
cmbTransName.Items.Clear()
cmbTransName.Enabled = Not cmbTransName.Enabled
cmbTransName.Visible = Not cmbTransName.Visible
cmbTransName.Text = ""
End If
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
cmbTransName.Items.Clear()
cmdadd.Focus()
End Sub
Private Sub cmdend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdend.Click
Me.Close()
End Sub
Private Sub cmdedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdedit.Click
cmbload()
textenable()
cmdenable()
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
If Not cmbTransName.Enabled Then
cmbTransName.Enabled = Not cmbTransName.Enabled
End If
cmbTransName.Visible = True
If Not cmdupdate.Enabled Then
cmdupdate.Enabled = Not cmdupdate.Enabled
End If
If Not cmdupdate.Visible Then
cmdupdate.Visible = Not cmdupdate.Visible
End If
cmdcancel.Enabled = Not cmdcancel.Enabled
If cmddelok.Visible Then
cmddelok.Visible = Not cmddelok.Visible
ElseIf cmdsave.Visible Then
cmdsave.Visible = Not cmdsave.Visible
End If
txttranscode.Focus()
End Sub
Private Sub cmddelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmddelete.Click
textenable()
cmdenable()
cmbload()
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
cmbTransName.Visible = True
If Not cmbTransName.Enabled Then
cmbTransName.Enabled = Not cmbTransName.Enabled
End If
cmdcancel.Enabled = Not cmdcancel.Enabled
If Not cmddelok.Enabled Then
cmddelok.Enabled = Not cmddelok.Enabled
End If
If Not cmddelete.Visible Then
cmddelok.Visible = Not cmddelok.Visible
End If
If cmdupdate.Visible Then
cmdupdate.Visible = Not cmdupdate.Visible
ElseIf cmdsave.Visible Then
cmdsave.Visible = Not cmdsave.Visible
End If
txttranscode.Focus()
End Sub
Private Sub cmdview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdview.Click
cmbload()
textenable()
cmdenable()
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
If Not cmbTransName.Enabled Then
cmbTransName.Enabled = Not cmbTransName.Enabled
End If
cmbTransName.Visible = True
cmdcancel.Enabled = Not cmdcancel.Enabled
If cmdupdate.Visible Then
cmdupdate.Visible = Not cmdupdate.Visible
ElseIf cmddelok.Visible Then
cmddelok.Visible = Not cmddelok.Visible
ElseIf cmdsave.Visible Then
cmdsave.Visible = Not cmdsave.Visible
End If
cmbTransName.Focus()
End Sub
Private Sub cmddelok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmddelok.Click
Try
Dim cmd As New OleDbCommand
con.Open()
cmd = New OleDbCommand("delete from transmaster where transname = '" & cmbTransName.Text & "'", con)
Deleted = cmd.ExecuteNonQuery()
con.Close()
If Deleted = 1 Then
MsgBox("Record(s) Deleted Successfully", , "Confirmation")
End If
textclear()
textenable()
cmdenable()
cmdcancel.Visible = True
cmdcancel.Enabled = Not cmdcancel.Enabled
cmddelok.Visible = True
cmddelok.Enabled = Not cmddelok.Enabled
If cmbTransName.Enabled Then
cmbTransName.Items.Clear()
cmbTransName.Enabled = Not cmbTransName.Enabled
cmbTransName.Visible = Not cmbTransName.Visible
cmbTransName.Text = ""
End If
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
cmbTransName.Items.Clear()
cmdadd.Focus()
Catch ex As Exception
MsgBox(ex.Message)
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Private Sub cmbTransName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbTransName.SelectedValueChanged
Try
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
con.Open()
cmd = New OleDbCommand("select transcode,transownname,add1,add2,add3,contactno,fax,email from transmaster where transname='" & cmbTransName.Text & "'", con)
dr = cmd.ExecuteReader
While dr.Read
txttranscode.Text = dr("transcode")
txttransownname.Text = dr("transownname")
txtaddress1.Text = dr("add1")
txtaddress2.Text = dr("add2")
txtaddress3.Text = dr("add3")
txtcontactno.Text = dr("contactno")
txtfax.Text = dr("fax")
txtemail.Text = dr("email")
End While
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
If con.State = ConnectionState.Open Then
con.Close()
End If
Finally
OldTransCode = Replace(txttranscode.Text, "'", "''")
End Try
End Sub
Private Sub cmdsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Try
Dim cmd As New OleDbCommand
con.Open()
cmd = New OleDbCommand("Insert into transmaster (transcode,transname,transownname,add1,add2,add3,contactno,fax,email) values('" & Trim(txttranscode.Text) & "','" & Trim(txttransownname.Text) & "','" & Trim(txtaddress1.Text) & "','" & Trim(txtaddress2.Text) & "','" & Trim(txtaddress3.Text) & "','" & Trim(txtcontactno.Text) & "','" & Trim(txtfax.Text) & "','" & Trim(txtemail.Text) & "') ", con)
Added = cmd.ExecuteNonQuery()
con.Close()
If Added = 1 Then
MsgBox("Record(s) Saved Successfully", , "Confirmation")
End If
textclear()
textenable()
cmdenable()
cmdcancel.Visible = True
cmdcancel.Enabled = Not cmdcancel.Enabled
cmdsave.Visible = True
cmdsave.Enabled = Not cmdsave.Enabled
If cmbTransName.Enabled Then
cmbTransName.Items.Clear()
cmbTransName.Enabled = Not cmbTransName.Enabled
cmbTransName.Visible = Not cmbTransName.Visible
cmbTransName.Text = ""
End If
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
cmbTransName.Items.Clear()
cmdadd.Focus()
Catch ex As Exception
MsgBox(ex.Message)
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Private Sub cmdupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
Try
Dim cmd As New OleDbCommand
con.Open()
cmd = New OleDbCommand("update transmaster set transcode='" & Trim(txttranscode.Text) & "',transname='" & Trim(cmbTransName.Text) & "',transownname='" & Trim(txttransownname.Text) & "',add1='" & Trim(txtaddress1.Text) & "',add2='" & Trim(txtaddress2.Text) & "',add3='" & Trim(txtaddress3.Text) & "',contactno='" & Trim(txtcontactno.Text) & "',fax='" & Trim(txtfax.Text) & "',email='" & Trim(txtemail.Text) & "' where transcode = '" & OldTransCode & "'", con)
Updated = cmd.ExecuteNonQuery()
con.Close()
If Updated = 1 Then
MsgBox("Record(s) Updated Successfully", , "Confirmation")
End If
textclear()
textenable()
cmdenable()
cmdcancel.Visible = True
cmdcancel.Enabled = Not cmdcancel.Enabled
cmdupdate.Visible = True
cmdupdate.Enabled = Not cmdupdate.Enabled
If cmbTransName.Enabled Then
cmbTransName.Items.Clear()
cmbTransName.Enabled = Not cmbTransName.Enabled
cmbTransName.Visible = Not cmbTransName.Visible
End If
If txttransname.Enabled Then
txttransname.Enabled = Not txttransname.Enabled
End If
cmbTransName.Items.Clear()
cmdadd.Focus()
Catch ex As Exception
MsgBox(ex.Message)
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Private Sub txttranscode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttranscode.KeyPress
If Asc(e.KeyChar) = "13" Then
txttransname.Focus()
End If
End Sub
Private Sub txttransname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttransname.KeyPress
If Asc(e.KeyChar) = "13" Then
txttransownname.Focus()
End If
End Sub
Private Sub txtaddress2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtaddress2.KeyPress
If Asc(e.KeyChar) = "13" Then
txtaddress3.Focus()
End If
End Sub
Private Sub txtaddress3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtaddress3.KeyPress
If Asc(e.KeyChar) = "13" Then
txtcontactno.Focus()
End If
End Sub
Private Sub txtcontactno_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcontactno.KeyPress
If Asc(e.KeyChar) = "13" Then
txtfax.Focus()
End If
End Sub
Private Sub txtfax_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtfax.KeyPress
If Asc(e.KeyChar) = "13" Then
txtemail.Focus()
End If
End Sub
Private Sub txtaddress1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtaddress1.KeyPress
If Asc(e.KeyChar) = "13" Then
txtaddress2.Focus()
End If
End Sub
Private Sub txttransownname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttransownname.KeyPress
If Asc(e.KeyChar) = "13" Then
txtaddress1.Focus()
End If
End Sub
Private Sub cmdadd_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdadd.GotFocus
cmdsave.Visible = True
cmdsave.Enabled = False
cmddelok.Visible = False
cmddelok.Enabled = False
cmdupdate.Visible = False
cmdupdate.Enabled = False
End Sub
Private Sub cmddelete_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmddelete.GotFocus
cmdsave.Visible = False
cmdsave.Enabled = False
cmddelok.Enabled = False
cmdupdate.Visible = False
cmdupdate.Enabled = False
cmddelok.Visible = True
End Sub
Private Sub cmdedit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdedit.GotFocus
cmdsave.Visible = False
cmdsave.Enabled = False
cmddelok.Visible = False
cmddelok.Enabled = False
cmdupdate.Visible = True
cmdupdate.Enabled = False
End Sub
Private Sub cmdview_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdview.GotFocus
cmdsave.Visible = False
cmdsave.Enabled = False
cmddelok.Enabled = False
cmdupdate.Visible = False
cmdupdate.Enabled = False
cmddelok.Visible = True
End Sub
Private Sub txtemail_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtemail.KeyPress
If Asc(e.KeyChar) = "13" Then
cmdsave.Focus()
End If
End Sub
End Class

|