private void CreateControl(PXFieldSelectingEventArgs arguments, CSAttributeGroup attributeGroup,
                                   string attributeId)
        {
            var attribute = GetAttribute(attributeGroup.AttributeID);

            switch (attribute.ControlType)
            {
            case CSAttribute.Text:
                CreateStringControl(arguments, attributeGroup);
                break;

            case CSAttribute.CheckBox:
                CreateCheckBoxControl(arguments, attributeGroup);
                break;

            case CSAttribute.Combo:
                CreateComboControl(attributeGroup, arguments, false);
                break;

            case CSAttribute.Datetime:
                CreateDatetimeControl(attributeGroup, arguments);
                break;

            case CSAttribute.MultiSelectCombo:
                CreateComboControl(attributeGroup, arguments, true);
                break;

            default:
                arguments.ReturnState = null;
                break;
            }
            ProcessReturnState(arguments, attributeId, attributeGroup);
        }
        private void CacheEventHandler(PXCache sender, object row, PXDBOperation operation, bool externalCall)
        {
            if (row == null)
            {
                return;
            }

            CSAttributeGroup cSAttributeGroup = (CSAttributeGroup)sender.CreateCopy(row);

            if (externalCall == true)
            {
                if (cSAttributeGroup.EntityType == typeof(TEntity1).FullName)
                {
                    cSAttributeGroup.EntityType = typeof(TEntity2).FullName;
                    UpdateCacheRecord(sender, cSAttributeGroup, operation);
                }
            }
            else
            {
                if (cSAttributeGroup.EntityType == typeof(TEntity2).FullName)
                {
                    cSAttributeGroup.EntityType = typeof(TEntity3).FullName;
                    UpdateCacheRecord(sender, cSAttributeGroup, operation);
                }
            }
        }
        protected virtual bool IsAttributeDefaultRowColumnAttribute(CSAttributeGroup attributeGroup, out string templateIDs)
        {
            const int    MaxTemplates = 10;
            const string Separator    = ", ";

            if (attributeGroup?.EntityType != typeof(InventoryItem).FullName)
            {
                templateIDs = null;
                return(false);
            }

            PXResultset <InventoryItem> template = PXSelect <InventoryItem,
                                                             Where <InventoryItem.isTemplate, Equal <True>, And <InventoryItem.itemClassID, Equal <Required <CSAttributeGroup.entityClassID> >,
                                                                                                                 And <Where <InventoryItem.defaultColumnMatrixAttributeID, Equal <Required <CSAttributeGroup.attributeID> >,
                                                                                                                             Or <InventoryItem.defaultRowMatrixAttributeID, Equal <Required <CSAttributeGroup.attributeID> > > > > > > >
                                                   .SelectWindowed(Base, 0, MaxTemplates, attributeGroup.EntityClassID, attributeGroup.AttributeID, attributeGroup.AttributeID);

            if (template.Count == 0)
            {
                templateIDs = null;
                return(false);
            }

            templateIDs = string.Join(Separator, template.RowCast <InventoryItem>().Select(s => s.InventoryCD));

            return(true);
        }
        private List <CSAttributeDetail> GetAttributeDetails(CSAttributeGroup attributeGroup)
        {
            var query = new PXSelect <CSAttributeDetail,
                                      Where <CSAttributeDetail.attributeID, Equal <Required <CSAttributeGroup.attributeID> > >,
                                      OrderBy <Asc <CSAttributeDetail.sortOrder> > >(graph);

            return(query.Select(attributeGroup.AttributeID).FirstTableItems.ToList());
        }
 private void ProcessAttributeGroup(PXCache cache, string documentsView,
                                    CSAttributeGroup attributeGroup)
 {
     if (!cache.Fields.Contains(attributeGroup.AttributeID.Trim()))
     {
         AddFieldsAndFieldEventHandlers(cache, documentsView, attributeGroup);
     }
 }
        private static string GetAnswerValue(CSAttributeGroup group, string value)
        {
            var checkboxValue = group.ControlType == CSAttribute.CheckBox
                                ? Convert.ToInt32(false).ToString()
                                : group.DefaultValue;

            return(value ?? checkboxValue);
        }
