예제 #1
0
        public void AddColumn(BTableColumnBase column)
        {
            if (Table.DataType == null)
            {
                throw new BlazuiException($"表格 {Table.GetType().Name} 没有设置 DataType 属性");
            }
            if (column.Property == null && !(column is BTableTemplateColumnBase))
            {
                throw new BlazuiException($"列 {column.Text} 没有设置 {nameof(BTableColumnBase.Property)} 属性");
            }

            PropertyInfo property = null;

            if (!string.IsNullOrWhiteSpace(column.Property))
            {
                property = Table.DataType.GetProperty(column.Property);
                if (property == null)
                {
                    throw new BlazuiException($"属性 {column.Property} 在 {Table.DataType.Name} 中不存在");
                }
            }
            var columnConfig = new TableHeader
            {
                Property   = property,
                Eval       = column.Property == null ? null : (Func <object, object>)(row => property.GetValue(row)),
                Text       = column.Text,
                Width      = column.Width,
                IsCheckBox = column.IsCheckBox,
                Template   = column.ChildContent
            };

            Table.Headers.Add(columnConfig);
        }
예제 #2
0
        public void AddColumn(BTableColumnBase column)
        {
            if (Table.DataType == null)
            {
                throw new BlazuiException($"表格 {Table.GetType().Name} 没有设置 DataType 属性");
            }
            if (column.Property == null && !(column is BTableTemplateColumnBase))
            {
                throw new BlazuiException($"列 {column.Text} 没有设置 {nameof(BTableColumnBase.Property)} 属性");
            }

            PropertyInfo property = null;

            if (!string.IsNullOrWhiteSpace(column.Property))
            {
                property = Table.DataType.GetProperty(column.Property);
                if (property == null)
                {
                    throw new BlazuiException($"属性 {column.Property} 在 {Table.DataType.Name} 中不存在");
                }
            }
            var columnConfig = new TableHeader
            {
                Property = property,
                Eval     = column.Property == null ? null : (Func <object, object>)(row =>
                {
                    var value = property.GetValue(row);
                    if (string.IsNullOrWhiteSpace(column.Format))
                    {
                        return(value);
                    }
                    if (value == null)
                    {
                        return(null);
                    }

                    try
                    {
                        return(Convert.ToDateTime(value).ToString(column.Format));
                    }
                    catch (InvalidCastException)
                    {
                        throw new BlazuiException("仅日期列支持 Format 参数");
                    }
                }),
                Text       = column.Text,
                Width      = column.Width,
                IsCheckBox = column.IsCheckBox,
                Template   = column.ChildContent,
                Format     = column.Format
            };

            Table.Headers.Add(columnConfig);
        }
예제 #3
0
        public void AddColumn(BTableColumnBase <TRow> column)
        {
            var columnConfig = new TableHeader <TRow>
            {
                Property   = column.Property == null ? string.Empty : GetPropertyName(column.Property),
                Eval       = column.Property == null ? null : column.Property.Compile(),
                Text       = column.Text,
                Width      = column.Width,
                IsCheckBox = column.IsCheckBox,
                Template   = column.ChildContent
            };

            Table.Headers.Add(columnConfig);
        }