Basic concepts of Forms

In this article, the basic concepts of Forms are explained.

Forms interact

In terms of the MVC concept, the Operations could be called the Controllers. The Forms would be the Views and the Database would be the Model.

A form communicates with the user. Information (handed down from an operation) can be presented and actions (for example button clicks) can invoke new actions.

The AI-Framework distinguishes three types:

  1. A form that is invoked by an Operation 
    This Operation can have more than one form. Data from the Operation is accessible through Operation.SomePublicPropertyOrVar.

  2. A form that is part of an Operation
    This is called a SimpleForm, which inherits from a SimpleFormOperationBase. The Operation and Form are both coded in the same class.

  3. The third option is the FormApplicationBase 
    This is the mechanism in which the menus are built. It is therefore the Main Form, that can only be created once. It is possible to override CreateUI in order to make custom UI. This concept of the ApplicationBase will be explained in other articles.

See also: Operations 

Code examples

The following examples show the different type of forms.

1. Form invoked by Operation

public class InvoiceOverviewOp : FormOperationExBase
{
   public InvoiceOverviewOp( ... , ... , IExpression<IDbKey<User>> userKey)
      : base(database, customerKey)
   {
      RegisterInputParameter(UserKey, userKey);
   }

   protected override IForm CreateStartupForm()
   {
      return new InvoiceOverviewFrm(this);
   }
   ...

This is an operation (normally we end the name of an operation file with the letters Op, as in InvoiceOverviewOp), that needs a form, in this case InvoiceOverviewFrm.

  • Line 1 defines the name of the class, which inherits from a Base class.
  • Line 3 is the constructor where the input parameters are registered.
  • Line 9 overrides a method, namely CreateStartupForm(), and returns an interface, namely IForm. Here, we tell the Operation which Form to use.
  • Line 11 mentions the name of the form and connects it with this very operation (this).
public class InvoiceOverviewFrm : FormBase<InvoiceOverviewOp>
  {
     public InvoiceOverviewFrm(InvoiceOverviewOp operation)
         : base(operation)
     {
     }

     protected override IUIElement CreateGui()
     {
         return new VBox
         {
         ...

This is the form, connected to the operation. 

  • Line 1 shows that the form inherits from the FormBase InvoiceOverviewOp.
  • Line 3 tells the form thatInvoiceOverviewOp is the base operation.
  • Line 8 overrides a method, CreateGui(), and returns an interface, IUIElement.
  • Line 10 and down override the UI elements, specific for this form.

Note 1: In the AI-Framework, the form has access to all public properties and methods of the operation.
The code is simply: Operation.SomeProperty for a property, or Operation.DoSomething() for a method.

Note 2: An operation may have more than one form. For example a form to show statistics, and another form to ask for additional input. A form can be associated with only one operation. In other words, the same form cannot be used for more than one operation.

 

2. Form part of Operation

public class ConfirmPriceOp: SimpleFormOperationBase
{
   public ConfirmPriceOp(IDbDefinition database)
      : base(database)
   {
   }

   ...

   protected override IUIElement CreateGui(IForm form)
   {
      return new HBox
      {
         ...
      }
   }

The operation ConfirmPriceOp needs one form. In this example, the form is defined and called within the operation class itself. The class inherits from SimpleFormOperationBase, in order to have the necessary elements available. 

Different from the previous example, here the UI is overridden directly in line 10.

 

3. FormApplicationBase

public class SomeApplication : FormApplicationBase, IFiliaalProcess
{

...

   protected override IMenuItem[] CreateMenuItems()
   {
      var mainMenuItems = new List<IMenuItem>
      {
         new GroupMenuItem("articles", Images.Article)
         {
            new FunctionCallMenuItem(new ArticleMaintenanceOp(... some parameters ...)
               .Start(this)
               .AddDisabledWhen(... some boolean ...)
               .Call())
            {
               VisibleWhen = IsActive
            },
            new FunctionCallMenuItem(new ArtikelAddOp(...

The class inherits from FormApplicationBase. This base contains the elements to build up a (grouped) menu structure.

  • Line 6: Overrides the method CreateMenuItems and returns an interface.
  • Line 10: A group menu is declared, which is in this case the top level menu. Below are menu items. In case a new sublevel is needed, another group will be declared.
    The name of the group is articles (which will be capitalised by the AI-Framework). The menu-item has an image.
  • Line 12 through 18 define the menu item. This could all be written on one line but for readability it is formatted this way.
    • 12: An operation with the name ArticleMaintenanceOp is called, with its parameters,
    • 13: and is started.
    • 14: When the boolean returns true, the menu item is not available ('grey').
    • 17: When the boolean returns true, the menu is not displayed at all.

See also Operations 

See also the Tutorial: Setting up an operation and a form