Пример #1
0
        private ReportColumn FromPropertyItem(PropertyItem item, Field field)
        {
            var result = new ReportColumn();

            result.Name  = item.Name;
            result.Title = item.Title ?? item.Name;
            if (result.Title != null)
            {
                result.Title = LocalText.TryGet(result.Title) ?? result.Title;
            }

            if (item.Width != null)
            {
                result.Width = item.Width;
            }

            if (!string.IsNullOrWhiteSpace(item.DisplayFormat))
            {
                result.Format = item.DisplayFormat;
            }
            else
            {
                var dtf = field as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            var enumField = field as IEnumTypeField;

            if (enumField != null && enumField.EnumType != null)
            {
                result.Decorator = new EnumDecorator(enumField.EnumType);
            }

            if (!ReferenceEquals(null, field))
            {
                if (result.Title == null)
                {
                    result.Title = field.Title;
                }

                if (result.Width == null && field is StringField && field.Size != 0)
                {
                    result.Width = field.Size;
                }
            }

            result.DataType = !ReferenceEquals(null, field) ? field.ValueType : null;

            return(result);
        }
Пример #2
0
        public static ReportColumn FromField(Field field)
        {
            var column = new ReportColumn();
            column.Name = field.Name;
            column.Title = field.Title;

            if (field is StringField)
                if (field.Size != 0)
                    column.Width = field.Size;

            return column;
        }
Пример #3
0
        public static ReportColumn FromField(Field field)
        {
            var column = new ReportColumn();

            column.Name  = field.Name;
            column.Title = field.Title;

            if (field is StringField)
            {
                if (field.Size != 0)
                {
                    column.Width = field.Size;
                }
            }

            return(column);
        }
Пример #4
0
        private ReportColumn FromPropertyItem(PropertyItem item, Field field)
        {
            var result = new ReportColumn();
            result.Name = item.Name;
            result.Title = item.Title ?? item.Name;
            if (result.Title != null)
                result.Title = LocalText.TryGet(result.Title) ?? result.Title;

            if (item.Width != null)
                result.Width = item.Width;

            if (!string.IsNullOrWhiteSpace(item.DisplayFormat))
                result.Format = item.DisplayFormat;
            else
            {
                var dtf = field as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            var enumField = field as IEnumTypeField;
            if (enumField != null && enumField.EnumType != null)
            {
                result.Decorator = new EnumDecorator(enumField.EnumType);
            }

            if (!ReferenceEquals(null, field))
            {
                if (result.Title == null)
                    result.Title = field.Title;

                if (result.Width == null && field is StringField && field.Size != 0)
                    result.Width = field.Size;
            }

            result.DataType = !ReferenceEquals(null, field) ? field.ValueType : null;

            return result;
        }
Пример #5
0
        public static ReportColumn FromField(Field field, ITextLocalizer localizer)
        {
            var column = new ReportColumn
            {
                Name  = field.Name,
                Title = field.GetTitle(localizer)
            };

            if (field is StringField)
            {
                if (field.Size != 0)
                {
                    column.Width = field.Size;
                }
            }

            return(column);
        }
Пример #6
0
        private static ReportColumn FromMember(MemberInfo member, Type dataType, Field baseField)
        {
            if (member == null)
                throw new ArgumentNullException("member");

            var result = new ReportColumn();
            result.Name = member.Name;
            var displayAttr = member.GetCustomAttribute<DisplayNameAttribute>();
            if (displayAttr != null)
                result.Title = displayAttr.DisplayName;

            var sizeAttr = member.GetCustomAttribute<SizeAttribute>();
            if (sizeAttr != null && sizeAttr.Value != 0)
                result.Width = sizeAttr.Value;

            var formatAttr = member.GetCustomAttribute<DisplayFormatAttribute>();
            if (formatAttr != null)
                result.Format = formatAttr.Value;
            else
            {
                var dtf = baseField as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf) ||
                         dataType == typeof (DateTime) ||
                         dataType == typeof (DateTime?))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            if (!ReferenceEquals(null, baseField))
            {
                if (result.Title == null)
                    result.Title = baseField.Title;

                if (result.Width == null && baseField is StringField && baseField.Size != 0)
                    result.Width = baseField.Size;
            }

            result.DataType = dataType;

            return result;
        }
Пример #7
0
        private static ReportColumn FromMember(MemberInfo member, Type dataType, Field baseField)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            var result = new ReportColumn();

            result.Name = member.Name;
            var displayAttr = member.GetCustomAttribute <DisplayNameAttribute>();

            if (displayAttr != null)
            {
                result.Title = displayAttr.DisplayName;
            }

            var sizeAttr = member.GetCustomAttribute <SizeAttribute>();

            if (sizeAttr != null && sizeAttr.Value != 0)
            {
                result.Width = sizeAttr.Value;
            }

            var formatAttr = member.GetCustomAttribute <DisplayFormatAttribute>();

            if (formatAttr != null)
            {
                result.Format = formatAttr.Value;
            }
            else
            {
                var dtf = baseField as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf) ||
                         dataType == typeof(DateTime) ||
                         dataType == typeof(DateTime?))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            if (!ReferenceEquals(null, baseField))
            {
                if (result.Title == null)
                {
                    result.Title = baseField.Title;
                }

                if (result.Width == null && baseField is StringField && baseField.Size != 0)
                {
                    result.Width = baseField.Size;
                }
            }

            result.DataType = dataType;

            return(result);
        }
