예제 #1
0
        /// <summary>
        /// For a given data record containing a deferral code and a default deferral term,
        /// generates a warning message when the specified deferral code is flexible, but the specified
        /// default deferral term is zero.
        /// </summary>
        /// <param name="sender">The cache containing the records.</param>
        /// <param name="row">The currently processed data record.</param>
        /// <typeparam name="DeferralCode">The DAC field type for deferral code.</param>
        /// <typeparam name="DefaultTerm">The DAC field type for default deferral term.</param>
        public static void CheckZeroDefaultTerm <DeferralCode, DefaultTerm>(PXCache sender, object row)
            where DeferralCode : IBqlField
            where DefaultTerm : IBqlField
        {
            string  deferralCodeValue = sender.GetValue <DeferralCode>(row) as string;
            decimal?defaultTermValue  = sender.GetValue <DefaultTerm>(row) as decimal?;

            bool displayWarning = false;

            if (deferralCodeValue != null)
            {
                DRDeferredCode deferralCodeRecord =
                    PXSelect <
                        DRDeferredCode,
                        Where <DRDeferredCode.deferredCodeID, Equal <Required <DRDeferredCode.deferredCodeID> > > >
                    .Select(sender.Graph, deferralCodeValue);

                if (deferralCodeRecord != null &&
                    DeferredMethodType.RequiresTerms(deferralCodeRecord) &&
                    defaultTermValue.HasValue &&
                    defaultTermValue == 0)
                {
                    displayWarning = true;
                }
            }

            sender.RaiseExceptionHandling(
                typeof(DefaultTerm).Name,
                row,
                defaultTermValue,
                displayWarning ? new PXSetPropertyException(Messages.NoDefaultTermSpecified, PXErrorLevel.Warning) : null);
        }
예제 #2
0
        public override void FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs args)
        {
            if (args.NewValue != null)
            {
                var noteId = complianceDocumentEntityHelper.GetNoteId(cache.Graph, (string)args.NewValue);
                if (noteId != null)
                {
                    var oldReferenceId = (Guid?)cache.GetValue(args.Row, _FieldOrdinal);
                    var reference      = InsertComplianceDocumentReference(cache, args, noteId);
                    args.NewValue = reference.ComplianceDocumentReferenceId;
                    TryDeleteReference(cache, oldReferenceId);
                }
                else
                {
                    ComplianceDocument doc = args.Row as ComplianceDocument;

                    args.NewValue = cache.GetValue(doc, _FieldName);
                    args.Cancel   = true;
                }
            }
            else
            {
                DeleteExistingReference(cache, (ComplianceDocument)args.Row);
            }
        }
예제 #3
0
        public void Verify(PXCache cache, object item, List <object> pars, ref bool?result, ref object value)
        {
            string docType = cache.GetValue <TDocTypeField>(item) as string;
            string refNbr  = cache.GetValue <TRefNbrField>(item) as string;

            value = result = Select(cache.Graph, APPaymentType.GetVoidingAPDocType(docType), docType, refNbr) != null;
        }
예제 #4
0
        protected virtual void GLVoucherBatch_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            GLVoucherBatch row    = (GLVoucherBatch)e.Row;
            GLVoucherBatch oldRow = (GLVoucherBatch)e.OldRow;

            if (prevDirty == false)
            {
                bool nothingChanged = true;
                foreach (Type fieldType in sender.BqlFields)
                {
                    if (fieldType != typeof(GLVoucherBatch.selected))
                    {
                        string field = sender.GetField(fieldType);
                        if (!Equals(sender.GetValue(row, field), sender.GetValue(oldRow, field)))
                        {
                            nothingChanged = false;
                            break;
                        }
                    }
                }
                if (nothingChanged)
                {
                    sender.IsDirty = prevDirty;
                }
                else
                {
                    prevDirty = sender.IsDirty;
                }
            }
        }
예제 #5
0
        protected virtual void TaskFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            var row = e.Row as TaskFilter;

            if (row == null)
            {
                return;
            }

            var isCorrectOwner = row.OwnerID != null;

            if (!isCorrectOwner)
            {
                row.IsEscalated = false;
                row.IsFollowUp  = false;
            }

            PXUIFieldAttribute.SetEnabled <TaskFilter.isEscalated>(sender, row, isCorrectOwner);
            PXUIFieldAttribute.SetEnabled <TaskFilter.isFollowUp>(sender, row, isCorrectOwner);
            var me      = true.Equals(sender.GetValue(e.Row, typeof(TaskFilter.myOwner).Name));
            var myGroup = true.Equals(sender.GetValue(e.Row, typeof(TaskFilter.myWorkGroup).Name));

            PXUIFieldAttribute.SetEnabled(sender, e.Row, typeof(TaskFilter.ownerID).Name, !me);
            PXUIFieldAttribute.SetEnabled(sender, e.Row, typeof(TaskFilter.workGroupID).Name, !myGroup);
        }
