示例#1
0
        private static object ConvertFieldValue(DataFolderElementsTreeNode dataFolderElementsTreeNode, object fieldValue)
        {
            if (dataFolderElementsTreeNode.FirstLetterOnly)
            {
                string stringFieldValue = (string)fieldValue;

                return(stringFieldValue.IsNullOrEmpty() ? "" : stringFieldValue.Substring(0, 1));
            }

            if (dataFolderElementsTreeNode.DateFormat != null)
            {
                if (fieldValue is DateTime)
                {
                    return(dataFolderElementsTreeNode.DateTimeFormater.SerializeDateTime((DateTime)fieldValue));
                }

                dataFolderElementsTreeNode.DateTimeFormater.GetDateTime(fieldValue);
                return(dataFolderElementsTreeNode.DateTimeFormater.Serialize(fieldValue));
            }

            return(fieldValue);
        }
示例#2
0
        /// <exclude />
        protected override void OnInitialize()
        {
            var parentNode = this.ParentNode as DataFolderElementsTreeNode;

            if (this.InterfaceType == null)
            {
                if (parentNode == null)
                {
                    AddValidationError("TreeValidationError.DataFolderElements.MissingInterfaceType");
                    return;
                }

                this.InterfaceType = parentNode.InterfaceType;
            }
            else
            {
                if (!typeof(IData).IsAssignableFrom(this.InterfaceType))
                {
                    AddValidationError("TreeValidationError.Common.NotImplementingIData", this.InterfaceType, typeof(IData));
                    return;
                }

                if (parentNode != null && parentNode.InterfaceType != this.InterfaceType)
                {
                    AddValidationError("TreeValidationError.DataFolderElements.WrongInterfaceType", this.InterfaceType, parentNode.InterfaceType);
                    return;
                }
            }


            this.PropertyInfo = this.InterfaceType.GetPropertiesRecursively().SingleOrDefault(f => f.Name == this.FieldName);
            if (this.PropertyInfo == null)
            {
                AddValidationError("TreeValidationError.Common.MissingProperty", this.InterfaceType, this.FieldName);
                return;
            }



            if (this.DateFormat != null && this.PropertyInfo.PropertyType != typeof(DateTime))
            {
                AddValidationError("TreeValidationError.DataFolderElements.DateFormetNotAllowed", this.FieldName, typeof(DateTime), this.PropertyInfo.PropertyType);
            }

            if (this.PropertyInfo.PropertyType == typeof(DateTime) && this.DateFormat == null)
            {
                AddValidationError("TreeValidationError.DataFolderElements.DateFormetIsMissing", this.FieldName);
                return;
            }


            this.DateTimeFormater = new DateTimeFormater(this.DateFormat);


            if (!string.IsNullOrEmpty(this.Range) && this.FirstLetterOnly)
            {
                AddValidationError("TreeValidationError.DataFolderElements.RangesAndFirstLetterOnlyNotAllowed");
            }

            if (this.FirstLetterOnly && this.PropertyInfo.PropertyType != typeof(string))
            {
                AddValidationError("TreeValidationError.DataFolderElements.WrongFirstLetterOnlyPropertyType", this.FieldName, typeof(string), this.PropertyInfo.PropertyType);
            }

            if (!string.IsNullOrEmpty(this.Range))
            {
                this.FolderRanges = FolderRangesCreator.Create(this, this.Range, this.FieldName, this.PropertyInfo.PropertyType);
            }

            if (this.ChildNodes.OfType <DataElementsTreeNode>().Any(f => f.InterfaceType != this.InterfaceType))
            {
                AddValidationError("TreeValidationError.DataFolderElements.WrongDateChildInterfaceType", this.InterfaceType);
            }

            this.SerializedInterfaceType = TypeManager.SerializeType(this.InterfaceType);



            this.AllGroupingNodes = new List <DataFolderElementsTreeNode>();

            var usedPropertyNames = new List <string>();
            var fieldTypes        = new List <Type>();
            DataFolderElementsTreeNode treeNode = this;
            int dataFolderElementCount          = 0;

            while (treeNode != null)
            {
                dataFolderElementCount++;
                if (treeNode.InterfaceType != this.InterfaceType)
                {
                    AddValidationError("TreeValidationError.DataFolderElements.InterfaceTypeSwitchNotAllowed", treeNode.InterfaceType, this.InterfaceType);
                    break;
                }

                if (treeNode.PropertyInfo.PropertyType != typeof(DateTime))
                {
                    if (usedPropertyNames.Contains(treeNode.FieldName))
                    {
                        AddValidationError("TreeValidationError.DataFolderElements.SameFieldUsedTwice", treeNode.FieldName);
                        break;
                    }

                    usedPropertyNames.Add(treeNode.FieldName);
                }

                this.AllGroupingNodes.Add(treeNode);

                if (treeNode.FolderRanges != null)
                {
                    fieldTypes.Add(typeof(int));
                }
                else if (treeNode.PropertyInfo.PropertyType == typeof(DateTime))
                {
                    fieldTypes.Add(treeNode.DateTimeFormater.GetTupleConstructor().DeclaringType);
                }
                else
                {
                    fieldTypes.Add(treeNode.PropertyInfo.PropertyType);
                }

                treeNode = treeNode.ParentNode as DataFolderElementsTreeNode;
            }

            Type type = GetTupleType(this.AllGroupingNodes.Count);

            type = type.MakeGenericType(fieldTypes.ToArray());

            this.AllGroupingsTupleConstructor = type.GetConstructors().Single();


            Type listType = typeof(List <>).MakeGenericType(this.InterfaceType);

            this.FolderIndexListAddMethodInfo   = listType.GetMethods().Single(f => f.Name == "Add");
            this.FolderIndexListClearMethodInfo = listType.GetMethods().Single(f => f.Name == "Clear");

            this.FolderIndexListObject    = Activator.CreateInstance(listType);
            this.FolderIndexListQueryable = ((IEnumerable)this.FolderIndexListObject).AsQueryable();


            if (this.FieldName == null)
            {
                this.GroupingValuesFieldName = this.FieldName;
            }
            else
            {
                this.GroupingValuesFieldName = string.Format("■{0}_{1}", this.FieldName, dataFolderElementCount);
            }


            this.IsTopFolderParent = (this.ParentNode is DataFolderElementsTreeNode) == false;
            this.ChildGeneratingDataElementsTreeNode = this.DescendantsBreadthFirst().OfType <DataElementsTreeNode>().First();
            IEnumerable <ParentIdFilterNode> parentIdFilterNodes = this.ChildGeneratingDataElementsTreeNode.FilterNodes.OfType <ParentIdFilterNode>();

            if (parentIdFilterNodes.Count() <= 1)
            {
                this.ChildGeneratingParentIdFilterNode = this.ChildGeneratingDataElementsTreeNode.FilterNodes.OfType <ParentIdFilterNode>().SingleOrDefault();
            }
            else
            {
                AddValidationError("TreeValidationError.DataFolderElements.TooManyParentIdFilters", treeNode.FieldName);
            }

            this.KeyPropertyInfo = this.InterfaceType.GetKeyProperties()[0];

            if (typeof(ILocalizedControlled).IsAssignableFrom(this.InterfaceType) == false)
            {
                this.ShowForeignItems = false;
            }
        }