public void AddValue(Dictionary <GroupValueSearchKey, bool> map, GroupValueSearchKey groupKey, DataTable table, int valueIndex) { if (!map.ContainsKey(groupKey)) { object groupValue; if (groupKey.SearchKey != null) { for (var searchKey = groupKey.SearchKey; searchKey != null; searchKey = searchKey.NextKey) { if (searchKey.ReusedKey == null) { searchKey.ReusedKey = SearchKey.FindReusedKey(searchKey.KeyName); } if (searchKey.IsFixedValue) { if (!Equals(searchKey.ReusedKey.GetReusedValue(table, valueIndex), searchKey.KeyValue)) { return; } } } } if (!GroupValueDict.TryGetValue(groupKey, out groupValue)) { groupValue = 0; GroupValueDict.Add(groupKey, groupValue); } if (groupKey.ReusedKey == null) { groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName); } GroupValueDict[groupKey] = CalculateForumla(groupKey.Formula, groupValue, groupKey.ReusedKey.GetReusedValue(table, valueIndex)); map[groupKey] = true; } }
public object GetValue(GroupValueSearchKey groupKey, object defaultValue = null) { object groupValue; return(GroupValueDict.TryGetValue(groupKey, out groupValue) ? groupValue : defaultValue); }
private static GroupValueSearchKey ParseCellFormulaGroupKey(TplBlock block, TplLine line, string formulaName, string pairValue) { var groupKey = new GroupValueSearchKey { Formula = formulaName }; var valueKeyArray = pairValue.Trim() .Split(new[] { TemplateFlags.CellValueKeySpliter }, StringSplitOptions.RemoveEmptyEntries); SearchKey nextKey = null; for (var i = 0; i < valueKeyArray.Length; i++) { //GroupKey筛选固定值时 var valueFixedArray = valueKeyArray[i].Split(new[] { TemplateFlags.CellValueFixedSpliter }, StringSplitOptions.RemoveEmptyEntries); if (i == 0) { //第一项Key作为绑定关联列名 groupKey.ValueColName = valueFixedArray[0].Trim().ToUpper(); } else { var searchKey = new SearchKey { KeyName = valueFixedArray[0].Trim().ToUpper() }; if (valueFixedArray.Length > 1) { //包含=号赋固定值 searchKey.IsFixedValue = true; searchKey.KeyValue = valueFixedArray[1]; } if (searchKey.KeyName == TemplateFlags.CellGroupKeySearchPattern) { //从之前添加的分组cells中查找 searchKey = GetGroupedSearchKey(block, line); if (searchKey == null) { continue; } } if (nextKey == null) { groupKey.SearchKey = searchKey; nextKey = searchKey; } else { nextKey.NextKey = searchKey; nextKey = searchKey; } //nextKey置尾,后续值追加到searchKey尾部 while (nextKey.NextKey != null) { nextKey = nextKey.NextKey; } } } return(groupKey); }