Beispiel #1
0
        /// <summary>
        /// Initialize marker shape rules for newly selected QueryColumn
        /// </summary>

        internal void InitializeShapeRules()
        {
            CondFormatRule r;

            ShapeBy.Rules = new CondFormatRules();
            if (ShapeBy.QueryColumn == null)
            {
                return;
            }

            QueryColumn      qc    = ShapeBy.QueryColumn;
            ColumnStatistics stats = View.GetStats(qc);

            for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++)
            {
                MobiusDataType mdt = stats.DistinctValueList[i1];
                r       = new CondFormatRule();
                r.Value = View.GetFormattedText(qc, mdt);
                AddRule(r);
                if (i1 + 1 >= 25)
                {
                    break;                               // limit number of items
                }
            }

            if (stats.NullsExist)
            {
                r       = new CondFormatRule();
                r.Value = "(Blank)";
                AddRule(r);
            }
            return;
        }
Beispiel #2
0
        /// <summary>
        /// Get statistics for column, calculating if necessary
        /// </summary>
        /// <returns></returns>

        public ColumnStatistics GetStats()         // statistics on column
        {
            if (ResultsTable == null ||
                ResultsTable.ResultsFormat == null ||
                ResultsTable.ResultsFormat.QueryManager == null ||
                ResultsTable.ResultsFormat.QueryManager.DataTableManager == null)
            {
                throw new Exception("DataTableManager not defined");
            }

            if (_stats == null)
            {
                ColumnInfo ci = ResultsTable.ResultsFormat.GetColumnInfo(QueryColumn);
                _stats = QueryManager.DataTableManager.CalcColumnStatistics(ci);

                if (_stats.DistinctValueDict.Count == 0)
                {
                    _stats = _stats;                                                      // debug
                }
            }

            // Convert list to a csv string
            //StringBuilder sb = new StringBuilder();
            //foreach (MobiusDataType mdt in _stats.DistinctValueList)
            //{
            //  string s = mdt.ToString();
            //  sb.Append(s);
            //  sb.Append(", ");
            //}
            //string slist = sb.ToString();

            return(_stats);
        }
Beispiel #3
0
/// <summary>
/// Get stats for the specified QueryColumn
/// </summary>
/// <param name="qc"></param>
/// <returns></returns>

        internal ColumnStatistics GetStats(QueryColumn qc)
        {
            MetaColumn       mc      = qc.MetaColumn;
            ColumnInfo       colInfo = GetColumnInfo(qc);
            ColumnStatistics stats   = colInfo.Rfld.GetStats();

            return(stats);
        }
Beispiel #4
0
        /// <summary>
        /// Get the stats for the data associated with a QueryColumn
        /// </summary>
        /// <param name="qc"></param>
        /// <returns></returns>

        internal ColumnStatistics GetStats(QueryColumn qc)
        {
            MetaColumn       mc      = qc.MetaColumn;
            ColumnInfo       colInfo = ResultsFormat.GetColumnInfo(qc);
            int              voi     = colInfo.DataColIndex;
            ColumnStatistics stats   = colInfo.Rfld.GetStats();

            return(stats);
        }
