Exemplo n.º 1
0
        public void TestColumnsSerialization()
        {
            var childExprs = new List <IExpression> {
                new Int32ParameterExpression(1)
            };

            var column     = new BooleanColumn(new BooleanExpression("2 > ?", childExprs), "column");
            var serializer = new DataContractSerializer(typeof(BooleanColumn));
            var stream     = new MemoryStream();

            serializer.WriteObject(stream, column);
            stream.Seek(0, SeekOrigin.Begin);
            var deserializedColumn = (BooleanColumn)serializer.ReadObject(stream);

            Assert.AreEqual(column.Sql, deserializedColumn.Sql);
            Assert.AreEqual(column.ChildExpressions.Count, deserializedColumn.ChildExpressions.Count);
            Assert.AreEqual(1, (deserializedColumn.ChildExpressions[0] as Int32ParameterExpression).Value);
            Assert.AreEqual(column.ColumnName, deserializedColumn.ColumnName);

            var binaryExpr = new BinaryParameterExpression("id1", new byte[] { 0, 1, 2 });

            serializer = new DataContractSerializer(typeof(BinaryParameterExpression));
            stream     = new MemoryStream();
            serializer.WriteObject(stream, binaryExpr);
            stream.Seek(0, SeekOrigin.Begin);
            var deserializedExpr = (BinaryParameterExpression)serializer.ReadObject(stream);

            Assert.AreEqual(binaryExpr.ID, deserializedExpr.ID);
            Assert.AreEqual(binaryExpr.Value.Length, deserializedExpr.Value.Length);
            Assert.AreEqual(binaryExpr.Value[1], deserializedExpr.Value[1]);
        }
Exemplo n.º 2
0
 public BooleanPropertyMapping(BooleanColumn column, IMemberAccessor member, int fileIndex, int workIndex)
 {
     this.column    = column;
     this.member    = member;
     this.FileIndex = fileIndex;
     this.WorkIndex = workIndex;
 }
 public BooleanPropertyMapping(BooleanColumn column, IMemberAccessor member, int physicalIndex, int logicalIndex)
 {
     this.column   = column;
     Member        = member;
     PhysicalIndex = physicalIndex;
     LogicalIndex  = logicalIndex;
 }
Exemplo n.º 4
0
        private Column InitializeIsActiveColumn()
        {
            var column = new BooleanColumn
            {
                Name           = "IsActive",
                InitialVisible = true,
                Header         = Translator.Translate("ColumnIsActive.HeaderText"),
                Path           = "IsActive",
                CssClass       = "column-isactive",
            };

            return(column);
        }
Exemplo n.º 5
0
        public void BooleanColumn_AllDefault()
        {
            BooleanColumn c = new BooleanColumn(true);

            // Set a large number of values all to the default
            for (int i = 0; i < 8192; ++i)
            {
                c[i] = true;
            }

            // Verify the column serializes small (not to one bit per row)
            TreeDiagnostics diagnostics = TreeSerializer.Diagnostics(c, () => new BooleanColumn(true), TreeFormat.Binary);

            Assert.True(diagnostics.Length < 100);
        }
