Quick Objects Documentation Akal Tech Logo
Control And Flexibility

Glossary Item Box

Business Logic Framework - Tutorial 24:

Centralizing the business logic in a typical fashion can result in lack of control and flexibility for the user interface developer. The approach offered by the Business Logic Framework ensures that the control and flexibility is always in the architects' and developers' hands. The target of this tutorial is to demonstrate that you can leverage the centralized logic and additionally do further processing based on your requirements.

1 using (Users user = new Users())  
2 {  
3     string userName = tlsUserName.Text;  
4     if (!String.IsNullOrEmpty(userName))  
5     {  
6         // LoadByUserName method that we custom wrote in the CustomizedUsers.cs file in the BusinessLogicLayer  
7         // loads the Users object from a given user name and loads the Roles and any associated Customer + Order records.  
8         // LoadByUserName method only searches for records that are active i.e. IsActive is true  
9         // To be able to add additional criteria and modify the behavior, we can do something like the following:  
10         user.CaseConversion = CaseTypes.Upper;  
11           
12         // We can further control the user object by specifying additional criteria that will be used while searching for additional users.  
13         user.IsLockedOut.Value = false;  
14         user.IsLockedOut.UseInSearch = true;  
15  
16         // The above three lines demonstrate that you can excersice extreme amount of control over your business objects even after you have  
17         // centralized your logic. This can be very useful when you have something that is very specific to your interface and is not a fit  
18         // for a global change or addition to the centralized logic.  
19  
20         Users.MembershipStatus result = user.LoadByUserName(userName);  
21         if (result != Users.MembershipStatus.Success)  
22         {  
23             switch (result)  
24             {  
25                 case Users.MembershipStatus.InvalidUserName:  
26                     {  
27                         MessageBox.Show(userName + " is not a valid user name");  
28                         break;  
29                     }  
30                 default:  
31                     {  
32                         if (!String.IsNullOrEmpty(user.ErrorString))  
33                         {  
34                             MessageBox.Show("Error: " + user.ErrorString);  
35                         }  
36                         else 
37                         {  
38                             MessageBox.Show("Unable to load the user information. Please try again!");  
39                         }  
40                         break;  
41                     }  
42             }  
43         }  
44         else 
45         {  
46             MessageBox.Show("User loaded");  
47             if (user.UserID_UserRoles_Child != null)  
48             {  
49                 // Since the LoadByUserName created a join with the UserID_UserRoles_Child object instance the ResultSet properties of both the user and UserID_UserRoles_Child instances share the same data.  
50                 this.dgvRoles.DataSource = user.UserID_UserRoles_Child.ResultSet;  
51                 // The shared data set has multiple tables and hence we need to set the DataMember property with the name of the table in the data set that corrosponds to the UserID_UserRoles_Child object instance.  
52                 this.dgvRoles.DataMember = user.UserID_UserRoles_Child.GetResultSetName();  
53             }  
54             if (user.UserID_Customers_Child != null)  
55             {  
56                 // Since the UserID_Customers_Child (Customers) object also has a join with the CustomerID_Orders_Child (Orders) and Find method will automatically include all the visible fields from the Orders object   
57                 // into the result set of the Customers object. So in this case we get all Customer+Orders records in one table for the User record that was just loaded.  
58                 this.dgvOrders.DataSource = user.UserID_Customers_Child.ResultSet;  
59                 this.dgvOrders.DataSource = user.UserID_Customers_Child.GetResultSetName();  
60             }  
61         }  
62     }  
63     else 
64     {  
65         MessageBox.Show("User name must be specified!");  
66     }  
67 }  
68  
1 Using user As Users = New Users()  
2     Dim userName As String = tlsUserName.Text  
3     If Not [String].IsNullOrEmpty(userName) Then 
4         ' LoadByUserName method that we custom wrote in the CustomizedUsers.cs file in the BusinessLogicLayer  
5         ' loads the Users object from a given user name and loads the Roles and any associated Customer + Order records.  
6         ' LoadByUserName method only searches for records that are active i.e. IsActive is true  
7         ' To be able to add additional criteria and modify the behavior, we can do something like the following:  
8         user.CaseConversion = CaseTypes.Upper  
9  
10         ' We can further control the user object by specifying additional criteria that will be used while searching for additional users.  
11         user.IsLockedOut.Value = True 
12         user.IsLockedOut.UseInSearch = True 
13  
14         ' The above three lines demonstrate that you can excersice extreme amount of control over your business objects even after you have  
15         ' centralized your logic. This can be very useful when you have something that is very specific to your interface and is not a fit  
16         ' for a global change or addition to the centralized logic.  
17  
18         Dim result As Users.MembershipStatus = user.LoadByUserName(userName)  
19         If result <> Users.MembershipStatus.Success Then 
20             Select Case result  
21                 Case Users.MembershipStatus.InvalidUserName  
22                     MessageBox.Show(userName + " is not a valid user name")  
23                     Exit Select 
24                 Case Else 
25                     If Not [String].IsNullOrEmpty(user.ErrorString) Then 
26                         MessageBox.Show("Error: " + user.ErrorString)  
27                     Else 
28                         MessageBox.Show("Unable to load the user information. Please try again!")  
29                     End If 
30                     Exit Select 
31             End Select 
32         Else 
33             MessageBox.Show("User loaded")  
34             If user.UserID_UserRoles_Child IsNot Nothing Then 
35                 ' Since the LoadByUserName created a join with the UserID_UserRoles_Child object instance the ResultSet properties of both the user and UserID_UserRoles_Child instances share the same data.  
36                 Me.dgvRoles.DataSource = user.UserID_UserRoles_Child.ResultSet  
37                 ' The shared data set has multiple tables and hence we need to set the DataMember property with the name of the table in the data set that corrosponds to the UserID_UserRoles_Child object instance.  
38                 Me.dgvRoles.DataMember = user.UserID_UserRoles_Child.GetResultSetName()  
39             End If 
40             If user.UserID_Customers_Child IsNot Nothing Then 
41                 ' Since the UserID_Customers_Child (Customers) object also has a join with the CustomerID_Orders_Child (Orders) and Find method will automatically include all the visible fields from the Orders object  
42                 ' into the result set of the Customers object. So in this case we get all Customer+Orders records in one table for the User record that was just loaded.  
43                 Me.dgvOrders.DataSource = user.UserID_Customers_Child.ResultSet  
44                 Me.dgvOrders.DataSource = user.UserID_Customers_Child.GetResultSetName()  
45             End If 
46         End If 
47     Else 
48         MessageBox.Show("User name must be specified!")  
49     End If 
50 End Using  
51