Ejemplo n.º 1
0
        public GetAttributeRecords(PXGraph graph, ref int?bAccountID, ref int?inventoryID)
        {
            CROpportunity current1 = graph.Caches <CROpportunity>().Current as CROpportunity;
            PXFieldState  valueExt = graph.Caches <CROpportunity>().GetValueExt((object)current1, "AttributeENDCUSTOME") as PXFieldState;

            bAccountID = PXSelectBase <BAccountR, PXSelect <BAccountR, Where <BAccountR.acctCD, Equal <Required <BAccountR.acctCD> > > > .Config> .Select(graph, valueExt.Value).TopFirst.BAccountID;

            CROpportunityProducts current2 = graph.Caches <CROpportunityProducts>().Current as CROpportunityProducts;

            inventoryID = current2.InventoryID;
        }
Ejemplo n.º 2
0
        public void DeleteRelatedEntityAttribute <TCache>(CSAttributeGroup attribute)
            where TCache : IBqlTable
        {
            var entityAttribute = GetRelatedEntityAttribute <TCache>(attribute.AttributeID, attribute.EntityClassID);

            if (entityAttribute != null)
            {
                var attributeGroupCache = (PXCache)graph.Caches <CSAttributeGroup>();
                attributeGroupCache.Delete(entityAttribute);
            }
        }
        public void Commit()
        {
            if (_inconsistencyHandlingMode == InconsistencyHandlingMode.None || !_errors.Any())
            {
                return;
            }

            foreach (InconsistencyError error in _errors)
            {
                foreach (RecordContextInfo contextInfo in error.ContextData)
                {
                    PXTrace.WriteInformation(contextInfo.Cache.GetFullDescription(contextInfo.Record));
                }

                PXTrace.WriteInformation($"{error.ErrorCode} {error.IntegrityException.Message}");
            }

            if (_inconsistencyHandlingMode == InconsistencyHandlingMode.Prevent)
            {
                DataIntegrityException firstError = _errors.First().IntegrityException;

                throw new DataIntegrityException(
                          firstError.InconsistencyCode,
                          Messages.DataIntegrityErrorDuringProcessingFormat,
                          firstError.Message);
            }

            if (_inconsistencyHandlingMode == InconsistencyHandlingMode.Log)
            {
                DateTime now = DateTime.UtcNow;

                foreach (InconsistencyError error in _errors)
                {
                    DataIntegrityLog logEntry = _graph.Caches <DataIntegrityLog>().Insert(new DataIntegrityLog
                    {
                        UtcTime          = now,
                        UserBranchID     = _graph.Accessinfo.BranchID,
                        UserID           = _graph.Accessinfo.UserID,
                        ExceptionMessage = error.IntegrityException.Message,
                        ContextInfo      = error.ContextData.Any()
                                                        ? string.Format(
                            "<Context>\r\n{0}\r\n</Context>",
                            string.Join("\r\n", error.ContextData.Select(contextInfo => contextInfo.Cache.ToXml(contextInfo.Record))))
                                                        : null,
                        InconsistencyCode = error.IntegrityException.InconsistencyCode,
                    }) as DataIntegrityLog;
                }

                _graph.Caches <DataIntegrityLog>().Persist(PXDBOperation.Insert);
                _graph.Caches <DataIntegrityLog>().Persisted(false);
            }
        }
        public bool ValidateRelatedField <TEntity, TComplianceDocumentField, TEntityField>(
            TEntity entity, object fieldValue)
            where TEntity : class, IBqlTable, new()
            where TComplianceDocumentField : IBqlField
            where TEntityField : IBqlField
        {
            var cache = graph.Caches <TEntity>();
            var hasExpiredDocuments = DoExpiredDocumentsExist <TComplianceDocumentField>(fieldValue);

            RaiseOrClearExceptionForRelatedField <TEntityField>(cache, entity, hasExpiredDocuments,
                                                                PXErrorLevel.Warning);
            return(hasExpiredDocuments);
        }
        protected virtual void SetInventoryCombinationNumber(int?inventoryID, int combinationNumber)
        {
            var inventoryItemCache = _graph.Caches <InventoryItem>();

            var item = InventoryItem.PK.Find(_graph, inventoryID);

            if (item == null)
            {
                throw new RowNotFoundException(inventoryItemCache, inventoryID);
            }

            item.AttributeDescriptionGroupID = combinationNumber;
            item.ColumnAttributeValue        = _columnAttributeValue;
            item.RowAttributeValue           = _rowAttributeValue;
            item = (InventoryItem)inventoryItemCache.Update(item);
        }
        protected Table Update <Table>(PXGraph graph, Table row)
            where Table : class, IBqlTable, new()
        {
            var cache      = graph.Caches <Table>();
            var updatedRow = (Table)cache.Update(row);

            Assert.NotNull(updatedRow);
            return(updatedRow);
        }
        protected Table Insert <Table>(PXGraph graph, Table row)
            where Table : class, IBqlTable, new()
        {
            var cache       = graph.Caches <Table>();
            var insertedRow = (Table)cache.Insert(row);

            Assert.NotNull(insertedRow);
            return(insertedRow);
        }
