/// <summary> /// Add a new pivot grid field /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddPivotField_Click(object sender, EventArgs e) { QueryManager qm = PivotView.Qm; Query q = qm.Query; FieldSelectorControl.Query = q; FieldSelectorControl.MetaColumn = null; Point p = AddPivotField.PointToScreen(new Point(0, AddPivotField.Height)); Mobius.Data.QueryColumn qc = FieldSelectorControl.ShowMenu(p); if (qc == null) { return; } PivotGridPropertiesMx pp = PivotView.PivotGridPropertiesMx; ResultsField rfld = qm.ResultsFormat.GetResultsField(qc); if (rfld == null) { return; } PivotGridFieldMx field = // add new field (must add to base view) PivotGridView.AddField(rfld, pp.PivotFields, null, GroupingTypeEnum.EqualValues); PivotGridFieldMx field2 = new PivotGridFieldMx(); field.CopyField(field2); pp.PivotFields.Remove(field); // remove from base view PivotGrid.BeginUpdate(); object ds = PivotGrid.DataSource; PivotGrid.DataSource = null; PivotGrid.Fields.Add(field2); // add to pivot grid PivotView.ConfigurePivotGridControlField(field2); PivotGrid.DataSource = ds; PivotGrid.EndUpdate(); FillFieldDetailsGrid(); return; }
/// <summary> /// Render the view into the specified results control /// </summary> public override void ConfigureRenderingControl() { Query q; ResultsFormat rf = ResultsFormat; ResultsTable rt; QueryTable qt; MetaTable mt; ResultsField rfld; Mobius.Data.QueryColumn qc; MetaColumn mc; PivotGridField pgf; bool includeActivityClass = true; if (!BuildUnpivotedResults(includeActivityClass)) { return; } PivotGridPropertiesMx p = PivotGridPropertiesMx; if (p == null) { return; } if (p.PivotFields == null) // if not defined then configure { PivotGridCtl.Fields.Clear(); // clear any prev display PivotGridCtl.Groups.Clear(); if (DataIncludesDates) { DialogResult dr = DateGroupingDialog.ShowDialog(ref DateGroupInterval); } p.PivotFields = new List <PivotGridFieldMx>(); foreach (ResultsTable rt0 in rf.Tables) // determine visible fields { rt = rt0; qt = rt.QueryTable; mt = qt.MetaTable; if (Lex.Eq(mt.Name, MultiDbAssayDataNames.CombinedNonSumTableName)) { if ((rfld = rt.GetResultsFieldByName("activity_bin")) != null) { pgf = PivotGridView.AddField(rfld, p.PivotFields, PivotArea.RowArea, true, null, GroupingTypeEnum.EqualValues); } if ((rfld = rt.GetResultsFieldByName("run_dt")) != null && DataIncludesDates && DateGroupInterval != GroupingTypeEnum.EqualValues) { GroupingTypeEnum pgi = DateGroupInterval; int intervalCnt = 0; bool week = false, month = false, year = false; // include larger date units up to year if (pgi == GroupingTypeEnum.DateDayOfWeek) { week = month = year = true; intervalCnt = 3; } else if (pgi == GroupingTypeEnum.DateWeekOfMonth) { intervalCnt = 3; month = year = true; } else if (pgi == GroupingTypeEnum.DateMonth || pgi == GroupingTypeEnum.DateQuarter) { year = true; } PivotGridGroup g = null; if (intervalCnt > 1) { g = new PivotGridGroup(); PivotGridCtl.Groups.Add(g); } if (year) { PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, GroupingTypeEnum.DateYear); } if (month) { PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, GroupingTypeEnum.DateMonth); } if (week) { PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, GroupingTypeEnum.DateWeekOfMonth); } PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, pgi); } if ((rfld = rt.GetResultsFieldByName("assy_nm")) != null) { pgf = PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, null, GroupingTypeEnum.EqualValues); } if ((rfld = rt.GetResultsFieldByName("rslt_val")) != null) { pgf = PivotGridView.AddField(rfld, p.PivotFields, PivotArea.DataArea, true, null, GroupingTypeEnum.EqualValues); } } else // tables other than the standard pivoted table { foreach (ResultsField rfld0 in rt.Fields) { rfld = rfld0; qc = rfld.QueryColumn; mc = qc.MetaColumn; } } } } // done defining initial set of fields SyncMxFieldListWithSourceQuery(BaseQuery, ref p.PivotFields); // be sure main grid & pivot view fields are in synch ConfigurePivotGridControl(); // configure the control to display the data PivotGridCtl.DataSource = Qm.DataTableManager.DataSource; // set the data table to start rendering return; }