我编写了一个从数据库中删除记录的方法。
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
我需要向用户显示当我实现此方法时是否可以删除记录。
答案 0 :(得分:0)
如果这是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)