Ejemplo n.º 8
0
        public static TDestinationDAC Clone <TSourceDAC, TDestinationDAC>(PXGraph graph, TSourceDAC source)
            where TSourceDAC : class, IBqlTable, new()
            where TDestinationDAC : class, IBqlTable, new()
        {
            PXCache         sourceCache      = graph.Caches <TSourceDAC>();
            PXCache         destinationCache = graph.Caches <TDestinationDAC>();
            TDestinationDAC result           = (TDestinationDAC)destinationCache.CreateInstance();

            foreach (string field in destinationCache.Fields)
            {
                if (sourceCache.Fields.Contains(field))
                {
                    destinationCache.SetValue(result, field, sourceCache.GetValue(source, field));
                }
            }

            return(result);
        }
        private void EnsureCurrentForUpdate <T>(PXGraph graph) where T : class, IBqlTable, new()
        {
            var cache = graph.Caches <T>();

            if (cache.Current as T == null)
            {
                // just for sure, if there is trash too
                graph.Clear();
                cache.Insert();
            }
        }
        private void EnsureCurrentForInsert <T>(PXGraph graph) where T : class, IBqlTable, new()
        {
            var cache = graph.Caches <T>();

            if (cache.Insert() as T == null)
            {
                // this means there is trash in graph from previous session
                graph.Clear();
                cache.Insert();
            }
        }
Ejemplo n.º 11
0
        protected virtual void TMasterFieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            TMaster row = (TMaster)e.Row;

            if (row == null || row.ClassID == null)
            {
                return;
            }

            RelatedEntity pars = this.Caches <RelatedEntity>().Current as RelatedEntity;

            if (pars == null || pars.Type == null || pars.RefNoteID == null)
            {
                return;
            }

            EntityHelper helper     = new EntityHelper(this);
            Type         entityType = PXBuildManager.GetType(pars.Type, false);
            var          related    = new EntityHelper(this).GetEntityRow(entityType, pars.RefNoteID);

            if (related == null)
            {
                return;
            }

            Type graphType = helper.GetPrimaryGraphType(entityType, related, true);

            if (graphType == null)
            {
                return;
            }

            TMaster copy = PXCache <TMaster> .CreateCopy(row);

            PXGraph graph = CreateInstance(graphType);

            Type   noteType = EntityHelper.GetNoteType(entityType);
            PXView view     = new PXView(this, false, BqlCommand.CreateInstance(BqlCommand.Compose(typeof(Select <,>), entityType, typeof(Where <,>), noteType, typeof(Equal <>), typeof(Required <>), noteType)));

            graph.Caches[entityType].Current = view.SelectSingle(pars.RefNoteID);

            PXCache <TMaster> cache = graph.Caches <TMaster>();

            cache.SetDefaultExt(copy, typeof(CRActivity.bAccountID).Name);
            cache.SetDefaultExt(copy, typeof(CRActivity.contactID).Name);
            if (copy.BAccountID != null)
            {
                row.BAccountID = copy.BAccountID;
            }
            if (copy.ContactID != null)
            {
                row.ContactID = copy.ContactID;
            }
        }
