Access Variables in the Data Access Layer

"If your Data Access Layer customization depends on the value of a control which is not data bound, you can retrieve it with the help of the DataAccessSettings class."
- Anh Trinh, Software Engineer, Iron Speed, Inc.

December 13, 2006
Iron Speed Designer V4.0

Introduction
Iron Speed Designer-generated applications maintain strict separation between the Presentation Layer (user interface) and the Data Access Layer. While code customizations are typically added to an application’s Presentation Layer code-behind files, it is sometimes useful to add customizations in the Data Access Layer. If your Data Access Layer customization depends on the value of a control which is not data bound, you can retrieve it with the help of the DataAccessSettings class. The DataAccessSettings class can also be used to retrieve other useful information, such as the SignedInUserId and the SignedInUserName.

In the example below, the AddOrdersPage.aspx page has an ASPX text box control. The value of the text box cannot be accessed directly in the Data Access Layer, so the value is passed from the Presentation Layer to the Data Access Layer via the SystemUtils.SetDataAccessSettingsParameterValue method.

Procedure
Step 1: Handle the GetUIData() method in the RecordControl class of AddOrdersPage.aspx. Use the SetDataAccessSettingsParameterValue method to pass the value of the ASPX text box.

The SetDataAccessSettingsParameterValue method has two arguments. The first argument is a key and the second argument is its value. In the code below, “MYKEY” is the key and its value is “myKeyValue”. The SetDataAccessSettingsParameterValue method can be called in any methods and, in this example, is called in the GetUIData() event in the AddOrdersPage class.

The DataAccessSettings class is used to retrieve the value of the ASPX text box in the Data Access Layer. Override the GetUIData() method in the OrdersRecordControl class, located in:

.NET Framework 1.1:

...\<App Folder>\Orders\AddOrdersPage.Controls.cs or .vb

.NET Framework 2.0:

...\<App Folder>\App_Code\Orders\AddOrdersPage.Controls.cs or .vb

C#:

public override string ModifyRedirectUrl(string redirectUrl, string redirectArgument)
{
    string myStr = this.ShipCountry.Text + this.ShipCity.Text;
    redirectUrl = redirectUrl + "?myparam=" + myStr;
    return base.ModifyRedirectUrl(redirectUrl, redirectArgument);
}

Visual Basic .NET:

Public Overrides Function ModifyRedirectUrl(ByVal redirectUrl As String, ByVal redirectArgument As String) As String
    Dim myStr As String = (Me.ShipCountry.Text + Me.ShipCity.Text)
    redirectUrl = (redirectUrl + ("?myparam=" + myStr))
    return MyBase.ModifyRedirectUrl(redirectUrl, redirectArgument)
End Function

Step 2: Add the following code in the OrdersRecord class in the Data Access Layer. This code overrides the default constructor with a newly defined OrderRecord_InsertedRecord() method. This new method gets the DataAccessSetting object which contains the key value. In addition, the UserID and Password can be retrieved from this object.

The OrdersRecord class is located in:

.NET Framework 1.1:

...\<Application Folder>\DataAccess\OrdersRecord.cs or .vb

.NET Framework 2.0:

...\<Application Folder>\App_Code\Business Layer\OrdersRecord.cs or .vb

C#:

public OrdersRecord()
{
    this.InsertedRecord+= new
        BaseClasses.IRecordWithTriggerEvents.InsertedRecordEventHandler(OrdersRecord_InsertedRecord);
}
 
private void OrdersRecord_InsertedRecord(object sender, System.EventArgs e)
{
    DataAccessSettings dataAccessSettingsObj = DataAccessSettings.Current;
    if(dataAccessSettingsObj.ContainsKey("MYKEY"))
    {
        String myKey = (String)dataAccessSettingsObj["MYKEY"];
        String myUserID = dataAccessSettingsObj.SignedInUserId;
        String myUserName = dataAccessSettingsObj.SignedInUserName;
 
        //More code customization to fit your logic
    }
}

Visual Basic .NET:

Public Sub New()
    MyBase.New
    AddHandler InsrtedRecord, AddressOf Me.OrdersRecord_InsertedRecord
End Sub
  Private Sub OrdersRecord_InsertedRecord(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim dataAccessSettingsObj As DataAccessSettings = DataAccessSettings.Current
If dataAccessSettingsObj.ContainsKey("MYKEY") Then
        Dim myKey As String = CType(dataAccessSettingsObj("MYKEY"),String)
        Dim myUserID As String = dataAccessSettingsObj.SignedInUserId
        Dim myUserName As String = dataAccessSettingsObj.SignedInUserName
      ‘More code customization to fit your logic
      End If
End Sub

Note: You can retrieve the value of a control in any of the events available in the OrdersRecord class based on where you want to add your business logic. The events available in the OrdersRecord class are:

InsertingRecord

InsertedRecord

SavingRecord

SavedRecord

DeletingRecord

DeletedRecord

UpdatedRecord

UpdatingRecord

About the Author
Anh Trinh
Software Engineer, Iron Speed, Inc.

Anh is a software engineer at Iron Speed, Inc. He enjoys developing applications with Iron Speed Designer and Microsoft .NET technology.



  Privacy Statement