public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                string raw = value as string;

                try
                {
                    MeasureFilter mFilt = new MeasureFilter();
                    // Segments
                    string[] parts = raw.Split(new char[] { '.' }, 3);
                    if (parts[0].ToLower()[0] == 'm')
                    {
                        mFilt.MeasureIndex = Int32.Parse(parts[0].Substring(1));
                    }
                    if (parts[1].ToLower()[0] == 'r')
                    {
                        mFilt.RangeIndex = Int32.Parse(parts[1].Substring(1));
                    }
                    if (parts.Length > 2)
                    {
                        string diffRaw = parts[2].Split(new char[] { '<', '>', '=' }, 2)[0];
                        mFilt.DiffType = diffRaw.ToLower() == "value" ?
                                         DiffType.None :
                                         (DiffType)Enum.Parse(typeof(DiffType), diffRaw, true);
                    }
                    else
                    {
                        mFilt.DiffType = DiffType.None;
                    }
                    parts             = raw.Split(new char[] { '<', '>', '=' }, 2);
                    mFilt.FilterValue = Convert.ToInt32(parts[1]);
                    if (raw.Contains(">"))
                    {
                        mFilt.Operator = ">";
                    }
                    if (raw.Contains("<"))
                    {
                        mFilt.Operator = "<";
                    }
                    if (raw.Contains("="))
                    {
                        mFilt.Operator = "=";
                    }

                    return(mFilt);
                }
                catch (NullReferenceException)
                {
                    return(null);
                }
                catch (Exception ex)
                {
                    throw new Exception("Invalid measure filter: " + raw, ex);
                }
            }
Ejemplo n.º 2
0
        public List <ObjData> GetData(
            int account,
            DataGrouping grouping,
            int top,
            MeasureRef[] measures,
            DayCodeRange[] ranges,
            MeasureDiff[] diff,
            MeasureSort[] dataSort,
            MeasureSort[] viewSort,
            MeasureFormat[] format,
            MeasureFilter filter
            )
        {
            // Get measures
            List <Measure>            measuresList = GetMeasures(account, true);
            Dictionary <int, Measure> measuresByID = measuresList.ToDictionary(m => m.MeasureID);

            EdgeBI.Web.DataServices.DataHandler dataHandler = new EdgeBI.Web.DataServices.DataHandler();
            return(dataHandler.GetData(account, grouping, top, measures, ranges, diff, dataSort, viewSort, format, measuresByID, filter));
        }
 private void GetFieldsSQL(MeasureRef measure, int measureIndex, int RangeIndex, out string AggregateFunction, out string HavingString, Dictionary <int, Measure> measuresList, MeasureFilter filter)
 {
     AggregateFunction = BuildAggregateFunction(measure, measuresList);
     HavingString      = AggregateFunction + " IS NOT NULL ";
     try
     {
         if (filter.MeasureIndex == measureIndex && filter.RangeIndex == RangeIndex)
         {
             HavingString += " AND " + AggregateFunction + filter.Operator.ToString() + filter.FilterValue;
         }
     }
     catch (NullReferenceException)
     {
     }
     AggregateFunction = AggregateFunction + " AS 'M" + measureIndex + ".R" + RangeIndex + ".Value'";
 }
        public List <ObjData> GetData(
            int accountID,
            DataGrouping grouping,
            int top,
            MeasureRef[] measures,
            DayCodeRange[] ranges,
            MeasureDiff[] diff,
            MeasureSort[] dataSort,
            MeasureSort[] viewSort,
            MeasureFormat[] format,
            Dictionary <int, Measure> measuresList,
            MeasureFilter filter
            )
        {
            Mode mode = GetMode(dataSort);

            Measures = new List <Measure>(measuresList.Values);
            List <ObjData> Data = new List <ObjData>();
            Dictionary <string, ObjData> arrAllReturnData = new Dictionary <string, ObjData>();
            int    measureIndex = 1, RangeIndex = 1;
            string Sql = null, IdsList = null;

            foreach (DayCodeRange dc in ranges)
            {
                string AggregateFunction = null, HavingString = null;
                measureIndex = 1;
                foreach (MeasureRef mf in measures)
                {
                    string  lAggregateFunction = null, lHavingString = null;
                    Measure m = measuresList[mf.MeasureID];
                    if (mf.IsTargetRef)
                    {
                        m = measuresList[m.TargetMeasureID];
                    }
                    GetFieldsSQL(mf, measureIndex, RangeIndex, out lAggregateFunction, out lHavingString, measuresList, filter);
                    AggregateFunction += "," + lAggregateFunction;
                    HavingString      += HavingString != null ? " AND " + lHavingString : lHavingString;
                    DicMeasuresFormat.Add("M" + measureIndex + ".R" + RangeIndex + ".Value", m.StringFormat);
                    measureIndex++;
                }
                Sql = GetSQL(AggregateFunction.Substring(1), HavingString, accountID, dc, grouping, dataSort, top, IdsList, mode);
                GetData(Sql, arrAllReturnData, out arrAllReturnData);
                RangeIndex++;
                if (IdsList == null)
                {
                    foreach (string id in arrAllReturnData.Keys)
                    {
                        IdsList += "," + id;
                    }
                    if (IdsList != null)
                    {
                        IdsList = IdsList.Substring(1);
                    }
                }
            }
            Data = new List <ObjData>(arrAllReturnData.Values);
            if (diff != null && diff.Length > 0)
            {
                GetDiffCalculation(out Data, Data, diff);
            }
            if (viewSort != null && viewSort.Length > 0 && mode == Mode.Simple)
            {
                GetSortData(out Data, Data, viewSort);
            }
            if (mode == Mode.Advanced)
            {
                GetDataByDataSort(out Data, Data, top, dataSort);
            }
            if (Data.Count > 0)
            {
                GetFormateData(out Data, Data);
            }
            return(Data);
        }