protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { var tenants = GetPossibleTenants(); CurrentTenantField.SetBusinessObjectList(tenants); var currentTenant = SecurityManagerPrincipal.Current.Tenant; CurrentTenantField.LoadUnboundValue(currentTenant, false); bool isCurrentTenantTheOnlyTenantInTheCollection = tenants.Length == 1 && currentTenant != null && tenants[0].ID.Equals(currentTenant.ID); bool isCurrentTenantTheOnlyTenant = tenants.Length == 0 && currentTenant != null; bool hasExactlyOneTenant = isCurrentTenantTheOnlyTenantInTheCollection || isCurrentTenantTheOnlyTenant; IsTenantSelectionEnabled = !hasExactlyOneTenant; var substitutions = GetPossibleSubstitutions(); CurrentSubstitutionField.SetBusinessObjectList(substitutions); var currentSubstitution = SecurityManagerPrincipal.Current.Substitution; CurrentSubstitutionField.LoadUnboundValue(currentSubstitution, false); IsSubstitutionSelectionEnabled = substitutions.Length > 0; } if (!IsTenantSelectionEnabled) { CurrentTenantField.Command.Type = CommandType.None; } if (!IsSubstitutionSelectionEnabled) { CurrentSubstitutionField.Command.Type = CommandType.None; } }
protected void CurrentSubstitutionField_SelectionChanged(object sender, EventArgs e) { string substitutionID = CurrentSubstitutionField.BusinessObjectUniqueIdentifier; var possibleSubstitutions = GetPossibleSubstitutions(); CurrentSubstitutionField.SetBusinessObjectList(possibleSubstitutions); if (substitutionID != null && !possibleSubstitutions.Where(s => s.UniqueIdentifier == substitutionID).Any()) { CurrentSubstitutionField.Value = null; _isCurrentSubstitutionFieldReadOnly = false; return; } var oldSecurityManagerPrincipal = SecurityManagerPrincipal.Current; var newSecurityManagerPrincipal = ApplicationInstance.SecurityManagerPrincipalFactory.Create( oldSecurityManagerPrincipal.Tenant.Handle, oldSecurityManagerPrincipal.User.Handle, substitutionID != null ? ObjectID.Parse(substitutionID).GetHandle <Substitution>() : null); ApplicationInstance.SetCurrentPrincipal(newSecurityManagerPrincipal); _isCurrentSubstitutionFieldReadOnly = true; CurrentSubstitutionField.IsDirty = false; }
protected void CurrentSubstitutionField_CommandClick(object sender, BocCommandClickEventArgs e) { _isCurrentSubstitutionFieldReadOnly = false; CurrentSubstitutionField.SetBusinessObjectList(GetPossibleSubstitutions()); CurrentSubstitutionField.LoadUnboundValue(SecurityManagerPrincipal.Current.Substitution, false); }