Public Class Form1
' 定义航班类
Class Flight
Public FlightNumber As String
Public DepartureCity As String
Public DestinationCity As String
Public DepartureTime As Date
Public AvailableSeats As Integer
End Class
' 航班列表
Private flights As New List(Of Flight)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 初始化一些航班数据
flights.Add(New Flight With {.FlightNumber = "FL001",.DepartureCity = "北京",.DestinationCity = "上海",.DepartureTime = #8/20/2024 9:00 AM#,.AvailableSeats = 50})
flights.Add(New Flight With {.FlightNumber = "FL002",.DepartureCity = "上海",.DestinationCity = "广州",.DepartureTime = #8/20/2024 12:00 PM#,.AvailableSeats = 30})
' 初始化界面元素
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 departureCity As String = InputBox("请输入出发城市")
Dim destinationCity As String = InputBox("请输入目的地城市")
Dim resultText As String = "符合的航班:" & vbCrLf
For Each flight In flights
If flight.DepartureCity = departureCity AndAlso flight.DestinationCity = destinationCity Then
resultText &= $"航班号:{flight.FlightNumber},出发时间:{flight.DepartureTime},剩余座位:{flight.AvailableSeats}" & vbCrLf
End If
Next
MessageBox.Show(resultText)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' 订票的逻辑
Dim flightNumber As String = InputBox("请输入要预订的航班号")
Dim selectedFlight As Flight = Nothing
For Each flight In flights
If flight.FlightNumber = flightNumber Then
selectedFlight = flight
Exit For
End If
Next
If selectedFlight IsNot Nothing And selectedFlight.AvailableSeats > 0 Then
selectedFlight.AvailableSeats -= 1
MessageBox.Show("订票成功!")
ElseIf selectedFlight IsNot Nothing And selectedFlight.AvailableSeats = 0 Then
MessageBox.Show("该航班已满,无法订票。")
Else
MessageBox.Show("未找到该航班。")
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
' 查看订单的逻辑
' 这里假设没有实际的订单存储,仅显示模拟信息
MessageBox.Show("当前无订单信息。")
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