Form1>>>Register form
Imports System.IO
Imports System.Data.SqlClient
Public Class Form1
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
password.UseSystemPasswordChar = False
Else
password.UseSystemPasswordChar = True
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
OpenFileDialog1.ShowDialog()
image_path.Text = Path.GetDirectoryName(OpenFileDialog1.FileName) & "\" & Path.GetFileName(OpenFileDialog1.FileName)
PictureBox1.Image = Image.FromFile(image_path.Text)
End Sub
Private Sub lastname_KeyDown(sender As Object, e As KeyEventArgs) Handles lastname.KeyDown
If e.KeyCode = Keys.Enter Then
username.Text = firstname.Text + lastname.Text
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If username.Text = "" Then
MessageBox.Show("Please enter username")
Return
End If
If m1.Checked = False And f1.Checked = False Then
MessageBox.Show("Please select gender")
Return
End If
Dim conn As New SqlConnection("Data source=.;initial catalog=register2;integrated security=true")
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cmd As New SqlCommand("Select username from table1 where username=@username", conn)
cmd.Parameters.AddWithValue("username", username.Text)
Dim myreader As SqlDataReader = cmd.ExecuteReader
If (myreader.Read()) Then
MessageBox.Show("Username inserted before")
conn.Close()
Return
Else
conn.Close()
Dim cmd2 As New SqlCommand("Insert into table1(firstname,lastname,username,password,phone,date_birth,gender,image1)Values(@firstname,@lastname,@username,@password,@phone,@date_birth,@gender,@image1)", conn)
cmd2.Parameters.AddWithValue("firstname", firstname.Text)
cmd2.Parameters.AddWithValue("lastname", lastname.Text)
cmd2.Parameters.AddWithValue("username", username.Text)
cmd2.Parameters.AddWithValue("password", password.Text)
cmd2.Parameters.AddWithValue("phone", phone.Text)
cmd2.Parameters.AddWithValue("date_birth", date_birth.Text)
Dim gender_v As Boolean
If m1.Checked = True Then
gender_v = 1
End If
If f1.Checked = True Then
gender_v = 0
End If
cmd2.Parameters.AddWithValue("gender", gender_v)
cmd2.Parameters.AddWithValue("image1", image_path.Text)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
cmd2.ExecuteNonQuery()
conn.Close()
username_v = username.Text
Form2.Show()
End If
End Sub
end class
Form2>>>user form
Imports System.Data.SqlClient
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
username.Text = username_v
Dim conn As New SqlConnection("Data source=.;initial catalog=register2;integrated security=true")
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cmd As New SqlCommand("Select * from table1 where username=@username", conn)
cmd.Parameters.AddWithValue("username", username.Text)
Dim myreader As SqlDataReader = cmd.ExecuteReader
If (myreader.Read()) Then
firstname.Text = myreader("firstname")
lastname.Text = myreader("lastname")
phone.Text = myreader("phone")
password.Text = myreader("password")
Dim gender_v As Boolean = myreader("gender")
If gender_v = True Then
m1.Checked = True
Else
f1.Checked = True
End If
image_path.Text = myreader("image1")
PictureBox1.Image = Image.FromFile(image_path.Text)
date_birth.Text = myreader("date_birth")
conn.Close()
End If
End Sub
End Class
No comments:
Post a Comment