2

I am looking to develop a program that contains a script that a call center person could use. I would like it to start with some set of basic fields/questions (Name, Phone, Why are you calling) and then update the available fields/questions based on the answers to the previous questions.

For example:

Start with the fields/questions of Name, Phone and Why are you calling (possible answers would be "schedule appointment", "cancel appointment", "office call"). Once the caller answered the "Why are you calling question" additional fields would be displayed. These additional fields would be dependent upon the answer given. If the caller was calling for an appointment then a calendar might be displayed, if calling to cancel then any existing appointments would be shown, etc.

Unfortunately, I have no idea how to go about this. I think XML might be the way to go so that I can store the field/question data in a tree like structure but not sure if that will work.

Has anyone done anything similar that could offer some guidance? I will be doing this using C# and WPF.

Thanks in advance, Brian

BrianKE
  • 4,035
  • 13
  • 65
  • 115

3 Answers3

1

You're describing a simple workflow. There are a number of approaches to this, depending on the complexity.

The simplest option might be to use the VisualStateManager to display a group of fields depending on a static list of "call reasons." Set the visual state of the form when the call reason is selected from the dropdown.

If you need to be able to design a data-driven workflow where there are multiple paths and screens, you should consider a wizard-style interface in which the user navigates through pages. The next page that appears is dependent on the answers in the previous page.

If you need a complex workflow that you need to be able to update visually, consider Windows Workflow Foundation (WF.) The WF editor is hostable in a WPF application, which would allow superusers to design new workflows.

Look in to PRISM, also known as the Composite Application Library, for information on how to dynamically compose an application. Prism will allow you to build views that can be injected into a UserControl at runtime, depending on business logic.

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
  • +1 For different solutions for different levels of complexity. Sounds like representing a workflow / flowchart will be core to the OP's solution. – Dan J Dec 22 '10 at 17:54
  • WF looks to be exactly what I need. I was not aware of this package. Thanks for your help! – BrianKE Dec 23 '10 at 15:16
0

I haven't done this thing you are asking about, but if I did here is the approach I would take. First, you have to map out all of the possible paths of logic. So you would have sets of questions and to each of those questions a set of possible responses. Then to each of those responses new sets of questions. So, this would logically create a graph of sets of possible questions and their possible responses. I would codify this relationship as Question and Response objects. Also, you would need to define some way with the Response object to indicate what to do next (either point to a new set of Questions, or it is complete). So, following that line of thinking you would wind up with a graph, or more precisely, a tree structure. And it could be iterated simply like this using a Stack:

// need to pull the Initial Set of Questions to start
List<Question> currentQuestions = GetInitalQuestions();
// a stack to track the chosen responses, so we can unwind if needed
Stack<Response> responseStack = new Stack<Response>();
// out exit condition is when currentQuestions is null
while(currentQuestions != null)
{
    // display the questions and get the user's response
    Response resp = DisplayQuestions(currentQuestions);
    // if we need to back up...
    if (resp == Response.Back)
    {
        // make sure we have something to fall back to...
        if (responseStack.Count > 0)
            resp = responseStack.Pop();
        else
            HandleAtBeginningOfStack();
    }
    else
    {
        // add the chosen response to the stack
        responseStack.Push(resp);
    }
    // get the next set of questions based on the response, unless we are at the end
    if (resp.IsFinal)
        currentQuestions = null;
    else
        currentQuestions = GetQuestionSetFromResponse(resp);
}

With this being the underlying logic, you would need to construct a UI to present the Questions and Responses. I would create a Form with a single Panel. On the form have a method called DrawPanel, or something like that, when passed a set of Questions and their responses it would clear the Panel and draw the necessary controls. So, it would dynamically create the display as the questions and responses are chosed by the user. Since we have a Stack of the chosen responses you could use it somewhere on the form to display to the user the options they have previously selected.

EchoCoder
  • 19
  • 1
-1

Your statement that "you have no idea how to go about this" makes it sound like you are new to programming and data structures? If that's the case, a C# book geared toward the absolute beginner would be a good place to start.

Beyond that, your question concerns the hiding and/or collapsing of controls in WPF, which is covered in the answers to this other question.

Community
  • 1
  • 1
Buggieboy
  • 4,636
  • 4
  • 55
  • 79