Represents the method that will handle BeforeDataReceive and BeforeDataSend events of the form.
Syntax
public delegate void FormDataTransformEventHandler( object sender, FormDataTransformEventArgs e )
Parameters
sender
Type: System.Object
The delegate method is called by the eForm but the sender parameter is always null.
e
Type: Neurodot.Forms.Silverlight.Render.Interfaces.FormDataTransformEventArgs
The event data.
Example
In this example the current form is a response to another form’s submission to Government Gateway. The form has a Code block that defines event handlers for eForm’s events Loaded, BeforeDataReceive and BeforeDataSend. The incoming response data are filled to some prepared controls on the form (user info controls, two CheckBoxes and two DataGrids).
The response XML data looks like this:
<Body Id="0" xmlns="http://www.govtalk.gov.uk/CM/envelope"> <Message xmlns="http://gateway.gov/schema/common/v1"> <Body> <PropertySearchResponse xmlns="http://gateway.gov/schema/moi/ls/v1"> <Applicant> <Identity> <Number xmlns="http://gateway.gov/schema/common/v1">111111</Number> </Identity> <FirstName>John</FirstName> <LastName>Smith</LastName> <IsRepresentativeOrAdministrator>true</IsRepresentativeOrAdministrator> </Applicant> <ls:Delivery Source="Gilys" xmlns:ls="http://gateway.gov/schema/moi/ls/v1"> <ls:ExistingAddress>123th street 3A, apartment AB Larnaca, Cyprus </ls:ExistingAddress> </ls:Delivery> <Properties> <IsEnabled>true</IsEnabled> <Property> <District>District1</District> <Quarter>Quarter1</Quarter> <RegistrationBlock>Block</RegistrationBlock> <RegistrationNo>123</RegistrationNo> <Address>1st Street</Address> </Property> <Property> <District>District 2</District> <Quarter>Qtr 2</Quarter> <RegistrationBlock>Another block</RegistrationBlock> <RegistrationNo>456</RegistrationNo> <Address>23rd Street</Address> </Property> </Properties> </PropertySearchResponse> </Body> </Message> </Body>
The code example assumes that both DataGrids have defined the same number of columns with exactly the same types and names. The code looks like this:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
using System.Xml.XPath;
using Neurodot.Forms.Silverlight.Controls;
using Neurodot.Forms.Silverlight.Render.Interfaces;
#region Form Fields
static NDTextBox txtName;
static NDTextBox txtSurname;
static NDTextBox txtCivilId;
static CheckBox chkAgent;
static CheckBox chkProps1;
static CheckBox chkProps2;
static NDDataGrid dgProps1;
static NDDataGrid dgProps2;
static XElement xmlDeliveryCache;
#endregion
public class FormDataTransform
{
public void OnFormLoaded(object sender, RoutedEventArgs e)
{
// find control instance references
dgProps1 = ThisForm.FindElement<NDDataGrid>("Properties1_Grid");
dgProps2 = ThisForm.FindElement<NDDataGrid>("Properties2_Grid");
chkProps1 = ThisForm.FindElement<CheckBox>("Properties1_Chk_Enabled");
chkProps2 = ThisForm.FindElement<CheckBox>("Properties2_Chk_Enabled");
chkAgent = ThisForm.FindElement<CheckBox>("Aplicant_Chk_IsAgent");
txtName = ThisForm.FindElement<NDTextBox>("Applicant_Txt_Name");
txtSurname = ThisForm.FindElement<NDTextBox>("Applicant_Txt_Surname");
txtCivilId = ThisForm.FindElement<NDTextBox>("Applicant_Txt_CivilId");
txtAgentsId = ThisForm.FindElement<NDTextBox>("Applicant_Txt_AgentsId");
}
public static void OnFormBeforeDataReceive(object sender, FormDataTransformEventArgs e)
{
XNamespaceResolver xresolver = new XNamespaceResolver();
xresolver.AddNamespace("com", "http://gateway.gov/schema/common/v1");
xresolver.AddNamespace("ls", "http://gateway.gov/schema/moi/ls/v1");
XElement xResp = e.Data.XPathSelectElement("//ls:PropertySearchResponse", xresolver);
if (xResp == null)
return;
// fill applicant information
XElement xAplc = xResp.XPathSelectElement("ls:Applicant", xresolver);
if (xAplc != null)
{
txtName.Text = xAplc.XPathSelectElement("ls:FirstName", xresolver).Value;
txtSurname.Text = xAplc.XPathSelectElement("ls:LastName", xresolver).Value;
txtCivilId.Text = xAplc.XPathSelectElement("ls:Identity/com:Number", xresolver).Value;
chkAgent.IsChecked = Convert.ToBoolean(
xAplc.XPathSelectElement("ls:IsRepresentativeOrAdmin", xresolver).Value
);
}
// cache the delivery address xml
xmlDeliveryCache = xResponse.XPathSelectElement("ls:Delivery", xresolver);
if (xmlDeliveryCache != null)
xmlDeliveryCache = XElement.Parse(_deliveryXML.ToString());
// fill properties controls
XElement xProps = xResponse.XPathSelectElement("ls:Properties", xresolver);
if (xProps != null)
{
// fill check boxes
bool check = Convert.ToBoolean(
xProps.XPathSelectElement("ls:IsEnabled", xresolver).Value);
NDDataGrid[] propsGrids = new NDDataGrid[2] { dgProps1, dgProps1 };
chkProps1.IsChecked = check;
chkProps2.IsChecked = check;
// remove existing rows in property grids
dgProps1.DataSource = null;
dgProps2.DataSource = null;
// fill property grids
foreach (var xprop in xProps.XPathSelectElements("ls:Property", xresolver))
{
// get xml data
string district = xprop.XPathSelectElement("ls:District", xresolver).Value,
quarter = xprop.XPathSelectElement("ls:Quarter", xresolver).Value,
regBlock = xprop.XPathSelectElement("ls:RegistrationBlock", xresolver).Value,
regNo = xprop.XPathSelectElement("ls:RegistrationNo", xresolver).Value,
address = xprop.XPathSelectElement("ls:Address", xresolver).Value;
// fill data grids
foreach (NDDataGrid grid in propsGrids)
{
Row row = grid.AddRow();
row["TextColumnDisctrict"] = district;
row["TextColumnQuarter"] = quarter;
row["TextColumnRegBlock"] = regBlock;
row["TextColumnRegNo"] = regNo;
row["TextColumnStreet"] = address;
}
}
}
}
public static void OnBeforeFormDataSend(object sender, FormDataTransformEventArgs e)
{
XNamespaceResolver xresolver = new XNamespaceResolver();
xresolver.AddNamespace("ls", "http://gateway.gov/schema/moi/ls/v1");
// insert the cached delivery data
XElement xDelivery =
e.Data.XPathSelectElement("ls:PropertySearchResponse/ls:Delivery", xresolver);
if (xDelivery != null)
xDelivery.ReplaceWith(xmlDeliveryCache);
}
}