예제 #1
0
        /// <summary>
        /// Adds the columns.
        /// </summary>
        /// <param name="columns">The columns.</param>
        /// <param name="itemType">Type of the item.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="prefix">The prefix.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="forFilter">if set to <c>true</c> [for filter].</param>
        /// <param name="displayColumns">The display columns.</param>
        /// <param name="columnOrder">The column order.</param>
        public static void AddColumns(
            this ColumnCollection columns,
            Type itemType,
            IRefreashable owner,
            string prefix = null,
            string tableName = null,
            bool forFilter = false,
            string[] displayColumns = null,
            IList<string> columnOrder = null)
        {
            //aggregate own and parent's columns and return in default order
            var columnsList = new ColumnCollection();

            AddColumnsInternal(columnsList, itemType, owner, prefix, tableName, forFilter, displayColumns, columnOrder);

            columns.AddRange(columnsList.OrderBy(c => c.DefaultOrder));
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnItem"/> class.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="columns">The columns.</param>
 public ColumnItem(IRefreashable model, ColumnCollection columns)
 {
     _model = model;
     _parentCollection = columns;
     AggregateCriteriaList = new List<AggregateDefinition>();
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnItem" /> class.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="columns">The columns.</param>
 public CrossRefColumnItem(IRefreashable model, ColumnCollection columns) : base(model, columns)
 {
 }
예제 #4
0
 /// <summary>
 /// Creates the column.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="columns">The columns.</param>
 /// <param name="crossRef">The cross reference.</param>
 /// <returns>ColumnItem.</returns>
 public static ColumnItem CreateColumn(IRefreashable owner, ColumnCollection columns, CrossRefFieldAttribute crossRef = null)
 {
     return crossRef != null ? new CrossRefColumnItem(owner, columns) : new ColumnItem(owner, columns);
 }
예제 #5
0
        /// <summary>
        /// Adds the columns internal.
        /// </summary>
        /// <param name="columnsList">The columns list.</param>
        /// <param name="itemType">Type of the item.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="prefix">The prefix.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="forFilter">if set to <c>true</c> [for filter].</param>
        /// <param name="displayColumns">The display columns.</param>
        /// <param name="columnOrder">The column order.</param>
        /// <param name="hiddenProps">The hidden props.</param>
        private static void AddColumnsInternal(
            ColumnCollection columnsList,
            Type itemType,
            IRefreashable owner,
            string prefix = null,
            string tableName = null,
            bool forFilter = false,
            string[] displayColumns = null,
            IList<string> columnOrder = null,
            List<string> hiddenProps = null)
        {
            var props = itemType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            var inheritanceHelperType = itemType.Assembly.GetType(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", itemType.Namespace, Constants.InheritanceHelperClassName));
            if (hiddenProps == null)
                hiddenProps = new List<string>();

            if (inheritanceHelperType != null)
            {
                var hiddenPropsProp = inheritanceHelperType.GetProperty(Constants.HiddenFieldListMethodName, BindingFlags.Static | BindingFlags.Public);

                if (hiddenPropsProp != null)
                {
                    var value = hiddenPropsProp.GetValue(null, null);
                    if (value != null)
                        hiddenProps.AddRange((List<string>)value);
                }
            }

            foreach (var prop in props)
            {
                if (prop.Name == Constants.BaseInfoPropertyName)
                {
                    AddBaseProcessProperties(columnsList, owner, prefix, forFilter, displayColumns, columnOrder, hiddenProps, prop);
                }

                if (hiddenProps.Contains(prop.Name))
                    continue;

                // for CR filter we need to skip some system fields
                if (forFilter)
                    if (Constants.CurrentStateColumnName.Equals(prop.Name))
                        continue;

                if (Constants.BaseInfoPropertyName.Equals(prefix) && Constants.DerivedProcessColumnName.Equals(prop.Name))
                    continue;

                var display = (from d in prop.GetCustomAttributes(typeof(DisplayAttribute), false) select d).FirstOrDefault() as DisplayAttribute;
                var crossRef = (CrossRefFieldAttribute)(from d in prop.GetCustomAttributes(typeof(CrossRefFieldAttribute), false) select d).FirstOrDefault();

                if (display == null || string.IsNullOrEmpty(display.Name))
                    continue;

                var column = ColumnFactory.CreateColumn(owner, columnsList, crossRef);
                column.Header = display.GetName();
                column.Property = prop;
                column.IsGroupable = column.CanBeGrouped(prop);

                column.ReferenceTableName = (crossRef == null || string.IsNullOrWhiteSpace(crossRef.ReferenceTableName)) ? string.Empty : crossRef.ReferenceTableName;

                column.IsBase = !string.IsNullOrWhiteSpace(prefix);

                if (forFilter)
                    column.ColumnName = crossRef != null && !crossRef.AllowMultiple ? prop.Name + "Id" : prop.Name;
                else
                    column.ColumnName = prop.Name;

                if (displayColumns != null)
                    if (!displayColumns.Contains(column.ColumnName))
                        continue;

                column.Prefix = prefix;
                column.TableName = tableName;

                if (columnOrder != null)
                {
                    var fullColumnName = column.IsBase ? string.Format(CultureInfo.InvariantCulture, "{0}.{1}", column.Prefix, column.ColumnName) : column.ColumnName;
                    if (columnOrder.Contains(fullColumnName))
                        column.DefaultOrder = columnOrder.ToList().IndexOf(fullColumnName);
                    else
                        continue;
                }

                columnsList.Add(column);
            }
        }
예제 #6
0
        /// <summary>
        /// Adds the base process properties.
        /// </summary>
        /// <param name="columnsList">The columns list.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="prefix">The prefix.</param>
        /// <param name="forFilter">if set to <c>true</c> [for filter].</param>
        /// <param name="displayColumns">The display columns.</param>
        /// <param name="columnOrder">The column order.</param>
        /// <param name="hiddenProps">The hidden props.</param>
        /// <param name="prop">The property.</param>
        private static void AddBaseProcessProperties(
            ColumnCollection columnsList,
            IRefreashable owner,
            string prefix,
            bool forFilter,
            string[] displayColumns,
            IList<string> columnOrder,
            IEnumerable<string> hiddenProps,
            PropertyInfo prop)
        {
            var method = prop.PropertyType.GetMethod(Constants.GetProcessDefinitionMethodName, BindingFlags.Static | BindingFlags.Public);

            var procDefinition = method.Invoke(null, BindingFlags.InvokeMethod, null, null, null);
            var table = ((ProcessDefinition)procDefinition).TableList.Last().Name;

            var baseProcessHiddenProps = hiddenProps.ToList();

            // Hide system fields from base process.
            if (!baseProcessHiddenProps.Contains(Constants.CurrentStateColumnName))
            {
                baseProcessHiddenProps.Add(Constants.CurrentStateColumnName);
            }

            if (!baseProcessHiddenProps.Contains(Constants.DerivedProcessDisplayNameColumnName))
            {
                baseProcessHiddenProps.Add(Constants.DerivedProcessDisplayNameColumnName);
            }

            if (!baseProcessHiddenProps.Contains(Constants.VersionNumber))
            {
                baseProcessHiddenProps.Add(Constants.VersionNumber);
            }

            if (!baseProcessHiddenProps.Contains(Constants.VersionDate))
            {
                baseProcessHiddenProps.Add(Constants.VersionDate);
            }

            if (!baseProcessHiddenProps.Contains(Constants.IdColumnName))
            {
                baseProcessHiddenProps.Add(Constants.IdColumnName);
            }

            AddColumnsInternal(
                columnsList,
                prop.PropertyType,
                owner,
                string.IsNullOrEmpty(prefix) ? Constants.BaseInfoPropertyName : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", prefix, Constants.BaseInfoPropertyName),
                table,
                forFilter,
                displayColumns,
                columnOrder,
                baseProcessHiddenProps);
        }