如何检查记录是否已被删除

问题描述:

我已经编写了一个从数据库中删除记录的方法。如何检查记录是否已被删除

Public Overrides Sub Delete(ByVal intDeletingUserID As Integer, Optional ByVal blnLogChanges As Boolean = True) 
    If BLMonitor.CountByCustomer(Customer_ID) = 0 And _ 
     BLComplaint.CountByCustomer(Customer_ID) = 0 And _ 
     BLRecommendation.CountByCustomer(Customer_ID) = 0 And _ 
     BLPublicFeedback.CountByCustomer(Customer_ID) = 0 And _ 
     BLCustomer.CountFeedbackAndReferences(Customer_ID).Rows.Count = 0 Then 
     MyBase.Delete(intDeletingUserID, blnLogChanges) 
    Else   
End Sub 

我需要向用户显示当我实现此方法时是否可以删除记录。

如果这是winforms应用程序,那么您可以使用MsgBox或MessageBox.Show来向用户显示消息。

例如:

Dim sMessage As String 
If ... 
    MyBase.Delete(intDeletingUserID, blnLogChanges) 
    sMessage = "Record Successfully Deleted" 
Else 
    sMessage = "Record Cannot Be Deleted" 
End If 

MsgBox(sMessage) 

否则,如果这是一个ASP.Net应用程序,该解决方案将取决于你如何执行该功能(AJAX,回发,部分回发等)很多​​。

假设你正在做一个完整的回传,您可以使用类似:

''' <summary> 
''' This method generates javascript that will raise an alert on the client side. This 
''' the text that will be displayed to the end user is cleaned of data that will cause 
''' javascript to fail. 
''' </summary> 
''' <param name="sText"></param> 
''' <returns></returns> 
''' <remarks></remarks> 
Public Function GenerateAlertJavascript(ByVal sText As String) As String 
    ' Exceptions are handled by the caller 

    If String.IsNullOrEmpty(sText) Then 
     Return "" 
    Else 
     Return "alert(""" & sText.Replace(""""c, "").Replace(CRLF, "\n") & """);" 
    End If 
End Function 

可以在你的函数被调用,如:

Dim sMessage As String 
If ... 
    MyBase.Delete(intDeletingUserID, blnLogChanges) 
    sMessage = "Record Successfully Deleted" 
Else 
    sMessage = "Record Cannot Be Deleted" 
End If 

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "AlertScript", GenerateAlertJavascript(sMessage), True)