Esempio n. 7
0
        //Remove trailing spaces received from PXDimensionSelector
        protected virtual void CSAttributeGroup_EntityClassID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            CSAttributeGroup row = e.Row as CSAttributeGroup;

            if (row != null)
            {
                e.NewValue = CurrentTemplate.Current.ContractCD.Trim();
            }
        }
 private static CSAnswers CreateAnswer(CSAttributeGroup group, string value, Guid?noteId)
 {
     return(new CSAnswers
     {
         AttributeID = group.AttributeID,
         RefNoteID = noteId,
         Value = GetAnswerValue(group, value)
     });
 }
Esempio n. 9
0
        public void CreateRelatedEntityAttribute <TCache>(CSAttributeGroup attribute)
            where TCache : IBqlTable
        {
            var attributeGroupCache = (PXCache)graph.Caches <CSAttributeGroup>();
            var entityAttribute     = (CSAttributeGroup)attributeGroupCache.CreateCopy(attribute);

            entityAttribute.EntityType = typeof(TCache).FullName;
            attributeGroupCache.Insert(entityAttribute);
        }
        private static void CreateStringControl(PXFieldSelectingEventArgs args, CSAttributeGroup attributeGroup)
        {
            var required = attributeGroup.Required == true
                                ? 1
                                : -1;

            args.ReturnState = PXStringState.CreateInstance(args.ReturnState, null, null,
                                                            nameof(CSAnswers.value), false, required, null, null, null, false, null);
        }
Esempio n. 11
0
        protected virtual void CSAttributeGroup_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            CSAttributeGroup row = e.Row as CSAttributeGroup;

            if (row != null && Filter.Current != null)
            {
                row.EntityClassID = Filter.Current.ClassID;
                row.EntityType    = Filter.Current.EntityType;
            }
        }
        /// <summary>
        /// Configures the type of control for default value field on adding an attribute. Should be used on
        /// FieldSelecting event for <see cref="CSAttributeGroup.defaultValue"/>.
        /// </summary>
        public PXFieldState GetNewReturnState(object returnState, CSAttributeGroup attributeGroup)
        {
            attribute        = GetAttribute(attributeGroup);
            attributeDetails = GetAttributeDetails(attributeGroup);
            var requiredFieldState = attributeGroup.Required.GetValueOrDefault()
                                ? 1
                                : -1;

            return(GetNeededReturnState(returnState, requiredFieldState));
        }
        private void CreateDatetimeControl(CSAttributeGroup attributeGroup, PXFieldSelectingEventArgs args)
        {
            var required = attributeGroup.Required == true
                                ? 1
                                : -1;
            var attribute = GetAttribute(attributeGroup.AttributeID);

            args.ReturnState = PXDateState.CreateInstance(args.ReturnState, nameof(CSAnswers.value),
                                                          false, required, attribute.EntryMask, attribute.EntryMask, null, null);
        }
Esempio n. 14
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);
            }
        }
        private void AddFieldsAndFieldEventHandlers(PXCache cache, string documentsView,
                                                    CSAttributeGroup attributeGroup)
        {
            var attributeId = attributeGroup.AttributeID.Trim();

            cache.Fields.Add(attributeId);
            graph.FieldSelecting.AddHandler(documentsView, attributeId,
                                            (sender, args) => CreateControl(args, attributeGroup, attributeId));
            graph.FieldUpdating.AddHandler(documentsView, attributeId,
                                           (sender, args) => InsertOrUpdateAnswerValue(args, attributeGroup));
        }
Esempio n. 16
0
        public void DeleteRelatedEntityAnswer <TCache>(CSAttributeGroup attributeGroup)
            where TCache : IBqlTable
        {
            var entityAttribute = GetRelatedEntityAttribute <TCache>(
                attributeGroup.AttributeID, attributeGroup.EntityClassID);

            if (entityAttribute != null)
            {
                CSAttributeGroupList <IBqlTable, TCache> .DeleteAttributesForGroup(graph, entityAttribute);
            }
        }
        private static void CreateCheckBoxControl(PXFieldSelectingEventArgs args,
                                                  CSAttributeGroup attributeGroup)
        {
            var required = attributeGroup.Required == true
                                ? 1
                                : -1;

            args.ReturnState = PXFieldState.CreateInstance(args.ReturnState, typeof(bool), false, null, required, null,
                                                           null, false, nameof(CSAnswers.value), null, null, null, PXErrorLevel.Undefined, null,
                                                           null, null);
        }
        private void InsertAnswer(CSAttributeGroup group, object document, string value = null)
        {
            var noteId         = entityHelper.GetEntityNoteID(document);
            var existingAnswer = GetAnswer(group.AttributeID, document);

            if (existingAnswer == null)
            {
                var answer     = CreateAnswer(group, value, noteId);
                var castAnswer = CastAnswerToViewType(answer);
                answers.Cache.Insert(castAnswer);
            }
        }
