Exemplo n.º 1
0
 public static string FormatName(Zetbox.Basic.Parties.Party party)
 {
     if (party is Zetbox.Basic.Parties.Organization)
     {
         return(FormatName((Zetbox.Basic.Parties.Organization)party));
     }
     else if (party is Zetbox.Basic.Parties.Person)
     {
         return(FormatName((Zetbox.Basic.Parties.Person)party));
     }
     return(string.Empty);
 }
Exemplo n.º 2
0
        public static void AddPartyRole(Zetbox.Basic.Parties.Party obj, MethodReturnEventArgs <PartyRole> e)
        {
            var ctx        = obj.Context;
            var candidates = new List <RoleSelectionViewModel>();

            // Common first
            if (!obj.PartyRole.Any(r => r is Customer))
            {
                candidates.Add(_vmf.CreateViewModel <RoleSelectionViewModel.Factory>().Invoke(ctx, null, typeof(Customer).GetObjectClass(_frozenCtx)));
            }

            ObjectClass clsPartyRole;

            if (obj is Person)
            {
                clsPartyRole = (ObjectClass)typeof(PersonRole).GetObjectClass(_frozenCtx);

                if (!obj.PartyRole.Any(r => r is Employee))
                {
                    candidates.Add(_vmf.CreateViewModel <RoleSelectionViewModel.Factory>().Invoke(ctx, null, typeof(Employee).GetObjectClass(_frozenCtx)));
                }
            }
            else if (obj is Organization)
            {
                clsPartyRole = (ObjectClass)typeof(OrganizationRole).GetObjectClass(_frozenCtx);

                if (!obj.PartyRole.Any(r => r is Supplier))
                {
                    candidates.Add(_vmf.CreateViewModel <RoleSelectionViewModel.Factory>().Invoke(ctx, null, typeof(Supplier).GetObjectClass(_frozenCtx)));
                }
                if (!obj.PartyRole.Any(r => r is InternalOrganization))
                {
                    candidates.Add(_vmf.CreateViewModel <RoleSelectionViewModel.Factory>().Invoke(ctx, null, typeof(InternalOrganization).GetObjectClass(_frozenCtx)));
                }
            }
            else
            {
                throw new InvalidOperationException("Party is of an unknown type");
            }

            List <ObjectClass> subClasses = new List <ObjectClass>();

            clsPartyRole.CollectChildClasses(subClasses, includeAbstract: false);
            // all other
            foreach (var roleCls in subClasses.Except(candidates.Select(c => c.TargetPropClass))
                     .Except(obj.PartyRole.Select(c => c.GetObjectClass(_frozenCtx)))
                     .OrderBy(r => r.Name)
                     .ToList())
            {
                candidates.Add(_vmf.CreateViewModel <RoleSelectionViewModel.Factory>().Invoke(ctx, null, roleCls));
            }

            var selectClass = _vmf
                              .CreateViewModel <SimpleSelectionTaskViewModel.Factory>()
                              .Invoke(
                ctx,
                null,
                candidates,
                (chosenClass) =>
            {
                if (chosenClass != null && chosenClass.Count() == 1)
                {
                    var propCls = ((RoleSelectionViewModel)chosenClass.Single()).TargetPropClass;
                    var ifType  = propCls.GetDescribedInterfaceType();
                    var newRole = (PartyRole)ctx.Create(ifType);
                    obj.PartyRole.Add(newRole);
                    var partyVmdl = (PartyViewModel)DataObjectViewModel.Fetch(_vmf, ctx, null, obj);
                    partyVmdl.UpdateRoleTabs(newRole);
                    e.Result = newRole;         // show result, UpdateTabs cannot show the new tab yet
                }
            },
                null);

            selectClass.RequestedKind = NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_DataObjectSelectionTaskSimpleKind.Find(_frozenCtx);
            _vmf.ShowDialog(selectClass);
        }