Beispiel #1
0
        private List <AbstractTuple> GetFilteredDataTuples(DatasetVersion datasetVersion)
        {
            DatasetManager datasetManager = new DatasetManager();

            try
            {
                List <AbstractTuple> datatuples = datasetManager.GetDatasetVersionEffectiveTuples(datasetVersion);

                if (Session["Filter"] != null)
                {
                    GridCommand command = (GridCommand)Session["Filter"];

                    List <AbstractTuple> dataTupleList = datatuples;

                    if (command.FilterDescriptors.Count > 0)
                    {
                        foreach (IFilterDescriptor filter in command.FilterDescriptors)
                        {
                            var test = filter;

                            // one filter is set
                            if (filter.GetType() == typeof(FilterDescriptor))
                            {
                                FilterDescriptor filterDescriptor = (FilterDescriptor)filter;

                                // get id as long from filtername
                                Regex r  = new Regex("(\\d+)");
                                long  id = Convert.ToInt64(r.Match(filterDescriptor.Member).Value);

                                var list = from datatuple in dataTupleList
                                           let val = datatuple.VariableValues.Where(p => p.Variable.Id.Equals(id)).FirstOrDefault()
                                                     where GridHelper.ValueComparion(val, filterDescriptor.Operator, filterDescriptor.Value)
                                                     select datatuple;

                                dataTupleList = list.ToList();
                            }
                            else
                            // more than one filter is set
                            if (filter.GetType() == typeof(CompositeFilterDescriptor))
                            {
                                CompositeFilterDescriptor filterDescriptor = (CompositeFilterDescriptor)filter;

                                List <AbstractTuple> temp = new List <AbstractTuple>();

                                foreach (IFilterDescriptor f in filterDescriptor.FilterDescriptors)
                                {
                                    if ((FilterDescriptor)f != null)
                                    {
                                        FilterDescriptor fd = (FilterDescriptor)f;
                                        // get id as long from filtername
                                        Regex r  = new Regex("(\\d+)");
                                        long  id = Convert.ToInt64(r.Match(fd.Member).Value);

                                        var list = from datatuple in dataTupleList
                                                   let val = datatuple.VariableValues.Where(p => p.Variable.Id.Equals(id)).FirstOrDefault()
                                                             where GridHelper.ValueComparion(val, fd.Operator, fd.Value)
                                                             select datatuple;

                                        //temp  = list.Intersect<AbstractTuple>(temp as IEnumerable<AbstractTuple>).ToList();
                                        dataTupleList = list.ToList();
                                    }
                                }

                                //dataTupleList = temp;
                            }
                        }
                    }

                    if (command.SortDescriptors.Count > 0)
                    {
                        foreach (SortDescriptor sort in command.SortDescriptors)
                        {
                            string direction = sort.SortDirection.ToString();

                            // get id as long from filtername
                            Regex r  = new Regex("(\\d+)");
                            long  id = Convert.ToInt64(r.Match(sort.Member).Value);

                            if (direction.Equals("Ascending"))
                            {
                                var list = from datatuple in dataTupleList
                                           let val = datatuple.VariableValues.Where(p => p.Variable.Id.Equals(id)).FirstOrDefault()
                                                     orderby GridHelper.CastVariableValue(val.Value, val.DataAttribute.DataType.SystemType) ascending
                                                     select datatuple;

                                dataTupleList = list.ToList();
                            }
                            else
                            if (direction.Equals("Descending"))
                            {
                                var list = from datatuple in dataTupleList
                                           let val = datatuple.VariableValues.Where(p => p.Variable.Id.Equals(id)).FirstOrDefault()
                                                     orderby GridHelper.CastVariableValue(val.Value, val.DataAttribute.DataType.SystemType) descending
                                                     select datatuple;

                                dataTupleList = list.ToList();
                            }
                        }
                    }

                    return(dataTupleList);
                }

                return(null);
            }
            finally
            {
                datasetManager.Dispose();
            }
        }