예제 #6
0
            private void ReqClassFieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
            {
                string oldClassId = (string)e.OldValue;
                string newClassId = (string)sender.GetValue(e.Row, reqClassID.Name);
                object value      = sender.GetValue(e.Row, _FieldName);

                if (oldClassId != newClassId)
                {
                    RQRequestClass newClass = (RQRequestClass)this.viewClass.SelectSingle(newClassId);
                    RQRequestClass oldClass = (RQRequestClass)this.viewClass.SelectSingle(oldClassId);

                    if (newClass != null && oldClass != null && newClass.CustomerRequest != oldClass.CustomerRequest)
                    {
                        sender.SetValue(e.Row, _FieldOrdinal, null);
                        sender.SetDefaultExt(e.Row, _FieldName);
                    }
                    else if (newClass != null && value != null)
                    {
                        BAccount account =
                            PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .Select(sender.Graph, value);

                        if (account == null)
                        {
                            return;
                        }

                        if ((account.Type != BAccountType.CustomerType && newClass.CustomerRequest == true) ||
                            (account.Type != BAccountType.EmployeeType && newClass.CustomerRequest != true))
                        {
                            sender.SetValue(e.Row, _FieldOrdinal, null);
                        }
                    }
                }
            }
        public virtual bool IsKeySourceValuesEquals(PXCache cache, object oldRow, object newRow)
        {
            TKeyWithSourceValuesCollection oldSourceValues =
                BuildKeyCollection(cache.Graph, cache, oldRow, CollectSourceValues);

            TKeyWithSourceValuesCollection newSourceValues =
                BuildKeyCollection(cache.Graph, cache, newRow, CollectSourceValues);

            if (oldSourceValues.Items.Count != newSourceValues.Items.Count)
            {
                return(false);
            }

            TSourcesSpecificationCollection specifications = GetSourcesSpecification(cache, oldRow);

            IEnumerable <object> oldAdditionalFieldsValues =
                specifications.DependsOnFields.Select(fieldType => cache.GetValue(oldRow, fieldType.Name));

            IEnumerable <object> additionalFieldsValues =
                specifications.DependsOnFields.Select(fieldType => cache.GetValue(newRow, fieldType.Name));

            for (int i = 0; i < oldSourceValues.Items.Count; i++)
            {
                if (!oldSourceValues.Items[i].SourcesEqual(newSourceValues.Items[i]))
                {
                    return(false);
                }
            }

            return(oldAdditionalFieldsValues.SequenceEqual(additionalFieldsValues));
        }
예제 #8
0
        public override void ProccessItem(PXGraph graph, TPrimary item)
        {
            PXCache  cache   = graph.Caches[typeof(TPrimary)];
            TPrimary newItem = (TPrimary)cache.CreateInstance();

            PXCache <TPrimary> .RestoreCopy(newItem, item);

            string entityType = CSAnswerType.GetAnswerType(cache.GetItemType());
            string entityID   = CSAnswerType.GetEntityID(cache.GetItemType());

            PXView primaryView = graph.Views[graph.PrimaryView];

            object[] searches    = new object[primaryView.Cache.BqlKeys.Count];
            string[] sortcolumns = new string[primaryView.Cache.BqlKeys.Count];
            for (int i = 0; i < cache.BqlKeys.Count(); i++)
            {
                sortcolumns[i] = cache.BqlKeys[i].Name;
                searches[i]    = cache.GetValue(newItem, sortcolumns[i]);
            }
            int startRow = 0, totalRows = 0;

            List <object> result = primaryView.Select(null, null, searches, sortcolumns, null, null, ref startRow, 1, ref totalRows);

            newItem = (TPrimary)cache.CreateCopy(PXResult.Unwrap <TPrimary>(result[0]));

            foreach (FieldValue fieldValue in Fields.Cache.Cached.Cast <FieldValue>().Where(o => o.AttributeID == null && o.Selected == true))
            {
                PXFieldState  state    = cache.GetStateExt(newItem, fieldValue.Name) as PXFieldState;
                PXIntState    intState = state as PXIntState;
                PXStringState strState = state as PXStringState;
                if ((intState != null && intState.AllowedValues != null && intState.AllowedValues.Length > 0 &&
                     intState.AllowedValues.All(v => v != int.Parse(fieldValue.Value)))
                    ||
                    (strState != null && strState.AllowedValues != null && strState.AllowedValues.Length > 0 &&
                     strState.AllowedValues.All(v => v != fieldValue.Value)))
                {
                    throw new PXSetPropertyException(ErrorMessages.UnallowedListValue, fieldValue.Value, fieldValue.Name);
                }
                if (state != null && !Equals(state.Value, fieldValue.Value))
                {
                    cache.SetValueExt(newItem, fieldValue.Name, fieldValue.Value);
                    cache.Update(newItem);
                }

                result  = primaryView.Select(null, null, searches, sortcolumns, null, null, ref startRow, 1, ref totalRows);
                newItem = (TPrimary)cache.CreateCopy(PXResult.Unwrap <TPrimary>(result[0]));
            }

            PXCache attrCache = cache.Graph.Caches[typeof(CSAnswers)];

            foreach (FieldValue attrValue in Attributes.Cache.Cached.Cast <FieldValue>().Where(o => o.AttributeID != null && o.Selected == true))
            {
                CSAnswers attr = (CSAnswers)attrCache.CreateInstance();
                attr.AttributeID = attrValue.AttributeID;
                attr.EntityID    = cache.GetValue(newItem, entityID) as int?;
                attr.EntityType  = entityType;
                attr.Value       = attrValue.Value;
                attrCache.Update(attr);
            }
        }
예제 #9
0
        protected void UpateSiteLocation <Field, FieldResult>(PXCache cache, PXRowUpdatingEventArgs e)
            where Field : IBqlField
            where FieldResult : IBqlField
        {
            int?newValue = (int?)cache.GetValue <Field>(e.NewRow);
            int?value    = (int?)cache.GetValue <Field>(e.Row);

            if (value != newValue && e.ExternalCall == true)
            {
                INItemSite itemsite =
                    PXSelect <INItemSite,
                              Where <INItemSite.siteID, Equal <Required <INItemSite.siteID> > > > .SelectWindowed(this, 0, 1,
                                                                                                                  cache.GetValue <INSite.siteID>(e.Row));

                if (itemsite != null &&
                    site.Ask(Messages.Warning, Messages.SiteLocationOverride, MessageButtons.YesNo) == WebDialogResult.Yes)
                {
                    cache.SetValue <FieldResult>(e.NewRow, true);
                }
                else
                {
                    cache.SetValue <FieldResult>(e.NewRow, false);
                }
            }
        }
        public void RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
        {
            if (e.TranStatus == PXTranStatus.Completed)
            {
                return;
            }

            var newVal = sender.GetValue(e.Row, ordinal);
            // we should skip update if the row has not been changed

            int  ixNote  = sender.GetFieldOrdinal(NoteID);
            var  noteId  = sender.GetValue(e.Row, ixNote);
            bool updated = PXDatabase.Provider.Update(typeof(ExtraFieldValue),
                                                      new PXDataFieldRestrict <ExtraFieldValue.noteId>(noteId),
                                                      new PXDataFieldRestrict <ExtraFieldValue.extFieldId>(attributeId),
                                                      new PXDataFieldAssign <ExtraFieldValue.value>(newVal));

            if (!updated)
            {
                PXDatabase.Provider.Insert(typeof(ExtraFieldValue),
                                           new PXDataFieldAssign <ExtraFieldValue.noteId>(noteId),
                                           new PXDataFieldAssign <ExtraFieldValue.extFieldId>(attributeId),
                                           new PXDataFieldAssign <ExtraFieldValue.value>(newVal));
            }
        }
예제 #11
0
 public override void DescriptionFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, string alias)
 {
     if (e.Row == null || (sender.GetValue(e.Row, _FieldOrdinal) == null))
     {
         base.DescriptionFieldSelecting(sender, e, alias);
     }
     else
     {
         UPCompany item  = null;
         Object    value = sender.GetValue(e.Row, _FieldOrdinal);
         Int32     key   = (Int32)value;
         foreach (UPCompany info in PXCompanyHelper.SelectCompanies())
         {
             if (info.CompanyID == key)
             {
                 item = info;
                 break;
             }
         }
         if (item != null)
         {
             e.ReturnValue = sender.Graph.Caches[_Type].GetValue(item, _DescriptionField.Name);
         }
     }
 }
        protected virtual void POLandedCostDoc_CuryTaxTot_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            decimal?curyTaxTotal   = (decimal?)sender.GetValue(e.Row, _CuryTaxTotal);
            decimal?curyWhTaxTotal = (decimal?)sender.GetValue(e.Row, _CuryWhTaxTotal);

            CalcDocTotals(sender, e.Row, curyTaxTotal.GetValueOrDefault(), 0, curyWhTaxTotal.GetValueOrDefault(), 0);
        }
        public void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            if (task == null)
            {
                return;
            }

            if (AllowNullValue)
            {
                return;
            }

            if (!UseCostCode())
            {
                return;
            }

            int?taskID = (int?)sender.GetValue(e.Row, task.Name);

            if (taskID == null)
            {
                return;
            }

            int?costCodeID = (int?)sender.GetValue(e.Row, FieldOrdinal);

            if (costCodeID == null)
            {
                if (sender.RaiseExceptionHandling(FieldName, e.Row, null, new PXSetPropertyException(Data.ErrorMessages.FieldIsEmpty, FieldName)))
                {
                    throw new PXRowPersistingException(FieldName, null, Data.ErrorMessages.FieldIsEmpty, FieldName);
                }
            }
        }
        public override INItemPlan DefaultValues(PXCache sender, INItemPlan plan_Row, object origRow)
        {
            ARTran tran = (ARTran)origRow;

            if (tran.Released == true || tran.SOShipmentNbr != null || tran.SOOrderNbr != null || tran.LineType != SOLineType.Inventory ||
                tran.InvtMult == 0)
            {
                return(null);
            }
            PXCache cache = sender.Graph.Caches[BqlCommand.GetItemType(_ParentNoteID)];
            bool?   hold  = (bool?)cache.GetValue(cache.Current, _ParentHoldEntry.Name) | (bool?)cache.GetValue <ARInvoice.creditHold>(cache.Current);

            plan_Row.BAccountID   = tran.CustomerID;
            plan_Row.PlanType     = (hold == true) ? INPlanConstants.Plan69 : INPlanConstants.Plan62;
            plan_Row.InventoryID  = tran.InventoryID;
            plan_Row.SubItemID    = tran.SubItemID;
            plan_Row.SiteID       = tran.SiteID;
            plan_Row.LocationID   = tran.LocationID;
            plan_Row.LotSerialNbr = tran.LotSerialNbr;
            plan_Row.Reverse      = (tran.InvtMult > 0) ^ (tran.BaseQty < 0m);
            plan_Row.PlanDate     = (DateTime?)cache.GetValue <ARRegister.docDate>(cache.Current);
            plan_Row.PlanQty      = Math.Abs(tran.BaseQty ?? 0m);
            plan_Row.RefNoteID    = (Guid?)cache.GetValue(cache.Current, _ParentNoteID.Name);
            plan_Row.Hold         = hold;

            return(plan_Row);
        }
예제 #15
0
 protected virtual void CuryFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, string curyField, string baseField)
 {
     if (Base.Accessinfo.CuryViewState)
     {
         recalculateFieldBaseValue(sender, e.Row, sender.GetValue(e.Row, curyField), curyField, baseField);
         e.ReturnValue = sender.GetValue(e.Row, baseField);
     }
 }
예제 #16
0
        protected virtual void OwnedFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            var me      = true.Equals(sender.GetValue(e.Row, typeof(CR.OwnedFilter.myOwner).Name));
            var myGroup = true.Equals(sender.GetValue(e.Row, typeof(CR.OwnedFilter.myWorkGroup).Name));

            PXUIFieldAttribute.SetEnabled(sender, e.Row, typeof(CR.OwnedFilter.ownerID).Name, !me);
            PXUIFieldAttribute.SetEnabled(sender, e.Row, typeof(CR.OwnedFilter.workGroupID).Name, !myGroup);
        }
예제 #17
0
        public virtual void CATran_RowPersisted(PXCache sender, PXRowPersistedEventArgs e)
        {
            PXCache cache = sender.Graph.Caches[_ChildType];
            long?   newKey;

            if (e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Open && _SelfKeyToAbort != null)
            {
                newKey = (long?)sender.GetValue <CATran.tranID>(e.Row);

                if (!_persisted.ContainsKey(newKey))
                {
                    _persisted.Add(newKey, _SelfKeyToAbort);
                }

                foreach (object item in cache.Inserted)
                {
                    if ((long?)cache.GetValue(item, _FieldOrdinal) == (long?)_SelfKeyToAbort)
                    {
                        cache.SetValue(item, _FieldOrdinal, newKey);
                    }
                }

                foreach (object item in cache.Updated)
                {
                    if ((long?)cache.GetValue(item, _FieldOrdinal) == (long?)_SelfKeyToAbort)
                    {
                        cache.SetValue(item, _FieldOrdinal, newKey);
                    }
                }

                _SelfKeyToAbort = null;
            }

            if (e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Aborted)
            {
                foreach (object item in cache.Inserted)
                {
                    if ((newKey = (long?)cache.GetValue(item, _FieldOrdinal)) != null && _persisted.TryGetValue(newKey, out _SelfKeyToAbort))
                    {
                        cache.SetValue(item, _FieldOrdinal, _SelfKeyToAbort);
                    }
                }

                foreach (object item in cache.Updated)
                {
                    if ((newKey = (long?)cache.GetValue(item, _FieldOrdinal)) != null && _persisted.TryGetValue(newKey, out _SelfKeyToAbort))
                    {
                        cache.SetValue(item, _FieldOrdinal, _SelfKeyToAbort);
                    }
                }
            }

            if (e.TranStatus != PXTranStatus.Open)
            {
                _KeyToAbort     = null;
                _SelfKeyToAbort = null;
            }
        }
        private string GetFolderNameForActivityRow(object entityRow)
        {
            PXCache cache      = Caches[entityRow.GetType()];
            string  folderName = String.Format("{0:yyyy-MM-dd} - {1} (ID: {2})",
                                               cache.GetValue(entityRow, "StartDate"),
                                               cache.GetValue(entityRow, "Subject"),
                                               cache.GetValue(entityRow, "NoteID"));

            return(BoxUtils.CleanFileOrFolderName(folderName));
        }
예제 #19
0
        public void RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            bool?flagValue = (bool?)sender.GetValue(e.Row, _FieldOrdinal);

            if (flagValue == null)
            {
                bool newValue = sender.GetValue(e.Row, _TaxZoneID.Name) != null && CheckCondition(sender, e.Row);
                sender.SetValue(e.Row, _FieldOrdinal, newValue);
            }
        }
예제 #20
0
        protected virtual IEnumerable GetRecords()
        {
            bool    ar      = true;
            PXCache cache   = this._Graph.Caches[BqlCommand.GetItemType(moduleField)];
            string  docType = ARDocType.Invoice;
            string  refNbr  = null;

            if (cache.Current != null)
            {
                docType = (string)cache.GetValue(cache.Current, docTypeField.Name);
                refNbr  = (string)cache.GetValue(cache.Current, refNbrField.Name);
                string module = (string)cache.GetValue(cache.Current, moduleField.Name);
                if (module == BatchModule.AP)
                {
                    ar = false;
                }
            }

            if (ar)
            {
                PXSelectBase <ARTran> select = new PXSelect <ARTran,
                                                             Where <ARTran.tranType, Equal <Required <ARTran.tranType> >,
                                                                    And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > >(this._Graph);
                foreach (ARTran tran in select.Select(docType, refNbr))
                {
                    DRLineRecord record = new DRLineRecord();
                    record.CuryInfoID  = tran.CuryInfoID;
                    record.CuryTranAmt = tran.CuryTranAmt;
                    record.InventoryID = tran.InventoryID;
                    record.LineNbr     = tran.LineNbr;
                    record.TranAmt     = tran.TranAmt;
                    record.TranDesc    = tran.TranDesc;

                    yield return(record);
                }
            }
            else
            {
                PXSelectBase <APTran> select = new PXSelect <APTran,
                                                             Where <APTran.tranType, Equal <Required <APTran.tranType> >,
                                                                    And <APTran.refNbr, Equal <Required <APTran.refNbr> > > > >(this._Graph);
                foreach (APTran tran in select.Select(docType, refNbr))
                {
                    DRLineRecord record = new DRLineRecord();
                    record.CuryInfoID  = tran.CuryInfoID;
                    record.CuryTranAmt = tran.CuryTranAmt;
                    record.InventoryID = tran.InventoryID;
                    record.LineNbr     = tran.LineNbr;
                    record.TranAmt     = tran.TranAmt;
                    record.TranDesc    = tran.TranDesc;

                    yield return(record);
                }
            }
        }
예제 #21
0
 public static void RaiseOrHideError <T>(PXCache cache, object row, bool isIncorrect, string message, PXErrorLevel errorLevel, params object[] parameters)
     where T : IBqlField
 {
     if (isIncorrect)
     {
         cache.RaiseExceptionHandling <T>(row, cache.GetValue <T>(row), new PXSetPropertyException(message, errorLevel, parameters));
     }
     else
     {
         cache.RaiseExceptionHandling <T>(row, cache.GetValue <T>(row), null);
     }
 }
        protected override bool PeriodSourceFieldsEqual(PXCache cache, object oldRow, object newRow)
        {
            bool res = base.PeriodSourceFieldsEqual(cache, oldRow, newRow);

            if (UseMasterCalendarSourceType != null)
            {
                res &= (bool?)cache.GetValue(newRow, UseMasterCalendarSourceType.Name) ==
                       (bool?)cache.GetValue(oldRow, UseMasterCalendarSourceType.Name);
            }

            return(res);
        }
예제 #23
0
        private void RowUpdated(PXCache cache, PXRowUpdatedEventArgs args)
        {
            var field    = cache.GetField(fieldType);
            var oldValue = cache.GetValue(args.OldRow, field);
            var newValue = cache.GetValue(args.Row, field);

            if (!Equals(oldValue, newValue))
            {
                cache.SetValue(args.Row, FieldName, null);
                cache.RaiseExceptionHandling(FieldName, args.Row, null, null);
            }
        }
        protected virtual void RowSelectingCollectMatches(PXCache sender, PXRowSelectingEventArgs e)
        {
            long?id = (long?)sender.GetValue(e.Row, _FieldOrdinal);

            if (id != null)
            {
                string cury = (string)sender.GetValue(e.Row, "CuryID");
                if (!String.IsNullOrEmpty(cury))
                {
                    _Matches[(long)id] = cury;
                }
            }
        }
예제 #25
0
        protected virtual IEnumerable CurrencyView(PXAdapter adapter)
        {
            Base.Accessinfo.CuryViewState = !Base.Accessinfo.CuryViewState;
            PXCache cache   = adapter.View.Cache;
            bool    anyDiff = !cache.IsDirty;

            foreach (object ret in adapter.Get())
            {
                if (!anyDiff)
                {
                    TPrimary item;
                    if (ret is PXResult)
                    {
                        item = (TPrimary)((PXResult)ret)[0];
                    }
                    else
                    {
                        item = (TPrimary)ret;
                    }
                    if (item == null)
                    {
                        anyDiff = true;
                    }
                    else
                    {
                        TPrimary oldItem = _oldRow as TPrimary;
                        if (item == null || oldItem == null)
                        {
                            anyDiff = true;
                        }
                        else
                        {
                            foreach (string field in cache.Fields)
                            {
                                object oldV = cache.GetValue(oldItem, field);
                                object newV = cache.GetValue(item, field);
                                if ((oldV != null || newV != null) && !object.Equals(oldV, newV) && (!(oldV is DateTime && newV is DateTime) || ((DateTime)oldV).Date != ((DateTime)newV).Date))
                                {
                                    anyDiff = true;
                                }
                            }
                        }
                    }
                }
                yield return(ret);
            }
            if (!anyDiff)
            {
                cache.IsDirty = false;
            }
        }
        protected virtual bool PeriodSourceFieldsEqual(PXCache cache, object oldRow, object newRow)
        {
            if (oldRow != null && newRow == null ||
                oldRow == null && newRow != null)
            {
                return(false);
            }

            string newOrgFinPeriodID = (string)cache.GetValue(newRow, _FieldName);
            string oldOrgFinPeriodID = (string)cache.GetValue(oldRow, _FieldName);

            return(PeriodKeyProvider.IsKeySourceValuesEquals(cache, oldRow, newRow) &&
                   newOrgFinPeriodID == oldOrgFinPeriodID);
        }
        private bool ValidateDuplicateMap <BranchField>(PXCache sender, PXView view, object row, object oldrow)
            where BranchField : IBqlField
        {
            int?   branch   = (int?)sender.GetValue <BranchField>(row);
            string fromMask = (string)sender.GetValue <BranchAcctMap.fromAccountCD>(row);
            string toMask   = (string)sender.GetValue <BranchAcctMap.toAccountCD>(row);

            if (string.IsNullOrEmpty(fromMask) || string.IsNullOrEmpty(toMask))
            {
                return(false);
            }

            PXSetPropertyException ex = null;

            if (string.Compare(fromMask, toMask, true) > 0)
            {
                ex = new PXSetPropertyException(Messages.MapAccountError);
            }

            if (ex == null)
            {
                foreach (var item in view.SelectMulti())
                {
                    if (item == row || item == oldrow)
                    {
                        continue;
                    }
                    int?itemBranch = (int?)sender.GetValue <BranchField>(item);
                    if (branch == itemBranch)
                    { // same branch
                        string itemFromMask = (string)sender.GetValue <BranchAcctMap.fromAccountCD>(item);
                        string itemToMask   = (string)sender.GetValue <BranchAcctMap.toAccountCD>(item);
                        if (string.Compare(fromMask, itemToMask, true) < 0 &&
                            string.Compare(itemFromMask, toMask, true) < 0)
                        {
                            ex = new PXSetPropertyException(Messages.MapAccountDuplicate);
                            break;
                        }
                    }
                }
            }

            if (ex != null)
            {
                if (!sender.ObjectsEqual <BranchAcctMapFrom.toAccountCD>(row, oldrow) || (oldrow == null && sender.GetValue <BranchAcctMap.toAccountCD>(row) != null))
                {
                    sender.RaiseExceptionHandling <BranchAcctMapFrom.toAccountCD>(row,
                                                                                  sender.GetValue <BranchAcctMap.toAccountCD>(
                                                                                      row), ex);
                }
                else
                {
                    sender.RaiseExceptionHandling <BranchAcctMapFrom.fromAccountCD>(row,
                                                                                    sender.GetValue <BranchAcctMap.fromAccountCD>(
                                                                                        row), ex);
                }
            }
            return(ex == null);
        }
