The state of real world business objects modeled in the application database is frequently determined by the values of multiple object attributes.
For example, an order status may depend on the Order Date and Shipped Date. It would take some time for an end user to analyze the values to understand the status of an order. It would be beneficial for an application to provide a graphical representation of the order status.
Let’s implement a graphical representation of the internal object state using the Orders table of the Northwind sample. Most records have Shipped Date before Required Date. Some records do not have a value in the Shipped Date column. Other records have a Shipped Date past the Required Date.
It would be reasonable to assume that records without a Shipped Date have not been shipped yet, records that have a Shipped Date past the Required Date have been shipped late, and that the order is on time when the Shipped Date is before Required Date.
Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on Orders / Fields node, and select New Field option.
Give this field the following settings:
|The value of this field is computed at run-time by SQL expression.||True|
case when ShippedDate is null then 'Waiting To Ship' when ShippedDate < RequiredDate then 'Shipped' when ShippedDate > RequiredDate then 'Shipped Late' end
|Values of this field cannot be edited||True|
Press OK to save the field. Right-click on Orders / Views / editForm1 / c1 – Orders node, and select New Data Field.
Give this data field the following settings:
|The field is hidden||True|
Double-click on Orders controller node.
Change the Status Bar property:
Orders.editForm1.Status: Waiting To Ship
Orders.editForm1.Status: Shipped Late
Press OK to save the controller. On the toolbar, press Browse.
Navigate to the Orders page. Select an order in which the Shipped Date is before the Required Date. A status bar above the form provides a quick status update on the status of the order.
Select an order where Shipped Date is after Required Date. The status bar shows that the order has been delayed.
Finally, select an order without a value in Shipped Date field. The status bar will show that the order has not yet been shipped.
Status can be figured with complex calculations. For example, we configured the following SQL Formula for a new Status field in Products controller:
case when Discontinued = 1 then 'Discontinued' when UnitsInStock + UnitsOnOrder < ReorderLevel then 'Low On Stock' when UnitsOnOrder > 0 then 'On Order' when UnitsOnOrder = 0 then 'In Stock' end
The Status Bar configuration for Products controller looks like this:
Flagged for Review > [ The production of the product has been discontinued] >
Products.Status: Low On Stock
High Demand > [The product will be out of stock soon] > Place an order >
Products.Status: On Order
Product stock low > [An order has been placed] > Restocking >
Products.Status: In Stock
Recently restocked > [Plenty of stock] >
A product that has a large amount of Units In Stock will display the following status bar.
When there are a large amount of Units On Order, the status bar will notify that there is sufficient items ordered.
Discontinued products will be displayed like the picture below.
When the stock is low, the status bar will warn the user.