我有这两个子程序来处理表单上两个按钮的按钮单击事件。每一个都会导致另一个较小的表单显示在窗口上,需要用户输入才能继续。
在这两种情况下,我都使用Enabled = False来禁用主窗体,而较小的窗体是活动的。在第一个Sub,AddNewPatientButton_Click中,这具有禁用主窗体所需的效果。但是,对于DeletePatientButton_Click,这没有任何效果。
以下是事件处理程序的代码:
Private Sub AddNewPatientButton_Click(sender As Object, e As EventArgs) Handles AddNewPatientButton.Click
NewPatientForm.Show()
Enabled = False
End Sub
Private Sub DeletePatientButton_Click(sender As Object, e As EventArgs) Handles DeletePatientButton.Click
AreYouSureForm.Show()
Enabled = False
If AreYouSureForm.yesSelected Then
Dim sqlQuery As String = "DELETE FROM Patients WHERE "
Dim firstName As String = PatientDataGridView.CurrentRow.Cells.Item(0).Value.ToString()
Dim lastName As String = PatientDataGridView.CurrentRow.Cells.Item(1).Value.ToString()
Dim dOB As String = PatientDataGridView.CurrentRow.Cells.Item(2).Value.ToString()
dOB = dOB.Substring(0, 2) & dOB.Substring(3, 2) & dOB.Substring(6, 4)
sqlQuery = sqlQuery & "Firstname = '" & firstName & "' AND Surname = '" & lastName & "' AND DateOfBirth = '" & dOB & "'"
DatabaseModule.AddOrDelete(sqlQuery, True, True)
End If
Enabled = True
End Sub
以下是第一个事件带来的NewPatientForm的代码:
Public Class NewPatientForm
Private Sub NewPatientForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Populate the year drop-down box with all of the years between now and 1900
Dim year As Integer = Date.Today.Year()
Do Until year = 1899
YearComboBox.Items.Add(year)
year -= 1
Loop
End Sub
Private Sub CancelAddButton_Click(sender As Object, e As EventArgs) Handles CancelAddButton.Click
PatientDatabaseForm.Enabled = True
Me.Close()
End Sub
Private Sub OkayButton_Click(sender As Object, e As EventArgs) Handles OkayButton.Click
Dim sqlQuery As String = "INSERT INTO Patients (Firstname, Surname, DateOfBirth) VALUES ("
'Get inputs
Dim firstName As String = FirstNameTextBox.Text
Dim surname As String = LastNameTextBox.Text
Dim dOB As String = DayComboBox.Text & "-" & MonthComboBox.Text & "-" & YearComboBox.Text
'Build sql insert string from inputted values
If (firstName <> "") And (surname <> "") And (dOB <> "--") Then 'If no input, then display message
sqlQuery = sqlQuery & "'" & firstName & "', "
sqlQuery = sqlQuery & "'" & surname & "', "
sqlQuery = sqlQuery & "'" & dOB & "')"
DatabaseModule.AddOrDelete(sqlQuery, True, False)
Else
MessageBox.Show("Invalid input")
End If
End Sub
End Class
第二个事件带来的AreYouSureForm的代码:
Public Class AreYouSureForm
Public yesSelected As Boolean
Public Sub YesButton_Click(sender As Object, e As EventArgs) Handles YesButton.Click
yesSelected = True
Close()
End Sub
Private Sub NoButton_Click(sender As Object, e As EventArgs) Handles NoButton.Click
yesSelected = False
Close()
End Sub
End Class
我可能只是错过了一些非常愚蠢的东西,但我看不到它:(
感谢任何帮助,谢谢