Sie sind auf Seite 1von 3

Add SKUs builder pattern

public enum FormType { T58W = 0, T54W = 1, T5HL = 2, T5BF = 3, GCH8W = 4, GCH4W = 5, GCHHL = 6, FF = 7 }; public interface IWSBuilder { FormType FormType { get; } void BuildAttributesPage(params Control[] placeholders); void BuildConfirmationPage(params Control[] placeholders); void BuildAddToPlanPage(params Control[] placeholders); } public class BuilderFactory { private static BuilderFactory instance; private static Dictionary<FormType, IWSBuilder> builders; public static BuilderFactory Instance { get { if (instance == null) instance = new BuilderFactory(); return instance; } } protected BuilderFactory() { builders = new Dictionary<FormType, IWSBuilder>(); builders.Add(FormType.T58W, new T58WBuilder()); builders.Add(FormType.T54W, new T54WBuilder()); builders.Add(FormType.T5HL, new T5HLBuilder()); builders.Add(FormType.T5BF, new T5BFBuilder()); builders.Add(FormType.GCH8W, new GCH8WBuilder()); builders.Add(FormType.GCH4W, new GCH4WBuilder()); builders.Add(FormType.GCHHL, new GCHHLBuilder()); builders.Add(FormType.FF, new FFBuilder()); } public IWSBuilder GetBuilder(FormType formType) { return builders[formType]; } }

All builders implement the IWSBuilder interface which specifies the form type and methods for constructing each workflow steps dynamic controls.

BuildFactory is a singleton and can return builders with the GetBuilder method.
IWSBuilder genericBuilder = BuildFactory.Instance.GetBuilder(FormType.GCH8W);

The BuildAttributesPage method has variable parameteres specified by the keyword params:
void BuildAttributesPage(params Control[] placeholders)

If we have the placeholders phdCarrier for carrier, phdGames for games and phdDevices for devices, we can simply use the builder like this:
genericBuilder.BuildAttributesPage(phdCarrier, phdGames, phdDevices);

Example builder class for Generic Carrier Hitlist: public class GCH8WBuilder : IWSBuilder { public FormType FormType { get { return FormType.GCH8W; } } public void BuildAttributesPage(params Control[] placeholders) {
//UI element placeholders[0].Controls.Add(new Label(){ Text = Generic Carrier Hitlist }); //data holder for carrier ID placeholders[0].Controls.Add(new HiddenField(){ Value = 1 });

etc. } public void BuildConfirmationPage(params Control[] placeholders) { } public void BuildAddToPlanPage(params Control[] placeholders) { } } Notes for BuildAttributesPage follow on the next page.

In the builders BuildAttributesPage method I have created the UI element along with a hidden field that holds the data for that control. When retreiving data from the form the hidden fields must be used instead of the generated controls. Also, the controls must provide javascript methods for updating the hidden field for example if I select an item form a combobox. This can be done by attaching client side events when building the controls:
carrierDropDown.Attributes["onChange"] = "carrierChanged(hfCarrier)";

When moving to the next step in the workflow, data is carried from the hidden fields.

Das könnte Ihnen auch gefallen