Beispiel #5
0
        public void Setup(ColumnInfo colInfo)
        {
            MobiusDataType mdtLow, mdtHigh;

            InSetup = true;

            ColInfo = colInfo;             // save ref to colInfo

            Stats = colInfo.Rfld.GetStats();
            ItemFilter.Properties.Minimum = 0;
            ItemFilter.Properties.Maximum = Stats.DistinctValueList.Count + 2 - 1;                // (All) on left, (Blanks) on right

            ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(ColInfo.Qc.SecondaryCriteria); // parse criteria

            ItemFilter.Value = 0;
            ValueLabel.Text  = "(All)";
            if (psc != null && psc.OpEnum == CompareOp.Eq && Stats.DistinctValueList.Count > 0)
            {
                MetaColumnType type    = ColInfo.Mc.DataType;
                MobiusDataType lowVal  = MobiusDataType.New(type, psc.Value);
                MobiusDataType highVal = MobiusDataType.New(type, psc.Value);

                if (MetaColumn.IsDecimalMetaColumnType(type))
                {                 // adjust decimal comparison values by an epsilon
                    double e = MobiusDataType.GetEpsilon(Stats.MaxValue.FormattedText);
                    lowVal.NumericValue  -= e;
                    highVal.NumericValue += e;
                }

                for (int i1 = 0; i1 < Stats.DistinctValueList.Count; i1++)
                {
                    MobiusDataType mdt  = Stats.DistinctValueList[i1];
                    string         fTxt = mdt.FormattedText;

                    if (Lex.Eq(psc.Value, fTxt) ||
                        (mdt.CompareTo(lowVal) >= 0 && mdt.CompareTo(highVal) <= 0))
                    {
                        ItemFilter.Value = i1 + 1;
                        ValueLabel.Text  = Stats.DistinctValueList[i1].FormattedText;
                        break;
                    }
                }
            }

            else if (psc != null && psc.OpEnum == CompareOp.IsNull)             // (Blanks)
            {
                ItemFilter.Value = Stats.DistinctValueList.Count + 1;
                ValueLabel.Text  = "(Blanks)";
            }

            ItemFilter.Focus();
            InSetup = false;
            return;
        }
Beispiel #6
0
        public void Setup(ColumnInfo colInfo)
        {
            bool   check;
            string s;

            InSetup = true;
            ColInfo = colInfo;             // save ref to colInfo
            QueryColumn qc = colInfo.Qc;

            ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(ColInfo.Qc.SecondaryCriteria);             // parse criteria

            Dictionary <string, object> listDict = new Dictionary <string, object>();

            if (psc != null && psc.OpEnum != CompareOp.In)
            {
                psc = null;                 // switching from other criteria type
            }
            if (psc != null && Lex.Contains(qc.SecondaryCriteria, "(All)"))
            {
                psc = null;              // rebuild if "all" items
            }
            if (psc != null)             // list of previously selected items
            {
                foreach (string vs in psc.ValueList)
                {
                    if (qc.MetaColumn.DataType == MetaColumnType.CompoundId)
                    {
                        s = CompoundId.Format(vs);
                    }
                    else if (qc.MetaColumn.DataType == MetaColumnType.Date)
                    {
                        s = DateTimeMx.Format(vs);
                    }
                    else
                    {
                        s = vs;
                    }
                    listDict[s.ToUpper()] = null;
                }
            }

            else             // setup default criteria
            {
                qc.SecondaryCriteria        = qc.MetaColumn.Name + " in ('(All)')";
                qc.SecondaryCriteriaDisplay = qc.ActiveLabel + " in list (All)";
            }

            ColumnStatistics             stats = colInfo.Rfld.GetStats();
            CheckedListBoxItemCollection items = ItemList.Items;

            items.Clear();
            check = (psc == null || listDict.ContainsKey("(All)".ToUpper()) || listDict.ContainsKey("All".ToUpper()));
            AddItem("(All)", check);

            if (stats.NullsExist || Math.Abs(1) == 1)
            {             // always include blank/nonblank since there may be null rows because other tables have more rows for key
                check     = (psc == null || listDict.ContainsKey("(Blanks)".ToUpper()) || listDict.ContainsKey("Blanks".ToUpper()));
                BlanksPos = items.Count;
                AddItem("(Blanks)", check);

                check        = (psc == null || listDict.ContainsKey("(Non blanks)".ToUpper()) || listDict.ContainsKey("Nonblanks".ToUpper()));
                NonBlanksPos = items.Count;
                AddItem("(Non blanks)", check);
            }

            else
            {
                BlanksPos = NonBlanksPos = -1;
            }

            foreach (MobiusDataType mdt in stats.DistinctValueList)
            {
                s     = mdt.FormattedText;
                check = (psc == null || listDict.ContainsKey(s.ToUpper()));
                AddItem(s, check);
                if (items.Count >= 100)
                {
                    AddItem("...", check);
                    break;
                }
            }

            int itemHeight = 18;                                                   // height of single item (really 17 but add a bit extra)
            int fullHeight = ItemList.Top + 6 + ItemList.Items.Count * itemHeight; // full height of control

            if (fullHeight < this.Height)
            {
                this.Height = fullHeight;
            }

            InSetup = false;
            return;
        }
