📄 form7.vb
字号:
Public Class Form7
Inherits System.Windows.Forms.Form
Friend WithEvents Button2 As System.Windows.Forms.Button
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 Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Dim s_name As String
Dim s_date, s_time, s_barcode, s_kh As String
Dim file_num As Integer
Dim i 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
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.ListBox1 = New System.Windows.Forms.ListBox
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(144, 112)
Me.Button2.Size = New System.Drawing.Size(72, 24)
Me.Button2.Text = "退出"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 112)
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.Text = "增加"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(104, 64)
Me.TextBox2.Text = ""
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(104, 24)
Me.TextBox1.Text = ""
'
'Label2
'
Me.Label2.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.Label2.Location = New System.Drawing.Point(40, 64)
Me.Label2.Size = New System.Drawing.Size(48, 16)
Me.Label2.Text = "口令:"
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.Label1.Location = New System.Drawing.Point(40, 24)
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.Text = "工号:"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(65, 208)
Me.ListBox1.Size = New System.Drawing.Size(120, 86)
'
'Form7
'
Me.ClientSize = New System.Drawing.Size(250, 151)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Text = "员工注册"
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
''''''''''''''''''''''''''''''''''''''''''''
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
Exit Do
Else
ListBox1.Items.Add(lstr)
i = i + 1
If InStr(1, lstr, Trim(TextBox1.Text) + Chr(9)) Then
MsgBox("你所输入的用户已存在!", MsgBoxStyle.DefaultButton1, "对不起")
swMyfile.Close()
fsMyfile.Close()
Exit Sub
End If
End If
Loop
swMyfile.Close()
fsMyfile.Close()
'''''''''''''''''''''''''''''''''''''''''''''
Dim fsMyfile1 As IO.FileStream
Dim swMyfile1 As IO.StreamWriter
fsMyfile1 = New IO.FileStream(P_filename, IO.FileMode.Append, IO.FileAccess.Write)
swMyfile1 = New IO.StreamWriter(fsMyfile1)
s_date = Trim(TextBox1.Text) + Chr(9) + Trim(TextBox2.Text)
swMyfile1.WriteLine(s_date)
swMyfile1.Flush()
swMyfile1.Close()
fsMyfile1.Close()
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 TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
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 = 37 Or e.KeyValue = 27 Then
Me.Close()
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyValue = 37 Or e.KeyValue = 27 Then
Me.Close()
End If
If e.KeyValue = 13 Then
''''''''''''''''''''''''''''''''''''''''''''
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
Exit Do
Else
ListBox1.Items.Add(lstr)
i = i + 1
If InStr(1, lstr, Trim(TextBox1.Text) + Chr(9)) Then
MsgBox("你所输入的用户已存在!", MsgBoxStyle.DefaultButton1, "对不起")
swMyfile.Close()
fsMyfile.Close()
TextBox1.Focus()
TextBox1.SelectAll()
Exit Sub
End If
End If
Loop
swMyfile.Close()
fsMyfile.Close()
'''''''''''''''''''''''''''''''''''''''''''''
Dim fsMyfile1 As IO.FileStream
Dim swMyfile1 As IO.StreamWriter
fsMyfile1 = New IO.FileStream(P_filename, IO.FileMode.Append, IO.FileAccess.Write)
swMyfile1 = New IO.StreamWriter(fsMyfile1)
s_date = Trim(TextBox1.Text) + Chr(9) + Trim(TextBox2.Text)
swMyfile1.WriteLine(s_date)
swMyfile1.Flush()
swMyfile1.Close()
fsMyfile1.Close()
End If
End Sub
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Focus()
TextBox1.SelectAll()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -