Static Facade Object

 

Example of a static facade object in the Object page of the Toolkit. Note that the typename is notAvectra.netForum.Data.DynamicFacade, and also observe that there are no records in the Data Objects child form

Static Facade Classes are subclasses of Avectra.netForum.Data.FacadeClass. Static Facade Classes were developed by Abila to run more advanced business logic.

Static Facade Object Override

This page contains a code sample illustrating how to override a Static Facade Object.

Important! Overriding a static Facade Object is a powerful way to implement custom business rules but needs to be done carefully. Abila recommends submitting your code for review to Abila to ensure compatibility with baseline and to help minimize any potential issues.

Code

This code overrides the baseline Avectra.netForum.Components.AC.InvoiceDetail class. You will add references to:

  • Common.dll
  • Data.dll
  • Components.dll

What this code does is return an error if a customer is buying a subscription that puts them over a limit of two subscriptions. You would have this rule if you want to allow people to have at most two subscriptions.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using Avectra.netForum.Data;
using Avectra.netForum.Common;
using Avectra.netForum.Components;
using Avectra.netForum.Components.AC;
using System.Xml.Serialization;
 
namespace AUDC2008Components
{
[Serializable()]
[XmlSchemaProvider("FacadeSchema")]
public class AUDCInvoiceDetail : Avectra.netForum.Components.AC.InvoiceDetail, IXmlSerializable
{
 
/// Set this property to call Workflow Rules from parent object
this.bExecuteInheritedWorkflow = true;
public override ErrorClass Insert(OleDbConnection CurrentConnection, OleDbTransaction CurrentTransaction)
{
ErrorClass oEr = new ErrorClass();
if (this.GetValue("ivd_prc_prd_ptp_key") == Config.GetSystemOption("DefaultProductTypeForSubscription"))
{
if (AUDCUtility.GetIndividualSubscriptionCount(this.GetValue("ivd_cst_ship_key"), CurrentConnection, CurrentTransaction) >= 2)
{
oEr.Message = "Error: Customer is over subscription maximum count.";
oEr.Number = (int)ErrorClass.ErrorNumber.GeneralError;
oEr.Level = ErrorClass.ErrorLevel.Error;
}
}
 
if (oEr.Number == (int)ErrorClass.ErrorNumber.NoError)
{
return base.Insert(CurrentConnection, CurrentTransaction);
}
else
{
return oEr;
}
}
}
}

This code calls a method called AUDCUtility.GetIndividualSubscriptionCount shown here:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using Avectra.netForum.Common;
using Avectra.netForum.Data;
using System.Xml.Serialization;
 
namespace AUDC2008Components
{
public struct AUDCUtility
{
/// <summary>
/// Returns the count of active subscriptions of a Customer
/// </summary>
/// <param name="szcst_key">Customer Key</param>
/// <param name="CurrentConnection"></param>
/// <param name="CurrentTransaction"></param>
/// <returns></returns>
public static Int32 GetIndividualSubscriptionCount(string szcst_key, OleDbConnection CurrentConnection, OleDbTransaction CurrentTransaction)
{
#region manage connection
// establish local Connection
OleDbConnection oConn;
 
// if this method is not given a Connection then declare one
 
if (CurrentConnection == null)
oConn = DataUtils.GetConnection();
else
oConn = CurrentConnection;
if (oConn.State != ConnectionState.Open)
oConn.Open();
//****************************************************************
#endregion
 
// Execute SP to get count of subs for an individual
// There is probably a better or more efficient way to do this
string szSQL = "oe_subscription_by_ind @ind_cst_key='" + szcst_key + "'";
 
int iCount = 0;
using (OleDbDataReader oDR = DataUtils.GetDataReader(szSQL, CurrentConnection, CurrentTransaction))
{
if (Config.LastError == null)
{
if (oDR != null && oDR.Read())
{
while (oDR.Read())
{
iCount++;
}
}
}
}
 
#region manage connection
 
if (CurrentConnection == null)
oConn.Close();
#endregion
 
return iCount;
}
}
}

After building and deploying your new class, you must go into the Toolkit module of netFORUM for this Object and update the assembly and type fields with "AUDC2008Components" and "AUDC2008Components.AUDCInvoiceDetail" respectively.

.NET assembly and type name (namespace) in the Object setup

Class Declaration

The following class declaration is supported:

public class AUDCInvoiceDetail : Avectra.netForum.Components.AC.InvoiceDetail

Some static facade objects are serializable for certain xWeb purposes. In order for xWeb to function properly, overrides to these objects must include the following additional lines:

[Serializable()]
[XmlSchemaProvider("FacadeSchema")]
public class AUDCInvoiceDetail : Avectra.netForum.Components.AC.InvoiceDetail, IXmlSerializable

The revised definition inherits the IXmlSerializable interface, indicates that it is serializable, and lets the system know what static method to invoke to get the schema. The attribute [Serializable()] lets the system know that this class can be serialized. The second attribute [XmlSchemaProvider("FacadeSchema")] indicates the static method that is invoked to get the schema for the object. FacadeSchema is a static method in all the baseline objects.

If you are instantiating a new object, you must use the Avectra.netForum.Data.DataUtils.InstantiateFacadeObject method. See this page for code sample.