Beispiel #7
0
/// <summary>
/// Configure dialog for current filter type and value
/// </summary>

        void ConfigureDialog()
        {
            QueryColumn     Qc, qc;
            MetaColumn      mc;
            XtraUserControl pc;
            int             dx, dy;

            qc = ColInfo.Qc;
            mc = qc.MetaColumn;

            FilterType ft = qc.SecondaryFilterType;

            if (qc.MetaColumn.DataType == MetaColumnType.Structure)
            {
                ft = FilterType.StructureSearch;
            }

            else if (ft == FilterType.Unknown)
            {
                ColumnStatistics stats = null;
                if (Qm != null && Qm.DataTableManager != null)
                {
                    stats = Qm.DataTableManager.GetStats(qc);
                }
                if (stats != null && stats.DistinctValueList.Count <= 5)                 // if small number of items default to checkbox list
                {
                    ft = FilterType.CheckBoxList;
                }
                else if (qc.MetaColumn.IsNumeric)
                {
                    ft = FilterType.RangeSlider;
                }
                else
                {
                    ft = FilterType.BasicCriteria;
                }
            }

            FilterBasicControl.Visible     = false;
            FilterListControl.Visible      = false;
            FilterItemControl.Visible      = false;
            FilterRangeControl.Visible     = false;
            FilterStructureControl.Visible = false;

            ChangeFilterType.Visible = true;
            EditStructure.Visible    = false;

            SetupFilter(ft);

            if (ft == FilterType.BasicCriteria)
            {
                pc = FilterBasicControl;
            }
            else if (ft == FilterType.CheckBoxList)
            {
                pc = FilterListControl;
                if (pc.Height < 30)
                {
                    pc.Height = Prototype.FilterListControl.Height;                                 // maintain minimum size
                }
                pc.Width = Width - 8;
            }
            else if (ft == FilterType.ItemSlider)
            {
                pc = FilterItemControl;
            }
            else if (ft == FilterType.RangeSlider)
            {
                pc = FilterRangeControl;
            }

            else if (ft == FilterType.StructureSearch)
            {
                pc = FilterStructureControl;
                if (pc.Height < 30)
                {
                    pc.Height = Prototype.FilterStructureControl.Height;                                 // maintain minimum size
                }
                pc.Width = Width - 8;
                EditStructure.Location   = Prototype.ChangeFilterType.Location;               // show edit structure in place of change filter type
                EditStructure.Visible    = true;
                ChangeFilterType.Visible = false;
            }

            else
            {
                throw new Exception("Unexpected SecondaryCriteriaType: " + ft);
            }

            pc.Visible = true;

            Size s0 = pc.Size;

            pc.Location = new Point(0, 0);
            int formHeight = pc.Bottom + HeightBelowDivider;

            if (Text != "")
            {
                formHeight += TitleBarHeight;                         // add title bar height if visible
            }
            Height  = formHeight;
            pc.Size = s0;             // restore filter control size

            Rectangle r = GetColumnHeaderBounds(ColInfo.GridColumn);
            Point     p = new Point(r.Left, r.Top - Height);         // place above cell header

            p = Grid.PointToScreen(p);
            if (p.Y < 0)
            {
                p = new Point(p.X, 0);                      // keep on screen
            }
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;

            if (p.X + Width > screenWidth)
            {
                p = new Point(screenWidth - Width, p.Y);
            }
            Location = p;

            string crit = qc.SecondaryCriteria;

            return;
        }
