public static PivotGridSettings LayoutPivotGridSettings(HttpRequestBase request) { AvrPivotGridModel model = GetModelFromSession(request); if (model.ControlPivotGridSettings == null || model.IsFirstLoad) { model.IsFirstLoad = false; m_CustomSummaryHandler = null; model.ControlPivotGridSettings = CreateLayoutPivotGridSettings(model); } return(model.ControlPivotGridSettings); }
private static void PivotGridOnFieldAreaChanged(object sender, PivotFieldEventArgs pivotFieldEventArgs) { var pivotGrid = (MVCxPivotGrid)sender; AvrPivotGridModel model = GetModelFromSession(pivotGrid.Request); PivotGridField field = pivotFieldEventArgs.Field; WebPivotGridField webField = GetWebPivotGridFieldByName(model.PivotSettings.Fields, field.ID); if (field.Area == webField.Area && field.AreaIndex == webField.AreaIndex && field.Visible == webField.Visible) { return; } bool copyAddMissedValues = field.Visible && (field.Area == PivotArea.ColumnArea || field.Area == PivotArea.RowArea) && (!webField.Visible || !(webField.Area == PivotArea.ColumnArea || webField.Area == PivotArea.RowArea)); bool clearMissedValues = !field.Visible || !(field.Area == PivotArea.ColumnArea || field.Area == PivotArea.RowArea); webField.Area = field.Area; webField.AreaIndex = field.AreaIndex; webField.Visible = field.Visible; if (copyAddMissedValues) { CopyMissedValuesToField(webField, model.PivotSettings.Fields); } else if (clearMissedValues) { ClearMissedValues(webField); } var adminUnitsList = AvrPivotGridHelper.GetAdministrativeUnitView(model.PivotSettings.QueryId, model.PivotSettings.Fields.ToList <IAvrPivotGridField>()); foreach (PivotGridField f in pivotGrid.Fields) { WebPivotGridField webF = GetWebPivotGridFieldByName(model.PivotSettings.Fields, f.ID); if (f.Visible && f.Area == field.Area && f.ID != field.ID) { webF.AreaIndex = f.AreaIndex; } if (webF.UnitLayoutSearchFieldId != -1 && webF.UnitLayoutSearchFieldId != 0) { if (adminUnitsList == null || adminUnitsList.Count == 0 || webF.Area != PivotArea.RowArea) { webF.UnitLayoutSearchFieldId = -1L; } else if (!webF.UnitLayoutSearchFieldId.Equals(adminUnitsList[0]["Id"])) { webF.UnitLayoutSearchFieldId = DBNull.Value.Equals(adminUnitsList[0]["Id"]) ? -1L : (long)adminUnitsList[0]["Id"]; } } } if (model.PivotSettings.ShowMissedValues) { AddMissedValues(model, true); pivotGrid.JSProperties["cpNeedCallback"] = true; //pivotGrid.ReloadData(); } else { LayoutValidateResult validateResult = FillEmptyValuesInDataArea(model); pivotGrid.JSProperties["cpNeedCallback"] = validateResult.IsCancelOrUserDialogCancel(); } // because AvrPivotGridHelperWeb which used inside m_CustomSummaryHandler should be re-initialized m_CustomSummaryHandler = null; }
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); }