In this tutorial I'll explain how you can simply add State management to your application.
State management can be used to keep track of the state of different entitities, these states can be used as filters in the display grids,
as triggers for workflow processes or used in your own custom code to do anything you (or your customers) can imagine.
In this example I will add a state to a loan application form, so employees of this loan company can easily approve the registered loan applications with a single mouse-click.
1. Login to the 42Windmills.com designer.
2. Create the Loan application entity.
When creating the entity make sure you set the HasState property to
Yes (see screenshot)
I didn't add any extra fields for this tutorial, but you'll get the idea.
As you can see, the form will automatically have the "State" field added to it.
Navigate to the Ribbon designer (top of the page).
Pick the area on which you want to add the SetState button, in our example this would be 'Loans'
1. Create a new section, name it Applications (or any other name)
2. Create a new button in this section,
3. Name this button "Approve" (or any other name)
4. Choose the action type, pick Set State
5. Choose the entity that you want to have the State changed by this button
6. Pick a name for your new state, in this case I picked "Approved"
7. Save your changes :)
As you can see, this is pretty simple, and all that is needed for this button to work. You could just as easily add a button for "Declined" or any other state you may wish to use in this same fashion.
Being a developer, we would like to add some fancy stuff to this button, so in the next example I will show you how we can let the application display a message once our button is clicked.
We now have our button, but we would like to add a message for the user once he has clicked our button.
Luckily, this can be implemented really in a really simple way...
A special partial class has been generated for us in the App.Lib project in the BLL (business logic) folder.
This class will be located in the folder <area name>/<entity name>/<action name>.cs
In this example it will be Loans/newLoanApplication/SetApproved.cs
This is what our generated method looks like:
Copy code
using System;
namespace Ideabase
{
partial class newLoanApplicationEntity
{
///
/// Sets the state of the newLoanApplicationEntity to Approved
///
/// The user requesting the state change
public bool SetApproved(UserEntity user, out string message)
{
// user cannot be null, or SetState will fail
if (user == null)
throw new ArgumentNullException("user");
// TODO: Add checks and conditions to set the state of the
//newLoanApplicationEntity to Approved
this.SetState("Approved", user);
message = string.Empty;
return true;
}
}
}
If we want to display a message, all we have to do is fill the "message" variable and presto, message implemented :)
So we change the message = string.Empty; to message = "Thank you for approving this loan";
Copy code
using System;
namespace Ideabase
{
partial class newLoanApplicationEntity
{
///
/// Sets the state of the newLoanApplicationEntity to Approved
///
/// The user requesting the state change
public bool SetApproved(UserEntity user, out string message)
{
// user cannot be null, or SetState will fail
if (user == null)
throw new ArgumentNullException("user");
// TODO: Add checks and conditions to set the state of the
//newLoanApplicationEntity to Approved
this.SetState("Approved", user);
message = "Thank you for approving this loan";
return true;
}
}
}
The end application will look something like this:
This would also be the place to implement your other business logic, like using a webservice to check the credit rate of the applicant,
or generating an email message to inform the applicant of the approval or anything else you can think of.
Good luck building your state aware 42Windmills.com applications!