Пример #8
0
        public static ReportColumn FromPropertyItem(PropertyItem item, Field field, PropertyInfo property,
                                                    IServiceProvider provider, ITextLocalizer localizer)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (localizer is null)
            {
                throw new ArgumentNullException(nameof(localizer));
            }

            var result = new ReportColumn
            {
                Name  = item.Name,
                Title = item.Title ?? item.Name
            };

            if (result.Title != null)
            {
                result.Title = localizer.TryGet(result.Title) ?? result.Title;
            }

            if (item.Width != null)
            {
                result.Width = item.Width;
            }

            if (!string.IsNullOrWhiteSpace(item.DisplayFormat))
            {
                if (item.FormatterType == "Date" || item.FormatterType == "DateTime")
                {
                    result.Format = item.DisplayFormat switch
                    {
                        "d" => DateHelper.CurrentDateFormat,
                        "g" => DateHelper.CurrentDateTimeFormat.Replace(":ss", ""),
                        "G" => DateHelper.CurrentDateTimeFormat,
                        "s" => "yyyy-MM-ddTHH:mm:ss",
                        "u" => "yyyy-MM-ddTHH:mm:ss.fffZ",
                        _ => item.DisplayFormat,
                    };
                }
                else
                {
                    result.Format = item.DisplayFormat;
                }
            }
            else
            {
                var dtf = field as DateTimeField;
                if (dtf is object &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = DateHelper.CurrentDateTimeFormat;
                }
                else if (dtf is object)
                {
                    result.Format = DateHelper.CurrentDateTimeFormat;
                }
            }

            if (field is IEnumTypeField enumField && enumField.EnumType != null)
            {
                result.Decorator = new EnumDecorator(enumField.EnumType, localizer);
            }

            if (property != null)
            {
                var decorator = property.GetCustomAttribute <CellDecoratorAttribute>();
                if (decorator != null && decorator.DecoratorType != null)
                {
                    result.Decorator = (ICellDecorator)Activator.CreateInstance(decorator.DecoratorType);
                }
            }

            if (field is object)
            {
                if (result.Title == null)
                {
                    result.Title = field.GetTitle(localizer);
                }

                if (result.Width == null && field is StringField && field.Size != 0)
                {
                    result.Width = field.Size;
                }
            }

            result.DataType = field?.ValueType;

            return(result);
        }
Пример #9
0
        private static ReportColumn FromMember(MemberInfo member, Type dataType,
                                               Field baseField, ITextLocalizer localizer)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            var result = new ReportColumn
            {
                Name = member.Name
            };
            var displayAttr = member.GetCustomAttribute <DisplayNameAttribute>();

            if (displayAttr != null)
            {
                result.Title = displayAttr.DisplayName;
            }

            var sizeAttr = member.GetCustomAttribute <SizeAttribute>();

            if (sizeAttr != null && sizeAttr.Value != 0)
            {
                result.Width = sizeAttr.Value;
            }

            var formatAttr = member.GetCustomAttribute <DisplayFormatAttribute>();

            if (formatAttr != null)
            {
                result.Format = formatAttr.Value;
            }
            else
            {
                var dtf = baseField as DateTimeField;
                if (dtf is object && !dtf.DateOnly)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (dtf is object ||
                         dataType == typeof(DateTime) ||
                         dataType == typeof(DateTime?))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            if (baseField is object)
            {
                if (result.Title == null)
                {
                    result.Title = baseField.GetTitle(localizer);
                }

                if (result.Width == null && baseField is StringField && baseField.Size != 0)
                {
                    result.Width = baseField.Size;
                }
            }

            result.DataType = dataType;

            return(result);
        }