protected virtual void Account_CuryID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Account acct = cache.Locate(e.Row) as Account;

            string newCuryID = (string)e.NewValue;

            if (acct != null && string.IsNullOrEmpty(acct.CuryID) && !string.IsNullOrEmpty(newCuryID))
            {
                if (!PostedTransInOtherCuryExists(acct, newCuryID))
                {
                    return;
                }
            }

            if (acct != null && acct.CuryID != newCuryID)
            {
                if (newCuryID != null || acct.IsCashAccount == true)
                {
                    bool hasHistory = GLUtility.IsAccountHistoryExist(this, acct.AccountID);
                    if (hasHistory)
                    {
                        throw new PXSetPropertyException(Messages.CannotChangeAccountCurrencyTransactionsExist);
                    }
                }
            }

            if (acct != null && acct.IsCashAccount == true && string.IsNullOrEmpty(newCuryID))
            {
                throw new PXSetPropertyException(Messages.CannotClearCurrencyInCashAccount);
            }
        }
Example #2
0
        protected virtual void Account_CuryID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Account acct = cache.Locate(e.Row) as Account;

            string newCuryID = (string)e.NewValue;

            if (acct != null && string.IsNullOrEmpty(acct.CuryID) && !string.IsNullOrEmpty(newCuryID))
            {
                if (PXSelect <CuryGLHistory, Where <CuryGLHistory.accountID, Equal <Current <Account.accountID> >, And <CuryGLHistory.curyID, NotEqual <Required <CuryGLHistory.curyID> >, And <CuryGLHistory.balanceType, NotEqual <LedgerBalanceType.report> > > > > .SelectSingleBound(this, new object[] { acct }, newCuryID).Count == 0)
                {
                    return;
                }
            }

            if (acct != null && acct.CuryID != newCuryID)
            {
                bool hasHistory = GLUtility.IsAccountHistoryExist(this, acct.AccountID);
                if (hasHistory)
                {
                    throw new PXSetPropertyException(Messages.AccountExistsCurrencyID);
                }
            }

            if (acct != null && acct.IsCashAccount == true && string.IsNullOrEmpty(newCuryID))
            {
                throw new PXSetPropertyException(Messages.CannotClearCurrencyInCashAccount);
            }
        }
        public override void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            object key;

            if (IsTopLevel && (key = sender.GetValue(e.Row, FieldName)) != null)
            {
                PXCache      cache = sender.Graph.Caches[typeof(CurrencyInfo)];
                CurrencyInfo info  = (CurrencyInfo)cache.Locate(new CurrencyInfo {
                    CuryInfoID = Convert.ToInt64(key)
                });
                PXEntryStatus status = PXEntryStatus.Notchanged;
                if (info != null && ((status = cache.GetStatus(info)) == PXEntryStatus.Inserted))
                {
                    cache.PersistInserted(info);
                }
                else if (status == PXEntryStatus.Updated)
                {
                    cache.PersistUpdated(info);
                }
                else if (status == PXEntryStatus.Deleted)
                {
                    cache.PersistDeleted(info);
                }
            }
            base.RowPersisting(sender, e);
        }
        private GLTran LocateReverseTran(PXCache cache, GLTranForReclassification tranForReclass)
        {
            var reverseTran = new GLTran()
            {
                Module   = State.EditingBatchModule,
                BatchNbr = State.EditingBatchNbr,
                LineNbr  = tranForReclass.EditingPairReclassifyingLineNbr - 1
            };

            return((GLTran)cache.Locate(reverseTran));
        }
Example #5
0
        public virtual void INLocation_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            INLocation row = (INLocation)e.Row;

            if (row != null)
            {
                INLocation located = (INLocation)sender.Locate(row);
                if (located != null)
                {
                    row.LocationID = located.LocationID;
                }
            }
        }