Esempio n. 19
0
        public void UpdateRelatedEntityAttribute <TCache>(CSAttributeGroup attribute)
            where TCache : IBqlTable
        {
            var entityAttribute = GetRelatedEntityAttribute <TCache>(attribute.AttributeID, attribute.EntityClassID);

            if (entityAttribute != null)
            {
                var attributeGroupCache = (PXCache)graph.Caches <CSAttributeGroup>();
                attributeGroupCache.RestoreCopy(entityAttribute, attribute);
                entityAttribute.EntityType = typeof(TCache).FullName;
                attributeGroupCache.Update(entityAttribute);
            }
        }
        public virtual void MergeAttribute(INItemClass child, CSAttributeGroup existingAttribute, CSAttributeGroup attr,
                                           Action <INItemClass, CSAttributeGroup, CSAttributeGroup> baseMethod)
        {
            if (existingAttribute == null)
            {
                ValidateInsert(Base.Mapping.Cache, _childItemClassHasTemplateWithItems, attr, true);
            }
            else
            {
                ValidateUpdate(Base.Mapping.Cache, _childItemClassHasTemplateWithItems, attr, true, existingAttribute);
            }

            baseMethod.Invoke(child, existingAttribute, attr);
        }
        private void CreateComboControl(CSAttributeGroup attributeGroup, PXFieldSelectingEventArgs args,
                                        bool isMultiSelect)
        {
            var details  = GetAttributeDetails(attributeGroup.AttributeID);
            var values   = details.ToDictionary(detail => detail.ValueID, detail => detail.Description);
            var required = attributeGroup.Required == true
                                ? 1
                                : -1;

            args.ReturnState = PXStringState.CreateInstance(args.ReturnState, 255, null,
                                                            nameof(CSAnswers.value), false, required, null, values.Keys.ToArray(),
                                                            values.Values.ToArray(), true, null);
            ((PXStringState)args.ReturnState).MultiSelect = isMultiSelect;
        }
 private void InsertOrUpdateAnswerValue(PXFieldUpdatingEventArgs arguments, CSAttributeGroup group)
 {
     if (arguments.Row != null)
     {
         var answer = GetAnswer(group.AttributeID, arguments.Row);
         if (answer != null)
         {
             UpdateAnswer(arguments.NewValue, answer);
         }
         else
         {
             InsertAnswer(group, arguments.Row, arguments.NewValue.ToString());
         }
     }
 }
