Public Class Form1
' 定义员工类
Class Employee
Public ID As Integer
Public Name As String
Public Age As Integer
Public Department As String
End Class
' 员工列表
Private employees As New List(Of Employee)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 初始化一些员工数据
employees.Add(New Employee With {.ID = 1,.Name = "张三",.Age = 25,.Department = "研发"})
employees.Add(New Employee With {.ID = 2,.Name = "李四",.Age = 30,.Department = "销售"})
employees.Add(New Employee With {.ID = 3,.Name = "王五",.Age = 28,.Department = "市场"})
' 初始化界面元素
Button1.Text = "添加员工"
Button2.Text = "查看员工列表"
Button3.Text = "修改员工信息"
Button4.Text = "继续"
Button5.Text = "退出"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' 添加员工的逻辑
Dim name As String = InputBox("请输入员工姓名")
Dim age As Integer = CInt(InputBox("请输入员工年龄"))
Dim department As String = InputBox("请输入员工所在部门")
Dim newEmployee As New Employee
newEmployee.ID = employees.Count + 1
newEmployee.Name = name
newEmployee.Age = age
newEmployee.Department = department
employees.Add(newEmployee)
MessageBox.Show("员工添加成功!")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' 查看员工列表的逻辑
Dim listText As String = "员工列表:" & vbCrLf
For Each employee In employees
listText &= $"ID:{employee.ID},姓名:{employee.Name},年龄:{employee.Age},部门:{employee.Department}" & vbCrLf
Next
MessageBox.Show(listText)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
' 修改员工信息的逻辑
Dim id As Integer = CInt(InputBox("请输入要修改的员工ID"))
Dim foundEmployee As Employee = Nothing
For Each employee In employees
If employee.ID = id Then
foundEmployee = employee
Exit For
End If
Next
If foundEmployee IsNot Nothing Then
foundEmployee.Name = InputBox("请输入新的员工姓名", "修改姓名", foundEmployee.Name)
foundEmployee.Age = CInt(InputBox("请输入新的员工年龄", "修改年龄", foundEmployee.Age))
foundEmployee.Department = InputBox("请输入新的员工部门", "修改部门", foundEmployee.Department)
MessageBox.Show("员工信息修改成功!")
Else
MessageBox.Show("未找到该员工。")
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
' 继续(返回主菜单)的逻辑
MessageBox.Show("返回主菜单")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
' 退出的逻辑
Me.Close()
End Sub
End Class