예제 #1
0
 public GridOptions()
 {
     BandOptions   = new BandOptions();
     ColumnOptions = new ColumnOptions();
 }
예제 #2
0
        private static BandedGridColumn CreateColumn(IDynamicProperty property, ref int visibleIndexValue,
                                                     ColumnOptions columnOptions)
        {
            var newColumn = new BandedGridColumn();
            var isNumeric = true;

            newColumn.Caption   = property.DisplayName;
            newColumn.FieldName = property.Key;
            newColumn.Name      = "col" + property.Key;
            newColumn.OptionsColumn.ReadOnly = property.ReadOnly;
            newColumn.Visible = property.Visible;
            newColumn.Tag     = property.Key;
            newColumn.ToolTip = property.Description;
            newColumn.OptionsColumn.AllowSort   = columnOptions.AllowSort;
            newColumn.OptionsFilter.AllowFilter = columnOptions.AllowFilter;

            if (columnOptions.MinWidth.HasValue)
            {
                newColumn.MinWidth = columnOptions.MinWidth.Value;
            }

            if (columnOptions.ColumnEdit != null)
            {
                newColumn.ColumnEdit = columnOptions.ColumnEdit;
            }

            if (columnOptions.HorzAlign.HasValue)
            {
                newColumn.AppearanceCell.Options.UseTextOptions   = true;
                newColumn.AppearanceCell.TextOptions.HAlignment   = columnOptions.HorzAlign.Value;
                newColumn.AppearanceHeader.Options.UseTextOptions = true;
                newColumn.AppearanceHeader.TextOptions.HAlignment = columnOptions.HorzAlign.Value;
            }

            if (columnOptions.SummaryType == SummaryItemType.Custom)
            {
                newColumn.AppearanceHeader.Options.UseTextOptions = true;
                if (columnOptions.HorzAlign.HasValue)
                {
                    newColumn.AppearanceHeader.TextOptions.HAlignment = columnOptions.HorzAlign.Value;
                }
            }

            if (newColumn.Visible)
            {
                visibleIndexValue++;
                newColumn.VisibleIndex = visibleIndexValue;
                newColumn.ColVIndex    = visibleIndexValue;
            }
            else
            {
                newColumn.VisibleIndex = -1;
                newColumn.ColVIndex    = -1;
            }

            if (property.GetPropertyType() == typeof(string))
            {
                newColumn.UnboundType = UnboundColumnType.String;
                isNumeric             = false;
            }
            else if (property.GetPropertyType() == typeof(double))
            {
                newColumn.UnboundType = UnboundColumnType.Integer;
            }
            else if (property.GetPropertyType() == typeof(decimal))
            {
                newColumn.DisplayFormat.FormatString = "{0:n2}";
                newColumn.DisplayFormat.FormatType   = FormatType.Numeric;
                newColumn.UnboundType = UnboundColumnType.Decimal;
            }
            else if (property.GetPropertyType() == typeof(decimal?))
            {
                newColumn.DisplayFormat.FormatString = "{0:n2}";
                newColumn.DisplayFormat.FormatType   = FormatType.Numeric;
                newColumn.UnboundType = UnboundColumnType.Decimal;
            }
            else if (property.GetPropertyType() == typeof(int))
            {
                newColumn.DisplayFormat.FormatString = "{0:n0}";
                newColumn.DisplayFormat.FormatType   = FormatType.Numeric;
                newColumn.UnboundType = UnboundColumnType.Integer;
            }
            else if (property.GetPropertyType() == typeof(int?))
            {
                newColumn.DisplayFormat.FormatString = "{0:n0}";
                newColumn.DisplayFormat.FormatType   = FormatType.Numeric;
                newColumn.UnboundType = UnboundColumnType.Integer;
            }
            else if (property.GetPropertyType() == typeof(Quantity))
            {
                newColumn.DisplayFormat.FormatType = FormatType.None;
                newColumn.UnboundType = UnboundColumnType.Object;
            }
            else if (property.GetPropertyType() == typeof(DateTime) || property.GetPropertyType() == typeof(DateTime?))
            {
                // Wenn nur der Datumsanteil angezeigt werden soll, muss Value ein Datum ohne Uhrzeit haben.
                isNumeric = false;
                var d = property.Value as DateTime?;
                newColumn.DisplayFormat.FormatType = FormatType.DateTime;
                if (d != null && d.Value == d.Value.Date)
                {
                    newColumn.DisplayFormat.FormatString = "d"; // Nur Datum
                }
                else
                {
                    newColumn.DisplayFormat.FormatString = "g"; // Default: Datum und Zeit.
                }
                newColumn.UnboundType = UnboundColumnType.DateTime;
            }
            else if (property.GetPropertyType() == typeof(bool))
            {
                newColumn.UnboundType = UnboundColumnType.Boolean;
            }
            else
            {
                throw new PhuLiException(
                          string.Format("Type [{0}] not handled. Please add this type to the function.",
                                        property.GetPropertyType().FullName));
            }

            if (!string.IsNullOrEmpty(columnOptions.DisplayFormatString))
            {
                newColumn.DisplayFormat.FormatString = columnOptions.DisplayFormatString;
            }

            if (columnOptions.DisplayFormatType != null)
            {
                newColumn.DisplayFormat.FormatType = FormatType.Numeric;
            }

            if (isNumeric)
            {
                if (columnOptions.SummaryType != SummaryItemType.None)
                {
                    newColumn.SummaryItem.SummaryType   = columnOptions.SummaryType;
                    newColumn.SummaryItem.DisplayFormat = "{0:n0}";
                }
            }
            return(newColumn);
        }