When entering client information into tables, many of the clients may have the same value such as VAT rate, payment terms or membership status. Many clients will all have the same default value in these fields except for the odd few which are the exception. To enable quicker data entry we can add a default flag to the administration tables so that when a new client record is created the system will automatically pull through the default value into these fields against the client.
Within your Administration Item XAF Business Object is necessary to add an IsDefault Boolean as shown below:
/// <summary> /// The administration item name /// </summary> private string administrationItemName; /// <summary> /// The is default /// </summary> private bool isDefault; /// <summary> /// Initializes a new instance of the <see cref="AdministrationItem"/> class. /// </summary> /// <param name="session">An object which represents a persistent object's cache where the business object will be instantiated.</param> public AdministrationItem(Session session) : base(session) /// <summary> /// Gets or sets the name of the administration item. /// </summary> /// <value> /// The name of the administration item. /// </value> [Size(100)] public string AdministrationItemName get return this.administrationItemName; set this.SetPropertyValue<string>("AdministrationItemName", ref this.administrationItemName, value); /// <summary> /// Gets or sets a value indicating whether this instance is default. /// </summary> /// <value> /// <c>true</c> if this instance is default; otherwise, <c>false</c>. /// </value> public bool IsDefault get return this.isDefault; set this.SetPropertyValue<bool>("IsDefault", ref this.isDefault, value);
/// <summary> /// Invoked when the current object is about to be initialized after its creation. /// </summary> public override void AfterConstruction() base.AfterConstruction(); this.isDefault = false;
/// <summary> /// Initializes a new instance of the <see cref="AdministrationItemViewController"/> class. /// </summary> public AdministrationItemViewController() this.InitializeComponent(); this.RegisterActions(this.components); this.TargetObjectType = typeof(AdministrationItem); /// <summary> /// Called when [activated]. /// </summary> protected override void OnActivated() base.OnActivated(); this.ObjectSpace.Committing += new EventHandler<System.ComponentModel.CancelEventArgs>(this.ObjectSpace_Committing); /// <summary> /// Called when [deactivated]. /// </summary> protected override void OnDeactivated() base.OnDeactivated(); this.ObjectSpace.Committing -= this.ObjectSpace_Committing; /// <summary> /// Handles the Committing event of the ObjectSpace control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param> protected void ObjectSpace_Committing(object sender, System.ComponentModel.CancelEventArgs e) List<AdministrationItem> administrationItems = this.ObjectSpace.GetObjectsToSave(false).OfType<AdministrationItem>().ToList(); foreach (AdministrationItem administrationItem in administrationItems) if (administrationItem.IsDefault) this.ResetDefaults(administrationItem); /// <summary> /// Resets the defaults. /// </summary> /// <param name="administrationItem">The administration item.</param> private void ResetDefaults(AdministrationItem administrationItem) List<AdministrationItem> defaultAdministrationItems = this.ObjectSpace.GetObjects<AdministrationItem>(CriteriaOperator.Parse(string.Format("IsDefault == true and Oid != '0
'", administrationItem.Oid.ToString()))).ToList(); foreach (AdministrationItem defaultAdministrationItem in defaultAdministrationItems) defaultAdministrationItem.IsDefault = false; defaultAdministrationItem.Save();
/// <summary> /// Invoked when the current object is about to be initialized after its creation. /// </summary> public override void AfterConstruction() base.AfterConstruction(); this.administrationItemId = this.Session.FindObject<AdministrationItem>(CriteriaOperator.Parse("IsDefault == true"));
We'd love to welcome you into our office! We're only 20 miles north of Peterborough, conveniently just off the A16.
Carver House
Apex Court, Elsoms Way
Pinchbeck
Lincolnshire
PE11 3UL