Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a function that check validity of inserted data of a form, and in this function I have to ask some confirmation from user, and this confirmation need to be asked outside of the function, so if I hit one of this confirmations, I create the message and send out the validation function, user confirms or not and the function would called again

so here is the problem: I need to put some checkpoints in my function so when I call the validation function I jump to that checkpoint with the selected confirmation from user and run the validation function from that checkpoint

1: is this possible at all?

2: any ideas to do this?

Edit 1: I'm doing this validation in my business layer and can not show any message boxes from there, I just create the message and return it to the UI layer and the answer get from the user and function call again with this answer but I don't want to run the function from beginning and need to run it from where I left

Public Class BL
    Private Queue As Queue(Of String)
    Public Sub New()
        Dim checkpoints = New String(){"CheckPoint1","CheckPoint2","CheckPoint3"}
        checkpoints.ToList.ForEach(Function(item) <b>Queue.Enqueue(item)</b>)
    End Sub

    Public Function Func(ByVal res As Response,ParamArray ByVal params As String()) As Response
        Dim response As Response
        Dim chk = Queue.Dequeue()
        GoTo chk
        CheckPoint1:
        'Do some stuff
        response = New Response(Response.ResponseType.Message,"Are you sure you wanna do this?")
        Return response
        CheckPoint2:
        If(res.Type = Response.ResponseType.ResponseBack)
           Dim r As DialogResult = Convert.ChangeType([Enum].Parse(GetType(DialogResult),res.Message),GetType(DialogResult))
            If (r= DialogResult.OK)
            'Do stuffs on DialogResult.Yes
                Else
            'Do stuffs on DialogResult.No
            End If
            'Do other stuffs with database
        End If
        ' Do other stuff 
        response = New Response(Response.ResponseType.Message,"You should do this!!OK?")
        Return response
        CheckPoint3:
        'Do stuff like CheckPoint1

    End Function
End Class
 Public Class Response
   Friend  Enum ResponseType
        Message
        Result
        ResponseBack
        None
    End Enum
    Friend Message As String
    Friend Type As ResponseType
    Friend Sub New(ByVal type As ResponseType,msg As String)
        Message=msg
        Type= type
    End Sub
    End Class

Public Class Form1
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        Dim BL As New BL()
        ' Add any initialization after the InitializeComponent() call.
        Dim rese As Response
        Do 
            rese =BL.Func(Nothing)
            BL.Func(new Response(Response.ResponseType.ResponseBack,if(MessageBox.Show(rese.Message).ToString())))
        Loop Until rese.Type <> Response.ResponseType.Result
        MessageBox.Show(if(rese.Message="True","OK","ERROR"))
    End Sub
End Class
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
175 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is not an objective answer but could help. You need some sort of class that contains question and answers. Your validation class would return a list of question (are you sure?).

Class ValidationOutput
    ValidationId
    Message
    Result
End Class

After calling your validation function, you get a list of validation that need extra information from the user. This can be handle outside of the validation function. When you get the extra information, call the validation again and pass the same list as parameter. When validating, look at the list to see if all the extra information needed is there.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...