好的,所以我正在为 VB.net II 做我的最后一个项目。我为酒店住宿情况创建了一个项目,并且一切正常。但是,我需要帮助来添加一些东西。
我把它送到你的新客人/客户或回头客的地方。如果您是新的,当您提交表单时,它会将客户信息添加到数据库中。我的 Access 数据库有 2 个表:Customer和CustomerStays。
现在,它们的主键是一个名为:CustomerID的字段 ,它们在数据库本身中具有联系在一起的关系。
Customer 表的字段包括:CustomerID、CustomerName、CustomerAddress、CustomerZipcode和CustomerTagNumber
CustomerStays 表的字段包括:CustomerID、CustomerDateIn、CustomerDateOut和TotalDays
这是我的主要形式的图像:
当他们点击total for stay时,这里是通过它的代码
Private Sub TotalForStayBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalForStayBtn.Click
ErrorChecking() 'Sub routine that checks for errors
If YourGood = True Then 'Only good if you pass the error check
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''ADDING CUSTOMER INFORMATION TO THE DATABASE''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If ExistingCustomer = False Then
Try
myconnection.Open()
Dim str As String
str = "SELECT * FROM Customer WHERE CustomerTagNumber='" & CustomerTagNumbertxt.Text & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myconnection)
dr = cmd.ExecuteReader
If dr.Read Then
If MsgBox("That license plate tag number already exists. Are you an existing customer?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
ReturningCustomerLookup.Show()
Me.Close()
ElseIf MsgBoxResult.No Then
MessageBox.Show("Please re-enter your own license plate tag number and verify that it is entered correctly.")
End If
Else
str = "INSERT INTO Customer (CustomerName, CustomerAddress, CustomerZip, CustomerTagNumber)" _
& " VALUES ('" & CustomerNametxt.Text & "','" _
& CustomerAddresstxt.Text & "','" _
& CustomerZipCodetxt.Text & "','" _
& CustomerTagNumbertxt.Text & "')"
cmd = New OleDbCommand(str, myconnection)
cmd.ExecuteNonQuery()
MessageBox.Show("Your information has been successfully added to the database", "Successful")
'''''''CALCULATING THE TOTAL'''''''
CalculateTotal()
'''''END CALCULATING THE TOTAL'''''
'''''''ADDING DATES INFO TO DATABASE'''''''
**CustomerStaysInsertion()**
'''''END ADDING DATES INFO TO DATABASE'''''
End If
Catch ex As Exception
MessageBox.Show("There was an error inserting your information into the database" _
& vbCrLf & vbCrLf & "Original Error: " & ex.ToString, _
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
myconnection.Close()
End Try
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''END ADDING CUSTOMER INFORMATION TO THE DATABASE''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''CALCULATING THE TOTAL'''''''
CalculateTotal()
'''''END CALCULATING THE TOTAL'''''
End If
End If
End Sub
现在我的问题是CustomerStays信息。它运行子例程,我想要它做的是使用客户的信息来获取Customer表中的CustomerID,并将 AS CustomerID连同他们签入和签出的日期以及总数一起放在CustomerStays表中停留的天数。
基本上,我需要它将所有这些信息与属于当前住在酒店的客户的 CustomerID 一起插入。
附加信息:
一些控件的名称:
日期输入 - DateInPicker
约会 - DateOutPicker
总天数 - TotalDayslbl