Ejemplo n.º 12
0
        public DateTime?GetNextRunDate(Schedule schedule)
        {
            if (schedule.Active == false)
            {
                return(null);
            }

            Schedule copy = PXCache <Schedule> .CreateCopy(schedule);

            if (copy.LastRunDate != null && !(copy.Active == true && copy.NextRunDate == null))
            {
                return(copy.NextRunDate);
            }

            copy.NextRunDate = null;

            try
            {
                DateTime?businessDate = _graph.Accessinfo.BusinessDate;

                _graph.Accessinfo.BusinessDate = copy.NoEndDate == true
                                        ? DateTime.MaxValue
                                        : copy.EndDate;

                try
                {
                    IEnumerable <ScheduleDet> occurrences = new Scheduler(_graph).MakeSchedule(copy, 1);

                    if (occurrences.Any())
                    {
                        return(occurrences.First().ScheduledDate);
                    }
                }
                finally
                {
                    _graph.Accessinfo.BusinessDate = businessDate;
                }
            }
            catch (PXFinPeriodException exc) when(schedule.NextRunDate != null)
            {
                _graph.Caches <Schedule>().RaiseExceptionHandling <Schedule.nextRunDate>(
                    schedule,
                    schedule.NextRunDate,
                    new PXSetPropertyException(exc.Message, PXErrorLevel.Warning));
                return(schedule.NextRunDate);
            }

            return(copy.NextRunDate);
        }
Ejemplo n.º 13
0
            public static IEnumerable <TCategory> GetChildren(PXGraph graph, int?categoryID)
            {
                CategoryCache <TCategory> instance = GetInstance(graph);
                IEnumerable <TCategory>   children = instance._lookup[categoryID];

                var cache  = graph.Caches <TCategory>();
                var cached = cache.Cached.RowCast <TCategory>().Where(c => c.ParentID == categoryID && cache.GetStatus(c).IsIn(PXEntryStatus.Inserted, PXEntryStatus.Updated, PXEntryStatus.Deleted, PXEntryStatus.Modified)).ToArray();

                if (cached.Length > 0)
                {
                    var untouchedShared = children.Except(cached, cache.GetComparer()).ToArray();
                    var aliveLocal      = cached.Where(c => cache.GetStatus(c) != PXEntryStatus.Deleted).ToArray();
                    children = untouchedShared.Concat(aliveLocal).ToArray();
                }

                return(children);
            }
        public static string GetDefaultLotSerClass(PXGraph graph)
        {
            INLotSerClass lotSerClass = PXSelect <INLotSerClass, Where <INLotSerClass.lotSerTrack, Equal <INLotSerTrack.notNumbered> > > .Select(graph);

            if (lotSerClass == null)
            {
                PXCache       cache  = graph.Caches <INLotSerClass>();
                INLotSerClass lotser = (INLotSerClass)cache.CreateInstance();
                lotser.LotSerClassID = DfltLotSerialClass;
                lotser.LotSerTrack   = INLotSerTrack.NotNumbered;
                cache.Insert(lotser);
                return(lotser.LotSerClassID);
            }
            else
            {
                return(lotSerClass.LotSerClassID);
            }
        }