Exemplo n.º 6
0
        public IDataTableHelper GetFeilds(Type type)
        {
            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var filed in properties)
            {
                var isHidden = Attribute.GetCustomAttribute(filed, typeof(HideInDataTableAttribute)) != null;
                if (!isHidden)
                {
                    var displayNameAttr = ((DisplayNameAttribute)Attribute.GetCustomAttribute(filed, typeof(DisplayNameAttribute)))?.DisplayName;
                    var displayName     = string.IsNullOrEmpty(displayNameAttr) ? filed.Name : displayNameAttr;
                    if (filed.PropertyType == typeof(bool))
                    {
                        var checboxField = new BooleanColumn
                        {
                            Title = filed.Name.ToLower()
                        };
                        var stringCheckboxAttr = Attribute.GetCustomAttribute(filed, typeof(StringCheckboxAttribute));
                        if (stringCheckboxAttr != null)
                        {
                            checboxField.WhenFalse = ((StringCheckboxAttribute)stringCheckboxAttr).WhenFalse;
                            checboxField.WhenTrue  = ((StringCheckboxAttribute)stringCheckboxAttr).WhenTrue;
                        }
                        model.CheckBoxes.Add(checboxField);
                    }
                    else
                    {
                        model.StringColumns.Add(new StringColumn()
                        {
                            data = filed.Name.ToLower()
                        });
                    }
                    model.Headers.Add(displayName);
                }
            }
            return(this);
        }
        protected static IColumnDefinition CreateColumnDefinition(TextColumnDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition), "Column definition is not provided.");
            }

            string columnName = definition.Caption ?? definition.ColumnName;

            if (string.IsNullOrWhiteSpace(columnName))
            {
                throw new ArgumentNullException(nameof(definition), $"{nameof(definition.ColumnName)} cannot be empty.");
            }

            if (definition.ColumnType == null)
            {
                return(new IgnoredColumn(columnName));
            }

            switch (Type.GetTypeCode(definition.ColumnType))
            {
            case TypeCode.Empty:
            case TypeCode.Object:
            case TypeCode.DBNull:
                throw new ArgumentException($"Invalid column type: {definition.ColumnType.FullName}");

            case TypeCode.Boolean:
                var boolColumn = new BooleanColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.TrueString != null)
                {
                    boolColumn.TrueString = definition.TrueString;
                }
                if (definition.FalseString != null)
                {
                    boolColumn.FalseString = definition.FalseString;
                }
                if (definition.DefaultValue != null)
                {
                    boolColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    boolColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(boolColumn);

            case TypeCode.Char:
                var charColumn = new CharColumn(columnName)
                {
                    IsNullable    = definition.IsNullable,
                    AllowTrailing = definition.AllowTrailing
                };
                if (definition.DefaultValue != null)
                {
                    charColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                return(charColumn);

            case TypeCode.SByte:
                var sbyteColumn = new SByteColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    sbyteColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    sbyteColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    sbyteColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    sbyteColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    sbyteColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(sbyteColumn);

            case TypeCode.Byte:
                var byteColumn = new ByteColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    byteColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    byteColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    byteColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    byteColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    byteColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(byteColumn);

            case TypeCode.Int16:
                var shortColumn = new Int16Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    shortColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    shortColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    shortColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    shortColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    shortColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(shortColumn);

            case TypeCode.UInt16:
                var ushortColumn = new UInt16Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    ushortColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    ushortColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    ushortColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    ushortColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    ushortColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(ushortColumn);

            case TypeCode.Int32:
                var intColumn = new Int32Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    intColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    intColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    intColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    intColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    intColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(intColumn);

            case TypeCode.UInt32:
                var uintColumn = new UInt32Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    uintColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    uintColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    uintColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    uintColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    uintColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(uintColumn);

            case TypeCode.Int64:
                var longColumn = new Int64Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    longColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    longColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    longColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    longColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    longColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(longColumn);

            case TypeCode.UInt64:
                var ulongColumn = new UInt64Column(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    ulongColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    ulongColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    ulongColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    ulongColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    ulongColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(ulongColumn);

            case TypeCode.Single:
                var singleColumn = new SingleColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    singleColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    singleColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    singleColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    singleColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    singleColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(singleColumn);

            case TypeCode.Double:
                var doubleColumn = new DoubleColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    doubleColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    doubleColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    doubleColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    doubleColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    doubleColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(doubleColumn);

            case TypeCode.Decimal:
                var decimalColumn = new DecimalColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (definition.NumberStyles.HasValue)
                {
                    decimalColumn.NumberStyles = definition.NumberStyles.Value;
                }
                if (definition.DefaultValue != null)
                {
                    decimalColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    decimalColumn.OutputFormat = definition.OutputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    decimalColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    decimalColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(decimalColumn);

            case TypeCode.DateTime:
                var datetimeColumn = new DateTimeColumn(columnName)
                {
                    IsNullable = definition.IsNullable
                };
                if (!string.IsNullOrWhiteSpace(definition.InputFormat))
                {
                    datetimeColumn.InputFormat = definition.InputFormat;
                }
                if (!string.IsNullOrWhiteSpace(definition.OutputFormat))
                {
                    datetimeColumn.OutputFormat = definition.OutputFormat;
                }
                if (definition.DefaultValue != null)
                {
                    datetimeColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (!string.IsNullOrWhiteSpace(definition.Culture))
                {
                    datetimeColumn.FormatProvider = new CultureInfo(definition.Culture);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    datetimeColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(datetimeColumn);

            case TypeCode.String:
                var stringColumn = new StringColumn(columnName)
                {
                    IsNullable = definition.IsNullable,
                    Trim       = definition.Trim
                };
                if (definition.DefaultValue != null)
                {
                    stringColumn.DefaultValue = DefaultValue.Use(definition.DefaultValue);
                }
                if (definition.NullValues != null && definition.NullValues.Length > 0)
                {
                    stringColumn.NullFormatter = new NullFormatter(definition.NullValues, definition.NullComparison);
                }
                return(stringColumn);

            default:
                throw new ArgumentException("Invalid column type for text import/export.");
            }
        }
Exemplo n.º 8
0
        private void InitModel()
        {
            if (this.ItemType != null)
            {
                Model          item       = new Model();
                PropertyInfo[] infoArray2 = this.ItemType.GetProperties();
                GridFilters    filters    = new GridFilters();
                filters.MenuFilterText = "搜索";
                filters.ID             = "filters" + ID;
                for (int i = 0; i < infoArray2.Length; i++)
                {
                    Func <ColumnBase, bool> predicate = null;
                    PropertyInfo            property  = infoArray2[i];
                    ModelField field = new ModelField
                    {
                        Name = property.Name
                    };
                    #region  射字段类型
                    string fullName = property.PropertyType.FullName;
                    if (fullName.Contains("System.Int"))
                    {
                        var enumDataTypeAttr = AttributeHelper.GetAttribute <EnumDataTypeAttribute>(property);
                        if (enumDataTypeAttr == null)
                        {
                            field.Type = ModelFieldType.Int;
                        }
                    }
                    else if (fullName.Contains("System.DateTime"))
                    {
                        field.Type = ModelFieldType.Date;
                    }
                    else if (fullName.Contains("System.Single"))
                    {
                        field.Type = ModelFieldType.Float;
                    }
                    else if (fullName.Contains("System.Boolean"))
                    {
                        field.Type = ModelFieldType.Boolean;
                    }
                    else if (fullName.Contains("System.String"))
                    {
                        field.Type = ModelFieldType.String;
                    }
                    else if (!property.PropertyType.IsPrimitive)
                    {
                        field.Type = ModelFieldType.Object;
                    }
                    else
                    {
                        field.Type = ModelFieldType.Auto;
                    }
                    #endregion
                    item.Fields.Add(field);

                    if (predicate == null)
                    {
                        predicate = x => x.DataIndex == property.Name;
                    }
                    ColumnBase column = this.ColumnModel.Columns.FirstOrDefault <ColumnBase>(predicate);
                    if (column == null)
                    {
                        ColumnBase base2;
                        DataGridColumnAttribute displayAttr = AttributeHelper.GetAttribute <DataGridColumnAttribute>(property);
                        FilterAttribute         filterAttr  = AttributeHelper.GetAttribute <FilterAttribute>(property);
                        bool       simpleFilterable         = filterAttr != null && filterAttr.Enabled && filterAttr.FilterType == null;
                        GridFilter filter = null;
                        #region  射列类型
                        if (fullName.Contains("System.Int") ||
                            fullName.Contains("System.Single") ||
                            fullName.Contains("System.Decimal") ||
                            fullName.Contains("System.Double"))
                        {
                            NumberColumn column1 = new NumberColumn
                            {
                                Format = this.GetFormat(displayAttr, "0")
                            };
                            base2 = column1;
                            if (simpleFilterable && filterAttr.FilterType == null)
                            {
                                filter = new NumericFilter();
                            }
                        }
                        else if (fullName.Contains("System.DateTime"))
                        {
                            DateColumn column2 = new DateColumn
                            {
                                Format = this.GetFormat(displayAttr, "Y-m-d")
                            };
                            base2 = column2;
                            if (simpleFilterable)
                            {
                                filter = new DateFilter()
                                {
                                    AfterText  = "在这之后",
                                    BeforeText = "在这之前",
                                    OnText     = "在这天"
                                };
                            }
                        }
                        else if (fullName.Contains("System.Boolean"))
                        {
                            string[]      strArray = this.GetFormat(displayAttr, "是|否").Split(new char[] { '|' });
                            BooleanColumn column4  = new BooleanColumn
                            {
                                TrueText  = strArray[0],
                                FalseText = strArray[1]
                            };
                            base2 = column4;
                            if (simpleFilterable)
                            {
                                filter = new BooleanFilter()
                                {
                                    NoText  = strArray[1],
                                    YesText = strArray[0]
                                };
                            }
                        }
                        else if (fullName.Contains("System.String"))
                        {
                            base2 = new Column();
                            if (simpleFilterable)
                            {
                                filter = new StringFilter();
                            }
                        }
                        else if (!property.PropertyType.IsPrimitive)
                        {
                            base2 = new Column();
                            if (simpleFilterable)
                            {
                                filter = new StringFilter();
                            }
                        }
                        else
                        {
                            base2 = new Column();
                            if (simpleFilterable)
                            {
                                filter = new StringFilter();
                            }
                        }
                        #endregion
                        #region 生成外键过滤器
                        if (filterAttr != null && filterAttr.Enabled && filterAttr.FilterType != null)
                        {
                            Store store = new Store();
                            store.ID = "filterStore" + property.Name;
                            if (filterAttr.FilterType.IsEnum)
                            {
                                var valueType = filterAttr.FilterType;
                                var values    = Enum.GetValues(valueType);
                                var names     = Enum.GetNames(valueType);
                                List <KeyValueModel> enumDict = new List <KeyValueModel>();
                                for (int it = 0; it < values.Length; it++)
                                {
                                    var fieldInfo = valueType.GetField(names[it]);
                                    var descAttr  = AttributeHelper.GetAttribute <DescriptionAttribute>(fieldInfo);
                                    if (descAttr == null)
                                    {
                                        throw new Exception("枚举必须要有Description");
                                    }
                                    int key = (int)values.GetValue(it);
                                    enumDict.Add(new KeyValueModel()
                                    {
                                        Id   = key,
                                        Name = descAttr.Description
                                    });
                                }
                                Model model = new Model();
                                model.Fields.Add(new ModelField("Id", ModelFieldType.Int));
                                model.Fields.Add(new ModelField("Name", ModelFieldType.String));
                                store.Model.Add(model);
                                store.DataSource = enumDict;
                                store.DataBind();
                                filter = new ListFilter()
                                {
                                    StoreID    = store.ID,
                                    Single     = true,
                                    IDField    = "Id",
                                    LabelField = "Name"
                                };
                            }
                            else
                            {
                                var filterObject = Activator.CreateInstance(filterAttr.FilterType);
                                var filterGen    = filterObject as ForeignFilterBase;
                                if (filterGen == null)
                                {
                                    throw new ArgumentException("FilterAttribute中的FilterType的类型必须为ForeignFilterBase的子类或枚举类型");
                                }
                                store.Model.Add(filterGen.GetModel());
                                store.DataSource = filterGen.GetData();
                                store.DataBind();
                                filter = new ListFilter()
                                {
                                    StoreID    = store.ID,
                                    Single     = true,
                                    IDField    = filterGen.IdField,
                                    LabelField = filterGen.LabelField
                                };
                            }
                            Bin.Add(store);
                        }
                        #endregion
                        base2.Text      = (displayAttr == null) ? property.Name : displayAttr.DisplayName;
                        base2.DataIndex = property.Name;
                        if (displayAttr != null && displayAttr.Width != -1)
                        {
                            base2.Width = displayAttr.Width;
                        }
                        if (displayAttr != null && displayAttr.ValueType != null)
                        {
                            Type valueType = displayAttr.ValueType;
                            var  values    = Enum.GetValues(valueType);
                            var  names     = Enum.GetNames(valueType);
                            Dictionary <int, string> enumDict  = new Dictionary <int, string>();
                            List <string>            valueList = new List <string>();
                            for (int it = 0; it < values.Length; it++)
                            {
                                var fieldInfo = valueType.GetField(names[it]);
                                var descAttr  = AttributeHelper.GetAttribute <DescriptionAttribute>(fieldInfo);
                                int key       = (int)values.GetValue(it);
                                enumDict.Add(key, descAttr.Description);
                                valueList.Add("values[" + key + "]=\"" + (descAttr != null ? descAttr.Description : names[it]) + "\";");
                            }

                            base2.Renderer.Fn = "function(){var values=Array();" + string.Join(string.Empty, valueList) + "return values[arguments[0]];}";
                        }
                        if (filter != null)
                        {
                            filter.DataIndex = property.Name;
                            filters.Filters.Add(filter);
                        }
                        column = base2;
                        this.ColumnModel.Columns.Add(base2);
                    }
                    column.TabIndex = (short)i;
                }
                Features.Add(filters);
                if (this.ColumnModel.Columns.Count >= 10)
                {
                    this.AutoScroll = true;
                }
                var list = ColumnModel.Columns.OrderBy(x => x.TabIndex).ToList();
                ColumnModel.Columns.Clear();
                ColumnModel.Columns.AddRange(list);
                this._store.Model.Add(item);
            }
        }
 public BooleanPropertyMapping(BooleanColumn column, PropertyInfo property)
 {
     this.column = column;
     this.property = property;
 }
 public BooleanPropertyMapping(BooleanColumn column, PropertyInfo property)
 {
     this.column   = column;
     this.property = property;
 }
Exemplo n.º 11
0
        public virtual ColumnBase CreateColumn()
        {
            ColumnBase column;

            if (HasChildren)
            {
                column = new Column {
                    Text = Header
                };

                if (ConfigureColumnHandler != null)
                {
                    ConfigureColumnHandler(column);
                }

                return(column);
            }

            var editor = CreateEditor();

            if (CreateColumnHandler != null)
            {
                column = CreateColumnHandler(this);
                if (editor != null)
                {
                    column.Editor.Add(editor);
                }

                if (ConfigureColumnHandler != null)
                {
                    ConfigureColumnHandler(column);
                }

                return(column);
            }

            if (IsTreeColumn)
            {
                column = new TreeColumn
                {
                    DataIndex = ColumnNameIndex,
                    Text      = Header,
                    Width     = new Unit(Width),
                    Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                    Sortable  = !string.IsNullOrEmpty(Sort),
                };
            }
            else
            {
                switch (ModelFieldType)
                {
                case ModelFieldType.Auto:
                    column = new Column
                    {
                        DataIndex = ColumnNameIndex,
                        Text      = Header,
                        Width     = new Unit(Width),
                        Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                        Hidden    = DefaultHidden,
                        Sortable  = !string.IsNullOrEmpty(Sort),
                    };
                    break;

                case ModelFieldType.String:
                    column = new Column
                    {
                        DataIndex = ColumnNameIndex,
                        Text      = Header,
                        Width     = new Unit(Width),
                        Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                        Hidden    = DefaultHidden,
                        Wrap      = Wrap ?? true,
                        Sortable  = !string.IsNullOrEmpty(Sort),
                    };
                    break;

                case ModelFieldType.Int:
                    var intColumn = new NumberColumn
                    {
                        DataIndex = ColumnNameIndex,
                        Text      = Header,
                        Width     = new Unit(Width),
                        Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                        Hidden    = DefaultHidden,
                        Sortable  = !string.IsNullOrEmpty(Sort),
                    };
                    if (!string.IsNullOrEmpty(Format))
                    {
                        intColumn.Format = GetIntFormat();
                    }
                    intColumn.Align = Alignment.Right;
                    //intColumn.Renderer.Handler = "debugger;return record.raw[metadata.column.dataIndex] == null && !value ? '' : value;";
                    column = intColumn;
                    break;

                case ModelFieldType.Float:
                    var floatColumn = new NumberColumn
                    {
                        DataIndex = ColumnNameIndex,
                        Text      = Header,
                        Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                        Hidden    = DefaultHidden,
                        Sortable  = !string.IsNullOrEmpty(Sort),
                    };
                    if (!string.IsNullOrEmpty(Format))
                    {
                        floatColumn.Format = GetFloatFormat();
                    }
                    floatColumn.Align = Alignment.Right;
                    //floatColumn.Renderer.Handler = "debugger;return record.raw[metadata.column.dataIndex] == null && !value ? '' : value;";
                    column = floatColumn;
                    break;

                case ModelFieldType.Boolean:
                    if (EditModeForBool && CanEdit)
                    {
                        column = new CheckColumn
                        {
                            DataIndex     = ColumnNameIndex,
                            Text          = Header,
                            StopSelection = false,
                            Editable      = CanEdit,
                            Width         = new Unit(Width),
                            Flex          = string.IsNullOrEmpty(Width) ? Flex : 0,
                            Hidden        = DefaultHidden,
                            Sortable      = !string.IsNullOrEmpty(Sort),
                        };

                        if (column.Renderer == null)
                        {
                            column.Renderer = new Renderer();
                        }
                        column.Renderer.Handler = string.Format(
                            "if (!record.data.CanEdit) return '<span style=\"font-size:11px\">' + (record.data.{0} ? {1} : {2}) + '</span>'; return (new Ext.ux.CheckColumn()).renderer(record.data.{0});",
                            ColumnNameIndex,
                            JSON.Serialize(TrueText),
                            JSON.Serialize(FalseText));
                    }
                    else
                    {
                        column = new BooleanColumn
                        {
                            DataIndex = ColumnNameIndex,
                            Text      = Header,
                            TrueText  = TrueText,
                            FalseText = FalseText,
                            Width     = new Unit(Width),
                            Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                            Hidden    = DefaultHidden,
                            Sortable  = !string.IsNullOrEmpty(Sort),
                        };
                    }

                    break;

                case ModelFieldType.Date:
                    column = new DateColumn
                    {
                        DataIndex = ColumnNameIndex,
                        Text      = Header,
                        Format    = GetDateFormat(),
                        Width     = new Unit(Width),
                        Flex      = string.IsNullOrEmpty(Width) ? Flex : 0,
                        Hidden    = DefaultHidden,
                        Sortable  = !string.IsNullOrEmpty(Sort),
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (SummaryType != null)
                {
                    column.SummaryType     = SummaryType.Value;
                    column.SummaryRenderer = new Renderer {
                        Handler = SummaryRendererHandler
                    };
                    column.CustomSummaryType = CustomSummaryType;
                }
            }

            if (editor != null)
            {
                column.Editor.Add(editor);
            }

            if (!string.IsNullOrEmpty(RendererFunction))
            {
                var handler = RendererFunction.Contains(" ") ?
                              $"function (value, metadata, record, rowIndex, colIndex, store, view) {{\n{RendererFunction}\n}}"
                    : RendererFunction;
                column.Renderer = new Renderer {
                    Handler = handler,
                };
            }

            if (Locked)
            {
                column.Locked = true;
            }

            ConfigureColumnHandler?.Invoke(column);

            return(column);
        }