Example #1
0
/// <summary>
/// Set default summary type
/// </summary>
/// <param name="f"></param>

        internal static void SetDefaultFieldSummaryType(
            PivotGridFieldMx f)
        {
            ResultsField rfld = f.ResultsField as ResultsField;

            if (rfld == null)
            {
                return;
            }
            MetaColumn mc = rfld.MetaColumn;

            if (mc.IsNumeric)
            {
                f.SummaryTypeMx = SummaryTypeEnum.ArithmeticMean;
            }

            else if (mc.DataType == MetaColumnType.Date)
            {
                f.SummaryTypeMx = SummaryTypeEnum.Count;
            }

            else
            {
                f.SummaryTypeMx = SummaryTypeEnum.Count;
            }
        }
Example #2
0
/// <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;
        }
Example #3
0
        /// <summary>
        /// Get the ResultsField associated with a PivotGridField
        /// </summary>
        /// <param name="Rf"></param>
        /// <param name="f0"></param>
        /// <returns></returns>

        internal ResultsField GetPivotGridFieldResultsField(
            PivotGridField pgf)
        {
            Query q = Rf.Query;

            string[] sa = pgf.UnboundFieldName.Split('.');
            if (sa.Length < 2)
            {
                return(null);
            }
            QueryTable qt = q.GetTableByName(sa[0]);

            if (qt == null)
            {
                return(null);
            }
            QueryColumn qc = qt.GetQueryColumnByName(sa[1]);

            if (qc == null)
            {
                return(null);
            }
            ResultsField rfld = Rf.GetResultsField(qc);

            return(rfld);
        }
Example #4
0
        public static string BuildFieldCaption(
            PivotGridFieldMx f)
        {
            ResultsField rfld = f.ResultsField as ResultsField;

            if (rfld == null)
            {
                return("Unknown");
            }
            QueryColumn    qc = rfld.QueryColumn;
            ResultsTable   rt = rfld.ResultsTable;
            ResultsFormat  rf = rt.ResultsFormat;
            AggregationDef ad = f.Aggregation;

            string caption = qc.GetActiveLabel(includeAggregationType: false);

            if (rf.Tables.Count > 1)
            {
                caption = "T" + (rt.Position + 1) + "." + caption;
            }

            if (f.Role == AggregationRole.DataSummary)
            {
                if (!ad.IsGroupingType)
                {
                    caption += " " + ad.TypeLabel;
                }
            }

            f.Caption = caption;

            return(caption);
        }
Example #5
0
        /// <summary>
        /// Build the data table of unpivoted results
        /// </summary>
        /// <param name="includeActivityClass"></param>
        /// <returns></returns>

        internal bool BuildUnpivotedResults(
            bool includeActivityClass)
        {
            int fi;

            DialogResult dr = Qm.DataTableManager.CompleteRetrieval();

            if (dr == DialogResult.Cancel)
            {
                return(false);
            }

            DataIncludesDates = false;

            int tables = 0, tablesWithDates = 0;             // see what percentage of tables have dates

            foreach (ResultsTable rt in Rf.Tables)
            {
                for (fi = 0; fi < rt.Fields.Count; fi++)
                {
                    if (fi == 1)
                    {
                        tables++;                              // count if more that just key field
                    }
                    ResultsField rfld = rt.Fields[fi];
                    if (rfld.MetaColumn.DataType == MetaColumnType.Date)
                    {
                        tablesWithDates++;
                        break;
                    }
                }

                if (fi < rt.Fields.Count)
                {
                    break;
                }
            }

            if (tables > 0 && (float)tablesWithDates / tables >= .5)
            {
                DataIncludesDates = true;
            }

            SetupActivityClassCondFormat();

            if (Math.Sqrt(4) == 4)             // todo: determine when to do this
            {
                AssayHeatmapProperties p          = AssayHeatmapProperties;
                OutputDest             outputDest = OutputDest.WinForms;
                QueryManager           sqm        = Qm.DataTableManager.Summarize(p.SumLevel, p.SumMethod, p.ColsToSum, outputDest, null);
            }

            //string name = rootQuery.UserObject.Name; // (don't change name of base query)
            //if (!Lex.StartsWith(name, "Pivot View of "))
            //  name = "Pivot View of " + name;
            //Qm.Query.UserObject.Name = name;

            return(true);
        }
Example #6
0
        /// <summary>
        /// Add a new field associated with specified ResultsField
        /// </summary>
        /// <param name="rfld"></param>
        /// <returns></returns>

        internal static PivotGridFieldMx AddField(
            ResultsField rfld,
            List <PivotGridFieldMx> Fields,
            PivotGridGroup group,
            GroupingTypeEnum pgi)
        {
            return(AddField(rfld, Fields, PivotArea.RowArea, false, group, pgi));
        }
Example #7
0
        /// <summary>
        /// Setup continuous conditional formatting for the specified QueryColumn
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="qc"></param>

        public static void SetupContinuousCondFormat(
            QueryManager qm,
            QueryColumn qc)
        {
            ResultsField rfld = qm.ResultsFormat.GetResultsField(qc);

            qc.CondFormat = CondFormatRulesControl.InitializeColorScaleCondFormat(rfld);
            return;
        }
Example #8
0
        /// <summary>
/// User has changed the value of a cell
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void FieldGridView_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            int ri = e.RowHandle;

            if (ri < 0)
            {
                return;
            }

            GridColumn gc = e.Column;

            if (gc == null)
            {
                return;
            }
            int gci = gc.AbsoluteIndex;

            PivotGridFieldMx f    = PivotGrid.Fields[ri] as PivotGridFieldMx;
            ResultsField     rfld = f.ResultsField as ResultsField;

            Mobius.Data.QueryColumn qc = rfld.QueryColumn;
            MetaColumn mc = qc.MetaColumn;

            if (gc.FieldName == "FieldNameCol")
            {
                f.Caption = e.Value.ToString();
            }

            else if (gc.FieldName == "AggRoleCol")
            {
                return;                 // handled in CellValueChanging
            }

            else if (gc.FieldName == "AggTypeCol")
            {
                return;
            }

            //else if (gc.FieldName == "HeaderBinningCol")
            //{
            //	return;
            //}

            else if (gc.FieldName == "SourceColumnCol" || gc.FieldName == "SourceTableCol")
            {
                return;
            }

            else
            {
                return;              // something else
            }
        }
