예제 #1
0
        private List <TabularItemNode> Sort(CacheFieldNode cacheField, SharedItemsCollection cacheItems)
        {
            // Sort the fields according to their types.
            IComparer <string> comparer = null;

            if (this.TabularDataNode.CustomListSort && cacheField.IsDateGrouping)
            {
                if (cacheField.FieldGroup.GroupBy == PivotFieldDateGrouping.Months)
                {
                    comparer = new MonthComparer();
                }
                else if (cacheField.FieldGroup.GroupBy == PivotFieldDateGrouping.Days)
                {
                    comparer = new DayComparer();
                }
            }
            else
            {
                comparer = new NaturalComparer();
            }

            // Sort the slicer cache items.
            if (this.TabularDataNode.SortOrder == SortOrder.Descending)
            {
                return(this.TabularDataNode.Items.OrderByDescending(t => cacheItems[t.AtomIndex].Value, comparer).ToList());
            }
            return(this.TabularDataNode.Items.OrderBy(t => cacheItems[t.AtomIndex].Value, comparer).ToList());
        }
예제 #2
0
        public void SlicerRangeNodeItems()
        {
            var node           = this.CreateCacheFieldNode();
            var cacheFieldNode = new CacheFieldNode(TestUtility.CreateDefaultNSM(), node);

            Assert.AreEqual(3, cacheFieldNode.SharedItems.Count);
            Assert.AreEqual("10000", cacheFieldNode.SharedItems[0].Value);
            Assert.AreEqual("20000", cacheFieldNode.SharedItems[1].Value);
            Assert.AreEqual("30000", cacheFieldNode.SharedItems[2].Value);
        }
예제 #3
0
        public void SlicerRangeNodeNumFormatId()
        {
            var node           = this.CreateCacheFieldNode();
            var cacheFieldNode = new CacheFieldNode(TestUtility.CreateDefaultNSM(), node);

            Assert.AreEqual(49, cacheFieldNode.NumFormatId);
            cacheFieldNode.NumFormatId = 30;
            Assert.AreEqual(30, cacheFieldNode.NumFormatId);
            Assert.AreEqual($@"<cacheField name=""Customer No."" numFmtId=""30"" xmlns=""{ExcelPackage.schemaMain}""><sharedItems count=""3""><s v=""10000"" /><s v=""20000"" /><s v=""30000"" /></sharedItems></cacheField>", node.OuterXml);
        }
예제 #4
0
        public void RemoveXmlUAttributeWithNoSharedItemsTest()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml(@"<cacheField xmlns=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"" name=""Item"" numFmtId=""0""></cacheField>");
            var node = new CacheFieldNode(TestUtility.CreateDefaultNSM(), document.FirstChild);

            node.RemoveXmlUAttribute();
            Assert.IsNull(node.SharedItems);
        }
예제 #5
0
        private List <TabularItemNode> ApplyNoDataSettings(List <TabularItemNode> sortedItems, ExcelPivotCacheDefinition cacheDefinition,
                                                           int cacheFieldIndex, CacheFieldNode cacheField, SharedItemsCollection cacheItems)
        {
            var pivotTables = this.GetRelatedPivotTables(cacheDefinition);

            if (this.HideItemsWithNoData)
            {
                foreach (var item in sortedItems)
                {
                    // TODO: Task #13685 - Implement hide items with no data settings.
                    if (!this.PivotTablesContainItem(item, pivotTables, cacheFieldIndex, cacheItems))
                    {
                        item.NoData = true;
                    }
                }
            }
            else
            {
                if (this.TabularDataNode.CrossFilter == CrossFilter.Both)
                {
                    var usedItems   = new List <TabularItemNode>();
                    var unusedItems = new List <TabularItemNode>();
                    foreach (var item in sortedItems)
                    {
                        bool hasData = this.PivotTablesContainItem(item, pivotTables, cacheFieldIndex, cacheItems);
                        if (hasData)
                        {
                            usedItems.Add(item);
                        }
                        else
                        {
                            unusedItems.Add(item);
                        }
                    }
                    sortedItems = usedItems.Concat(unusedItems).ToList();
                }

                if (!this.TabularDataNode.ShowMissing)
                {
                    foreach (var item in sortedItems)
                    {
                        if (cacheItems[item.AtomIndex].Unused)
                        {
                            item.NoData = true;
                        }
                    }
                }
            }
            return(sortedItems);
        }
예제 #6
0
        private List <Tuple <int, int> > ResolveFieldValuePairs(List <FunctionArgument> fieldValueArguments, ExcelPivotCacheDefinition cacheDefinition)
        {
            var indices = new List <Tuple <int, int> >();

            for (int i = 0; i + 1 < fieldValueArguments.Count; i += 2)
            {
                string         fieldName  = fieldValueArguments[i].Value.ToString();
                string         value      = fieldValueArguments[i + 1].Value.ToString();
                int            fieldIndex = -1;
                CacheFieldNode cacheField = null;
                for (int j = 0; j < cacheDefinition.CacheFields.Count; j++)
                {
                    var currentCacheField = cacheDefinition.CacheFields[j];
                    if (currentCacheField.Name.IsEquivalentTo(fieldName))
                    {
                        fieldIndex = j;
                        cacheField = currentCacheField;
                        break;
                    }
                }
                if (fieldIndex == -1)
                {
                    return(null);
                }

                int valueIndex = -1;
                for (int j = 0; j < cacheField.SharedItems.Count; j++)
                {
                    if (cacheField.SharedItems[j].Value.IsEquivalentTo(value))
                    {
                        valueIndex = j;
                        break;
                    }
                }
                if (valueIndex == -1)
                {
                    return(null);
                }

                var indexPair = new Tuple <int, int>(fieldIndex, valueIndex);
                indices.Add(indexPair);
            }
            return(indices);
        }
예제 #7
0
        public void RemoveXmlUAttributeTest()
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml(@"<cacheField xmlns=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"" name=""Item"" numFmtId=""0"">
					<sharedItems count=""2"">
						<s v=""Bike"" u=""1""/>
						<s v=""Car""/>
						<s v=""Scooter"" u=""1""/>
						<s v=""Skateboard""/>
					</sharedItems>
				</cacheField>"                );
            var node = new CacheFieldNode(TestUtility.CreateDefaultNSM(), document.FirstChild);

            node.RemoveXmlUAttribute();
            foreach (var item in node.SharedItems)
            {
                Assert.IsNull(item.TopNode.Attributes["u"]);
                Assert.AreEqual(1, item.TopNode.Attributes.Count);
            }
        }