Example #6
0
        // specified attributes
        public virtual IEnumerable <PopupAttributes> GetFilledAttributes()
        {
            PXCache cache = Base.Caches[typeof(PopupAttributes)];

            foreach (var field in GetPreparedAttributes())
            {
                var item = (PopupAttributes)cache.Locate(field);

                if (item == null)
                {
                    cache.Hold(field);
                }

                yield return(item ?? field);
            }
        }
        public override object Insert(PXCache sender, object row)
        {
            object existing = sender.Locate(row);

            if (existing != null)
            {
                bool contains = false;
                if (!(contains = _persisted.Contains(existing)) && sender.GetStatus(existing) == PXEntryStatus.Inserted)
                {
                    sender.Current = existing;
                    return(existing);
                }
                sender.Remove(existing);

                if (contains)
                {
                    object newrow = base.Insert(sender, row);
                    sender.ResetPersisted(existing);

                    List <object> chunk;
                    if (!_chunks.TryGetValue(existing, out chunk))
                    {
                        chunk = new List <object>();
                    }

                    _chunks[newrow] = chunk;
                    chunk.Add(existing);
                    _chunks.Remove(existing);
                    _persisted.Remove(existing);

                    return(newrow);
                }
                else
                {
                    return(base.Insert(sender, row));
                }
            }
            return(base.Insert(sender, row));
        }
        private HashSet <T> GetItems(string range, Func <T, string> getValuePredicate, Action <T, string> prepareForLocatePredicate)
        {
            var items = new HashSet <T>();

            string[] pairs = range.Split(RMReportConstants.RangeUnionChar);

            foreach (string pair in pairs)
            {
                string start, end;
                ParseRangeStartEndPair(pair, out start, out end);

                if (!String.IsNullOrEmpty(start))
                {
                    if (String.IsNullOrEmpty(end) || end == start)
                    {
                        string itemCode = String.Empty;

                        if (_wildcardMode == RMReportConstants.WildcardMode.Fixed)
                        {
                            itemCode = RMReportWildcard.EnsureWildcardForFixed(start, _wildcard);
                        }
                        else if (_wildcardMode == RMReportConstants.WildcardMode.Normal)
                        {
                            itemCode = RMReportWildcard.EnsureWildcard(start, _wildcard);
                        }
                        else
                        {
                            throw new ArgumentException(Messages.InvalidWildcardMode);
                        }

                        if (itemCode.Contains(RMReportConstants.DefaultWildcardChar))
                        {
                            items.UnionWith(from T x in _cache.Cached where RMReportWildcard.IsLike(itemCode, getValuePredicate(x)) select x);
                        }
                        else
                        {
                            prepareForLocatePredicate(_instance, itemCode);
                            if (_cache.IsKeysFilled(_instance))
                            {
                                T x = (T)_cache.Locate(_instance);
                                if (x != null)
                                {
                                    items.Add(x);
                                }
                            }
                            else     // composite key
                            {
                                items.UnionWith(from T x in _cache.Cached where String.Equals(itemCode, getValuePredicate(x), StringComparison.Ordinal) select x);
                            }
                        }
                    }
                    else
                    {
                        if (_betweenMode == RMReportConstants.BetweenMode.ByChar)
                        {
                            items.UnionWith(from T x in _cache.Cached where RMReportWildcard.IsBetweenByChar(start, end, getValuePredicate(x)) select x);
                        }
                        else if (_betweenMode == RMReportConstants.BetweenMode.Fixed)
                        {
                            items.UnionWith(RMReportWildcard.GetBetweenForFixed <T>(start, end, _wildcard, _cache.Cached, getValuePredicate));
                        }
                        else
                        {
                            throw new ArgumentException(Messages.InvalidBetweenMode);
                        }
                    }
                }
                else
                {
                    items.UnionWith(_cache.Cached.Cast <T>());
                }
            }
            return(items);
        }
