📄 form5.vb
字号:
Public Class Form5
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button3 As System.Windows.Forms.Button
Dim s_name As String
Dim s_date, s_time, s_barcode, s_kh As String
Dim file_num As Integer
Dim i, j As Long
Dim txtlineCount As Long
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Button3 = New System.Windows.Forms.Button
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.Label2 = New System.Windows.Forms.Label
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 152)
Me.Button1.Text = "确定"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(80, 72)
Me.TextBox2.Text = ""
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(80, 24)
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular)
Me.Label1.ForeColor = System.Drawing.Color.MediumBlue
Me.Label1.Location = New System.Drawing.Point(24, 32)
Me.Label1.Size = New System.Drawing.Size(48, 18)
Me.Label1.Text = "工号:"
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular)
Me.Label3.ForeColor = System.Drawing.Color.MediumBlue
Me.Label3.Location = New System.Drawing.Point(24, 72)
Me.Label3.Size = New System.Drawing.Size(48, 16)
Me.Label3.Text = "口令:"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(136, 152)
Me.Button3.Text = "退出"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(48, 232)
Me.ListBox1.Size = New System.Drawing.Size(216, 62)
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold)
Me.Label2.ForeColor = System.Drawing.Color.Red
Me.Label2.Location = New System.Drawing.Point(8, 104)
Me.Label2.Size = New System.Drawing.Size(184, 20)
'
'Form5
'
Me.ClientSize = New System.Drawing.Size(202, 127)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Button3)
Me.MaximizeBox = False
Me.Text = "员工登录"
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'打开文件
TextBox1.Focus()
i = -1
P_path = "\data\"
P_filename = P_path + "work.dat"
Dim lstr, pass As String
'存在时,不存在时新建
''''''''''''''''''''''''''''''''////////////////
Dim fsMyfile As IO.FileStream
Dim swMyfile As IO.StreamReader
'存在时,不存在时新建
Try
fsMyfile = New IO.FileStream(P_filename, IO.FileMode.Open, IO.FileAccess.Read)
swMyfile = New IO.StreamReader(fsMyfile)
Catch ex As Exception
MsgBox("文件不存在!", MsgBoxStyle.DefaultButton1, "对不起")
Exit Sub
End Try
Do
lstr = swMyfile.ReadLine
If Len(Trim(lstr)) < 1 Then
MsgBox("你所输入的用户不存在!", MsgBoxStyle.DefaultButton1, "对不起")
swMyfile.Close()
fsMyfile.Close()
Exit Sub
Else
ListBox1.Items.Add(lstr)
i = i + 1
If InStr(1, lstr, Trim(TextBox1.Text) + Chr(9)) Then
Exit Do
End If
End If
Loop
swMyfile.Close()
fsMyfile.Close()
If i >= 0 Then
pass = mdi_str(ListBox1.Items(i).ToString)
p_input = ListBox1.Items(i).ToString
P_pass = pass
P_kh = Trim(TextBox1.Text)
If pass = Trim(TextBox2.Text) Then
Dim frm As New Form1 'form1
Me.Hide()
frm.ShowDialog()
Me.Close()
Else
MsgBox("你所输入的口令不正确!", MsgBoxStyle.DefaultButton1, "对不起")
End If
Else
MsgBox("你所输入的用户不存在!", MsgBoxStyle.DefaultButton1, "对不起")
End If
End Sub
Function mdi_str(ByVal str As String)
Dim s, t As String
s = ""
Dim mdi_i As Integer
mdi_i = InStr(1, str, Chr(9))
mdi_i = mdi_i + 1
Do While mdi_i <= Len(str)
s = s + Mid(str, mdi_i, 1)
mdi_i = mdi_i + 1
Loop
Return s
End Function
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Focus()
TextBox1.SelectAll()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Form5_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = 13 Then
TextBox2.Focus()
TextBox2.SelectAll()
ElseIf e.KeyValue = 27 Or e.KeyValue = 37 Then
Me.Close()
End If
End Sub
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyValue = 27 Or e.KeyValue = 37 Then
Me.Close()
End If
If e.KeyValue = 13 Then
'打开文件
TextBox1.Focus()
i = -1
P_path = "\data\"
P_filename = P_path + "work.dat"
Dim lstr, pass As String
'存在时,不存在时新建
''''''''''''''''''''''''''''''''////////////////
Dim fsMyfile As IO.FileStream
Dim swMyfile As IO.StreamReader
'存在时,不存在时新建
Try
fsMyfile = New IO.FileStream(P_filename, IO.FileMode.Open, IO.FileAccess.Read)
swMyfile = New IO.StreamReader(fsMyfile)
Catch ex As Exception
Label2.Text = "文件不存在!"
Exit Sub
End Try
Do
lstr = swMyfile.ReadLine
If Len(Trim(lstr)) < 1 Then
Label2.Text = "你所输入的用户不存在!"
swMyfile.Close()
fsMyfile.Close()
Exit Sub
Else
ListBox1.Items.Add(lstr)
i = i + 1
If InStr(1, lstr, Trim(TextBox1.Text) + Chr(9)) Then
Exit Do
End If
End If
Loop
swMyfile.Close()
fsMyfile.Close()
If i >= 0 Then
pass = mdi_str(ListBox1.Items(i).ToString)
p_input = ListBox1.Items(i).ToString
P_pass = pass
P_kh = Trim(TextBox1.Text)
If pass = Trim(TextBox2.Text) Then
Dim frm As New Form1 'form1
Me.Hide()
frm.ShowDialog()
Me.Close()
Else
Label2.Text = "你所输入的口令不正确!"
TextBox2.Focus()
TextBox2.SelectAll()
End If
Else
Label2.Text = "你所输入的用户不存在!"
TextBox1.Focus()
TextBox1.SelectAll()
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown
If e.KeyValue = 13 Then
'打开文件
TextBox1.Focus()
i = -1
P_path = "\data\"
P_filename = P_path + "work.dat"
Dim lstr, pass As String
'存在时,不存在时新建
''''''''''''''''''''''''''''''''////////////////
Dim fsMyfile As IO.FileStream
Dim swMyfile As IO.StreamReader
'存在时,不存在时新建
Try
fsMyfile = New IO.FileStream(P_filename, IO.FileMode.Open, IO.FileAccess.Read)
swMyfile = New IO.StreamReader(fsMyfile)
Catch ex As Exception
Label1.Text = "文件不存在!"
Exit Sub
End Try
Do
lstr = swMyfile.ReadLine
If Len(Trim(lstr)) < 1 Then
Label1.Text = "你所输入的用户不存在!"
swMyfile.Close()
fsMyfile.Close()
Exit Sub
Else
ListBox1.Items.Add(lstr)
i = i + 1
If InStr(1, lstr, Trim(TextBox1.Text) + Chr(9)) Then
Exit Do
End If
End If
Loop
swMyfile.Close()
fsMyfile.Close()
If i >= 0 Then
pass = mdi_str(ListBox1.Items(i).ToString)
p_input = ListBox1.Items(i).ToString
P_pass = pass
P_kh = Trim(TextBox1.Text)
If pass = Trim(TextBox2.Text) Then
Dim frm As New Form1 'form1
Me.Hide()
frm.ShowDialog()
Me.Close()
Else
Label1.Text = "你所输入的口令不正确!"
TextBox2.Focus()
TextBox2.SelectAll()
End If
Else
Label1.Text = "你所输入的用户不存在!"
TextBox1.Focus()
TextBox1.SelectAll()
End If
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -