2017-03-16 1 views
1

Bevor der Datensatz in die Tabelle eingefügt wird, prüft das System zuerst, ob der Vorname und der Nachname der Person bereits vorhanden sind. Wenn die Person vorhanden ist, wird ein Meldungsfeld mit Ja oder Nein-Taste zu fragen erscheint, wenn der Benutzer hat Einsetzen den record.I fortgesetzt werden soll versucht, den folgenden Code:Wie zeigt man eine Message Box mit Ja oder Nein in AspNet Webforms mit vb.net?

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 [email protected] AND [email protected]" 
     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 

jedoch hob ich eine Fehlermeldung „MessageBox ist nicht deklariert ..... Schutzstufe. "

Hoffe jemand könnte helfen. Vielen Dank!

+0

In asp.net verwenden Sie ado.net oder linq in Ihrem Projekt – PRABA

Antwort

1

@roger. Ich denke, dass Sie in der Webanwendung arbeiten. Versuchen Sie dies, fügen Sie dieses Skript in Ihrer ASPX-Seite innerhalb des head-Tags hinzu.

<script type="text/javascript"> 
     function SomeMethod() { 
      try { 
       var result = true; 
       var obj = {}; 
       obj.Firstname = $('#<%=txtfirstname.ClientID %>').val(); 
       obj.Lastname = $('#<%=txtlastname.ClientID %>').val(); 
       $.ajax({ 
        type: "POST", 
        data: JSON.stringify(obj), 
        url: "yourformname.aspx/yourmethodname", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        async:false, 
        success: function (response) { 
         if (response.d.toString() == "true") { 
           if (confirm("first name and last name of the person is already exists?")) { 
            result = true; 
            // insert the user name 
           } 
           else { 
            result = false; 

           } 
         } 
         else { 

         } 
        }, 
        failure: function (response) { 
         alert(response.d); 
        } 
       }); 
      } 
      catch (e) { 
       alert(e); 
      } 
      return result; 
     } 
    </script> 

Rufen Sie die JavaScript-Funktion in Ihrem Button-Klick-Ereignis auf. Wenn Sie RequiredFieldValidator für die Validierung verwenden, verwenden Sie Page_ClientValidate(). Andernfalls entfernen Sie die Funktion PageClientValidate() im OnClick-Ereignis der Schaltfläche.

<asp:Button ID="btnbutton" CssClass="Designclass" OnClientClick="if(Page_ClientValidate()) return SomeMethod();" 
             runat="server" Text="Generate" /> 

erstellen Sie die folgende Web-Methode in Ihrer .aspx.vb Seite

<System.Web.Services.WebMethod()> 
Public Shared Function Checkuserexists(ByVal Firstname As String, ByVal Lastname As String) As String 
    'write your code for checking firstname and last name 
    If exists > 0 Then 
     Return true 
    Else 
     Return False 
    End If 
End Function 

Durch die Verwendung von Checkuserexists Methode des Vornamen überprüfen und Nachname ist in der Datenbank vorhanden. Wenn der Vorname und der Nachname vorhanden sind, wird true zurückgegeben und nach einer übereinstimmenden Nachricht gefragt. Wenn Sie auf Ja klicken, fügen Sie den Wert in die Datenbank ein.

+0

Vielen Dank! –

+0

@rogerbulawan glücklich, Ihnen zu helfen. – PRABA

Verwandte Themen