Search code examples
c#asp.net-mvcuser-interfacedesign-patterns

Pattern for UI: Same object, displayed differently


I have an application for entering in serial numbers to a database. A serial number has a set number of attributes that defines it and the the user must/may provide them to generate.

public class Serial
{
    public string Number {get; set;}
    public string Part {get; set;}
    public string MfgOrder {get; set;}
    public string CusOrder {get; set;}
    public string Note {get; set;}
    ... etc ...
}

Now the start point of this application asks the user for one of several pieces of information (for example a part number or manufacturing order, etc). This start point may already fill in some of the required user input. I'd like to then take those known items and alter the form based on them.

For example. If two of the pieces of information are Part Number and Mfg Order Number, and the user supplies the Mfg Order Number (which has a relationship to the Part Number from the database) I'd like to display these values but not allow them to be edited. If instead the user just gives me a Part Number, I want to allow the Mfg Order to be presented as a textbox with (maybe) optional or required next to it.

public class MfgOrder
{
    public string MfgOrder {get; set;}
    public string Part {get; set;}
}

...

MfgOrder order = new MfgOrder(some_user_value); // queries database, returns populated object
Serial serial = new Serial() {
    MfgOrder = order.MfgOrder,
    Part = order.Part
};

This application is working right now by just having if/then conditions in the UI -- if you gave me a Mfg Order, dispaly it this way, if you gave me something else, do it this way, etc. The problem is several new options have been requested and continually chaining if/then statements is getting really ugly.

if(serial.comes_from_mfgOrder == true)
{
    %>Manufacturing Order: <%=serial.MfgOrder %><%
} else if (serial.comes_from_part_number == true) {
    %>Manufacturing Order: <%=Html.Textbox("MfgOrder")%><%
} else if // continue this for way too long now ...

Is there a good design pattern here?

Thanks!


Solution

  • If there's an IF, make a Helper.