sisi 0 Light Poster

Hi i am making a application frm for user account .I already make it the user account frm with coding but i need to put login frm first what will search the login enter and password then let its appres the user frm.If the userid and pass enter does not match the person cant enter .I am copyin my coding for the user frm .I need help for the login frm plzzz urgent !!!

Option Explicit On
Option Strict On
Imports System.IO

Public Class frmUser

Private m_User As New User()
Private m_filepath As String = Application.StartupPath & _
"\User.txt"

Private Sub Btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnsave.Click
If (txtUserID.Text.Length <> 4) Then
MessageBox.Show("Userid must be a 4-digit number", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
txtUserID.Focus()
Exit Sub
End If
If (txtPassword.Text.Length > 15) Then
MessageBox.Show("You password must be 15-characters", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
txtPassword.Focus()
Exit Sub
End If

Dim answer As Integer = 0
Dim line As String
Dim fields() As String
Dim objsr As StreamReader

If File.Exists(m_filepath) Then

objsr = New StreamReader(m_filepath)
line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
If (fields(0) = txtUserID.Text) Then
MessageBox.Show("UserID already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
txtUserID.Focus()
objsr.Close()
Exit Sub
Else
line = objsr.ReadLine()

End If
Loop
objsr.Close()
End If


With m_User
.Userid = CInt(txtUserID.Text)
.Password = txtPassword.Text
.Jobtittle = Cbbjobtittle.Text
End With

answer = MessageBox.Show("Do you really want to save the record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

If answer = vbYes Then
Dim objSw As New StreamWriter(m_filepath, True)
objSw.WriteLine(m_User.Userid & "," & m_User.Password & "," & m_User.Jobtittle)
objSw.Close()
MessageBox.Show("The user account has been created successfully", "Record saved", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Else
End If

End Sub


Private Sub Btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnsearch.Click
Dim line As String
Dim fields() As String
Dim objsr As StreamReader

objsr = New StreamReader(m_filepath)
line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
If (fields(0) = txtUserID.Text) Then
txtPassword.Text = fields(1)
Cbbjobtittle.Text = fields(2)
objsr.Close()
Exit Sub
Else
line = objsr.ReadLine()

End If
Loop
objsr.Close()
MessageBox.Show("User account not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Sub

Private Sub Btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnclear.Click
txtUserID.Text = ""
txtPassword.Text = ""
Cbbjobtittle.SelectedIndex = -1
lvwUsers.Items.Clear()


End Sub

Private Sub Btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnexit.Click
Dim answer As Integer
answer = MessageBox.Show("Do you want to exit?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If answer = vbYes Then
Application.Exit()
Else

End If

End Sub

Private Sub Btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndelete.Click

Dim line As String
Dim fields() As String
Dim objsr As StreamReader
objsr = New StreamReader(m_filepath)

Dim objSw As New StreamWriter(Application.StartupPath & _
"\Temp.txt", True)

line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
If (fields(0) = txtUserID.Text) Then
MessageBox.Show("Do you want really want to delete your file", "delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)


Else
objSw.WriteLine(fields(0) & "," & fields(1) & "," & fields(2))


End If
line = objsr.ReadLine()
Loop
objsr.Close()
MessageBox.Show("User has been deleted successfully", "delete", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)

My.Computer.FileSystem.DeleteFile(m_filepath)
objSw.Close()
My.Computer.FileSystem.RenameFile(Application.StartupPath & _
"\Temp.txt", "User.txt")


End Sub


Private Sub Btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnupdate.Click
Dim line As String
Dim answer As Integer
Dim fields() As String
Dim objsr As StreamReader
objsr = New StreamReader(m_filepath)

With m_User
.Userid = CInt(txtUserID.Text)
.Password = txtPassword.Text
.Jobtittle = Cbbjobtittle.Text
End With

Dim objSw As New StreamWriter(Application.StartupPath & _
"\Temp.txt", True)

line = objsr.ReadLine()
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
If (fields(0) = txtUserID.Text) Then
MessageBox.Show("Do you want really want to update the user?", "update", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

If CInt(answer) = vbNo Then
Exit Sub
End If
objSw.WriteLine(m_User.Userid & "," & m_User.Password & "," & m_User.Jobtittle)

Else
objSw.WriteLine(fields(0) & "," & fields(1) & "," & fields(2))


End If
line = objsr.ReadLine()
Loop
MessageBox.Show("The user account has been updated successfully", "Record updated", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
objsr.Close()
My.Computer.FileSystem.DeleteFile(m_filepath)
objSw.Close()
My.Computer.FileSystem.RenameFile(Application.StartupPath & _
"\Temp.txt", "User.txt")

End Sub

Private Sub btnListUsers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListUsers.Click
Dim line As String
Dim fields() As String
Dim objsr As StreamReader

lvwUsers.Items.Clear()

objsr = New StreamReader(m_filepath)
line = objsr.ReadLine()
If line Is Nothing Then
MessageBox.Show("No user account has been created", "No user", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Exit Sub
End If
Do Until (line Is Nothing)
fields = line.Split(Convert.ToChar(","))
Dim lvwitem As New ListViewItem
With lvwitem
.SubItems(0).Text = fields(0)
.SubItems.Add(fields(1))
.SubItems.Add(fields(2))
End With
lvwUsers.Items.Add(lvwitem)
line = objsr.ReadLine
Loop
objsr.Close()
End Sub

Private Sub Btnsave_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Btnsave.KeyPress
If (Char.IsControl(e.KeyChar) = False) Then
If (Char.IsLetter(e.KeyChar) Or (Char.IsWhiteSpace(e.KeyChar))) Then
Else
e.Handled = True

End If

End If
End Sub

Private Sub txtUserID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUserID.KeyPress
If (Char.IsControl(e.KeyChar) = False) Then
If (Char.IsDigit(e.KeyChar)) Then
Else
e.Handled = True
End If

End If
End Sub
End Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.