Beispiel #8
0
/// <summary>
/// Add a new filter
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void AddFilterButton_Click(object sender, EventArgs e)
        {
            QueryColumn qc = null;

            FieldSelectorControl fieldSelector = new FieldSelectorControl();
            Point p = new Point(AddFilterButton.Left, AddFilterButton.Bottom);

            p = this.PointToScreen(p);

            SelectColumnOptions flags = new SelectColumnOptions();

            flags.SearchableOnly      = true;
            flags.FirstTableKeyOnly   = true;
            flags.SelectFromQueryOnly = true;
            DialogResult dr = fieldSelector.SelectColumnFromQuery(Qm.Query, null, flags, p.X, p.Y, out qc);

            if (dr != DialogResult.OK)
            {
                return;
            }

            if (qc.SecondaryFilterType != FilterType.Unknown)
            {
            }                                                                 // already have a filter
            if (qc.MetaColumn.DataType == MetaColumnType.Structure)
            {
                qc.SecondaryFilterType = FilterType.StructureSearch;
            }

            else
            {
                ColumnStatistics stats = null;
                if (Qm != null && Qm.DataTableManager != null)
                {
                    stats = Qm.DataTableManager.GetStats(qc);
                }
                if (stats != null && stats.DistinctValueList.Count <= 10)
                {
                    qc.SecondaryFilterType = FilterType.CheckBoxList;
                }
                else if (qc.MetaColumn.IsNumeric)
                {
                    qc.SecondaryFilterType = FilterType.RangeSlider;
                }
                else
                {
                    qc.SecondaryFilterType = FilterType.BasicCriteria;
                }
            }

            ActiveQueryColumn = qc;

            if (!Qm.DataTableManager.FiltersEnabled)             // be sure filters are enabled & view also
            {
                Qm.DataTableManager.FiltersEnabled = true;
                Qm.DataTableManager.ApplyFilters();
                Qm.DataTableManager.UpdateFilterState();
                QueryResultsControl.GetQrcThatContainsControl(this).UpdateFilteredViews();
            }

            Render();
        }
Beispiel #9
0
        public void Setup(ColumnInfo colInfo)
        {
            InSetup = true;

            ColInfo = colInfo;             // save ref to colInfo
            QueryColumn qc = colInfo.Qc;

            Stats = colInfo.Rfld.GetStats();
            RangeFilter.Properties.Minimum = 0;
            RangeFilter.Properties.Maximum = Stats.DistinctValueList.Count - 1;

            ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(ColInfo.Qc.SecondaryCriteria);             // parse criteria

            TrackBarRange tbr = new TrackBarRange(0, Stats.DistinctValueList.Count - 1);

            RangeFilter.Value = tbr;

            if (psc != null && psc.OpEnum == CompareOp.Between && Stats.DistinctValueList.Count > 0)             // setup prev value
            {
                MetaColumnType type    = ColInfo.Mc.DataType;
                MobiusDataType lowVal  = MobiusDataType.New(type, psc.Value);
                MobiusDataType highVal = MobiusDataType.New(type, psc.Value2);
                if (MetaColumn.IsDecimalMetaColumnType(type))
                {                 // adjust decimal comparison values by an epsilon
                    double e = MobiusDataType.GetEpsilon(Stats.MaxValue.FormattedText);
                    lowVal.NumericValue  += e;
                    highVal.NumericValue -= e;
                }

                int lowPos = -1;
                for (int i1 = 0; i1 < Stats.DistinctValueList.Count; i1++)
                {
                    MobiusDataType mdt  = Stats.DistinctValueList[i1];
                    string         fTxt = mdt.FormattedText;

                    if (mdt.CompareTo(lowVal) <= 0 || Lex.Eq(fTxt, psc.Value))
                    {
                        lowPos = i1;
                    }
                    else
                    {
                        break;
                    }
                }

                int highPos = -1;
                for (int i1 = Stats.DistinctValueList.Count - 1; i1 >= 0; i1--)
                {
                    MobiusDataType mdt  = Stats.DistinctValueList[i1];
                    string         fTxt = mdt.FormattedText;

                    if (mdt.CompareTo(highVal) >= 0 || Lex.Eq(fTxt, psc.Value2))
                    {
                        highPos = i1;
                    }
                    else
                    {
                        break;
                    }
                }

                if (lowPos >= 0 && highPos >= 0)
                {
                    tbr = new TrackBarRange(lowPos, highPos);
                    RangeFilter.Value = tbr;
                }
            }

            UpdateLabels();

            RangeFilter.Focus();
            InSetup = false;
            return;
        }