Beispiel #1
0
        private void OpenEntityScreen(IBqlTable entity, PXRedirectHelper.WindowMode windowMode)
        {
            if (entity == null)
            {
                return;
            }

            PXPrimaryGraphCollection primaryGraph = new PXPrimaryGraphCollection(Base);

            PXRedirectHelper.TryRedirect(primaryGraph[entity], entity, windowMode);
        }
        public virtual IEnumerable openContact(PXAdapter adapter)
        {
            var entity = this.Caches[typeof(SMPersonalDataIndex)].Current as SMPersonalDataIndex;

            if (entity == null)
            {
                return(adapter.Get());
            }

            var primary = RemapToPrimary(new List <SMPersonalDataIndex> {
                entity
            });

            foreach (IBqlTable table in primary)
            {
                if (table is Contact)
                {
                    PXPrimaryGraphCollection primaryGraph = new PXPrimaryGraphCollection(this);

                    PXGraph graph = primaryGraph[table];

                    PXRedirectHelper.TryRedirect(graph, table, PXRedirectHelper.WindowMode.New);
                }
                else if (table is CRContact)
                {
                    var opp = new PXSelect <
                        CROpportunity,
                        Where <CROpportunity.opportunityContactID, Equal <Required <CRContact.contactID> > > >(this)
                              .SelectSingle((table as CRContact).ContactID);

                    var graph = PXGraph.CreateInstance <OpportunityMaint>();
                    PXRedirectHelper.TryRedirect(graph, opp, PXRedirectHelper.WindowMode.New);
                }
            }

            return(adapter.Get());
        }
Beispiel #3
0
        protected void MergeDuplicates(int targetID, List <TMain> duplicateEntities, List <FieldValue> values, bool IsContractBasedAPI)
        {
            TMain targetEntity = GetTargetEntity(targetID);

            object realTargetEntity = targetEntity;
            var    graphType        = new EntityHelper(Base).GetPrimaryGraphType(ref realTargetEntity, false);

            if (graphType == null)
            {
                return;
            }

            PXGraph targetGraph = PXGraph.CreateInstance(graphType);

            PXCache cache = targetGraph.Caches[typeof(TMain)];

            var refNoteIdField = EntityHelper.GetNoteField(cache.GetItemType());

            realTargetEntity = cache.CreateCopy(realTargetEntity);

            Contact targetContact = GetTargetContact(targetEntity);
            Address targetAddress = GetTargetAddress(targetEntity);

            Dictionary <Type, object> targets = new Dictionary <Type, object>
            {
                [typeof(TMain)]   = realTargetEntity,
                [typeof(Contact)] = targetContact,
                [typeof(Address)] = targetAddress
            };

            foreach (FieldValue fieldValue in values)
            {
                if (fieldValue.AttributeID == null)
                {
                    Type         type  = Type.GetType(fieldValue.CacheName);
                    PXFieldState state = (PXFieldState)targetGraph.Caches[type].GetStateExt(targets[type], fieldValue.Name);
                    if (state == null || !Equals(state.Value, fieldValue.Value))
                    {
                        targetGraph.Caches[type].SetValueExt(targets[type], fieldValue.Name, fieldValue.Value);
                        targets[type] = targetGraph.Caches[type].CreateCopy(targetGraph.Caches[type].Update(targets[type]));
                    }
                }
                else
                {
                    PXCache   attrCache = cache.Graph.Caches[typeof(CSAnswers)];
                    CSAnswers attr      = new CSAnswers
                    {
                        AttributeID = fieldValue.AttributeID,
                        RefNoteID   = cache.GetValue(targetEntity, refNoteIdField) as Guid?,
                        Value       = fieldValue.Value,
                    };

                    Dictionary <string, object> keys = new Dictionary <string, object>();
                    foreach (string key in attrCache.Keys.ToArray())
                    {
                        keys[key] = attrCache.GetValue(attr, key);
                    }


                    if (attrCache.Locate(keys) == 0)
                    {
                        attrCache.Insert(attr);
                    }
                    else
                    {
                        var located = attrCache.Locate(attr) as CSAnswers;
                        located.Value = attr.Value;
                        attrCache.Update(located);
                    }
                }
            }

            PXPrimaryGraphCollection primaryGraph = new PXPrimaryGraphCollection(targetGraph);

            using (PXTransactionScope scope = new PXTransactionScope())
            {
                foreach (TMain duplicateEntity in duplicateEntities)
                {
                    // only int, only single field
                    if (cache.GetValue(duplicateEntity, cache.Keys[0]) as int? == targetID)
                    {
                        continue;
                    }

                    targetGraph.Caches[realTargetEntity.GetType()].Current = realTargetEntity;

                    MergeEntities(targetGraph, realTargetEntity as TMain, duplicateEntity);

                    targetGraph.Actions.PressSave();

                    PXGraph operGraph = primaryGraph[duplicateEntity];

                    RunActionWithAppliedAutomation(operGraph, duplicateEntity, nameof(CloseAsDuplicate));

                    operGraph.Actions.PressSave();
                }

                scope.Complete();
            }

            // should become validated if no possible duplicates
            Base.Views[Base.PrimaryView].Cache.Current = targetEntity;

            Base.Actions.PressCancel();

            RunActionWithAppliedAutomation(Base, targetEntity, nameof(CheckForDuplicates));

            if (!IsContractBasedAPI)
            {
                RunActionWithAppliedAutomation(targetGraph, realTargetEntity, "Cancel");

                throw new PXRedirectRequiredException(targetGraph, "");
            }
        }