0

I want to create an application that has some optional steps. But I could not decide how to do step plans. It looks like a workflow.

I have a Work entity. This work includes specific business steps.

  • Step-1 : Demand of work. ( DemanderName, DemandDate, DemandFiles )
  • Step-2 : ...
  • Step-3 : ...
  • Step-4 : Work investigation starts. ( InvestigatorName, StartDate, EndDate, Files )
  • Step-5 : After investigation, a decision done. This work is accepted or cancelled. ( Result, Date )

After a work created, the steps will done by order. But some steps could be cancelled. For example: I work on a work that does not include step-2 and step-3.

  1. Should I need create a database table for every step? (And I need to sign the step of work as completed or not completed.)
  2. I need to show work completion percentage. (Work-1 %20, Work-2 %60). If I use tables, how can I see the percentages?

I could not decide how I can design this.

  • This sounds like a Workflow problem, like something that Activiti (activiti.org) or similar framework is designed to handle. My team has used that tool and built the rest of the support around it. Many of those tools do use a database, but the data structure is built for you. But No, you do not need a table per step. – Berin Loritsch Feb 7 at 1:15
0
  1. Should I need create a database table for every step? (And I need to sign the step of work as completed or not completed.)

Do you need to store all of the results of the work in a database? I mean, you could do this, but it's not clear if it's necessary.

If each step has distinct attributes, and you want to store results from many executions of your workflow, using a database and having a separate table for each step might be a good approach. But if you want to be able to add/remove steps to your workflow easily, or regularly change the attributes of each step, database tables might not be flexible enough for you. Of course, you could come up with a data model that keeps all of the data in one table (probably with some supporting reference-data tables), though that might be more complex. It's really hard to recommend anything concrete without knowing more detail about the problem you're having.

  1. I need to show work completion percentage. (Work-1 %20, Work-2 %60). If I use tables, how can I see the percentages?

How you do this would probably depend on how you model the data. In general, you would probably query all of the "step" tables for a given workflow execution. If only the "step 1" table and "step 2" table are populated for "Work-1", then you have 2/5 tables populated, so that would be 20% complete.

0

This might be naive, but you could try to create a state-machine based on steps. Then each step with a list of completed and remaining steps (alongside any other related data) would be your state. Each work could be represented as a single row in the DB with all of the step and other information and then all your application would do is simply handle step transitions by updating appropriate DB rows.

0

My advice is to avoid hardcoding the workflow steps in your business objects-- workflows tend to change and steps tend to get removed or added. Instead, just define a single object representing all the data you need:

class MyTaskData
{
    public string DemanderName { get; set; }
    public DateTime DemandDate { get; set; }
    public List<FileInfo> DemandFiles { get; set; } = new List<FileInfo>();
    public string InvestigatorName { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public List<FileInfo> Files { get; set; } = new List<FileInfo>();
    public string Result { get; set; }
    public DateTime ResultDate { get; set; }
}

Then to figure out which step to show the user, inspect the fields and determine what additional data is needed. For example, if you are working on a web site, you could write a function to choose what page to show next, like this:

string GetNextPage(MyTaskData data)
{
    if (data.DemanderName == null) return "Step1.htm";
    if (data.DemandDate != DateTime.MinValue) return "Step1.htm";
    if (data.DemandFiles.Count == 0) return "Step1.htm";
    if (data.InvestigatorName == null) return "Step4.htm";
    if (data.StartDate == null) return "Step4.htm";
    if (data.EndDate == DateTime.MinValue) return "Step4.htm";
    if (data.Files.Count == 0) return "Step4.htm";
    if (data.Result == null) return "Step5.htm";
    return "WorkflowAlreadyCompleted.htm";
}

Which you'd use like this:

Response.Redirect(GetNextPage(taskData));

This has the added benefit of ensuring that all fields are filled out before proceeding to the next step, and is resilient with respect to things like double-posting or accidentally skipping steps. It'll always get you where you need to be.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.