Object Status. Getting Started

In this lesson we will learn, how to start using Object Status in XAF application. As an example we consider the Order business class in the Xafari Northwind demo. Follow the steps described below.

Add XafariBСModule to Module Project. The next step is different for Win or Web applications.

For Win application add XafariBСWindowsFormsModule в Windows Forms Module Project. Modify constructor of the WinApplication class and set UseOldTemplates property to the "true" value as follows:

  • c#
  • VB

public partial class Solution1WindowsFormsApplication : WinApplication
{
  public Solution1WindowsFormsApplication()
  {
    InitializeComponent();
    UseOldTemplates = True;
  }
}

Public Partial Class Solution1WindowsFormsApplication
  Inherits WinApplication
  Public Sub New()
    InitializeComponent()
    UseOldTemplates = [True]
  End Sub
End Class

Note.

Some Xafari controls , such as Check Action, works correctly only with templates of version 1. This controls are used to provide Statuses. Therefore, in Windows Forms applications it is necessary to set UseOldTemplates property to "True".

For ASP.NET application add XafariBСWebModule to ASP.NET Web Module Project. Then customize default template (see https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument113460):

  • Create new template.
  • Modify .ascx file: replase all the «ActionContainerHolder» strings on «XafariActionContainerHolder».
  • Modify Global.asax file. Add created template in Session_Start method.
  • c#
  • VB

protected void Session_Start(Object sender, EventArgs e)
{
  //...
  WebApplication.Instance.Settings.DefaultTemplateContentPath = "~/MyTemplateContent.ascx";
  WebApplication.PreferredApplicationWindowTemplateType = TemplateType.Horizontal;
  WebApplication.Instance.Setup();
  WebApplication.Instance.Start();
}

Protected Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
  '...
  WebApplication.Instance.Settings.DefaultTemplateContentPath = "~/MyTemplateContent.ascx"
  WebApplication.PreferredApplicationWindowTemplateType = TemplateType.Horizontal
  WebApplication.Instance.Setup()
  WebApplication.Instance.Start()
End Sub

Other operations are the same for both platforms.

Implement Xafari.BC.IStatusSupport interface in the Order class. The following code snippet demonstrates this.

  • c#
  • VB

public class Order : DocumentBase, IStatusSupport
{
  public Order(Session session)
    : base(session)
  {
  }
  public override void AfterConstruction()
  {
    base.AfterConstruction();
    this.CurrentStatus = StatusTypes.Draft;
    //. . . . . . . . . . . . . . . . . . . .
  }
  //Class properties
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  public string Name { get; set; }
  public StatusTypes CurrentStatus
  {
    get
    {
      return this.GetPropertyValue<StatusTypes>("CurrentStatus");
    }
    set
    {
      this.SetPropertyValue("CurrentStatus", value);
    }
  }
  /// <summary>
  /// Gets and sets the name of the last user who changed the status.
  /// </summary>
  [VisibleInListView(false)]
  [VisibleInLookupListView(false)]
  [Browsable(false)]
  [NonPersistent]
  [Obsolete("Use StatusModify", true)]
  public string LastStatusModifyUser
  {
    get
    {
      return this.StatusModify.Executor;
    }
    set
    {
      this.StatusModify.Executor = value;
    }
  }
  /// <summary>
  /// Gets and sets the date of the last status change.
  /// </summary>
  [VisibleInListView(false)]
  [VisibleInLookupListView(false)]
  [Browsable(false)]
  [NonPersistent]
  [Obsolete("Use StatusModify", true)]
  public DateTime LastStatusModifyDate
  {
    get
    {
      return this.StatusModify.Date.HasValue ? this.StatusModify.Date.Value : DateTime.MinValue;
    }
    set
    {
      this.StatusModify.Date = value;
    }
  }
  [Browsable(false)]
  public ActionInfo StatusModify;
  ActionInfo IStatusSupport.StatusModify
  {
    get
    {
      return this.StatusModify;
    }
    set
    {
      this.StatusModify = value;
    }
  }
}

Public Class Order
  Inherits DocumentBase
  Implements IStatusSupport
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Overrides Sub AfterConstruction()
    MyBase.AfterConstruction()
    Me.CurrentStatus = StatusTypes.Draft
    '. . . . . . . . . . . . . . . . . . . .
  End Sub
  'Class properties
  ' . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  Public Property Name As String
  Public Property CurrentStatus As StatusTypes
    Get
      Return Me.GetPropertyValue(Of StatusTypes)("CurrentStatus")
    End Get
    Set
      Me.SetPropertyValue("CurrentStatus", value)
    End Set
  End Property
  ''' <summary>
  ''' Gets and sets the name of the last user who changed the status.
  ''' </summary>
  <VisibleInListView(False)> _
<VisibleInLookupListView(False)> _
<Browsable(False)> _
<NonPersistent> _
<Obsolete("Use StatusModify", True)> _
Public Property LastStatusModifyUser As String
    Get
      Return Me.StatusModify.Executor
    End Get
    Set
      Me.StatusModify.Executor = value
    End Set
  End Property
  ''' <summary>
  ''' Gets and sets the date of the last status change.
  ''' </summary>
  <VisibleInListView(False)> _
<VisibleInLookupListView(False)> _
<Browsable(False)> _
<NonPersistent> _
<Obsolete("Use StatusModify", True)> _
Public Property LastStatusModifyDate As DateTime
    Get
      Return If(Me.StatusModify.[Date].HasValue, Me.StatusModify.[Date].Value, DateTime.MinValue)
    End Get
    Set
      Me.StatusModify.[Date] = value
    End Set
  End Property
  <Browsable(False)> _
Public StatusModify As ActionInfo
  Private Property StatusModify As ActionInfo Implements IStatusSupport.StatusModify
    Get
      Return Me.StatusModify
    End Get
    Set
      Me.StatusModify = value
    End Set
  End Property
End Class

  • Run the application and invoke object's List View or Detail View, it will support operations with the object status.

Windows Forms:

object_status_3

ASP.NET:

object_status_4