Before inserting the record to the table,the system will check first if the first name and last name of the person is already exists. If the person is existing, a message box will appear with yes or no button asking if the user want to continue inserting the record.I have tried the following code:
Imports ChurchMIS.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web
Imports System.Web.Security
Imports System.Data.SqlClient
Namespace ChurchMIS.Rules
Partial Public Class IndividualBusinessRules
Inherits ChurchMIS.Data.BusinessRules
''' <summary>
''' This method will execute in any view for an action
''' with a command name that matches "SQL".
''' </summary>
<Rule("r107")> _
Public Sub r107Implementation( _
ByVal individualId As Nullable(Of Integer), _
ByVal firstName As String, _
ByVal lastName As String, _
ByVal dateOfBirth As Nullable(Of DateTime), _
ByVal addressTypeId As Nullable(Of Integer), _
ByVal suburb As String, _
ByVal streetAddress As String, _
ByVal postCode As Nullable(Of Integer), _
ByVal contactInfoTypeId As Nullable(Of Integer), _
ByVal contactNo As String, _
ByVal fullName As String, _
ByVal individualTypeId As Nullable(Of Integer), _
ByVal state As String, _
ByVal dateOfBaptism As Nullable(Of DateTime), _
ByVal dateOfTransfer As Nullable(Of DateTime), _
ByVal email As String, _
ByVal faithStatus As Nullable(Of Integer), _
ByVal noOfVisits As Nullable(Of Integer), _
ByVal name As String, _
ByVal name_1 As String, _
ByVal name_2 As String)
'This is the placeholder for method implementation.
Dim con As SqlConnection = New SqlConnection("Data Source=CNEPHILS;Initial Catalog=ChurchMIS;User ID=sa;Password=Cn$phil$")
Dim theQuery As String = "SELECT * FROM Individual WHERE FirstName=@FirstName AND LastName=@LastName"
Dim cmd1 As SqlCommand = New SqlCommand(theQuery, con)
cmd1.Parameters.AddWithValue("@FirstName", firstName)
cmd1.Parameters.AddWithValue("@LastName", lastName)
Using reader As SqlDataReader = cmd1.ExecuteReader()
If reader.HasRows Then
' person already exists
Dim result As Integer=
Dim result As Integer = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel)
If result = DialogResult.Cancel Then
MessageBox.Show("Cancel pressed")
ElseIf result = DialogResult.No Then
MessageBox.Show("No pressed")
ElseIf result = DialogResult.Yes Then
Dim cmd As SqlCommand = New SqlCommand("exec spInsertIndividual @FirstName,@LastName,@DateOfBirth,@Suburb,@StreetAddress,@PostCode,@State,@AddressTypeId,@ContactInfoTypeId,@ContactNo,@IndividualTypeId,@Email,@FaithStatus,@DateOfBaptism,@DateOfTransfer", con)
cmd.ExecuteNonQuery()
MsgBox("Records Successfully Added!", MsgBoxStyle.Information)
End If
Else
' person does not exist, add them
Dim cmd As SqlCommand = New SqlCommand("exec spInsertIndividual @FirstName,@LastName,@DateOfBirth,@Suburb,@StreetAddress,@PostCode,@State,@AddressTypeId,@ContactInfoTypeId,@ContactNo,@IndividualTypeId,@Email,@FaithStatus,@DateOfBaptism,@DateOfTransfer", con)
cmd.ExecuteNonQuery()
MsgBox("Records Successfully Added!", MsgBoxStyle.Information)
End If
End Using
con.Close()
End Sub
End Class
End Namespace
However,i raised an error "MessageBox is not declared.....protection level."
Hope someone could help. Thanks!