Example #9
0
        //void SetMeasureUnits(params DateTimeMeasureUnit[] units)
        //{
        //	object prevUnit = String.IsNullOrEmpty(ChartDataMeasureUnit.SelectedItem.ToString()) ? null : Enum.Parse(typeof(DateTimeMeasureUnit), ChartDataMeasureUnit.SelectedItem.ToString());
        //	string prevItem = "";
        //	ChartDataMeasureUnit.Properties.Items.Clear();
        //	foreach (DateTimeMeasureUnit unit in units)
        //	{
        //		string unitName = Enum.GetName(typeof(DateTimeMeasureUnit), unit);
        //		ChartDataMeasureUnit.Properties.Items.Add(unitName);
        //		if (prevUnit != null && object.Equals(unit, (DateTimeMeasureUnit)prevUnit))
        //			prevItem = unitName;
        //	}
        //	if (!String.IsNullOrEmpty(prevItem))
        //		ChartDataMeasureUnit.SelectedItem = prevItem;
        //	else
        //		ChartDataMeasureUnit.SelectedIndex = 0;
        //}


        //private void cbChartDataMeasureUnit_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //	XYDiagram diagram = null; // (XYDiagram)Chart.Diagram;
        //	DateTimeMeasureUnit unit = (DateTimeMeasureUnit)Enum.Parse(typeof(DateTimeMeasureUnit), ChartDataMeasureUnit.SelectedItem.ToString());
        //	diagram.AxisX.DateTimeScaleOptions.GridAlignment = (DateTimeGridAlignment)unit;
        //	diagram.AxisX.DateTimeScaleOptions.MeasureUnit = unit;
        //	switch (unit)
        //	{
        //		case DateTimeMeasureUnit.Year:
        //			diagram.AxisX.Label.TextPattern = "{A:yyyy}";
        //			break;
        //		case DateTimeMeasureUnit.Quarter:
        //			diagram.AxisX.Label.TextPattern = "{A:yyyy}"; // todo: fix
        //			//diagram.AxisX.Label.DateTimeOptions.Format = DateTimeFormat.QuarterAndYear;
        //			break;
        //		case DateTimeMeasureUnit.Month:
        //			diagram.AxisX.Label.TextPattern = "{A:yyyy}"; // todo: fix
        //			//diagram.AxisX.DateTimeOptions.Format = DateTimeFormat.MonthAndYear;
        //			break;
        //		default:
        //			break;
        //	}
        //}

/// <summary>
/// Field grid cell clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void FieldGrid_MouseClick(object sender, MouseEventArgs e)
        {
            GridHitInfo hi = FieldGridView.CalcHitInfo(e.Location);
            int         ri = hi.RowHandle;

            if (ri < 0)
            {
                return;
            }

            PivotGridFieldMx f    = Field = PivotGrid.Fields[ri] as PivotGridFieldMx;
            ResultsField     rfld = f.ResultsField as ResultsField;
            AggregationDef   agg  = f.Aggregation;

            Mobius.Data.QueryColumn qc = rfld.QueryColumn;
            MetaColumn mc = qc.MetaColumn;

            GridColumn gc = hi.Column;

            if (gc == null)
            {
                return;
            }

            FieldGridRow    = hi.RowHandle;
            FieldGridColumn = gc.AbsoluteIndex;

            GridViewInfo viewInfo = (GridViewInfo)FieldGridView.GetViewInfo();
            GridCellInfo cellInfo = viewInfo.GetGridCellInfo(hi);
            Point        menuLoc  = new Point(cellInfo.Bounds.Left, cellInfo.Bounds.Bottom);

            menuLoc = FieldGrid.PointToScreen(menuLoc);

            if (gc.FieldName == "AggRoleCol")             // show appropriate aggregation type menu
            {
                AggregationDefMenus.ShowRoleMenu(qc, f.Aggregation, menuLoc, AggregationRoleChanged);
                return;
            }


            else if (gc.FieldName == "AggTypeCol")             // show appropriate aggregation type menu
            {
                AggregationDefMenus.ShowTypeMenu(qc, f.Aggregation, menuLoc, AggregationTypeChanged);
                return;
            }

            else if (gc.FieldName == "SourceColumnCol" || gc.FieldName == "SourceTableCol")
            {
                return;
            }
        }
Example #10
0
/// <summary>
/// Configure the binding for a pivot grid field
/// </summary>
/// <param name="field"></param>

        internal void ConfigurePivotGridControlField(PivotGridFieldMx field)
        {
            ResultsField rfld = field.ResultsField as ResultsField;
            MetaColumn   mc   = rfld.MetaColumn;

            if (mc.DataType == MetaColumnType.CompoundId)
            {
                if (mc.IsNumeric)
                {
                    field.UnboundType = UnboundColumnType.Integer;
                }
                else
                {
                    field.UnboundType = field.UnboundType = UnboundColumnType.String;
                }
            }

            else if (mc.DataType == MetaColumnType.Integer)
            {
                field.UnboundType = UnboundColumnType.Integer;
            }

            else if (mc.IsNumeric)
            {
                field.UnboundType = UnboundColumnType.Decimal;
            }

            else if (mc.DataType == MetaColumnType.Date)
            {
                field.UnboundType = UnboundColumnType.DateTime;
            }

            else
            {
                field.UnboundType = UnboundColumnType.String;
            }

            if (mc.IsKey)
            {
                field.ImageIndex = (int)Bitmaps16x16Enum.Key;
            }
            else
            {
                field.ImageIndex = (int)mc.DataTypeImageIndex;
            }

            field.Options.AllowRunTimeSummaryChange = true;
            field.Options.ShowUnboundExpressionMenu = true;

//				field.SummaryTypeChanged += new System.EventHandler(PivotGridPanel.PivotGridField_SummaryTypeChanged);
        }
Example #11
0
        /// <summary>
        /// Lookup a results column by the underlying metacolumn name and return the column index
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>

        public int GetResultsFieldIndexByName(
            string name)
        {
            for (int fi = 0; fi < Fields.Count; fi++)
            {
                ResultsField rfld = Fields[fi];
                MetaColumn   mc   = rfld.MetaColumn;
                if (Lex.Eq(mc.Name, name))
                {
                    return(fi);
                }
            }

            return(-1);
        }
Example #12
0
        private void ChangeRole(AggregationRole role)
        {
            PivotGridFieldMx f    = PivotGridField;
            ResultsField     rfld = f.ResultsField as ResultsField;
            MetaColumn       mc   = rfld.MetaColumn;

            f.Aggregation.Role = role;                   // set the role for Mobius
            f.Aggregation.SetDefaultTypeIfUndefined(mc); // and default type if needed
            f.SyncDxAreaToMxRole();                      // sync Dx Area

            if (UpdateViewWhenGridControlChanges)
            {
                View.UpdateViewFieldsFromGridFields();
            }

            return;
        }
Example #13
0
        /// <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;
            }
        }
Example #14
0
/// <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
            }
        }
Example #15
0
/// <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;
        }
Example #16
0
/// <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;
        }
Example #17
0
        /// <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);
        }
Example #18
0
        private void ColorColumnSelector_EditValueChanged(object sender, EventArgs e)
        {
            if (InSetup)
            {
                return;
            }

            InSetup = true;

            QueryColumn qc = ColorColumnSelector.QueryColumn;

            ColorBy.QueryColumn = qc;
            if (qc != null)
            {                   // setup for this column
                ColorByColumn.Checked = true;
                if (qc.CondFormat == null || qc.CondFormat.Rules.Count == 0)
                {                 // define default rules
                    qc.CondFormat = new CondFormat();
                    ResultsField rfld = View.ResultsFormat.GetResultsField(qc);
                    if (rfld != null)
                    {
                        CondFormatStyle cfStyle = qc.CondFormat.Rules.ColoringStyle;
                        ColorRulesControl.SetupControl(rfld.QueryColumn.MetaColumn.DataType, cfStyle, rfld);
                        //ColorRulesControl.SetupForResultsField(rfld, qc.CondFormat.Rules.ColoringStyle);
                    }
                    InitializeRulesBasedOnDataValues();
                    qc.CondFormat.Rules = ColorRulesControl.GetRules();                     // get rules back
                }

                ResetBackgroundColors(ColorBy.QueryColumn);
                SetupColorSchemeGrid(ColorBy.QueryColumn, View);
            }

            else
            {
                ColorByFixedColor.Checked = true;              // no col selected, goto fixed mode
            }
            InSetup = false;

            FireEditValueChanged(ColorColumnSelector);
            return;
        }
Example #19
0
/// <summary>
/// Get column count for results format (grid only)
/// Checks last column to get count
/// </summary>
/// <returns></returns>

        public int GridColumnCount()
        {
            for (int ti = this.Tables.Count - 1; ti >= 0; ti--)         // scan backwards til we find a table with columns
            {
                ResultsTable rt = this.Tables[ti];
                if (rt.Fields.Count == 0)
                {
                    continue;                                     // table may have zero cols
                }
                ResultsField rfld   = rt.Fields[rt.Fields.Count - 1];
                int          colcnt = rfld.FieldPosition + 1;        // number of data-containing columns in grid
                if (Query.ShowGridCheckBoxes)
                {
                    colcnt++;
                }
                return(colcnt);
            }

            return(0);            // no columns (shouldn't happen)
        }