Esempio n. 23
0
 private void UpdateCacheRecord(PXCache sender, CSAttributeGroup cSAttributeGroup, PXDBOperation operation)
 {
     if (operation == PXDBOperation.Insert)
     {
         sender.Insert(cSAttributeGroup);
     }
     else if (operation == PXDBOperation.Update)
     {
         sender.Update(cSAttributeGroup);
     }
     else if (operation == PXDBOperation.Delete)
     {
         sender.Delete(cSAttributeGroup);
     }
 }
 private void ProcessReturnState(PXFieldSelectingEventArgs arguments, string attributeId,
                                 CSAttributeGroup attributeGroup)
 {
     if (arguments.ReturnState is PXFieldState fieldState)
     {
         if (arguments.Row != null)
         {
             UpdateFieldStateForExistingDocument(attributeId, arguments.Row, fieldState);
         }
         fieldState.SetFieldName(attributeId);
         fieldState.Visible     = attributeGroup.IsActive == true;
         fieldState.Visibility  = PXUIVisibility.Visible;
         fieldState.DisplayName = attributeGroup.Description.Trim();
         fieldState.Enabled     = areControlsEnabled;
     }
 }
        private PXResultset <CSAnswers, CSAttributeGroup, CSAttributeDetail2> GenerateAttributeList(int attributeNum)
        {
            PXResultset <CSAnswers, CSAttributeGroup, CSAttributeDetail2> list = new PXResultset <CSAnswers, CSAttributeGroup, CSAttributeDetail2>();

            PXSelectBase <CSAttributeGroup> query = new PXSelectJoin <CSAttributeGroup,
                                                                      InnerJoin <CSAttributeDetail2, On <CSAttributeGroupExt.usrCategory, Equal <CSAttributeDetail2.valueID>,
                                                                                                         And <CSAttributeDetail2.attributeID, Equal <Required <INSetupExt.usrCategoryAttribute> >,
                                                                                                              And <CSAttributeDetail2.sortOrder, Equal <Required <CSAttributeDetail2.sortOrder> >,
                                                                                                                   And <CSAttributeDetail2.disabled, Equal <False> > > > > >,
                                                                      Where <CSAttributeGroup.entityClassID, Equal <Required <InventoryItem.itemClassID> >
                                                                             , And <CSAttributeGroup.entityType, Equal <PCBConst.entityTypeIN> >
                                                                             >,
                                                                      OrderBy <Asc <CSAttributeGroup.sortOrder> > >(Base);

            InventoryItem current  = Base.Item.Current;
            INSetupExt    setupExt = Base.insetup.Current.GetExtension <INSetupExt>();

            if (current != null && current.InventoryID != null && setupExt != null) //&& current.InventoryID > 0
            {
                foreach (PXResult <CSAttributeGroup, CSAttributeDetail2> item in query.Select(setupExt.UsrCategoryAttribute, attributeNum, current.ItemClassID))
                {
                    CSAttributeGroup   attribute = item;
                    CSAttributeDetail2 detail    = item;

                    CSAnswers answerCheck = PXSelect <CSAnswers, Where <CSAnswers.refNoteID, Equal <Required <CSAnswers.refNoteID> >,
                                                                        And <CSAnswers.attributeID, Equal <Required <CSAnswers.attributeID> > > > >
                                            .Select(Base, current.NoteID, attribute.AttributeID);

                    if (answerCheck == null)
                    {
                        CSAnswers newAnswer = new CSAnswers();
                        newAnswer.AttributeID = attribute.AttributeID;
                        newAnswer.Value       = string.Empty;
                        newAnswer.Order       = attribute.SortOrder;
                        newAnswer.IsRequired  = attribute.Required;
                        newAnswer.RefNoteID   = current.NoteID;
                        list.Add(new PXResult <CSAnswers, CSAttributeGroup, CSAttributeDetail2>(newAnswer, attribute, detail));
                    }
                    else
                    {
                        list.Add(new PXResult <CSAnswers, CSAttributeGroup, CSAttributeDetail2>(answerCheck, attribute, detail));
                    }
                }
            }
            return(list);
        }
        protected virtual void ValidateUpdate(PXCache cache, Lazy <bool> hasTemplateWithChild, CSAttributeGroup row, bool throwException = false, CSAttributeGroup oldRow = null)
        {
            string templateIDs = string.Empty;

            if (oldRow == null)
            {
                oldRow = CSAttributeGroup.PK.Find(Base, row.AttributeID, row.EntityClassID, row.EntityType);
            }

            if (oldRow != null && oldRow.AttributeCategory != row.AttributeCategory &&
                row.IsActive == true && (hasTemplateWithChild.Value || IsAttributeDefaultRowColumnAttribute(row, out templateIDs)))
            {
                var exception = hasTemplateWithChild.Value ?
                                new PXSetPropertyException <CSAttributeGroup.attributeCategory>(Messages.CantChangeAttributeCategoryForMatrixItem) :
                                new PXSetPropertyException <CSAttributeGroup.attributeCategory>(Messages.CantChangeAttributeCategoryForMatrixTemplate, templateIDs);

                if (!throwException)
                {
                    cache.RaiseExceptionHandling <CSAttributeGroup.attributeCategory>(row, row.AttributeCategory, exception);
                }
                else
                {
                    throw exception;
                }
            }

            if (oldRow?.AttributeCategory == CSAttributeGroup.attributeCategory.Variant &&
                oldRow.IsActive != row.IsActive && (hasTemplateWithChild.Value || IsAttributeDefaultRowColumnAttribute(row, out templateIDs)))
            {
                var exception = hasTemplateWithChild.Value ?
                                new PXSetPropertyException <CSAttributeGroup.isActive>(Messages.CantChangeAttributeIsActiveFlagForMatrixItem) :
                                new PXSetPropertyException <CSAttributeGroup.isActive>(Messages.CantChangeAttributeIsActiveFlagForMatrixTemplate, templateIDs);

                if (!throwException)
                {
                    cache.RaiseExceptionHandling <CSAttributeGroup.isActive>(row, row.IsActive, exception);
                }
                else
                {
                    throw exception;
                }
            }
        }
        protected virtual void ValidateInsert(PXCache cache, Lazy <bool> hasTemplateWithChild, CSAttributeGroup row, bool throwException = false)
        {
            if (row.AttributeCategory == CSAttributeGroup.attributeCategory.Variant && row.IsActive == true && hasTemplateWithChild.Value)
            {
                var exception = new PXSetPropertyException <CSAttributeGroup.attributeCategory>(Messages.CantAddVariantAttributeForMatrixItem, row.AttributeID);

                if (!throwException)
                {
                    cache.RaiseExceptionHandling <CSAttributeGroup.attributeCategory>(row, row.AttributeCategory, exception);
                }
                else
                {
                    throw exception;
                }
            }
        }