Example #9
0
            private void AddNewInjection(PXCache target, string specificModule)
            {
                var graph = target.Graph;

                foreach (PX.SM.RelationGroup group in PXSelect <PX.SM.RelationGroup,
                                                                Where <PX.SM.RelationGroup.specificModule, Equal <Required <Dimension.specificModule> >,
                                                                       And <PX.SM.RelationGroup.specificType, Equal <Required <PX.SM.RelationGroup.specificType> > > > >
                         .Select(graph, specificModule, typeof(SegmentValue).FullName))
                {
                    string name = @group.GroupName;
                    byte[] mask = @group.GroupMask;
                    if (!target.Fields.Contains(name) && mask != null)
                    {
                        PXFieldSelecting fieldSelectingHandler = delegate(PXCache cache, PXFieldSelectingEventArgs a)
                        {
                            a.ReturnState = PXFieldState.CreateInstance(a.ReturnState, typeof(Boolean), null, null, null, null, null, null, name, null, null, null, PXErrorLevel.Undefined, null, null, null, PXUIVisibility.Dynamic, null, null, null);
                            SegmentValue value = (SegmentValue)a.Row;
                            if (value != null)
                            {
                                a.ReturnValue = false;
                                if (value.GroupMask != null)
                                {
                                    for (int i = 0; i < value.GroupMask.Length && i < mask.Length; i++)
                                    {
                                        if (mask[i] != 0x00 && (mask[i] & value.GroupMask[i]) == mask[i])
                                        {
                                            a.ReturnValue = true;
                                            return;
                                        }
                                    }
                                }
                            }
                        };
                        PXFieldUpdating fieldUpdatingHandler = delegate(PXCache cache, PXFieldUpdatingEventArgs a)
                        {
                            SegmentValue value = (SegmentValue)a.Row;
                            if (value != null && a.NewValue != null)
                            {
                                bool included = false;
                                if (a.NewValue is string)
                                {
                                    bool.TryParse((string)a.NewValue, out included);
                                }
                                else
                                {
                                    included = (bool)a.NewValue;
                                }
                                if (value.GroupMask == null)
                                {
                                    value.GroupMask = new byte[mask.Length];
                                }
                                else if (value.GroupMask.Length < mask.Length)
                                {
                                    byte[] arr = value.GroupMask;
                                    Array.Resize <byte>(ref arr, mask.Length);
                                    value.GroupMask = arr;
                                }
                                for (int i = 0; i < mask.Length; i++)
                                {
                                    if (mask[i] != 0x00)
                                    {
                                        if (included)
                                        {
                                            value.GroupMask[i] = (byte)(value.GroupMask[i] | mask[i]);
                                        }
                                        else
                                        {
                                            value.GroupMask[i] = (byte)(value.GroupMask[i] & ~mask[i]);
                                        }
                                        if (target.Locate(value) != null && target.GetStatus(value) == PXEntryStatus.Notchanged)
                                        {
                                            target.SetStatus(value, PXEntryStatus.Updated);
                                        }
                                        return;
                                    }
                                }
                            }
                        };
                        _items.Add(new Box(name, fieldSelectingHandler, fieldUpdatingHandler));
                        target.Fields.Add(name);
                        graph.FieldSelecting.AddHandler(typeof(SegmentValue), name, fieldSelectingHandler);
                        graph.FieldUpdating.AddHandler(typeof(SegmentValue), name, fieldUpdatingHandler);
                    }
                }
            }