예제 #28
0
        /// <summary>
        /// Update a record with the values in another one.
        /// </summary>
        /// <param name="cacheTo">The cache of the record to be updated.</param>
        /// <param name="rowTo">The record to be updated.</param>
        /// <param name="cacheFrom">The cache of the record to be read.</param>
        /// <param name="rowFrom">The record to be read.</param>
        /// <returns>Returns true if some value changes, otherwise it returns false.</returns>
        private static bool CopyEPEquipmentFields(PXCache cacheTo, IBqlTable rowTo, PXCache cacheFrom, IBqlTable rowFrom)
        {
            string fieldTo;
            string fieldFrom;
            string tempSwap;

            bool   someValueChanged = false;
            string stringValue;

            //// Copy Status
            fieldTo   = typeof(FSEquipment.status).Name;
            fieldFrom = typeof(EPEquipment.status).Name;

            if (rowTo is EPEquipment)
            {
                tempSwap  = fieldTo;
                fieldTo   = fieldFrom;
                fieldFrom = tempSwap;
            }

            stringValue = (string)cacheFrom.GetValue(rowFrom, fieldFrom);

            if (string.Equals(stringValue, cacheTo.GetValue(rowTo, fieldTo)) == false)
            {
                cacheTo.SetValueExt(rowTo, fieldTo, stringValue);
                someValueChanged = true;
            }

            //// Copy Description
            fieldTo   = typeof(FSEquipment.descr).Name;
            fieldFrom = typeof(EPEquipment.description).Name;

            if (rowTo is EPEquipment)
            {
                tempSwap  = fieldTo;
                fieldTo   = fieldFrom;
                fieldFrom = tempSwap;
            }

            stringValue = (string)cacheFrom.GetValue(rowFrom, fieldFrom);

            if (string.Equals(stringValue, cacheTo.GetValue(rowTo, fieldTo)) == false)
            {
                cacheTo.SetValueExt(rowTo, fieldTo, stringValue);
                someValueChanged = true;
            }

            return(someValueChanged);
        }
예제 #29
0
        protected virtual void EmailProcessingFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            var row = e.Row as EmailProcessingFilter;

            if (row == null)
            {
                return;
            }

            var me      = true.Equals(sender.GetValue(e.Row, typeof(EmailProcessingFilter.myOwner).Name));
            var myGroup = true.Equals(sender.GetValue(e.Row, typeof(EmailProcessingFilter.myWorkGroup).Name));

            PXUIFieldAttribute.SetEnabled(sender, e.Row, typeof(EmailProcessingFilter.ownerID).Name, !me);
            PXUIFieldAttribute.SetEnabled(sender, e.Row, typeof(EmailProcessingFilter.workGroupID).Name, !myGroup);
        }
        public static bool ObjectsEqualExceptFields(this PXCache cache, object a, object b, params Type[] exceptFields)
        {
            var exceptFieldsHashSet = exceptFields
                                      .Select(efld => efld.Name)
                                      .ToHashSet(StringComparer.OrdinalIgnoreCase);

            foreach (string fld in cache.Fields.Where(fld => !exceptFieldsHashSet.Contains(fld)))
            {
                if (!object.Equals(cache.GetValue(a, fld), cache.GetValue(b, fld)))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #31
0
		protected virtual void SOInvoice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
		{
			if (e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update)
			{
				SOInvoice doc = (SOInvoice)e.Row;

				if ((doc.DocType == ARDocType.CashSale || doc.DocType == ARDocType.CashReturn))
				{
                    if (String.IsNullOrEmpty(doc.PaymentMethodID) == true)
                    {
                        if (sender.RaiseExceptionHandling<SOInvoice.pMInstanceID>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(SOInvoice.pMInstanceID).Name)))
                        {
                            throw new PXRowPersistingException(typeof(SOInvoice.pMInstanceID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOInvoice.pMInstanceID).Name);
                        }
                    }
                    else
                    {
                        
                        CA.PaymentMethod pm = PXSelect<CA.PaymentMethod, Where<CA.PaymentMethod.paymentMethodID, Equal<Required<CA.PaymentMethod.paymentMethodID>>>>.Select(this, doc.PaymentMethodID);
                        bool pmInstanceRequired = (pm.IsAccountNumberRequired == true);
                        if (pmInstanceRequired && doc.PMInstanceID == null)
                        {
                            if (sender.RaiseExceptionHandling<SOInvoice.pMInstanceID>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(SOInvoice.pMInstanceID).Name)))
                            {
                                throw new PXRowPersistingException(typeof(SOInvoice.pMInstanceID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOInvoice.pMInstanceID).Name);
                            }
                        }
                    }
				}

				bool isCashSale = (doc.DocType == AR.ARDocType.CashSale) || (doc.DocType == AR.ARDocType.CashReturn);
                if (isCashSale && SODocument.GetValueExt<SOInvoice.cashAccountID>((SOInvoice)e.Row) == null)
				{
					if (sender.RaiseExceptionHandling<SOInvoice.cashAccountID>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(SOInvoice.cashAccountID).Name)))
					{
						throw new PXRowPersistingException(typeof(SOInvoice.cashAccountID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOInvoice.cashAccountID).Name);
					}
				}

				object acctcd;

				if ((acctcd = SODocument.GetValueExt<SOInvoice.cashAccountID>((SOInvoice)e.Row)) != null && sender.GetValue<SOInvoice.cashAccountID>(e.Row) == null)
				{
					sender.RaiseExceptionHandling<SOInvoice.cashAccountID>(e.Row, null, null);
					sender.SetValueExt<SOInvoice.cashAccountID>(e.Row, acctcd is PXFieldState ? ((PXFieldState)acctcd).Value : acctcd);
				}

				//if (doc.PMInstanceID != null && string.IsNullOrEmpty(doc.ExtRefNbr))
				//{
				//    if (sender.RaiseExceptionHandling<SOInvoice.extRefNbr>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(SOInvoice.extRefNbr).Name)))
				//    {
				//        throw new PXRowPersistingException(typeof(SOInvoice.extRefNbr).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOInvoice.extRefNbr).Name);
				//    }
				//}
			}
		}
