请你帮忙。我创建了一个简单的航班预订系统。当用户选择计算按钮时,它将计算从组合框选项中选择的成人和儿童数量的价格。计算是在 try catch 和 if 语句中创建的,具体取决于组合框 1 和组合框 2 中的选择。我需要创建一个模块并将计算函数放入模块中,调用计算按钮中的函数。航班价格取决于所选目的地。
这是该程序的源代码,我们将非常感谢您的帮助。
公开课形式1
Private Sub btncalculateprice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculateprice.Click
Dim PricechildrenLocal As Integer = 1200
Dim PriceadultsLocal As Integer = 12000
Dim totalAdults As Integer
Dim totalChildren As Integer
Dim totalPrice As Integer
Dim totalPrice1 As Integer
Dim totalPrice2 As Integer
Try
If cmbadults.Text = 0 Then
totalAdults += 0
End If
If cmbadults.Text = 1 Then
totalAdults += 1
End If
If cmbadults.Text = 2 Then
totalAdults += 2
End If
If cmbadults.Text = 3 Then
totalAdults += 3
End If
If cmbadults.Text = 4 Then
totalAdults += 4
End If
If cmbadults.Text = 5 Then
totalAdults += 5
End If
If cmbadults.Text = 6 Then
totalAdults += 6
End If
If cmbadults.Text = 7 Then
totalAdults += 7
End If
If cmbadults.Text = 8 Then
totalAdults += 8
End If
If cmbadults.Text = 9 Then
totalAdults += 9
End If
If cmbadults.Text = 10 Then
totalAdults += 10
End If
Catch ex As Exception
End Try
Try
If cmbchildren.Text = 0 Then
totalChildren += 0
End If
If cmbchildren.Text = 1 Then
totalChildren += 1
End If
If cmbchildren.Text = 2 Then
totalChildren += 2
End If
If cmbchildren.Text = 3 Then
totalChildren += 3
End If
If cmbchildren.Text = 4 Then
totalChildren += 4
End If
If cmbchildren.Text = 5 Then
totalChildren += 5
End If
If cmbchildren.Text = 6 Then
totalChildren += 6
End If
If cmbchildren.Text = 7 Then
totalChildren += 7
End If
If cmbchildren.Text = 8 Then
totalChildren += 8
End If
If cmbchildren.Text = 9 Then
totalChildren += 9
End If
If cmbchildren.Text = 10 Then
totalChildren += 10
End If
Catch ex As Exception
End Try
Try
If ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Cape Town International (CPT)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 100
totalPrice2 = totalAdults * PriceadultsLocal + 150
ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 100
totalPrice2 = totalAdults * PriceadultsLocal + 150
ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 1000
totalPrice2 = totalAdults * PriceadultsLocal - 2000
ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 100
totalPrice2 = totalAdults * PriceadultsLocal + 150
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Cape Town International (CPT)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 100
totalPrice2 = totalAdults * PriceadultsLocal + 150
ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Cape Town International (CPT)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 100
totalPrice2 = totalAdults * PriceadultsLocal + 150
ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Cape Town International (CPT)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Lanseria Airport (JHB) (CPT)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "Cape Town International (CPT)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "Cape Town International (CPT)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
totalPrice1 = totalChildren * PricechildrenLocal
totalPrice2 = totalAdults * PriceadultsLocal
ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
totalPrice1 = totalChildren * PricechildrenLocal - 500
totalPrice2 = totalAdults * PriceadultsLocal - 1000
ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
totalPrice1 = totalChildren * PricechildrenLocal + 150
totalPrice2 = totalAdults * PriceadultsLocal + 200
End If
Catch ex As Exception
End Try
totalPrice = totalPrice1 + totalPrice2
Price.Text = Format(totalPrice, "currency")
Adults.Text = totalAdults
Children.Text = totalChildren
End Sub
Private Sub btnbookflight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbookflight.Click
Dim form As New Confirm
If cmbadults.SelectedItem = "" Then
MessageBox.Show("Please select the number of adults")
Else
If cmbchildren.SelectedItem = "" Then
MessageBox.Show("Please select the number of children")
Else
If ComboBox1.SelectedItem = "" Then
MessageBox.Show("Please select the depature destination")
Else
If ComboBox2.SelectedItem = "" Then
MessageBox.Show("Please select the going to destination")
Else
Confirm.Show()
End If
End If
End If
End If
End Sub
Private Sub cmbadults_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbadults.SelectedIndexChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub rbnoneway_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbnoneway.CheckedChanged
If rbnoneway.Checked Then
lblreturndate.Hide()
Else
lblreturndate.Show()
End If
If rbnoneway.Checked Then
dtereturn.Hide()
Else
dtereturn.Show()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
cmbtitle.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
cmbadults.Text = ""
cmbchildren.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
dtedepature.Text = ""
dtereturn.Text = ""
rbnoneway.Checked = False
rbnroundtrip.Checked = False
End Sub
结束类