Example #10
0
        public virtual void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            object  key   = sender.GetValue(e.Row, _FieldOrdinal);
            PXCache cache = sender.Graph.Caches[typeof(CATran)];
            CATran  info  = null;

            if (key != null)
            {
                //do not read cached record in release processes
                if ((info = PXSelectReadonly <CATran, Where <CATran.tranID, Equal <Required <CATran.tranID> > > > .Select(sender.Graph, key)) != null)
                {
                    CATran cached = (CATran)cache.Locate(info);
                    if (cached != null)
                    {
                        if ((cached.OrigModule != null && info.OrigModule != null && cached.OrigModule != info.OrigModule) ||
                            (cached.OrigRefNbr != null && info.OrigRefNbr != null && cached.OrigRefNbr != info.OrigRefNbr) ||
                            (cached.OrigTranType != null && info.OrigTranType != null && cached.OrigTranType != info.OrigTranType))
                        {
                            // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details)
                            throw new PXException(Messages.CouldNotInsertCATran);
                        }
                        if (cache.GetStatus(cached) == PXEntryStatus.Notchanged)
                        {
                            PXCache <CATran> .RestoreCopy(cached, info);
                        }
                        info = cached;
                    }
                    else
                    {
                        cache.SetStatus(info, PXEntryStatus.Notchanged);
                    }
                }

                if ((long)key < 0L && info == null)
                {
                    info        = new CATran();
                    info.TranID = (long)key;
                    info        = (CATran)cache.Locate(info);
                }

                if (info == null)
                {
                    key = null;
                    sender.SetValue(e.Row, _FieldOrdinal, null);
                }
            }

            if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete)
            {
                if (info != null)
                {
                    cache.Delete(info);
                    cache.PersistDeleted(info);
                }
            }
            else if (info == null)
            {
                if (!this.NeedPreventCashTransactionCreation(sender, e.Row))
                {
                    info = DefaultValues(sender, new CATran(), e.Row);

                    if (info != null)
                    {
                        info = (CATran)cache.Insert(info);
                        if (!(info.TranID < 0L))
                        {
                            throw new PXException(Messages.CouldNotInsertCATran);
                        }

                        // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details)
                        sender.SetValue(e.Row, _FieldOrdinal, info.TranID);
                        _KeyToAbort = info.TranID;
                        cache.PersistInserted(info);
                        long id = info.TranID ?? 0;
                        if (id == 0 || id < 0)
                        {
                            throw new PXException(Messages.CATranNotSaved, sender.GetItemType().Name);
                        }
                        sender.SetValue(e.Row, _FieldOrdinal, id);
                        info.TranID = id;
                        cache.Normalize();
                    }
                }
            }
            else if (info.TranID < 0L)
            {
                info = DefaultValues(sender, PXCache <CATran> .CreateCopy(info), e.Row);
                if (info != null)
                {
                    info = (CATran)cache.Update(info);

                    sender.SetValue(e.Row, _FieldOrdinal, info.TranID);
                    _KeyToAbort = info.TranID;
                    cache.PersistInserted(info);
                    long id = info.TranID ?? 0;
                    if (id == 0 || id < 0)
                    {
                        throw new PXException(Messages.CATranNotSaved, sender.GetItemType().Name);
                    }
                    sender.SetValue(e.Row, _FieldOrdinal, id);
                    info.TranID = id;
                    cache.Normalize();
                }
            }
            else
            {
                CATran copy = PXCache <CATran> .CreateCopy(info);

                copy = DefaultValues(sender, copy, e.Row);
                if (copy != null)
                {
                    if ((copy.OrigModule != null && info.OrigModule != null && copy.OrigModule != info.OrigModule) ||
                        (copy.OrigRefNbr != null && info.OrigRefNbr != null && copy.OrigRefNbr != info.OrigRefNbr) ||
                        (copy.OrigTranType != null && info.OrigTranType != null && copy.OrigTranType != info.OrigTranType))
                    {
                        // TO Be removed after solving CATran issue (check JIRA item AC-57875 for details)
                        throw new PXException(Messages.CouldNotInsertCATran);
                    }
                    info = (CATran)cache.Update(copy);
                    //to avoid another process updated DefaultValues will return null for Released docs, except for GLTran
                    cache.PersistUpdated(info);
                }
                //JournalEntry is usually persisted prior to ReleaseGraph to obtain BatchNbr reference, read info should contain set Released flag
                else if (info.Released == false)
                {
                    key = null;
                    sender.SetValue(e.Row, _FieldOrdinal, null);

                    cache.Delete(info);
                }
            }
            foreach (CATran toDelete in cache.Deleted)
            {
                cache.PersistDeleted(toDelete);
            }
        }
Example #11
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, "");
            }
        }