Beispiel #1
0
        public void PrepareWebFields(AvrPivotSettings pivotSettings)
        {
            //fill lookups for pivot header
            pivotSettings.Intervals         = GroupIntervalHelper.GetGroupIntervalLookup();
            pivotSettings.AggregateFuncions = GetAggregateFunctionsView();
            foreach (WebPivotGridField webField in pivotSettings.Fields)
            {
                if (webField.IsHiddenFilterField)
                {
                    webField.Visible = true;
                    //We set webField.Tag = true for all hidden fields
                    //to override PivotGridField.CanShowInPrefilter property that operates correctly with original propertied only.
                    webField.Tag             = true;
                    webField.SearchFieldType = GetSearchFieldType(webField);
                    //SetLookupValues(webField);
                }

                if (webField.IsDateTimeField && webField.GroupInterval == PivotGroupInterval.Default)
                {
                    webField.DefaultGroupInterval = GroupIntervalHelper.GetGroupInterval(pivotSettings.DefaultGroupInterval);
                }

//                PivotSummaryType summaryType = webField.CustomSummaryType == CustomSummaryType.Count
//                   ? PivotSummaryType.Count
//                   : PivotSummaryType.Custom;
//                webField.SummaryType = summaryType;
            }
        }
Beispiel #2
0
 public void PivotPresenterGetGroupIntervalTypeTest()
 {
     Assert.AreEqual(PivotGroupInterval.DateYear, GroupIntervalHelper.GetGroupInterval(-1));
     Assert.AreEqual(PivotGroupInterval.DateMonth,
                     GroupIntervalHelper.GetGroupInterval((long)DBGroupInterval.gitDateMonth));
     Assert.AreEqual(PivotGroupInterval.DateDayOfWeek,
                     GroupIntervalHelper.GetGroupInterval((long)DBGroupInterval.gitDateDayOfWeek));
     Assert.AreEqual(PivotGroupInterval.DateYear, GroupIntervalHelper.GetGroupInterval(DBNull.Value));
     Assert.AreEqual(PivotGroupInterval.DateYear, GroupIntervalHelper.GetGroupInterval(null));
 }