Ejemplo n.º 15
0
        public IEnumerable <Table> Cache <Table>(string parentKey, Func <IEnumerable <Table> > apiMethod) where Table : class, IBqlTable, new()
        {
            var inCache = new Dictionary <string, Table>();

            var cache = Graph.Caches <Table>();

            foreach (Table item in cache.Cached)
            {
                var name = (string)cache.GetValue(item, "name");

                if (name != null && inCache.ContainsKey(name) == false)
                {
                    inCache.Add(name, item);
                }

                var status = cache.GetStatus(item);

                if (status == PXEntryStatus.Inserted || status == PXEntryStatus.Updated || status == PXEntryStatus.Notchanged)
                {
                    yield return(item);
                }
            }

            bool isDirty = cache.IsDirty;

            foreach (object item in GetRecords(parentKey, apiMethod))
            {
                var key = (cache.GetValue(item, "id") ?? cache.GetValue(item, "name")).ToString();

                if (!inCache.ContainsKey(key))
                {
                    var record = cache.Insert(item) as Table;

                    if (record != null)
                    {
                        cache.SetStatus(record, PXEntryStatus.Notchanged);

                        yield return(record);
                    }
                }
            }

            cache.IsDirty = isDirty;
        }
 public void HoldPaymentIfNeeded(APRegister payment, bool?shouldStopPayments)
 {
     payment.Hold = shouldStopPayments == true &&
                    lienWaiverDataProvider.DoesAnyOutstandingComplianceExist(payment);
     graph.Caches <APPayment>().Update(payment);
 }
        public void DeleteJointPayeePayments(APPayment payment)
        {
            var jointPayeePayments = JointPayeePaymentDataProvider.GetJointPayeePayments(graph, payment);

            graph.Caches <JointPayeePayment>().DeleteAll(jointPayeePayments);
        }
		public virtual MatrixInventoryItem CreateMatrixItemFromTemplate(
			EntryMatrix row, int attributeNumber, InventoryItem template,
			List<INMatrixGenerationRule> idGenRules, List<INMatrixGenerationRule> descrGenRules)
		{
			int? inventoryId = GetValueFromArray(row?.InventoryIDs, attributeNumber);
			bool? selected = GetValueFromArray(row?.Selected, attributeNumber);
			if (inventoryId != null || selected != true)
				return null;

			var currentHeader = (EntryHeader)_graph.Caches[typeof(EntryHeader)].Current;
			var currentAdditionalAttr = (AdditionalAttributes)_graph.Caches[typeof(AdditionalAttributes)].Current;
			var matrixCache = _graph.Caches[typeof(MatrixInventoryItem)];

			var newItem = PropertyTransfer.Transfer(template, new MatrixInventoryItem());

			List<string> attributes = new List<string>(currentAdditionalAttr?.AttributeIdentifiers);
			attributes.Add(currentHeader?.RowAttributeID);
			attributes.Add(currentHeader?.ColAttributeID);
			List<string> attrValues = new List<string>(currentAdditionalAttr?.Values);
			attrValues.Add(row.RowAttributeValue);
			attrValues.Add(GetValueFromArray(row?.ColAttributeValues, attributeNumber));
			List<string> attrValueDescrs = new List<string>(currentAdditionalAttr?.Descriptions);
			attrValueDescrs.Add(row.RowAttributeValueDescr);
			attrValueDescrs.Add(GetValueFromArray(row?.ColAttributeValueDescrs, attributeNumber));

			newItem.AttributeIDs = attributes.ToArray();
			newItem.AttributeValues = attrValues.ToArray();
			newItem.AttributeValueDescrs = attrValueDescrs.ToArray();

			object newCD = GenerateMatrixItemID(template, idGenRules, newItem);
			matrixCache.RaiseFieldUpdating<MatrixInventoryItem.inventoryCD>(newItem, ref newCD);
			newItem.InventoryCD = (string)newCD;

			object newDescr = GenerateMatrixItemID(template, descrGenRules, newItem);
			matrixCache.RaiseFieldUpdating<MatrixInventoryItem.descr>(newItem, ref newDescr);
			newItem.Descr = (string)newDescr;

			if (PXDBLocalizableStringAttribute.IsEnabled)
			{
				PXCache templateCache = _graph.Caches<InventoryItem>();
				var oldDescr = template.Descr;

				DBMatrixLocalizableDescriptionAttribute.CopyTranslations<InventoryItem.descr, MatrixInventoryItem.descr>
					(templateCache, template, matrixCache, newItem, (translation) =>
				{
					template.Descr = translation;
					object newTranslation = GenerateMatrixItemID(template, descrGenRules, newItem);
					matrixCache.RaiseFieldUpdating<MatrixInventoryItem.descr>(newItem, ref newTranslation);
					return (string)newTranslation;
				});

				template.Descr = oldDescr;
			}

			newItem.Exists = (InventoryItem.UK.Find(_graph, newItem.InventoryCD) != null);
			newItem.Duplicate = matrixCache.Cached.RowCast<MatrixInventoryItem>().Any(mi => mi.InventoryCD == newItem.InventoryCD);
			newItem.Selected = (newItem.Exists != true && newItem.Duplicate != true);
			newItem.IsTemplate = false;

			return newItem;
		}