Exemplo n.º 1
0
 /// <summary>
 /// 获取分组值
 /// </summary>
 /// <param name="holder"></param>
 /// <param name="table"></param>
 /// <param name="valueIndex"></param>
 /// <returns></returns>
 public object GetGroupValue(GroupDataHolder holder, DataTable table, int valueIndex)
 {
     if (ReusedKey == null)
     {
         ReusedKey = SearchKey.FindReusedKey(TplGroupColumnName);
     }
     return(ReusedKey.GetReusedValue(table, valueIndex));
 }
Exemplo n.º 2
0
        public int FillBlock(DataTable table)
        {
            var rowIndex = StartParseRowIndex;

            for (var i = 0; i < table.Rows.Count; i++)
            {
                CountedMap.Clear();
                if ((DynamicColumn != null) && !IsDynamicCloumnsCreated)
                {
                    DynamicColumn.CheckColumn(this, Holder, rowIndex, table, i);
                }
                foreach (var groupKey in GroupKeyList)
                {
                    if (groupKey.ReusedKey == null)
                    {
                        groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName);
                    }
                    var copyKey = groupKey.Copy();
                    if (copyKey.SearchKey != null)
                    {
                        copyKey.SearchKey.FillKey(table, i);
                    }
                    Holder.AddValue(CountedMap, copyKey, table, i);
                }
                for (var k = 0; k < TplLineList.Count; k++)
                {
                    var updateLine = TplLineList[k];
                    var isNewLine  = updateLine.FillLine(Holder, rowIndex, table, i);
                    if (isNewLine)
                    {
                        FillLastLine(k, LastUsedLine, rowIndex - 1, table, LastUsedLineValueIndex); //?填充上一行值
                        LastUsedLine           = updateLine;
                        LastUsedLineValueIndex = i;
                        if ((i + 1) >= table.Rows.Count)
                        {
                            FillLastLine(k, updateLine, rowIndex, table, LastUsedLineValueIndex);
                        }

                        rowIndex  += 1;
                        RowsCount += 1;
                    }
                }
            }
            MergeHGroupCells();
            if (!table.ExtendedProperties.ContainsKey("TableType") ||
                (table.ExtendedProperties["TableType"].ToString() != "CustumEmpty"))
            {
                MergeVGroupCells();
            }
            return(RowsCount);
        }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
        public void InsertOneColumn(TplBlock block, int colIndex, GroupDataHolder holder, DataTable columnTalbe,
                                    int valueIndex, bool hasData)
        {
            if (hasData)
            {
                var range = RangeHelper.GetRange(TplRange.Worksheet, StartColIndex + colIndex, block.StartParseRowIndex,
                                                 1,
                                                 block.RowsCount);
                RangeHelper.InsertCopyRange(TplRange.Worksheet, range,
                                            (StartColIndex + GroupColumnCount) + InsertCount, block.StartParseRowIndex,
                                            1, block.RowsCount,
                                            InsertRangeDirection.Right, TplLastColumnIndex);
            }
            var orign = RangeHelper.GetRange(TplRange.Worksheet, StartColIndex + colIndex, block.TplRange.Row, 1,
                                             block.TplRowCount);

            RangeHelper.InsertCopyRange(TplRange.Worksheet, orign,
                                        (StartColIndex + GroupColumnCount) + InsertCount, orign.Row,
                                        1, block.TplRowCount,
                                        InsertRangeDirection.Right, TplLastColumnIndex);

            RefreshLineTplRanges(block, 1);
            block.TplColumCount++;
            block.ColumnsCount++;
            for (var i = 0; i < block.TplLineList.Count; i++)
            {
                var line    = block.TplLineList[i];
                var num2    = StartCellIndex + colIndex;
                var tplCell = line.CellList[num2].Copy();
                tplCell.LastColIndex++;
                line.CellList.Insert((StartCellIndex + GroupColumnCount) + InsertCount, tplCell);
                if (tplCell.Formula != null)
                {
                    foreach (var groupKey in tplCell.Formula.KeyList)
                    {
                        if (groupKey.ReusedKey == null)
                        {
                            groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName);
                        }
                        for (var key3 = groupKey.SearchKey; key3 != null; key3 = key3.NextKey)
                        {
                            if (IsGroupedColumn(key3.KeyName))
                            {
                                key3.KeyValue     = RangeHelper.GetTableValue(columnTalbe, valueIndex, key3.KeyName);
                                key3.IsFixedValue = true;
                            }
                        }
                        block.GroupKeyList.Add(groupKey.Copy());
                        if (groupKey.SearchKey != null)
                        {
                            groupKey.SearchKey.FillKey(columnTalbe, valueIndex);
                        }
                        block.Holder.AddValue(block.CountedMap, groupKey, columnTalbe, valueIndex);
                    }
                }
                tplCell.GroupAlign = GroupAlign.None;
                Console.WriteLine(string.Concat("Inserted hg [", i.ToString().PadLeft(3), "][",
                                                num2.ToString().PadLeft(3), "] = ", tplCell.Formula));
                if (i < block.RowsCount)
                {
                    var currentCellRange = RangeHelper.GetCell(TplRange.Worksheet,
                                                               (StartColIndex + GroupColumnCount) + InsertCount,
                                                               block.StartParseRowIndex + i);
                    tplCell.WriteCell(Tpl, holder, currentCellRange, columnTalbe, valueIndex);
                }
            }
            InsertCount++;
        }