Beispiel #3
0
        private static PivotGridSettings CreateLayoutPivotGridSettings(AvrPivotGridModel model)
        {
            var  settings = new PivotGridSettings();
            bool readOnly = model.PivotSettings.IsPublished | !AvrPermissions.UpdatePermission;

            settings.Name = "pivotGrid";
            settings.CallbackRouteValues =
                new
            {
                Controller = "Layout",
                Action     = "PivotGridPartial",
                //queryId = model.PivotSettings.QueryId,
                layoutId = model.PivotSettings.LayoutId
            };
            settings.CustomActionRouteValues =
                new
            {
                Controller = "Layout",
                Action     = "PivotGridPartial",
                //queryId = model.PivotSettings.QueryId,
                layoutId = model.PivotSettings.LayoutId
            };
            settings.OptionsView.HorizontalScrollBarMode = model.PivotSettings.FreezeRowHeaders ? ScrollBarMode.Auto : ScrollBarMode.Hidden;
            if (model.PivotSettings.FreezeRowHeaders)
            {
                settings.Width = Unit.Percentage(99);
            }
            settings.OptionsView.ShowFilterHeaders              = false;
            settings.OptionsView.ShowColumnHeaders              = true;
            settings.OptionsView.ShowRowHeaders                 = true;
            settings.OptionsView.DataHeadersDisplayMode         = PivotDataHeadersDisplayMode.Popup;
            settings.OptionsView.DataHeadersPopupMaxColumnCount = 3;
            //settings.OptionsDataField.RowHeaderWidth = 100;
            settings.OptionsPager.Position    = PagerPosition.Bottom;
            settings.OptionsPager.RowsPerPage = BaseSettings.AvrRowsPerPage;

            // note: this option disables paging. commented by Ivan because of out of memory
            //  settings.OptionsPager.Visible = false;
            settings.OptionsBehavior.BestFitMode = PivotGridBestFitMode.FieldValue; // PivotGridBestFitMode.Cell;

            settings.CustomLoadCallbackState = CustomLoadCallbackState;

            settings.OptionsCustomization.AllowDrag   = !readOnly;
            settings.OptionsCustomization.AllowExpand = !readOnly;
            settings.OptionsCustomization.AllowDragInCustomizationForm = true;
            settings.OptionsCustomization.AllowHideFields        = AllowHideFieldsType.Always;
            settings.OptionsCustomization.CustomizationFormStyle = CustomizationFormStyle.Simple;
            settings.OptionsCustomization.AllowCustomizationForm = !readOnly;
            SetTotalSettings(settings.OptionsView, model.PivotSettings);
            if (!readOnly)
            {
                settings.PivotCustomizationExtensionSettings.Name           = "pivotCustomization";
                settings.PivotCustomizationExtensionSettings.Enabled        = true;
                settings.PivotCustomizationExtensionSettings.Visible        = true;
                settings.PivotCustomizationExtensionSettings.AllowedLayouts =
                    CustomizationFormAllowedLayouts.TopPanelOnly;
                settings.PivotCustomizationExtensionSettings.Layout      = CustomizationFormLayout.TopPanelOnly;
                settings.PivotCustomizationExtensionSettings.AllowSort   = true;
                settings.PivotCustomizationExtensionSettings.AllowFilter = false;
                settings.PivotCustomizationExtensionSettings.Height      = Unit.Percentage(100);
                settings.PivotCustomizationExtensionSettings.Width       = Unit.Percentage(100);
            }
            settings.OptionsCustomization.AllowPrefilter = false;
            settings.Prefilter.Enabled = false;
            settings.OptionsView.EnableFilterControlPopupMenuScrolling = true;
            settings.Prefilter.Criteria = CriteriaOperator.TryParse(model.PivotSettings.FilterCriteriaString);
            settings.Styles.PrefilterBuilderCloseButtonStyle.CssClass = "invisible";
            settings.Styles.PrefilterBuilderHeaderStyle.CssClass      = "roundbox";
            settings.PopupMenuCreated += PopupMenuCreated;
            settings.Styles.PrefilterBuilderMainAreaStyle.CssClass = "filterwindow";
            settings.FilterControlOperationVisibility = (sender, args) =>
            {
                WebPivotGridField webField = GetWebPivotGridFieldByName(model.PivotSettings.Fields, args.PropertyInfo.PropertyName);
                if (webField == null)
                {
                    args.Visible = false;
                    return;
                }
                switch (webField.SearchFieldType)
                {
                case SearchFieldType.ID:     //lookup
                    args.Visible = IsValidLookupClause(args.Operation);
                    break;

                case SearchFieldType.String:
                    args.Visible = IsValidStringClause(args.Operation);
                    break;

                case SearchFieldType.Date:
                    args.Visible = IsValidDateClause(args.Operation);
                    break;

                default:
                    args.Visible = IsValidDefaultClause(args.Operation);
                    break;
                }
            };
            settings.FilterControlCustomValueDisplayText = (sender, args) =>
            {
                if (args.Value == null)
                {
                    args.DisplayText = Translator.GetMessageString("FilterConrol_EmptyEnter");
                }
                else if (args.PropertyInfo.PropertyType == typeof(DateTime))
                {
                    args.DisplayText = string.Format("{0:d}", args.Value);
                }
            };
            settings.OptionsCustomization.AllowFilterInCustomizationForm = true;
            settings.Theme = GeneralSettings.Theme;
            settings.Fields.Clear();

            foreach (WebPivotGridField webField in
                     model.PivotSettings.Fields.Where(f => f.Visible && f.Area != PivotArea.FilterArea).OrderBy(f => (long)f.Area * 100000 + f.AreaIndex))
            {
                settings.Fields.Add(webField);
            }
            foreach (WebPivotGridField webField in
                     model.PivotSettings.Fields.Where(f => !f.Visible || f.Area == PivotArea.FilterArea).OrderBy(f => f.Caption))
            {
                settings.Fields.Add(webField);
            }

            settings.Init = (sender, args) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
                if (model.ShowingPrefilter)
                {
                    pivotGrid.PrefilterCriteriaChanged += PrefilterCriteriaChanged;
                }
                pivotGrid.FieldAreaChanged += PivotGridOnFieldAreaChanged;
                pivotGrid.HeaderTemplate    = new HeaderTemplate(model);
            };
            settings.PreRender = (sender, e) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
                pivotGrid.BeginUpdate();
                pivotGrid.HeaderTemplate = new HeaderTemplate(model);
                pivotGrid.EndUpdate();
            };

            settings.BeforeGetCallbackResult = (sender, e) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
                if (model.ShowPrefilter)
                {
                    pivotGrid.IsPrefilterPopupVisible = true;
                    CriteriaOperator criteria = CriteriaOperator.TryParse(model.PivotSettings.FilterCriteriaString);
                    criteria = ValidatePrefilterCriteria(criteria);
                    pivotGrid.Prefilter.Criteria = criteria;

                    model.ShowPrefilter    = false;
                    model.ShowingPrefilter = true;
                    return;
                }
                model.ShowingPrefilter = false;
                pivotGrid.BeginUpdate();
                try
                {
                    pivotGrid.Prefilter.Enabled = false;
                    UpdatePivotGridField(pivotGrid, model);

                    model.PivotSettings.UpdatedField = null;
                    if (model.PivotSettings.UpdateGroupInterval)
                    {
                        PivotGroupInterval interval = GroupIntervalHelper.GetGroupInterval(model.PivotSettings.DefaultGroupInterval);
                        SetInterval(pivotGrid, interval);
                        model.PivotSettings.UpdateGroupInterval = false;
                    }
                    SetTotalSettings(pivotGrid.OptionsView, model.PivotSettings);

                    pivotGrid.OptionsView.HorizontalScrollBarMode = model.PivotSettings.FreezeRowHeaders ? ScrollBarMode.Auto : ScrollBarMode.Hidden;
                    if (model.PivotSettings.FreezeRowHeaders)
                    {
                        pivotGrid.Width = Unit.Percentage(99);
                    }
                    else
                    {
                        pivotGrid.Width = Unit.Empty;
                    }
                    pivotGrid.ReloadData();
                }
                finally
                {
                    pivotGrid.EndUpdate();
                }
            };

            //settings.ClientSideEvents.EndCallback = "layoutPivotGrid.resizePivotGridEvent";

            settings.AfterPerformCallback = (sender, e) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;

                if (pivotGrid.HeaderTemplate == null)
                {
                    pivotGrid.HeaderTemplate = new HeaderTemplate(model);
                }
                //pivotGrid.BeginUpdate();
                //pivotGrid.ReloadData();
                //pivotGrid.EndUpdate();
            };

            settings.ClientSideEvents.CallbackError = "layoutPivotGrid.onCallbackError";
            settings.ClientSideEvents.EndCallback   = "layoutPivotGrid.onEndCallback";

            settings.CustomCellDisplayText = (sender, e) =>
            {
                InitDisplayTexthandler();

                m_DisplayTextHandler.DisplayAsterisk(new WebPivotCellDisplayTextEventArgs(e));
                if (e.DataField == null)
                {
                    return;
                }
                if (model.PivotSettings.FieldsDictionary.ContainsKey(e.DataField.FieldName))
                {
                    WebPivotGridField field = model.PivotSettings.FieldsDictionary[e.DataField.FieldName];
                    m_DisplayTextHandler.DisplayCellText(new WebPivotCellDisplayTextEventArgs(e), field.CustomSummaryType, field.Precision);
                }
            };

            settings.FieldValueDisplayText = (sender, e) =>
            {
                InitDisplayTexthandler();
                var eventArgs = new WebPivotFieldDisplayTextEventArgs(e);
                m_DisplayTextHandler.DisplayAsterisk(eventArgs);
                m_DisplayTextHandler.DisplayBool(eventArgs);

                if (m_CustomSummaryHandler == null)
                {
                    var helper = new AvrPivotGridHelperWeb((ASPxPivotGrid)sender)
                    {
                        SingleSearchObject = model.PivotSettings.IsSingleSearchObject
                    };

                    m_CustomSummaryHandler = new CustomSummaryHandler(helper);
                }
                var summaryTypes = new List <CustomSummaryType>();


                List <IAvrPivotGridField> dataFields = AvrPivotGridHelper.GetFieldCollectionFromArea(model.PivotSettings.Fields,
                                                                                                     PivotArea.DataArea);
                foreach (IAvrPivotGridField field in dataFields)
                {
                    summaryTypes.Add(field.CustomSummaryType);
                    m_DisplayTextHandler.DisplayStatisticsTotalCaption(eventArgs, summaryTypes);
                }
            };

            settings.CustomSummary = (sender, e) =>
            {
                if (m_CustomSummaryHandler == null)
                {
                    var helper = new AvrPivotGridHelperWeb((ASPxPivotGrid)sender);

                    m_CustomSummaryHandler = new CustomSummaryHandler(helper);
                }

                WebPivotGridField settingsField = model.PivotSettings.Fields.Find(f => f.FieldName == e.DataField.FieldName);
                var field = e.DataField as IAvrPivotGridField;

                if (settingsField != null && field != null && ((int)field.CustomSummaryType <= 0))
                {
                    field.CustomSummaryType    = settingsField.CustomSummaryType;
                    field.BasicCountFunctionId = settingsField.BasicCountFunctionId;
                    field.AggregateFunctionId  = settingsField.AggregateFunctionId;


                    field.UnitLayoutSearchFieldId = settingsField.UnitLayoutSearchFieldId;
                    field.UnitSearchFieldAlias    = settingsField.UnitSearchFieldAlias;
                    field.SearchFieldDataType     = settingsField.SearchFieldDataType;

                    field.DefaultGroupInterval = settingsField.DefaultGroupInterval;

                    field.Ordinal           = settingsField.Ordinal;
                    field.AddMissedValues   = settingsField.AddMissedValues;
                    field.DiapasonStartDate = settingsField.DiapasonStartDate;
                    field.DiapasonEndDate   = settingsField.DiapasonEndDate;
                    field.Precision         = settingsField.Precision;

                    field.AggregateFunctionId     = settingsField.AggregateFunctionId;
                    field.BasicCountFunctionId    = settingsField.BasicCountFunctionId;
                    field.UnitLayoutSearchFieldId = settingsField.UnitLayoutSearchFieldId;
                    field.UnitSearchFieldAlias    = settingsField.UnitSearchFieldAlias;
                    field.DateLayoutSearchFieldId = settingsField.DateLayoutSearchFieldId;
                    field.DateSearchFieldAlias    = settingsField.DateSearchFieldAlias;

                    if (settingsField.IsDateTimeField)
                    {
                        field.GroupInterval = settingsField.DefaultGroupInterval;
                    }

                    field.AllowMissedReferenceValues = settingsField.AllowMissedReferenceValues;
                    field.LookupTableName            = settingsField.LookupTableName;
                    field.GisReferenceTypeId         = settingsField.GisReferenceTypeId;
                    field.ReferenceTypeId            = settingsField.ReferenceTypeId;
                    field.LookupAttributeName        = settingsField.LookupAttributeName;
                    field.HaCode = settingsField.HaCode;

                    field.AllPivotFields       = settingsField.AllPivotFields;
                    field.FieldNamesDictionary = settingsField.FieldNamesDictionary;
                }
                m_CustomSummaryHandler.OnCustomSummary(sender, new WebPivotGridCustomSummaryEventArgs(e));
            };
            settings.CustomCellStyle = (sender, args) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
            };
            settings.HtmlCellPrepared = (sender, args) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
            };
            settings.HtmlFieldValuePrepared = (sender, args) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
            };
            settings.GridLayout = (sender, args) =>
            {
                var pivotGrid = (MVCxPivotGrid)sender;
                model.PivotSettings.HasChanges = true;
                var fieldsToDelete = new List <PivotGridFieldBase>();
                foreach (PivotGridField field in pivotGrid.Fields)
                {
                    WebPivotGridField webField = GetWebPivotGridFieldByFieldName(model.PivotSettings.Fields, field.FieldName);
                    if (webField != null)
                    {
                        PivotFieldItemBase visualField =
                            pivotGrid.Fields.Data.VisualItems.Data.FieldItems.SingleOrDefault(
                                s => s.FieldName == field.FieldName);
                        Dbg.Assert(visualField != null, "field {0} is not found in pivot fields list",
                                   field.FieldName);
                        if (!visualField.Visible && visualField.Area != PivotArea.FilterArea)
                        {
                            webField.Area      = PivotArea.FilterArea;
                            webField.AreaIndex = -1;
                            webField.FilterValues.Clear();
                            webField.SortOrder = field.SortOrder;
                            webField.Width     = field.Width;
                            ClearMissedValues(webField);
                        }
                        else
                        {
                            webField.Area      = field.Area;
                            webField.AreaIndex = field.AreaIndex;
                            webField.Visible   = field.Visible;
                            webField.SortOrder = field.SortOrder;
                            webField.Width     = field.Width;
                            webField.FilterValues.Assign(field.FilterValues);
                            //if (webField.IsDateTimeField && webField.GroupInterval == PivotGroupInterval.Default)
                            //{
                            //    webField.DefaultGroupInterval = GroupIntervalHelper.GetGroupInterval(model.PivotSettings.DefaultGroupInterval);
                            //    field.GroupInterval = webField.GroupInterval;
                            //}
                        }
                    }
                    else
                    {
                        fieldsToDelete.Add(field);
                    }
                }
                foreach (PivotGridFieldBase field in fieldsToDelete)
                {
                    field.Visible   = false;
                    field.Area      = PivotArea.FilterArea;
                    field.AreaIndex = -1;
                    pivotGrid.Fields.Remove(field);
                }
                //if (model.PivotSettings.ShowMissedValues)
                //{
                //    List<IAvrPivotGridField> fields = model.PivotSettings.Fields.Cast<IAvrPivotGridField>().ToList();
                //    AvrPivotGridHelper.AddMissedValuesInRowColumnArea(model, fields);
                //}
                if (fieldsToDelete.Count > 0)
                {
                    pivotGrid.ReloadData();
                }
            };
            return(settings);
        }