Example #20
0
/// <summary>
/// Get a primitive value from the in-memory Target Assay Results cache
/// </summary>
/// <param name="dri"></param>
/// <param name="rfld"></param>
/// <returns></returns>

        public object GetPrimitiveValueFromTarCache(
            int dri,
            ResultsField rfld)
        {
            AssayAttributes taa = null;
            BinaryReader    br;
            long            streamLength;
            string          s;
            int             rowNum;

            GetPrimitiveValueFromTarCacheCalls++;

            ushort aid = AssayId[dri];

            if (aid == LastAid)
            {
                taa = LastTaa;
            }
            else if (TargetAssayDict.AssayIdMap.ContainsKey(aid))             // link to associated target-assay attributes
            {
                LastAid = aid;
                LastTaa = taa = TargetAssayDict.AssayIdMap[aid];
            }

            int voi = rfld.VoPosition;

            if (voi < 0 || voi >= TarFieldPositionMap.VoiToTarColEnum.Length)
            {
                return(null);                                                                          // not in range
            }
            TarColEnum tarCol = TarFieldPositionMap.VoiToTarColEnum[voi];

            switch (tarCol)
            {
// Assay Attributes - Get from TargetAssayDictionary

            case TarColEnum.Id:
                if (taa != null)
                {
                    return(taa.Id);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TargetSymbol:
                if (taa != null)
                {
                    return(taa.GeneSymbol);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TargetId:
                if (taa != null)
                {
                    return(taa.GeneId);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TargetDescription:
                if (taa != null)
                {
                    return(taa.GeneDescription);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.GeneFamily:
                if (taa != null)
                {
                    return(taa.GeneFamily);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.GeneFamilyTargetSymbol:                     // catenation of target family & gene symbol
                if (taa != null)
                {
                    return(taa.GeneFamilyTargetSymbol);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayDatabase:
                if (taa != null)
                {
                    return(taa.AssayDatabase);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayMetaTableName:                     // name of the metatable containing the data
                if (taa != null)
                {
                    return(taa.AssayMetaTableName);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayName:
                if (taa != null)
                {
                    return(taa.AssayName);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayNameSx:                     // contains name & link when deserialized from StringEx
                if (taa != null)
                {
                    return(taa.AssayName);                                     // todo: add link
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayDesc:
                if (taa != null)
                {
                    return(taa.AssayDesc);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayLocation:
                if (taa != null)
                {
                    return(taa.AssaySource);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayType:
                if (taa != null)
                {
                    return(taa.AssayType);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayMode:
                if (taa != null)
                {
                    return(taa.AssayMode);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayStatus:
                if (taa != null)
                {
                    return(taa.AssayStatus);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayGeneCount:
                if (taa != null)
                {
                    return(taa.GeneCount);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.ResultName:                     // result label
                if (taa != null)
                {
                    return(taa.ResultName);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.ResultTypeIdTxt:                     // text form of result type code
                if (taa != null)
                {
                    return(taa.ResultTypeIdTxt);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.ResultTypeId2:                     // numeric form of result type code:
                if (taa != null)
                {
                    return(taa.ResultTypeId2);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.ResultTypeConcType:                     // SP or CRC
                if (taa != null)
                {
                    return(taa.ResultTypeConcType);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TopLevelResult:                     // Y if this is a CRC or if a SP with no associated CRC
                if (taa != null)
                {
                    return(taa.TopLevelResult);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.Remapped:
                if (taa != null)
                {
                    return(taa.Remapped);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.Multiplexed:
                if (taa != null)
                {
                    return(taa.Multiplexed);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.Reviewed:
                if (taa != null)
                {
                    return(taa.Reviewed);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.ProfilingAssay:
                if (taa != null)
                {
                    return(taa.ProfilingAssay);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.CompoundsAssayed:
                if (taa != null)
                {
                    return(taa.CompoundsAssayed);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.ResultCount:
                if (taa != null)
                {
                    return(taa.ResultCount);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssayUpdateDate:                     // date of most recent assay result
                if (taa != null)
                {
                    return(taa.AssayUpdateDate);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssociationSource:                     // ASSAY2EG
                if (taa != null)
                {
                    return(taa.AssociationSource);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.AssociationConflict:                     // conflicting source & it's assignment
                if (taa != null)
                {
                    return(taa.AssociationConflict);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TargetMapX:
                if (taa != null)
                {
                    return(taa.TargetMapX);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TargetMapY:
                if (taa != null)
                {
                    return(taa.TargetMapY);
                }
                else
                {
                    return(null);
                }

            case TarColEnum.TargetMapZ:
                if (taa != null)
                {
                    return(taa.TargetMapZ);
                }
                else
                {
                    return(null);
                }

// Results - Get from in-memory arrays, one per table column

            case TarColEnum.CompoundId:
                if (CompoundId == null)
                {
                    CompoundId = ReadIntArray("CompoundId.bin");
                }
                return(CompoundId[dri]);

            case TarColEnum.AssayId2:                     // numeric form of assay/table identifier
                return((int)AssayId[dri]);                // should already have data AssayId array

            case TarColEnum.AssayIdTxt:                   // text form of assay/table identifier
                return(AssayId.ToString());

            //case TarColEnum.ResultTypeIdTxt: // text form of result type code
            //  if (ResultTypeId == null)
            //    ResultTypeId = ReadUShortArray("ResultTypeId.bin");
            //  return ResultTypeId[dri].ToString(); // get from results data array

            //case TarColEnum.ResultTypeIdNbr: // numeric form of result type identifier
            //  if (ResultTypeId == null)
            //    ResultTypeId = ReadUShortArray("ResultTypeId.bin");
            //  return (int)ResultTypeId[dri]; // get from results data array

            case TarColEnum.ActivityBin:
                if (ActivityBin == null)
                {
                    ActivityBin = ReadByteArray("ActivityBin.bin");
                }
                return((int)ActivityBin[dri]);

            case TarColEnum.ResultValue:                     // just return numeric value
                if (ResultNumericValue == null)
                {
                    ResultNumericValue = ReadSingleArray("ResultNumericValue.bin");
                }
                return(ResultNumericValue[dri]);

            case TarColEnum.ResultQualifier:
                if (ResultQualifier == null)
                {
                    ResultQualifier = ReadByteArray("ResultQualifier.bin");
                }

                if (ResultQualifier[dri] != ' ')
                {
                    return(ResultQualifier[dri].ToString());
                }
                else
                {
                    return("");
                }

            case TarColEnum.ResultNumericValue:
                if (ResultNumericValue == null)
                {
                    ResultNumericValue = ReadSingleArray("ResultNumericValue.bin");
                }
                return(ResultNumericValue[dri]);

            case TarColEnum.ResultTextValue:
                if (ResultTextValue == null)
                {
                    ResultTextValue = new Dictionary <int, string>();
                    br           = OpenBinaryReader("ResultTextValue.bin");
                    streamLength = br.BaseStream.Length;
                    while (true)
                    {
                        if (br.BaseStream.Position >= streamLength - 1)
                        {
                            break;
                        }
                        rowNum = br.ReadInt32();
                        s      = br.ReadString();
                        ResultTextValue[rowNum] = s;
                    }
                    br.Close();
                }

                if (ResultTextValue.ContainsKey(dri))
                {
                    return(ResultTextValue[dri]);
                }
                else
                {
                    return("");
                }

            case TarColEnum.NValue:
                return(0);

            case TarColEnum.NValueTested:
                return(0);

            case TarColEnum.StdDev:
                return(0);

            case TarColEnum.Units:
                if (Units == null)
                {
                    Units        = new Dictionary <int, string>();
                    br           = OpenBinaryReader("Units.bin");
                    streamLength = br.BaseStream.Length;
                    while (true)
                    {
                        if (br.BaseStream.Position >= streamLength - 1)
                        {
                            break;
                        }
                        rowNum        = br.ReadInt32();
                        s             = br.ReadString();
                        Units[rowNum] = s;
                    }
                    br.Close();
                }

                if (ResultTextValue.ContainsKey(dri))
                {
                    return(ResultTextValue[dri]);
                }
                else
                {
                    return("");
                }

            case TarColEnum.Conc:
                if (Conc == null)
                {
                    ReadConcData();
                }

                if (Conc.ContainsKey(dri))
                {
                    return(Conc[dri]);
                }
                else
                {
                    return(0);
                }

            case TarColEnum.ConcUnits:
                if (ConcUnits == null)
                {
                    ReadConcData();
                }

                if (ConcUnits.ContainsKey(dri))
                {
                    return(ConcUnits[dri]);
                }
                else
                {
                    return("");
                }

            case TarColEnum.RunDate:
                if (RunDate == null)
                {
                    RunDate = ReadUShortArray("RunDate.bin");
                }
                ushort   days = RunDate[dri];
                DateTime dt   = BaseDate.AddDays(days);
                return(dt);

            case TarColEnum.ResultDetail:
                return("");

            default:
                throw new Exception("Unexpected TarColEnum: " + tarCol);
            }
        }
Example #21
0
        /// <summary>
        /// Build click function and field value text string for output
        /// ClickFunction arguments may be defined in the clickfunction definition including col values
        /// indicated by fieldName.Value in the metacolumn clickfunction definition.
        /// If no args are defined in the clickfunction definition then a field value
        /// argument will be added by default, the keyValue if [keyvalue] or
        /// [rowcol] as a grid row and column to be returned if these appear in the
        /// ClickFunction definition.
        /// </summary>
        /// <param name="rf">Results field to display link for</param>
        /// <param name="vo">Vo contain tuple values</param>
        /// <param name="displayValue">Formatted display value for field</param>
        /// <returns></returns>

        public static string BuildClickFunctionText(
            ResultsField rf,
            DataRowMx dr,
            int dri,
            string displayValue)
        {
            ResultsTable rt;
            MetaColumn   mc, mc2;
            MetaTable    mt;
            string       arg, arg2, argsString;
            int          ai, rfi, voi;

            if (rf == null || dr == null || dri < 0)
            {
                return("");
            }

            rt = rf.ResultsTable;
            mc = rf.MetaColumn;
            mt = mc.MetaTable;
            object[] vo = dr.ItemArray;

            if (String.IsNullOrEmpty(mc.ClickFunction))
            {
                return("");
            }

            List <string> args     = Lex.ParseAllExcludingDelimiters(mc.ClickFunction, "( , )", false);
            string        funcName = args[0];      // click function name

            int fieldRefs = 0;

            for (ai = 1; ai < args.Count; ai++)
            {             // see how many mcName.Value references there are
                arg = args[ai];
                string suffix = ".Value";
                if (!Lex.EndsWith(arg, suffix))
                {
                    continue;
                }

                arg = arg.Substring(0, arg.Length - suffix.Length);
                if (mt.GetMetaColumnByName(arg) != null)
                {
                    fieldRefs++;
                }
            }

            if (fieldRefs == 0)             // if no field references add either the field value, key value or grid row and column
            {
                if (Lex.Eq(funcName, "RunHtmlQuery") || Lex.Eq(funcName, "RunGridQuery") ||
                    Lex.Eq(funcName, "DisplayWebPage"))                     // fixups for old functions
                {
                    args.Add(Lex.AddSingleQuotes(mt.Name));                 // add metatable name
                    args.Add(Lex.AddSingleQuotes(mc.Name));                 // add metacolumn name
                }

                if (Lex.Contains(mc.ClickFunction, "[TableColumnValue]")) // convert to metatable, metacolumns, &value refDataTable row & col
                {
                    args.RemoveAt(1);                                     // remove [TableColumnValue] arg
                    args.Add(Lex.AddSingleQuotes(mt.Name));
                    args.Add(Lex.AddSingleQuotes(mc.Name));
                    args.Add(mc.Name + ".Value");
                }

                else if (Lex.Contains(mc.ClickFunction, "[keyvalue]"))
                {
                    args.Add(mt.KeyMetaColumn.Name + ".value");                     // pass key value rather than this col value
                }
                else
                {
                    args.Add(mc.Name + ".value");                  // pass column value
                }
            }

            argsString = "";
            for (ai = 1; ai < args.Count; ai++)
            {
                arg = args[ai];

                string suffix = ".Value";
                if (!arg.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                arg2 = arg.Substring(0, arg.Length - suffix.Length);
                mc2  = mt.GetMetaColumnByName(arg2);

                if (mc2 == null)
                {
                    continue;                              // assume unquoted string constant & pass as is
                }
                else if (mc2.IsKey && rt.Fields[0].MetaColumn.Name != mc2.Name)
                {                                      // see if undisplayed key value
                    voi = rt.Fields[0].VoPosition - 1; // position in vo
                }

                else                 // find the field name in the list of report fields
                {
                    for (rfi = 0; rfi < rt.Fields.Count; rfi++)
                    {
                        if (Lex.Eq(mc2.Name, rt.Fields[rfi].MetaColumn.Name))
                        {
                            break;
                        }
                    }

                    if (rfi >= rt.Fields.Count)
                    {
                        throw new Exception("Column name not selected in query: " + mc2.Name);
                    }
                    voi = rt.Fields[rfi].VoPosition;
                }

                if (vo[voi] == null)
                {
                    args[ai] = "";
                }
                else
                {
                    arg = vo[voi].ToString();
                    if (vo[voi] is MobiusDataType)
                    {                     // use dblink if defined
                        MobiusDataType mdt = vo[voi] as MobiusDataType;
                        if (!String.IsNullOrEmpty(mdt.DbLink))
                        {
                            arg = mdt.DbLink;
                        }
                    }

                    args[ai] = arg;
                }
            }

            for (ai = 1; ai < args.Count; ai++)
            {
                arg = args[ai];
                if (!Lex.IsDouble(arg) && !arg.StartsWith("'") && !arg.StartsWith("["))                 // quote if string
                {
                    arg = Lex.AddSingleQuotes(arg);
                }
                if (argsString != "")
                {
                    argsString += ",";
                }
                argsString += arg;
            }

            string txt =             // build full string including link & display value
                         "<a href=\"http:////Mobius/command?ClickFunction " +
                         funcName + "(" + argsString + ")\">" + displayValue + "</a>";

            return(txt);
        }
Example #22
0
        /// <summary>
        /// Clone
        /// </summary>
        /// <returns></returns>

        public ResultsField Clone()
        {
            ResultsField rf = (ResultsField)this.MemberwiseClone();

            return(rf);
        }
Example #23
0
        /// <summary>
        /// BuildFieldPopupMenu
        /// </summary>
        /// <param name="e"></param>

        void BuildFieldPopupMenu(
            PopupMenuShowingEventArgs e)
        {
            PivotArea     area      = (PivotArea)(-1);
            string        areaName  = "";
            Image         areaImage = null;
            DXSubMenuItem smi;

            PivotGridFieldContext f = GetPivotGridFieldContext(e.Field);

            if (f == null)
            {
                return;
            }
            PivotGridField = f.F;             // save as current field

            ResultsField rfld = f.ResultsField;
            QueryColumn  qc   = f.Qc;

            GetFieldAreaAttributes(e, out area, out areaName, out areaImage);

            DXPopupMenu dxpMenu = e.Menu;             // clear dest menu

            dxpMenu.Items.Clear();

            AggregationDefMenus ats = new AggregationDefMenus();             // used to build menus

            // Build DataArea summary type items

            if (area == PivotArea.DataArea)
            {
                ContextMenuStrip modelMenu = ats.SetupAggregationTypeMenu(qc, f.Aggregation, null, includeGroupingItems: false, includeSummaryItems: true);
                ConvertAndAppendContextMenuStripToDxPopupMenu(modelMenu, dxpMenu);
            }

            // Build ColumnArea or RowArea Grouping items

            if (area == PivotArea.ColumnArea || area == PivotArea.RowArea)
            {
                ContextMenuStrip modelMenu = ats.SetupAggregationTypeMenu(qc, f.Aggregation, null, includeGroupingItems: true, includeSummaryItems: false);
                ConvertAndAppendContextMenuStripToDxPopupMenu(modelMenu, dxpMenu);
            }

            if (dxpMenu.Items.Count == 0)             // just add to menu if nothing there so far
            {
                smi = dxpMenu;
            }

            else             // add to submenu
            {
                smi            = new DXSubMenuItem("Move Field to");
                smi.BeginGroup = true;
                dxpMenu.Items.Add(smi);
            }

            smi.Items.Add(new DXMenuCheckItem("Column Area", area == PivotArea.ColumnArea, Bitmaps16x16.Images[0], ColumnAreaMenuItem_Click));
            smi.Items.Add(new DXMenuCheckItem("Row Area", area == PivotArea.RowArea, Bitmaps16x16.Images[1], RowAreaMenuItem_Click));
            smi.Items.Add(new DXMenuCheckItem("Data Area", area == PivotArea.DataArea, Bitmaps16x16.Images[2], DataAreaMenuItem_Click));
            smi.Items.Add(new DXMenuCheckItem("Filter Area", area == PivotArea.FilterArea, Bitmaps16x16.Images[3], FilterAreaMenuItem_Click));
            smi.Items.Add(new DXMenuCheckItem("None", area == (PivotArea)(-1), null, UnassignedAreaMenuItem_Click));

            return;
        }
Example #24
0
/// <summary>
/// Display cell text as hyperlinks to allow drilldown
/// Also, set the background color if appropriate (e.g. bin that an SP/CRC value is in)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void Grid_CustomAppearance(object sender, PivotCustomAppearanceEventArgs e)
        {
            e.Appearance.Font      = new Font(e.Appearance.Font, FontStyle.Underline);
            e.Appearance.ForeColor = Color.Blue;

            PivotGridFieldContext f = GetPivotGridFieldContext(e.DataField);

            if (f == null)
            {
                return;
            }

            ResultsField rfld = f.ResultsField;

            if (rfld == null)
            {
                return;
            }
            Mobius.Data.QueryColumn qc = rfld.QueryColumn;
            MetaColumn mc = qc.MetaColumn;

            CondFormat cf = f.Qc.CondFormat;
            //if (cf == null || cf.Rules.Count == 0) return;

            object cv = e.GetCellValue(e.ColumnIndex, e.RowIndex);
            double d  = -1;

            if (cv is int)
            {
                d = (int)cv;
            }

            else if (cv is double)
            {
                d = (double)cv;
            }

            else
            {
                return;
            }

            if (Math.Abs(1) == 2)             // for compound by target
            {
                if (d >= 1 && d <= 10)
                {                 // todo: set proper color
                    Color c = UnpivotedAssayResult.CalculateBinColor((int)d);
                    e.Appearance.BackColor = c;
                }
            }

            if (DebugMx.False)             // color by count
            {
                d = d / 45;
                if (d > 10)
                {
                    d = 10;
                }
                if (d < 1)
                {
                    d = 1;
                }
                if (d >= 1 && d <= 10)
                {                 // todo: set proper color
                    Color c = UnpivotedAssayResult.CalculateBinColor((int)d);
                    e.Appearance.BackColor = c;
                }
            }

            if (DebugMx.False)             // for bin by target
            {
                PivotGridField[] rowFields = e.GetRowFields();
                if (d > 0 && rowFields.Length > 0)
                {
                    object rfv = e.GetFieldValue(rowFields[0]);
                    if (rfv == null)
                    {
                        return;
                    }

                    else if (rfv is int)
                    {
                        Color c = UnpivotedAssayResult.CalculateBinColor((int)rfv);
                        e.Appearance.BackColor = c;
                    }
                }
            }
        }
Example #25
0
/// <summary>
/// Draw conditional formatting field value headers with appropriate background color
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void Grid_CustomDrawFieldValue(object sender, PivotCustomDrawFieldValueEventArgs e)
        {
            string txt;
            PivotGridFieldContext fc = GetPivotGridFieldContext(e.Field);

            if (fc == null)
            {
                return;
            }
            ResultsField rfld = fc.ResultsField;

            if (rfld == null)
            {
                return;
            }

            //DebugLog.Message(rfld.QueryColumn.MetaColumn.Name);

            //if (rfld.QueryColumn.MetaColumn.Name == "ACTIVITY_BIN") rfld = rfld; // debug
            //if (e.DisplayText == "0") e = e; // debug

            CondFormat cf = rfld.QueryColumn.CondFormat;

            if (cf == null || cf.Rules.Count == 0)
            {
                return;
            }

            foreach (CondFormatRule rule in cf.Rules)
            {             // look for rule name that matches field value text
                if (Lex.Eq(rule.Name, e.DisplayText) || Lex.Eq(rule.Value, e.DisplayText))
                {
                    if (!Lex.IsNullOrEmpty(rule.Name))
                    {
                        txt = rule.Name;                                                    // display rule name if defined
                    }
                    else
                    {
                        txt = e.DisplayText;                      // otherwise display field value
                    }
                    Rectangle rect = e.Bounds;
                    ControlPaint.DrawBorder3D(e.Graphics, e.Bounds);
                    Brush brush =
                        e.GraphicsCache.GetSolidBrush(rule.BackColor1);
                    rect.Inflate(-1, -1);
                    e.Graphics.FillRectangle(brush, rect);
                    e.Appearance.DrawString(e.GraphicsCache, txt, e.Info.CaptionRect);
                    //e.Appearance.DrawString(e.GraphicsCache, e.Info.Caption, e.Info.CaptionRect);
                    foreach (DevExpress.Utils.Drawing.DrawElementInfo info in e.Info.InnerElements)
                    {
                        DevExpress.Utils.Drawing.ObjectPainter.DrawObject(e.GraphicsCache, info.ElementPainter,
                                                                          info.ElementInfo);
                    }
                    e.Handled = true;
                    return;

                    //e.Painter.DrawObject(e.Info); // change tone of skin
                    //e.Graphics.FillRectangle(e.GraphicsCache.GetSolidBrush(Color.FromArgb(50, 0, 0, 200)), e.Bounds);
                    //e.Handled = true;
                }
            }

            return;
        }
Example #26
0
        /// <summary>
        /// Value tentatively changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void FieldGridView_CellValueChanging(object sender, CellValueChangedEventArgs e)
        {
            int ri = e.RowHandle;

            if (ri < 0)
            {
                return;
            }
            DataRow dr = FieldGridDataTable.Rows[ri];

            GridColumn gc = e.Column;

            if (gc == null)
            {
                return;
            }
            int gci = gc.AbsoluteIndex;

            PivotGridFieldMx f    = PivotGrid.Fields[ri] as PivotGridFieldMx;
            ResultsField     rfld = f.ResultsField as ResultsField;

            Mobius.Data.QueryColumn qc = rfld.QueryColumn;
            MetaColumn mc = qc.MetaColumn;

            if (gc.FieldName == "FieldNameCol")
            {
                return;                 // wait til move out of cell
            }

            else if (gc.FieldName == "AggRoleCol")
            {
                //e=e;
                //object o = e.Value;
                //DataRow dr2 = FieldGridDataTable.Rows[e.RowHandle];
                //object vo = dr2["AggRoleCol"];
                //FieldGridDataTable

                f.SyncDxAreaToMxRole();                 // sync Dx area
                PivotGrid.RefreshData();                // refresh the PivotGrid to show new agg type results

                //dr["AggRoleCol"] = f.Aggregation.TypeLabel;
                return;                 // throw new NotImplementedException();

                //string txt = e.Value.ToString();
                //if (Lex.IsNullOrEmpty(txt) || Lex.Eq(txt, "None"))
                //{
                //	f.Visible = false;

                //	dr["SummaryTypeCol"] = "";
                //	//dr["HeaderBinningCol"] = "";
                //}
                //else
                //{
                //	f.Area = (PivotArea)Enum.Parse(typeof(PivotArea), txt);
                //	f.Visible = true;

                //	dr["SummaryTypeCol"] = SummaryTypeLabel(f);
                //	//dr["HeaderBinningCol"] = GroupingTypeLabel(f);
                //}

                //PivotGrid.SetFilterHeaderVisibility();
            }

            else if (gc.FieldName == "AggTypeCol")
            {
                return;
            }

            //else if (gc.FieldName == "HeaderBinningCol")
            //{
            //	return;
            //}

            else if (gc.FieldName == "SourceColumnCol" || gc.FieldName == "SourceTableCol")
            {
                return;
            }

            else
            {
                return;              // something else
            }
        }
Example #27
0
        /// <summary>
        /// Scale and translate structure and format into buffer
        /// </summary>
        /// <param name="mol">The structure</param>
        /// <param name="cellStyle">Style/conditional formatting to apply to cell</param>
        /// <param name="commandChar">Command character to use in buffer</param>
        /// <param name="x">Coordinate of left side of structure</param>
        /// <param name="width">Width of molecule box in milliinches</param>
        /// <param name="r">Row in buffer to put on. If less than 0 then return formatted data</param>
        /// <param name="heightInLines">number of lines used</param>

        public FormattedFieldInfo FormatStructure(
            MoleculeMx mol,
            CellStyleMx cellStyle,
            char commandChar,
            int x,
            int width,
            int r,
            ResultsField rfld = null,
            DataRowMx dataRow = null)
        {
            Rectangle destRect, boundingRect;
            int       height;       // formatted  height in milliinches
            bool      markBoundaries;
            int       fixedHeight;
            Bitmap    bm;
            Font      font;
            string    txt, molfile, molString = "", svg, cid = null;
            int       translateType, desiredBondLength = 100;
            int       pixWidth = 0, pixHeight = 0;

            bool debug = DataTableManager.DebugDetails;

            if (debug)
            {
                DebugLog.Message("=============================== FormattingStructure ===============================");
            }
            PerformanceTimer pt      = PT.Start("FormatStructure");
            Stopwatch        swTotal = Stopwatch.StartNew();
            Stopwatch        sw      = Stopwatch.StartNew();

            try
            {
                MoleculeFormat initialCsType  = mol.PrimaryFormat;
                string         initialCsValue = mol.PrimaryValue;

                QueryColumn qc = (rfld != null) ? rfld.QueryColumn : null;

                FormattedFieldInfo ffi = new FormattedFieldInfo();

                if (dataRow != null)                 // get any cid in row
                {
                    int ki = DataTableManager.DefaultKeyValueVoPos;
                    if (ki < dataRow.Length)
                    {
                        cid = dataRow[ki] as string;
                    }
                }

                //DebugLog.Message("FormatStructure " + cid);

                //if (!Rf.Grid) x = x; // debug

                ///////////////////////////////////
                // Highlight structure
                ///////////////////////////////////

                if (StructureHighlightPssc != null)
                {
                    ParsedStructureCriteria pssc = StructureHighlightPssc;

                    // Hilight substructure search match

                    if (pssc.SearchType == StructureSearchType.Substructure ||                     // regular SSS
                        pssc.SearchTypeUnion == StructureSearchType.Substructure)                  // handles related search for just SSS to get hilighting
                    {
                        if (HighlightStructureMatches)
                        {
                            try
                            {
                                mol = StrMatcher.HighlightMatchingSubstructure(mol);
                                if (DebugMx.False)                                 // debug
                                {
                                    //string highlightChildren = mol.MolLib.HighlightChildren;
                                    //Color highlightColor = mol.MolLib.HighlightColor;
                                    if (debug)
                                    {
                                        DebugLog.StopwatchMessage("tHilight", sw);
                                    }
                                }
                            }
                            catch (Exception ex) { ex = ex; }
                        }

                        if (AlignStructureToQuery)
                        {
                            try
                            {
                                mol = StrMatcher.AlignToMatchingSubstructure(mol);
                                if (debug)
                                {
                                    DebugLog.StopwatchMessage("tOrient", sw);
                                }
                            }
                            catch (Exception ex) { ex = ex; }
                        }
                    }

                    // Hilight SmallWorld structure match

                    else if (pssc.SearchType == StructureSearchType.SmallWorld)                     // Hilight SmallWorld structure search results
                    {
                        if (SmallWorldDepictions == null)
                        {
                            SmallWorldDepictions = new SmallWorldDepictions();
                        }

                        SmallWorldPredefinedParameters swp = pssc.SmallWorldParameters;

                        //DebugLog.Message("Depict " + cid + ", Hilight " + swp.Highlight + ", Align " + swp.Align); // + "\r\n" + new StackTrace(true));

                        if ((swp.Highlight || swp.Align) & Lex.IsDefined(cid))                         // call depiction for these
                        {
                            svg = SmallWorldDepictions.GetDepiction(cid, swp.Highlight, swp.Align);

                            if (Lex.IsDefined(svg))                             // have depiction?
                            {
                                {
                                    pixWidth            = MoleculeMx.MilliinchesToPixels(width);
                                    bm                  = SvgUtil.GetBitmapFromSvgXml(svg, pixWidth);
                                    ffi.FormattedBitmap = mol.FormattedBitmap = bm;                                     // store in formatting info and chem structure
                                    return(ffi);
                                }
                            }

                            else if (svg == null)                             // start retrieval of this decpiction type & fall through to get default structure initially
                            {
                                SmallWorldDepictions.StartDepictionRetrieval(Qm, StructureHighlightQc, swp.Highlight, swp.Align);
                            }

                            else
                            {
                            }                                    // tried to get it but failed, fall through to get basic structure
                        }
                    }

                    else if (mol.AltFormDefined("Svg"))                     // svg form exist (e.g. SmallWorld or "related" structure search)?
                    {
                        svg = mol.SvgString;
                        if (Lex.IsDefined(svg))
                        {
                            pixWidth            = MoleculeMx.MilliinchesToPixels(width);
                            bm                  = SvgUtil.GetBitmapFromSvgXml(svg, pixWidth);
                            ffi.FormattedBitmap = mol.FormattedBitmap = bm;                             // store in formatting info and chem structure
                            return(ffi);
                        }
                    }
                }

                ///////////////////////////////////
                // Handle each output device
                ///////////////////////////////////

                ffi.HeightInLines = 1;                 // min of 1 line

                if (Rf.SdFile)
                {
                    FormatSdfileStructure(mol);
                    return(null);
                }

                int pageHeight = 11000;
                if (Rf.PageMargins != null)
                {
                    pageHeight = Rf.PageMargins.Top + Rf.PageHeight + Rf.PageMargins.Bottom;
                }

                if (Rf.Excel || Rf.Word)
                {
                    translateType = 2;
                }
                else
                {
                    translateType = 0;
                }

                if (!Rf.FixedHeightStructures)
                {
                    fixedHeight = 0;                                            // not fixed height
                }
                else if (Rf.Excel || Rf.Word)
                {
                    fixedHeight = 1;                                           // always fixed height
                }
                else
                {
                    fixedHeight = 2;                  // fixed height unless need to expand
                }
                if (Rf.Word && Rf.FixedHeightStructures)
                {
                    markBoundaries = true;
                }
                else
                {
                    markBoundaries = false;
                }

                destRect = new Rectangle(0, 0, width, width * 4 / 5);                 // default dest rect

                ///////////////////////////////////////////////////////////////////////////
                // Tempory fake generation of HELM & associatedimage for biopolymer testing
                ///////////////////////////////////////////////////////////////////////////

                //if (MoleculeMx.HelmEnabled == DebugMx.False) // artificially generate helm molecules
                //	MoleculeMx.SetMoleculeToTestHelmString(mol.GetCorpId().ToString(), mol);

                ///////////////////////////////////////////////////////////////////////////
                // End of tempory fake generation of HELM & associatedimage for biopolymer testing
                ///////////////////////////////////////////////////////////////////////////

                bool fitStructure = true;

                if (mol.IsChemStructureFormat)
                {
                    if (Rf.Grid)                     // special scale for grid
                    {
                        double scale = (float)width / MoleculeMx.StandardBoxWidth;
                        desiredBondLength = mol.CdkMol.AdjustBondLengthToValidRange((int)(MoleculeMx.StandardBondLength * scale));
                        //desiredBondLength = (int)(ChemicalStructure.StandardBondLength * (Rf.PageScale / 100.0));
                        desiredBondLength = (int)(desiredBondLength * 90.0 / 100.0);                         // scale down a bit for grid
                        if (debug)
                        {
                            DebugLog.StopwatchMessage("tAdjustBondLength1", sw);
                        }
                    }

                    else                     // set desired bond length based on page scaling
                    {
                        float scale = (float)width / MoleculeMx.StandardBoxWidth;
                        desiredBondLength = mol.CdkMol.AdjustBondLengthToValidRange((int)(MoleculeMx.StandardBondLength * scale));
                        //desiredBondLength = (int)(ChemicalStructure.StandardBondLength * (Rf.PageScale / 100.0));
                        if (debug)
                        {
                            DebugLog.StopwatchMessage("tAdjustBondLength2", sw);
                        }
                    }

                    if (desiredBondLength < 1)
                    {
                        desiredBondLength = 1;
                    }
                    if (debug)
                    {
                        DebugLog.StopwatchMessage("tBeforeFit", sw);
                    }

                    if (fitStructure)
                    {
                        mol.CdkMol.FitStructureIntoRectangle                         // scale and translate structure into supplied rectangle.
                            (ref destRect, desiredBondLength, translateType, fixedHeight, markBoundaries, pageHeight, out boundingRect);
                    }

                    if (debug)
                    {
                        DebugLog.StopwatchMessage("tFitStructure", sw);
                    }

                    ffi.HeightInLines = (int)(destRect.Height / Rf.LineHeight + 1);                     // lines needed
                }

                else if (mol.IsBiopolymerFormat)
                {
                    if (mol.PrimaryFormat == MoleculeFormat.Helm && Rf.Excel)
                    {
                        svg = HelmControl.GetSvg(mol.HelmString);
                        float           inchWidth = width / 1000.0f;               // convert width milliinches to inches
                        Svg.SvgDocument svgDoc    = SvgUtil.AdjustSvgDocumentToFitContent(svg, inchWidth, Svg.SvgUnitType.Inch);
                        RectangleF      svgbb     = svgDoc.Bounds;
                        float           ar        = svgbb.Width / svgbb.Height; // aspect ratio of svg bounding box

                        height            = (int)(width / ar);                  // height in milliinches
                        ffi.HeightInLines = (int)(height / Rf.LineHeight) + 1;  // lines needed

                        destRect = new Rectangle(0, 0, width, height);
                    }
                }

                //////////////////////////
                /// Output to Grid
                //////////////////////////

                if (Rf.Grid)
                {
                    pixWidth  = MoleculeMx.MilliinchesToPixels(destRect.Width);
                    pixHeight = MoleculeMx.MilliinchesToPixels(destRect.Height);

                    if (cellStyle == null)
                    {
                        if (Qm == null || Qm.MoleculeGrid == null)
                        {
                            font = new Font("Tahoma", 8.25f);
                        }
                        else
                        {
                            font = new Font(Qm.MoleculeGrid.Font, FontStyle.Underline);
                        }
                        cellStyle = new CellStyleMx(font, Color.Blue, Color.Empty);
                    }

                    if (mol.IsChemStructureFormat)                     // molfile type molecule
                    {
                        if (debug)
                        {
                            DebugLog.StopwatchMessage("tBeforeGetDisplayPreferences", sw);
                        }
                        DisplayPreferences dp = mol.GetDisplayPreferences();
                        if (debug)
                        {
                            DebugLog.StopwatchMessage("tGetDisplayPreferences", sw);
                        }

                        //desiredBondLength = mol.CdkMol.AdjustBondLengthToValidRange(desiredBondLength); // be sure bond len within allowed range
                        //if (debug) DebugLog.StopwatchMessage("tAdjustBondLengthToValidRange", sw);
                        //dp.StandardBondLength = MoleculeMx.MilliinchesToDecipoints(desiredBondLength);
                        bm = mol.CdkMol.GetFixedHeightMoleculeBitmap(pixWidth, pixHeight, dp, cellStyle, mol.Caption);
                        if (debug)
                        {
                            DebugLog.StopwatchMessage("tGetBitmap", sw);
                        }
                    }

                    else if (mol.IsBiopolymerFormat)                     // Output HELM image for biopolymer
                    {
                        pixWidth = MoleculeMx.MilliinchesToPixels(width);
                        bm       = HelmConverter.HelmToBitmap(mol, pixWidth);
                    }

                    else
                    {
                        bm = new Bitmap(1, 1);
                    }

                    ffi.FormattedBitmap = mol.FormattedBitmap = bm;      // store in formatting & structure
                    ffi.FormattedText   = "Formatted";                   // indicate formatted (could save structure string but not needed and avoids possible conversion overhead)
                    return(ffi);
                }

                //////////////////////////
                /// Output to Html
                //////////////////////////

                else if (Rf.Html)
                {
                    if (r >= 0)
                    {
                        AssureTbFree(0, r + ffi.HeightInLines - 1);
                    }

                    if (mol.IsChemStructureFormat)
                    {
                        FormatChemStructureHtml(mol, destRect, width, r);
                    }

                    else if (mol.IsBiopolymerFormat)
                    {
                        FormatBiopolymerStructureHtml(mol, destRect, width, r);
                    }

                    if (debug)
                    {
                        DebugLog.StopwatchMessage("tFormatHtmlStructure", sw);
                    }

                    ffi.FormattedBitmap = mol.FormattedBitmap;
                    ffi.FormattedText   = mol.FormattedText;
                    return(ffi);
                }

                /////////////////////////////////////////////////////////////////
                /// Other format, store Smiles or Helm & any cellStyle in buffer
                /////////////////////////////////////////////////////////////////

                else
                {
                    if (mol.IsChemStructureFormat)
                    {
                        if (Rf.ExportStructureFormat == ExportStructureFormat.Smiles)
                        {
                            molString = mol.GetSmilesString();
                        }
                        else
                        {
                            molString = mol.GetChimeString();                          // use Chime if not smiles
                        }
                    }

                    else if (mol.IsBiopolymerFormat)
                    {
                        molString = mol.PrimaryValue;                         // usually Helm but could be sequence
                    }

                    txt = String.Format("{0} {1} {2} {3} {4} {5} {6}",
                                        x, width, destRect.Left, destRect.Top, destRect.Right, destRect.Bottom, molString);

                    if (cellStyle != null)                     // apply style to cell?
                    {
                        txt += " <CellStyle " + cellStyle.Serialize() + ">";
                    }

                    txt = commandChar + " " + txt + "\t";

                    if (r >= 0)
                    {
                        AssureTbFree(0, r + ffi.HeightInLines - 1);
                        Tb.Lines[r] += txt;                         // put in buffer
                    }

                    else
                    {
                        return(new FormattedFieldInfo(txt));                     // just return formatting
                    }
                }

                return(null);
            }

            catch (Exception ex)
            {
                DebugLog.Message(DebugLog.FormatExceptionMessage(ex));
                return(null);
            }

            finally
            {
                pt.Update();
                int formatCount = pt.Count;
                //ClientLog.Message(pt.ToString() + ", " + cs.GetMolHeader()[2]); // + ", " + new StackTrace(true));
                if (debug)
                {
                    DebugLog.StopwatchMessage("tTotalTime", swTotal);
                }
            }
        }
Example #28
0
        /// <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;
        }