Business Logic Framework - Tutorial 8:
Our eighth tutorial shows you how to join multiple tables, apply sorting and search criteria in addition to customizing the resulting column names. One of the very powerful features of the Quick Objects Business Logic Framework Each object can join with other objects it is related to, and in the joined objects can then further create joins with other objects they are related to. This allows the developer great flexibility and can get to any data in any table via any relationship.
Since each business object provides the same set of properties and methods and follows the same naming conventions (of your choice), it becomes very easy to use this framework. Once you get used to any one of the business objects the rest of the business objects are very familiar and easy to us.
Here is the code sample that shows how to join multiple tables, apply sorting, customization and search criteria to any of the fields from any of the selected objects.
| using (OrderItems orderItems = new OrderItems()) | |
| { | |
| orderItems.ObjectMode = Akal.QuickObjects.ObjectBase.ObjectModes.Search; | |
| // customize what fields are shown | |
| orderItems.UseAllFieldsForDisplay(false); | |
| orderItems.Quantity.Visible = true; | |
| orderItems.ItemAmount.Visible = true; | |
| // the following line changes the resulting columns display name to "Sub Total" instead of the default ItemAmount | |
| orderItems.ItemAmount.ResultSetName = "Sub Total"; | |
| // create join between the OrderItems and Products (a parent object) | |
| orderItems.Join_ProductID_Products_Parent(); | |
| // customize what fields are shown from the Products object i.e. Only the ProductName is shown. | |
| orderItems.ProductID_Products_Parent.UseAllFieldsForDisplay(false); | |
| orderItems.ProductID_Products_Parent.ProductName.Visible = true; | |
| // the following line changes the resulting columns display name to "Product" instead of the default ProductName | |
| orderItems.ProductID_Products_Parent.ProductName.ResultSetName = "Product"; | |
| // create join between OrderItems and Orders | |
| orderItems.Join_OrderID_Orders_Parent(); | |
| // customize what fields are shown from the Orders object. | |
| orderItems.OrderID_Orders_Parent.UseAllFieldsForDisplay(false); | |
| orderItems.OrderID_Orders_Parent.OrderDate.Visible = true; | |
| // OrderDate from the Orders object will be used for searching | |
| orderItems.OrderID_Orders_Parent.OrderDate.Value = Akal.QuickObjects.TimeZones.DateCalculations.GetStartOfLastYear(DateTime.Now); | |
| orderItems.OrderID_Orders_Parent.OrderDate.Operator = " >= "; | |
| // the following line changes the resulting columns display name to "Date Ordered" instead of the default OrderDate | |
| orderItems.OrderID_Orders_Parent.OrderDate.ResultSetName = "Date Ordered"; | |
| // OrderDate will also be used for sorting the result set and all the returned records will be sorted | |
| // in the descending order of the OrderDate values. | |
| orderItems.OrderID_Orders_Parent.OrderDate.Sort = Akal.QuickObjects.ObjectBase.SortTypes.Descending; | |
| orderItems.OrderID_Orders_Parent.OrderDate.SortPosition = 1; | |
| // Create join between the Orders and Customers objects. | |
| orderItems.OrderID_Orders_Parent.Join_CustomerID_Customers_Parent(); | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.UseAllFieldsForDisplay(false); | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.FirstName.Visible = true; | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.Visible = true; | |
| // the following line changes the resulting columns display name to "First Name" instead of the default FirstName | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.FirstName.ResultSetName = "First Name"; | |
| // the following line changes the resulting columns display name to "Last Name" instead of the default LastName | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.ResultSetName = "Last Name"; | |
| // LastName will be used in sorting the result set after the OrderDate. | |
| // Resulting records will be sorted in the ascending order of LastName after OrderDate in the descending order. | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.Sort = Akal.QuickObjects.ObjectBase.SortTypes.Ascending; | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.SortPosition = 2; | |
| orderItems.Find(); | |
| if (orderItems.AffectedRecords > 0) | |
| { | |
| this.GridView.DataSource = orderItems.ResultSet; | |
| this.GridView.DataMember = orderItems.GetResultSetName(); | |
| } | |
| } | |
| Using orderItems As OrderItems = New OrderItems() | |
| orderItems.ObjectMode = Akal.QuickObjects.ObjectBase.ObjectModes.Search | |
| ' customize what fields are shown | |
| orderItems.UseAllFieldsForDisplay(False) | |
| orderItems.Quantity.Visible = True | |
| orderItems.ItemAmount.Visible = True | |
| ' the following line changes the resulting columns display name to "Sub Total" instead of the default ItemAmount | |
| orderItems.ItemAmount.ResultSetName = "Sub Total" | |
| ' create join between the OrderItems and Products (a parent object) | |
| orderItems.Join_ProductID_Products_Parent() | |
| ' customize what fields are shown from the Products object i.e. Only the ProductName is shown. | |
| orderItems.ProductID_Products_Parent.UseAllFieldsForDisplay(False) | |
| orderItems.ProductID_Products_Parent.ProductName.Visible = True | |
| ' the following line changes the resulting columns display name to "Product" instead of the default ProductName | |
| orderItems.ProductID_Products_Parent.ProductName.ResultSetName = "Product" | |
| ' create join between OrderItems and Orders | |
| orderItems.Join_OrderID_Orders_Parent() | |
| ' customize what fields are shown from the Orders object. | |
| orderItems.OrderID_Orders_Parent.UseAllFieldsForDisplay(False) | |
| orderItems.OrderID_Orders_Parent.OrderDate.Visible = True | |
| ' OrderDate from the Orders object will be used for searching | |
| orderItems.OrderID_Orders_Parent.OrderDate.Value = Akal.QuickObjects.TimeZones.DateCalculations.GetStartOfLastYear(DateTime.Now) | |
| orderItems.OrderID_Orders_Parent.OrderDate.Operator = " >= " | |
| ' the following line changes the resulting columns display name to "Date Ordered" instead of the default OrderDate | |
| orderItems.OrderID_Orders_Parent.OrderDate.ResultSetName = "Date Ordered" | |
| ' OrderDate will also be used for sorting the result set and all the returned records will be sorted | |
| ' in the descending order of the OrderDate values. | |
| orderItems.OrderID_Orders_Parent.OrderDate.Sort = Akal.QuickObjects.ObjectBase.SortTypes.Descending | |
| orderItems.OrderID_Orders_Parent.OrderDate.SortPosition = 1 | |
| ' Create join between the Orders and Customers objects. | |
| orderItems.OrderID_Orders_Parent.Join_CustomerID_Customers_Parent() | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.UseAllFieldsForDisplay(False) | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.FirstName.Visible = True | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.Visible = True | |
| ' the following line changes the resulting columns display name to "First Name" instead of the default FirstName | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.FirstName.ResultSetName = "First Name" | |
| ' the following line changes the resulting columns display name to "Last Name" instead of the default LastName | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.ResultSetName = "Last Name" | |
| ' LastName will be used in sorting the result set after the OrderDate. | |
| ' Resulting records will be sorted in the ascending order of LastName after OrderDate in the descending order. | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.Sort = Akal.QuickObjects.ObjectBase.SortTypes.Ascending | |
| orderItems.OrderID_Orders_Parent.CustomerID_Customers_Parent.LastName.SortPosition = 2 | |
| orderItems.Find() | |
| If orderItems.AffectedRecords > 0 Then | |
| Me.GridView.DataSource = orderItems.ResultSet | |
| Me.GridView.DataMember = orderItems.GetResultSetName() | |
| End If | |
| End Using | |