예제 #32
0
		protected virtual void AddDiscount(PXCache sender, PXRowUpdatedEventArgs e)
		{
            AddDiscountDetails(sender, e);
            
            ARTran discount = (ARTran)Discount.Cache.CreateInstance();
			discount.LineType = SOLineType.Discount;
			discount.DrCr = (Document.Current.DrCr == "D") ? "C" : "D";
			discount.FreezeManualDisc = true;
			discount = (ARTran)Discount.Select() ?? (ARTran)Discount.Cache.Insert(discount);

			ARTran old_row = (ARTran)Discount.Cache.CreateCopy(discount);

			discount.CuryTranAmt = (decimal?)sender.GetValue<SOInvoice.curyDiscTot>(e.Row);
			discount.TaxCategoryID = null;
			discount.TranDesc = PXMessages.LocalizeNoPrefix(Messages.DocDiscDescr);
			
			DefaultDiscountAccountAndSubAccount(discount);

            if (discount.TaskID == null && !PM.ProjectDefaultAttribute.IsNonProject(this, discount.ProjectID))
            {
                PM.PMProject project = PXSelect<PM.PMProject, Where<PM.PMProject.contractID, Equal<Required<PM.PMProject.contractID>>>>.Select(this, discount.ProjectID);
                if (project != null && project.BaseType != "C")
                {
                    PM.PMAccountTask task = PXSelect<PM.PMAccountTask, Where<PM.PMAccountTask.accountID, Equal<Required<PM.PMAccountTask.accountID>>>>.Select(this, discount.AccountID);
                    if (task != null)
                    {
                        discount.TaskID = task.TaskID;
                    }
                    else
                    {
                        Account ac = PXSelect<Account, Where<Account.accountID, Equal<Required<Account.accountID>>>>.Select(this, discount.AccountID);
                        throw new PXException(string.Format(Messages.AccountMappingNotConfigured, project.ContractCD, ac.AccountCD));
                    }
                }
            }
			
			if (Discount.Cache.GetStatus(discount) == PXEntryStatus.Notchanged)
			{
				Discount.Cache.SetStatus(discount, PXEntryStatus.Updated);
			}

			discount.ManualDisc = true; //escape SOManualDiscMode.RowUpdated
			Discount.Cache.RaiseRowUpdated(discount, old_row);

			decimal auotDocDisc = GetAutoDocDiscount();
			if (auotDocDisc == discount.CuryTranAmt)
			{
				discount.ManualDisc = false;
			}
			
			if (discount.CuryTranAmt == 0)
			{
				Discount.Delete(discount);
			}
		}
예제 #33
0
			public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
			{
				CurrencyInfo info = e.Row as CurrencyInfo;
				if (info != null)
				{
					try
					{
						info.defaultCuryRate(sender);
					}
					catch (PXSetPropertyException ex)
					{
						sender.RaiseExceptionHandling(_FieldName, e.Row, sender.GetValue(e.Row, _FieldOrdinal), ex);
					}
				}
			}
예제 #34
0
			public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
			{
				CurrencyInfo info = e.Row as CurrencyInfo;
				if (info != null)
				{
					//reset effective date to document date first
					info.SetDefaultEffDate(sender);
					try
					{
						info.defaultCuryRate(sender);
					}
					catch (PXSetPropertyException ex)
					{
						sender.RaiseExceptionHandling(_FieldName, e.Row, sender.GetValue(e.Row, _FieldOrdinal), ex);
					}
					info.CuryPrecision = null;
				}
			}