1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using InABox.Configuration;
- using InABox.Core;
- namespace InABox.DynamicGrid
- {
- public class DynamicGridColumns : List<DynamicGridColumn>, GlobalConfigurationSettings, UserConfigurationSettings
- {
- public string GridName { get; set; }
- private static Dictionary<Type, List<DynamicGridColumn>> _columnscache = new Dictionary<Type, List<DynamicGridColumn>>();
- public void ExtractColumns(Type type, string prefix)
- {
- if (!_columnscache.ContainsKey(type))
- {
- _columnscache[type] = new List<DynamicGridColumn>();
- var properties = DatabaseSchema.Properties(type).OrderBy(x => x.Sequence);
- foreach (var prop in properties)
- {
- if (prop.Editor != null && !(prop.Editor is NullEditor))
- {
- var col = new DynamicGridColumn
- {
- ColumnName = prop.Name,
- Width = prop.Editor.Width,
- Alignment = prop.Editor.Alignment,
- Format = prop.Editor.Format,
- Editor = prop.Editor,
- Caption = prop.Caption
- };
- _columnscache[type].Add(col);
- }
- }
- }
- AddRange(_columnscache[type]);
- }
- public DynamicGridColumn Add<TType, TProperty>(Expression<Func<TType, TProperty>> member, int width, string caption, string format,
- Alignment alignment)
- {
- var name = CoreUtils.GetFullPropertyName(member, ".");
- var result = new DynamicGridColumn
- {
- ColumnName = name,
- Caption = caption,
- Width = width,
- Format = format,
- Alignment = alignment
- };
- Add(result);
- return result;
- }
- }
- }
|