Exemplo n.º 1
0
        public DefinitionTreeNode(Quantumart.QP8.BLL.Field fieldNotInDef, string parentPath, string ownPath, bool notInDefinition, bool isFromRelatedContent, IFieldService fieldService)
        {
            Id = ownPath ?? parentPath + Separator + fieldNotInDef.Id;

            text = fieldNotInDef.Name;

            using (fieldService.CreateQpConnectionScope())
            {
                if (isFromRelatedContent)
                {
                    if (!fieldNotInDef.Aggregated)
                    {
                        text += " из контента " + fieldNotInDef.Content.Name;
                    }
                }
            }

            expanded = false;

            //ноды которые не включены в описание не надо позволять раскрывать пока их не включат
            hasChildren = false;

            NotInDefinition = notInDefinition;

            MissingInQp = false;

            if (fieldNotInDef.RelationType != RelationType.None || fieldNotInDef.IsClassifier)
            {
                imageUrl = "images/icons/relation.gif";
                IconName = "link";
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rootContent"></param>
        /// <param name="notFoundInDef"></param>
        /// <param name="entityIds">int c id поля для невиртуальных полей и string с именем поля для виртуальных</param>
        /// <returns></returns>
        private object GetObjectFromDef(Content rootContent, out bool notFoundInDef, IEnumerable <object> entityIds)
        {
            object[] entityIdsToSearch = entityIds
                                         .Skip(1) //корень ровно один поэтому первый компонент пути нам не нужен
                                         .ToArray();

            object currentPositionObj = rootContent;

            notFoundInDef = false;

            foreach (object entityId in entityIdsToSearch)
            {
                if (currentPositionObj is Content)
                {
                    var currContent = (Content)currentPositionObj;

                    if (entityId is int)
                    {
                        currentPositionObj = currContent.Fields.SingleOrDefault(x => x.FieldId == (int)entityId);
                    }
                    else
                    {
                        currentPositionObj = currContent.Fields.SingleOrDefault(x => x.FieldName == (string)entityId && x is BaseVirtualField);
                    }

                    if (currentPositionObj == null)
                    {
                        //дурацкая система что Dictionaries это поле с id=0
                        if (entityId is int && (int)entityId == 0)
                        {
                            notFoundInDef = true;

                            return(new Dictionaries());
                        }

                        if (entityId is int)
                        {
                            int enitityIdInt = (int)entityId;

                            var qpField = _fieldService.Read(enitityIdInt);

                            if (qpField == null)
                            {
                                notFoundInDef = true;

                                return(null);
                            }

                            if (qpField.RelationType == RelationType.None && !qpField.IsClassifier)
                            {
                                currentPositionObj = new PlainField {
                                    FieldId = enitityIdInt, FieldName = qpField.Name
                                };

                                notFoundInDef = !currContent.LoadAllPlainFields;
                            }
                            else
                            {
                                using (_fieldService.CreateQpConnectionScope())
                                {
                                    if (qpField.ContentId == currContent.ContentId)
                                    {
                                        if (!qpField.IsClassifier)
                                        {
                                            currentPositionObj = new EntityField
                                            {
                                                FieldId     = enitityIdInt,
                                                FieldName   = qpField.Name,
                                                CloningMode = CloningMode.UseExisting,
                                                Content     =
                                                    new Content {
                                                    ContentId = qpField.RelateToContentId.Value, ContentName = qpField.RelatedToContent.Name
                                                }
                                            }
                                        }
                                    }
                                    ;
                                    else
                                    {
                                        currentPositionObj = new ExtensionField
                                        {
                                            FieldId     = qpField.Id,
                                            FieldName   = qpField.Name,
                                            CloningMode = CloningMode.UseExisting
                                        };

                                        var classifierContents = _fieldService.ListRelated(qpField.ContentId)
                                                                 .Where(x => x.Aggregated)
                                                                 .Select(x => x.Content);

                                        foreach (var classifierContent in classifierContents)
                                        {
                                            ((ExtensionField)currentPositionObj).ContentMapping.Add(
                                                classifierContent.Id,
                                                new Content {
                                                ContentId = classifierContent.Id, ContentName = classifierContent.Name
                                            });
                                        }
                                    }
                                    else
                                    {
                                        currentPositionObj = new BackwardRelationField
                                        {
                                            FieldId   = qpField.Id,
                                            FieldName = qpField.Name,
                                            Content   = new Content {
                                                ContentId = qpField.ContentId, ContentName = qpField.Content.Name
                                            },
                                            CloningMode = CloningMode.UseExisting
                                        };
                                    }
                                }

                                notFoundInDef = !qpField.IsClassifier || !currContent.LoadAllPlainFields;
                            }
                        }
Exemplo n.º 3
0
        public ConditionBase Map(ProductQuery source)
        {
            string[] queryParams   = source.Query.Split(new[] { '=' }, 2);
            string[] fields        = queryParams[0].Split('_');
            string   stringValue   = queryParams[1];
            object   value         = stringValue;
            var      queryFields   = new List <QueryField>();
            var      definition    = source.Definition;
            var      exstensionIds = source.ExstensionContentIds;
            int      fieldId       = 0;

            foreach (string fieldName in fields)
            {
                QueryField queryField = null;

                if (definition == null)
                {
                    throw new Exception("field " + fieldName + " does not match definition");
                }

                Field field = definition.Fields.FirstOrDefault(f => string.Equals(f.FieldName, fieldName, StringComparison.CurrentCultureIgnoreCase));
                if (field != null)
                {
                    fieldId = field.FieldId;
                }

                if (field is EntityField)
                {
                    queryField = new QueryField {
                        Name = fieldName
                    };
                    definition = ((EntityField)field).Content;
                }
                else if (field is ExtensionField)
                {
                    var extensionField = (ExtensionField)field;

                    var mapping = extensionField.ContentMapping
                                  .Where(m => exstensionIds.Contains(m.Key))
                                  .Select(m => new { ContentId = m.Key, Content = m.Value })
                                  .FirstOrDefault();


                    if (mapping == null)
                    {
                        throw new Exception("Field " + extensionField.FieldId + ", " + extensionField.FieldName + "does not registered");
                    }
                    else
                    {
                        queryField = new QueryField {
                            Name = fieldName, ContentId = mapping.ContentId
                        };
                        definition = mapping.Content;
                    }
                }
                else
                {
                    queryField = new QueryField {
                        Name = fieldName
                    };
                    definition = null;
                }

                queryFields.Add(queryField);
            }

            if (fieldId == 0)
            {
                throw new Exception("Incorrect condition or definition");
            }
            else
            {
                using (_fieldService.CreateQpConnectionScope())
                {
                    var field = _fieldService.Read(fieldId);

                    if (field.ExactType == FieldExactTypes.Numeric)
                    {
                        decimal numericValue;
                        if (decimal.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out numericValue))
                        {
                            value = numericValue;
                        }
                        else
                        {
                            throw new Exception("field " + field.Name + " must be numeric");
                        }
                    }
                    else if (new[] { FieldExactTypes.Time, FieldExactTypes.Date, FieldExactTypes.DateTime }.Contains(field.ExactType))
                    {
                        DateTime dateValue;
                        if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
                        {
                            value = dateValue;
                        }
                        else
                        {
                            throw new Exception("field " + field.Name + " must be date");
                        }
                    }
                }

                return(new ComparitionCondition(queryFields.ToArray(), value, "="));
            }
        }
Exemplo n.º 4
0
 public QPConnectionScope CreateQpConnectionScope()
 {
     return(_fieldService.CreateQpConnectionScope());
 }