Esempio n. 28
0
        protected virtual void CSAttributeGroup_DefaultValue_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            string           AnswerValueField  = "DefaultValue";
            int              AnswerValueLength = 60;
            CSAttributeGroup row = e.Row as CSAttributeGroup;

            if (row != null)
            {
                CSAttribute question = new PXSelect <CSAttribute>(this).Search <CSAttribute.attributeID>(row.AttributeID);
                PXResultset <CSAttributeDetail> options = PXSelect <CSAttributeDetail,
                                                                    Where <CSAttributeDetail.attributeID, Equal <Required <CSAttributeGroup.attributeID> > >,
                                                                    OrderBy <Asc <CSAttributeDetail.sortOrder> > > .Select(this, row.AttributeID);

                int required = -1;
                if ((bool)row.Required)
                {
                    required = 1;
                }

                if (options.Count > 0)
                {
                    //ComboBox:

                    List <string> allowedValues = new List <string>();
                    List <string> allowedLabels = new List <string>();

                    foreach (CSAttributeDetail option in options)
                    {
                        allowedValues.Add(option.ValueID);
                        allowedLabels.Add(option.Description);
                    }

                    string mask = question != null ? question.EntryMask : null;

                    e.ReturnState = PXStringState.CreateInstance(e.ReturnState, CSAttributeDetail.ParameterIdLength, true, AnswerValueField, false, required, mask, allowedValues.ToArray(), allowedLabels.ToArray(), true, null);
                    if (question.ControlType == CSAttribute.MultiSelectCombo)
                    {
                        ((PXStringState)e.ReturnState).MultiSelect = true;
                    }
                }
                else if (question != null)
                {
                    if (question.ControlType.Value == CSAttribute.CheckBox)
                    {
                        e.ReturnState = PXFieldState.CreateInstance(e.ReturnState, typeof(bool), false, false, required, null, null, false, AnswerValueField, null, null, null, PXErrorLevel.Undefined, true, true, null, PXUIVisibility.Visible, null, null, null);
                    }
                    else if (question.ControlType.Value == CSAttribute.Datetime)
                    {
                        string mask = question != null ? question.EntryMask : null;
                        e.ReturnState = PXDateState.CreateInstance(e.ReturnState, AnswerValueField, false, required, mask, mask, null, null);
                    }
                    else
                    {
                        //TextBox:
                        string mask = question != null ? question.EntryMask : null;

                        e.ReturnState = PXStringState.CreateInstance(e.ReturnState, AnswerValueLength, null, AnswerValueField, false, required, mask, null, null, true, null);
                    }
                }
            }
        }
Esempio n. 29
0
 /// <summary>
 /// Fills required fields for attribute group. Should be used on RowInserting event.
 /// </summary>
 public void InitializeInsertedAttribute <TPrimaryCache>(CSAttributeGroup attributeGroup, string classId)
     where TPrimaryCache : IBqlTable
 {
     attributeGroup.EntityClassID = classId;
     attributeGroup.EntityType    = typeof(TPrimaryCache).FullName;
 }
Esempio n. 30
0
 /// <summary>
 /// Configures the type of control for default value field on adding an attribute. Should be used on
 /// FieldSelecting event for <see cref="CSAttributeGroup.defaultValue"/>.
 /// </summary>
 public PXFieldState GetNewReturnState(object returnState, CSAttributeGroup attributeGroup)
 {
     return(dataProvider.GetNewReturnState(returnState, attributeGroup));
 }