/// <summary> /// Customize the display text of individual column and row headers and filter dropdown items /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Grid_FieldValueDisplayText(object sender, PivotFieldDisplayTextEventArgs e) { string txt; PivotGridValueType vt = e.ValueType; // Value, Total, GrantTotal, CustomTotal PivotGridFieldContext fc = GetPivotGridFieldContext(e.Field); if (fc == null) { return; } if (fc.Aggregation.IsGroupingType) { object vo = e.Value; txt = GroupingMethods.FormatGroupedValue(fc.Qc, fc.Aggregation, vo); e.DisplayText = txt; } else if (fc.Aggregation.Role == AggregationRole.DataSummary) // data area header when 2 or more data fields { txt = PivotGridControlMx.BuildFieldCaption(fc.F); e.DisplayText = txt; } else { return; } return; }
/// <summary> /// SetFieldGridDataRow /// </summary> /// <param name="dr"></param> /// <param name="f"></param> void SetFieldGridDataRow(DataRow dr, PivotGridFieldMx f) { string label, txt; ResultsField rfld = f.ResultsField as ResultsField; ResultsTable rt = rfld.ResultsTable; ResultsFormat rf = rt.ResultsFormat; MetaColumn mc = rfld.MetaColumn; QueryColumn qc = rfld.QueryColumn; QueryTable qt = qc.QueryTable; Query q = qt.Query; dr["ColTypeImageCol"] = QueryTableControl.GetMetaColumnDataTypeImage(mc); dr["PivotFieldCol"] = f; // store reference to pivot field dr["FieldNameCol"] = f.Caption; dr["AggRoleCol"] = f.Aggregation.RoleLabel; dr["AggTypeCol"] = f.Aggregation.TypeLabel; // txt = GroupingTypeLabel(f); // dr["HeaderBinningCol"] = txt; dr["SourceColumnCol"] = PivotGridControlMx.BuildFieldCaption(f); label = qt.ActiveLabel; if (rf.Tables.Count > 1) { label = "T" + (rt.Position + 1) + " - " + label; } dr["SourceTableCol"] = label; return; }
/// <summary> /// The area that a field is located in has changed. /// If changed by the DX UI then the added members in PivotGridFieldMx must be updated /// If changed by Mobius code (InSetup = true) then nothing needed here. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Grid_FieldAreaChanged(object sender, PivotFieldEventArgs e) { if (InSetup) { return; } try { InSetup = true; PivotGridFieldContext fc = GetPivotGridFieldContext(e.Field); if (fc == null) { return; } PivotGridFieldMx f = fc.F; f.SyncMxRoleToDxArea(); ResultsField rfld = fc.ResultsField; if (rfld == null || rfld.MetaColumn == null) { return; } f.Aggregation.SetDefaultTypeIfUndefined(rfld.MetaColumn); // may need to set default type as well PivotGridControlMx.SetFieldCaption(f); PivotGrid.RefreshData(); // recalc summaries if (UpdateViewWhenGridControlChanges) { View.UpdateViewFieldsFromGridFields(); } return; } finally { InSetup = false; } }
/// <summary> /// Key Mobius classes related to and/or extending the DX classes /// </summary> void PivotGridControlMx() { PivotGridControlMx pgcMx = new PivotGridControlMx(); // Mx method extensions of the DX PivotGridControl PivotGridFieldMx pgfMx = pgcMx.Fields[0] as PivotGridFieldMx; // Mx extensions of the DX PivotGridField { AggregationDef ad = pgfMx.Aggregation; // Grouping and summarization for Mx field { AggregationRole ar = ad.Role; // Role of field in agg/pivot (similar to DX Area) SummaryTypeEnum st = ad.SummaryType; // Type of Mx summary GroupingTypeEnum gt = ad.GroupingType; // Type of Mx grouping Decimal nis = ad.NumericIntervalSize; // interval size for numeric grouping } ResultsField rfld = pgfMx.ResultsField as ResultsField; // Mobius ResultsField, QueryColumn and MetaColumn associated with field } }
/// <summary> /// Build the Grid fields for the PivotGridControl from the persisted Mobius view fields /// </summary> void BuildGridFieldsFromViewFields() { PivotGridFieldMx gf, gf2; PivotGridCtl.Fields.Clear(); PivotGridCtl.Groups.Clear(); PivotGridPropertiesMx p = PivotGridPropertiesMx; for (int fi = 0; fi < p.PivotFields.Count; fi++) // build grid fields from view fields { PivotGridFieldMx pf = p.PivotFields[fi]; ResultsField rfld = pf.ResultsField as ResultsField; if (rfld == null) { continue; } PivotGridControlMx.SetFieldCaption(pf); // be sure we have a caption Mobius.Data.QueryColumn qc = rfld.QueryColumn; MetaColumn mc = rfld.MetaColumn; gf = new PivotGridFieldMx(); pf.CopyField(gf); pf.SyncDxAreaToMxRole(); if (mc.IsKey) { gf.ImageIndex = (int)Bitmaps16x16Enum.Key; } else { gf.ImageIndex = (int)mc.DataTypeImageIndex; } gf.Options.AllowRunTimeSummaryChange = true; gf.Options.ShowUnboundExpressionMenu = true; PivotGridCtl.Fields.Add(gf); } return; }
/// <summary> /// Add a new field associated with specified ResultsField /// </summary> /// <param name="rfld"></param> /// <param name="Fields"></param> /// <param name="area"></param> /// <param name="visible"></param> /// <param name="pgi"></param> /// <returns></returns> internal static PivotGridFieldMx AddField( ResultsField rfld, List <PivotGridFieldMx> Fields, PivotArea area, bool visible, PivotGridGroup group, GroupingTypeEnum pgi) { QueryColumn qc = rfld.QueryColumn; MetaColumn mc = qc.MetaColumn; QueryTable qt = qc.QueryTable; PivotGridFieldMx f = new PivotGridFieldMx(); if (mc.IsKey) { f.ImageIndex = (int)Bitmaps16x16Enum.Key; } else { f.ImageIndex = (int)mc.DataTypeImageIndex; } f.UnboundFieldName = qt.Alias + "." + mc.Name + // identify by tableAlias.mcName (allows multiple instances of same metatable in query) "." + (UnboundFieldNameCount++); // and make unique in case used in multiple PivotGroupIntervals (needed?) f.ResultsField = rfld; // store associated results field f.SummaryTypeMx = SummaryTypeEnum.Count; f.Area = area; f.Visible = visible; // if not visible then put in list of unused fields f.Aggregation.GroupingType = pgi; PivotGridControlMx.SetFieldCaption(f); Fields.Add(f); if (group != null) { group.Add(f); // add to group } return(f); }
/// <summary> /// BeginSerialization /// </summary> /// <param name="tw"></param> public override void BeginSerialization(XmlTextWriter tw) { base.BeginSerialization(tw); PivotGridPropertiesMx p = PivotGridPropertiesMx; if (p == null) { return; } tw.WriteStartElement("PivotGridView"); tw.WriteAttributeString("CompactLayout", p.CompactLayout.ToString()); tw.WriteAttributeString("ShowColumnTotals", p.ShowColumnTotals.ToString()); tw.WriteAttributeString("ShowColumnGrandTotals", p.ShowColumnGrandTotals.ToString()); tw.WriteAttributeString("ShowRowTotals", p.ShowRowTotals.ToString()); tw.WriteAttributeString("ShowRowGrandTotals", p.ShowRowGrandTotals.ToString()); tw.WriteAttributeString("ShowFilterHeaders", p.ShowFilterHeaders.ToString()); tw.WriteAttributeString("PivotGridChartType", p.PivotGridChartType); tw.WriteAttributeString("PgcShowSelectionOnly", p.PgcShowSelectionOnly.ToString()); tw.WriteAttributeString("PgcDataVertical", p.PgcProvideDataByColumns.ToString()); tw.WriteAttributeString("PgcShowPointLabels", p.PgcShowPointLabels.ToString()); tw.WriteAttributeString("PgcShowColumnGrandTotals", p.PgcShowColumnGrandTotals.ToString()); tw.WriteAttributeString("PgcShowRowGrandTotals", p.PgcShowRowGrandTotals.ToString()); if (p.PivotFields != null) { tw.WriteStartElement("PivotGridFields"); foreach (PivotGridFieldMx f in p.PivotFields) { ResultsField rfld = f.ResultsField as ResultsField; tw.WriteStartElement("PivotGridField"); if (rfld == null || f.Caption != PivotGridControlMx.BuildFieldCaption(f)) // write caption if different than field name { tw.WriteAttributeString("Caption", f.Caption); } tw.WriteAttributeString("UnboundFieldName", f.UnboundFieldName); // tableAlias.mcName link to source query table/column tw.WriteAttributeString("Role", f.Role.ToString()); tw.WriteAttributeString("AreaIndex", f.AreaIndex.ToString()); if (f.SummaryTypeMx != AggregationDef.Model.SummaryType) { tw.WriteAttributeString("SummaryType", f.SummaryTypeMx.ToString()); } if (f.GroupingType != AggregationDef.Model.GroupingType) { tw.WriteAttributeString("GroupingType", f.GroupingType.ToString()); } if (f.NumericIntervalSize != AggregationDef.Model.NumericIntervalSize) { tw.WriteAttributeString("NumericIntervalSize", f.NumericIntervalSize.ToString()); } if (f.Width != PivotGridField.DefaultWidth) { tw.WriteAttributeString("Width", f.Width.ToString()); } tw.WriteEndElement(); // PivotGridField } tw.WriteEndElement(); // PivotGridFields } tw.WriteEndElement(); // PivotGridView return; }
/// <summary> /// Setup & show the dialog /// </summary> /// <param name="queryManager"></param> /// <param name="control"></param> /// <returns></returns> public new static DialogResult Show( QueryManager queryManager, IPrintable control) { // When the GridView is active we can mostly the standard DevExpress printing stuff. // We just remove the Checkmark boxes and make sure all data is read in before starting the print. // However, when LayoutView is active (Cids & structures only) we must work around a couple of issues. // 1. Use CardView instead of LayoutView because LayoutView cards get split between pages. // 2. Scaling does not put the proper number of cards per row. Fix by scaling the cards rather // than the print Document. // // Print scaling is persisted in Query.PrintScale if (Instance == null) { Instance = new PrintPreviewDialog(); } Instance.Qm = queryManager; Query query = queryManager.Query; Instance.Control = control; if (control is MoleculeGridControl) { int printScalePct = query.PrintScale; // scale the document double scale = printScalePct / 100.0; queryManager.ResultsFormat.PageScale = printScalePct; // do view scaling based on printScale MoleculeGridControl grid = control as MoleculeGridControl; ResultsFormat rf = queryManager.ResultsFormat; queryManager.DataTableManager.ResetFormattedBitmaps(); // for structures to be redrawn in correct size if (rf.UseBandedGridView) // hide check mark band for printing { BandedGridView bgv = grid.MainView as BandedGridView; if (Lex.Eq(bgv.Bands[0].Name, "CheckMark")) // hide checkmark band { bgv.Bands[0].Visible = false; } if (printScalePct > 0) { grid.ScaleBandedGridView(scale); // scale the BandedGridView } } else // switch to special card view for printing { CardView cv = grid.GetCardView(); grid.MainView = cv; string keyLabel = queryManager.Query.Tables[0].MetaTable.KeyMetaColumn.Label; cv.CardCaptionFormat = keyLabel + ": {2}"; // set proper caption if (printScalePct > 0) { grid.ScaleCardView(scale); // scale the CardView } } DialogResult dr = ShowDialog(grid); // Reset the grid view queryManager.DataTableManager.ResetFormattedBitmaps(); // clear struct bitmaps so they get redrawn in correct size queryManager.ResultsFormat.PageScale = query.ViewScale; // switch back to doing view scaling based on viewScale if (rf.UseBandedGridView) // unhide check mark band { BandedGridView bgv = grid.MainView as BandedGridView; bgv.Bands[0].Visible = true; grid.ScaleBandedGridView(query.ViewScale / 100.0); // scale back for viewing } else // switch back to layout view { grid.MainView = grid.GetLayoutView(); } grid.Refresh(); return(dr); } else if (control is PivotGridControlMx) { PivotGridControlMx grid = control as PivotGridControlMx; DialogResult dr = ShowDialog(grid); return(dr); } //else if (control is ChartControlMx) //{ // ChartControlMx chart = control as ChartControlMx; // DialogResult dr = ShowDialog(chart); // return dr; //} else { throw new Exception("Invalid control type: " + control.GetType()); } }