Beispiel #4
0
        public void SaveChanges(WebPivotGridField webField, LayoutDetailDataSet ds)
        {
            if (!Equals(BasicCountFunctionId, webField.BasicCountFunctionId))
            {
                webField.BasicCountFunctionId = BasicCountFunctionId;
                webField.HasChanges           = true;
            }
            if (!Equals(AggregateFunctionId, webField.AggregateFunctionId))
            {
                webField.AggregateFunctionId = AggregateFunctionId;
                webField.HasChanges          = true;
            }
            if (!Equals(Precision, webField.Precision))
            {
                webField.Precision  = Precision;
                webField.HasChanges = true;
            }
            if (!Equals(UnitLayoutSearchFieldId, webField.UnitLayoutSearchFieldId))
            {
                webField.UnitLayoutSearchFieldId = UnitLayoutSearchFieldId;
                if (UnitLayoutSearchFieldId != -1)
                {
                    var unitRow = ds.LayoutSearchField.Rows.Find(UnitLayoutSearchFieldId) as LayoutDetailDataSet.LayoutSearchFieldRow;

                    webField.UnitSearchFieldAlias = unitRow == null
                        ? string.Empty
                        : unitRow.strSearchFieldAlias;
                }
                webField.HasChanges = true;
            }
            if (!Equals(DateLayoutSearchFieldId, webField.DateLayoutSearchFieldId))
            {
                webField.DateLayoutSearchFieldId = DateLayoutSearchFieldId;
                webField.HasChanges = true;
            }
            PivotGroupInterval?interval = null;

            if (PrivateGroupInterval.HasValue)
            {
                interval = GroupIntervalHelper.GetGroupInterval(PrivateGroupInterval.Value);
            }
            if (!Equals(interval, webField.PrivateGroupInterval))
            {
                webField.PrivateGroupInterval = interval;
                webField.HasChanges           = true;
            }

            if (!Equals(DiapasonStartDate, webField.DiapasonStartDate))
            {
                webField.DiapasonStartDate = DiapasonStartDate;
                webField.HasChanges        = true;
            }
            if (!Equals(DiapasonEndDate, webField.DiapasonEndDate))
            {
                webField.DiapasonEndDate = DiapasonEndDate;
                webField.HasChanges      = true;
            }
            if (!Equals(AddMissedValues, webField.AddMissedValues))
            {
                webField.AddMissedValues = AddMissedValues;
                webField.UpdateImageIndex();
                webField.HasChanges = true;
            }
            LayoutDetailDataSet.LayoutSearchFieldRow row = GetLayoutSearchFieldRowByField(ds, webField);
            webField.Caption = (ModelUserContext.CurrentLanguage == Localizer.lngEn) ? CaptionEn : Caption;
            if (
                !Equals(string.IsNullOrEmpty(row.strNewFieldENCaption) ? row.strOriginalFieldENCaption : row.strNewFieldENCaption, CaptionEn))
            {
                row.strNewFieldENCaption = CaptionEn;
                webField.HasChanges      = true;
            }
            if (ModelUserContext.CurrentLanguage != Localizer.lngEn)
            {
                if (!Equals(string.IsNullOrEmpty(row.strNewFieldCaption) ? row.strOriginalFieldCaption : row.strNewFieldCaption, Caption))
                {
                    row.strNewFieldCaption = Caption;
                    webField.HasChanges    = true;
                }
            }
        }