Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions
Public Class form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'("data source=TBPC25\SQLEXPRESS;Initial Catalog=RealEstate1;Integrated Security=True")
Dim sqlconn As New SqlConnection("data source=TBPC25\SQLEXPRESS;Initial Catalog=banking;Inetegrated Security=True")
Dim sqlcomm As New SqlCommand("insert into details values(acno=' " & TextBox1.Text & " ', name =' " & TextBox2.Text & " ', address = ' " & TextBox3.Text & " ',phone = " & TextBox4.Text & ",typeofac = ' " & ComboBox1.Text & " ',date = ' " & TextBox6.Text & " ', amount = " & TextBox7.Text & " ")
'Dim da As New SqlDataAdapter
sqlcomm.ExecuteNonQuery()
End Sub
Private Sub form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
End Sub
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Enabled = False
Dim num As Integer
Dim i As String = "AC01"
num = 1
While (num < 100)
If num < 10 Then
TextBox1.Text = i & num.ToString
MsgBox(num)
Else
'TextBox1.Text = Microsoft.VisualBasic.Left(i, 2) & num.ToString
'MsgBox(num)
End If
num += 1
End While
TextBox6.Enabled = False
TextBox6.Text = Today()
ComboBox1.Items.Add("Current A/C")
ComboBox1.Items.Add("Saving A/C")
ComboBox1.Items.Add("Fixed Deposit A/C")
End Sub
Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.LostFocus
If TextBox2.Text = "" Then
MsgBox("fill the name")
TextBox2.Focus()
End If
End Sub
Private Sub TextBox6_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox6.GotFocus
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub TextBox3_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.LostFocus
If TextBox3.Text = "" Then
MsgBox("enter address")
TextBox3.Focus()
End If
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
'e.Handled = TrapKey(Asc(e.KeyChar))
If Not ValidatePhone(TextBox4.Text) Then
MsgBox("Phone Numbers must be in a ###-###-#### format")
TextBox4.Text = ""
TextBox4.Focus()
Else
MsgBox("enter correct pattern")
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Function TrapKey(ByVal KCode As String) As Boolean
' If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then
'TrapKey = False
'Else
'TrapKey = True
'End If
'If Len(TextBox4.ToString) < 7 Or Len(TextBox4.ToString > 7) Then
'MsgBox("length should be 7 ")
'End If
End Function
Public Function ValidatePhone(ByVal num As String) As Boolean
'create our regular expression pattern
Dim pattern As String = "^\d{3}-\d{3}-\d{4}$"
'create our regular expression object
Dim check As New Regex(pattern)
Dim valid As Boolean = False
'Make sure a phone number was provided
If Not String.IsNullOrEmpty(num) Then
valid = check.IsMatch(num)
Else
valid = False
End If
Return valid
End Function
End Class
|