private static Type GetEntityInterfaceTypeFromInstance(IPersistentEntity entity) { return(entity .GetType() .GetInterfaces() .FirstOrDefault(type => type.FullName.StartsWith("Sage.Entity.Interfaces."))); }
/// <summary> /// Handles the ClickAction event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnSave_ClickAction(object sender, EventArgs e) { IPersistentEntity persistentEntity = BindingSource.Current as IPersistentEntity; _parentEntity = GetParentEntity() as IPersistentEntity; _parentEntityReference = _parentEntity as IComponentReference; if (persistentEntity != null) { bool hasContactMatches = false; IAddress address = (IAddress)BindingSource.Current; if (_parentEntity != null) { address.EntityType = _parentEntity.GetType().Name; } if (Mode.Value == "ADD") { persistentEntity.Save(); } if (Mode.Value == "UPDATE") { IContact contact = _parentEntityReference as IContact; IAccount account = _parentEntityReference as IAccount; bool hasSalesOrderMatches = (Helpers.HasMatchingSalesOrderAddresses(_parentEntityReference)); if (contact != null) { hasContactMatches = contact.HasAddressChanges(); } else if (account != null) { hasContactMatches = account.HasAddressChanges(); } if ((hasContactMatches || hasSalesOrderMatches) && DialogService != null) { UpdateAddressOptionManager addressOptions = new UpdateAddressOptionManager(); addressOptions.HasContactAddressChanges = hasContactMatches; addressOptions.OldAddressValues = contact != null ? Rules.getOriginalAddressValues( contact) : Sage.SalesLogix.Account.Rules.getOriginalAddressValues( account); addressOptions.HasSalesOrderAddressChanges = hasSalesOrderMatches; addressOptions.ParentEntityReference = _parentEntityReference; addressOptions.IsPrimaryAddress = (address.IsPrimary ?? false); DialogService.SetSpecs(200, 200, 200, 450, contact != null ? "UpdateContactOptions" : "UpdateAccountOptions", "", true); DialogService.EntityType = typeof(IAddress); DialogService.EntityID = address.Id.ToString(); DialogService.DialogParameters.Add("UpdateAddressOptionManager", addressOptions); DialogService.ShowDialog(); } persistentEntity.Save(); } } UpdateFlags(); btnSave_ClickActionBRC(sender, e); }