Ejemplo n.º 1
0
 public object GetGroupValue(GroupDataHolder holder, DataTable table, int valueIndex)
 {
     if (rGroupKey == null)
     {
         SearchKey key = new SearchKey();
         key.colName = this.tplGroupColName;
         rGroupKey   = ReusedKey.FindReusedKey(key);
     }
     return(rGroupKey.GetReusedValue(table, valueIndex));
     // return RangeHelper.GetColValue(table, valueIndex, tplGroupColName);
 }
Ejemplo n.º 2
0
        private static SearchKey CreateTopKey(SearchKey key)
        {
            SearchKey topKey = key.Copy();

            topKey.keyValue     = "";
            topKey.colName      = "";
            topKey.nextKey      = key;
            topKey.isFixedValue = true;
            topKey.keyValue     = null;
            return(topKey);
        }
Ejemplo n.º 3
0
        public static ReusedKey FindReusedKey(SearchKey key)
        {
            for (int i = 0; i < keyPool.Count; i++)
            {
                ReusedKey reusedKey = keyPool [i];

                if (Equals(reusedKey.colName, key.colName))
                {
                    return(reusedKey);
                }
            }

            ReusedKey rKey = new ReusedKey();

            rKey.colName = key.colName;

            keyPool.Add(rKey);

            return(rKey);
        }
Ejemplo n.º 4
0
        public SearchKey Copy0(bool copyValue)
        {
            SearchKey key = new SearchKey();

            key.colIndex = colIndex;
            key.colName  = colName;
            key.rKey     = rKey;
            if (copyValue)
            {
                key.keyValue     = keyValue;
                key.isFixedValue = isFixedValue;
            }

            if (nextKey != null)
            {
                key.nextKey = nextKey.Copy0(copyValue);
            }

            return(key);
        }
Ejemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            SearchKey searchKey = obj as SearchKey;

            if (searchKey == null)
            {
                return(false);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if (!Equals(nextKey, searchKey.nextKey))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        private static SearchKey GetGroupedKeys(TplBlock block, TplLine line)
        {
            SearchKey root = null;
            SearchKey pkey = null;

            // get Line cell first
            for (int i = 0; i < line.cellList.Count; i++)
            {
                TplCell leftCell = line.cellList [i];
                if (leftCell.align != GroupAlign.vGroup)
                {
                    continue;
                }
                SearchKey key = new SearchKey();
                key.colName = leftCell.tplGroupColName;
                if (root == null)
                {
                    root = key;
                }

                if (pkey == null)
                {
                    pkey = key;
                }
                else
                {
                    pkey.nextKey = key;
                    pkey         = key;
                }
            }

            for (int i = 0; i < block.lineList.Count; i++)
            {
                TplLine l = block.lineList [i];

                if (l.cellList.Count <= line.cellList.Count)
                {
                    continue;
                }

                TplCell upCell = l.cellList [line.cellList.Count];
                if (upCell.align != GroupAlign.hGroup)
                {
                    continue;
                }

                SearchKey key = new SearchKey();
                key.colName = upCell.tplGroupColName;
                if (root == null)
                {
                    root = key;
                }

                if (pkey == null)
                {
                    pkey = key;
                }
                else
                {
                    pkey.nextKey = key;
                    pkey         = key;
                }
            }
            return(root);
        }
Ejemplo n.º 7
0
        private static void ParseCell(TplBlock block, TplLine line, TplCell cell, string text)
        {
            text = text.Trim();
            if (text.StartsWith("R1C1:"))
            {
                cell.useR1C1Formula = true;
                cell.tplTextContent = text.Substring(5);
                return;
            }
            if (text [0] != '{')
            {
                // as text
                cell.tplTextContent = text;
                return;
            }

            int i = text.IndexOf('}');

            if (i > 0)
            {
                if (i + 1 != text.Length)
                {
                    cell.tplTextContent = text.Substring(i + 1);
                }

                text = text.Substring(1, i - 1);
            }

            // using text as col name.
            cell.tplValueColName = text;


            Dictionary <string, string> pair = ParseKeyValuePair(text);

            // parse format string
            cell.tplFormat = GetPairValue(pair, "f");
            if (!string.IsNullOrEmpty(cell.tplFormat))
            {
                cell.tplFormat = cell.tplFormat.ToLower();
            }

            // parse Merge option.
            cell.mOption = ParseMergeOption(GetPairValue(pair, "m"));

            // parse group options.
            if (GetPairValue(pair, "vg") != null)
            {
                cell.align = GroupAlign.vGroup;

                cell.tplGroupColName = GetPairValue(pair, "vg").Trim().ToUpper();
            }
            else if (GetPairValue(pair, "hg") != null)
            {
                cell.align           = GroupAlign.hGroup;
                cell.tplGroupColName = GetPairValue(pair, "hg").ToUpper();
                line.containsHGroup  = true;
                InsertOption option = GetLineInsertOption(GetPairValue(pair, "hgo"));
                if (option != InsertOption.afterChange && option != InsertOption.BeforeChange)
                {
                    option = InsertOption.afterChange;
                }

                cell.hgOption = option;
            }

            // parse value string including formula.
            string v = GetPairValue(pair, "v");

            if (string.IsNullOrEmpty(v))
            {
                if (!string.IsNullOrEmpty(cell.tplGroupColName))
                {
                    cell.tplValueColName = cell.tplGroupColName;
                }
                return;
            }


            //pase default value
            cell.tplDefaultContent = GetPairValue(pair, "default");

            i = v.IndexOf('(');

            if (i < 0)
            {
                cell.tplValueColName = v.Trim().ToUpper();
                return;
            }

            cell.formula = new CellForumla();

            cell.formula.formulaName = i == 0 ? "" : v.Substring(0, i).ToLower();

            int i2 = v.IndexOf(')');

            if (i2 < 0)
            {
                Console.WriteLine("Warning:: formula not closed. [" + v + "]");
                v = v.Substring(i + 1);
            }
            else
            {
                v = v.Substring(i + 1, i2 - i - 1);
            }

            v = v.Trim();
            string[] colList = v.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            SearchKey           pkey = null;
            GroupValueSearchKey gkey = new GroupValueSearchKey();

            gkey.formula = cell.formula.formulaName;
            cell.formula.keyList.Add(gkey);
            string colName = "";

            for (int j = 0; j < colList.Length; j++)
            {
                string colPair = colList [j];

                string[] cs = colPair.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                if (j == 0)
                {
                    colName = cs [0];
                    /* gkey.formula = "" ; */
                    gkey.valueColName = colName.Trim().ToUpper();
                    continue;
                }



                SearchKey key = new SearchKey();
                key.colName = cs [0].ToUpper();

                if (cs.Length > 1)
                {
                    key.isFixedValue = true;
                    key.keyValue     = cs [1];
                }


                if (key.colName == "%")
                {
                    key = GetGroupedKeys(block, line);

                    if (key == null)
                    {
                        continue;
                    }
                }

                if (pkey == null)
                {
                    gkey.key = key;
                    pkey     = key;
                }
                else
                {
                    pkey.nextKey = key;
                    pkey         = key;
                }
                while (pkey.nextKey != null)
                {
                    pkey = pkey.nextKey;
                }
            }

            block.gkeyList.Add(gkey.Copy());
        }
Ejemplo n.º 8
0
        public void InsertColumn(TplBlock block, GroupDataHolder holder, DataTable table, int valueIndex, bool hasData)
        {
            // do insert
            if (insertCount > 0)
            {
                if (hasData)
                {
                    // block.startRowIndex ;
                    Range colRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                          startColIndex + insertCount - gCols, block.startRowIndex,
                                                          gCols, block.rowCount);
                    // Insert new ;
                    RangeHelper.InsertCopyRange(tplRange.Worksheet, colRange,
                                                gCols, block.rowCount,
                                                startColIndex + insertCount, block.startRowIndex,
                                                XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
                }
                // Insert new Col in Template.
                Range tplColRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                         startColIndex + insertCount - gCols, block.tplRange.Row,
                                                         gCols, block.tplRowCount);

                RangeHelper.InsertCopyRange(tplRange.Worksheet, tplColRange,
                                            gCols, block.tplRowCount,
                                            startColIndex + insertCount, tplColRange.Row,
                                            XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
                // Refresh Line.TplRange ;
                RefreshLineTplRanges(block, gCols);

                block.tplColumCount += gCols;
                block.colCount      += gCols;
            }


            // Insert cell into exsit lineList.
            for (int lineIndex = 0; lineIndex < block.lineList.Count; lineIndex++)
            {
                TplLine line = block.lineList [lineIndex];

                for (int j = 0; j < gCols; j++)
                {
                    int cellIndex = startCellIndex + (insertCount > 0 ? (insertCount - gCols) : 0) + j;

                    TplCell cell = line.cellList [cellIndex];

                    /* if (cell.lastColIndex != nextCloIndex - (insertCount > 0 ? 1 : 0)) */
                    // if (cell.lastColIndex < nextCloIndex || cell.lastColIndex >= nextCloIndex + gCols)
                    //  continue ;

                    //	if (lineIndex == 2)
                    //		lineIndex = 2 ;

                    if (insertCount > 0)
                    {
                        cell = cell.Copy();
                        cell.lastColIndex += gCols;

                        line.cellList.Insert(cellIndex + gCols, cell);
                    }

                    if (cell.formula != null)
                    {
                        for (int keyIndex = 0; keyIndex < cell.formula.keyList.Count; keyIndex++)
                        {
                            GroupValueSearchKey gkey = cell.formula.keyList[keyIndex];
                            SearchKey           key  = gkey.key;
                            while (key != null)
                            {
                                if (IsGroupedColumn(key.colName))
                                {
                                    key.keyValue     = RangeHelper.GetColValue(table, valueIndex, key.colName);
                                    key.isFixedValue = true;
                                }
                                key = key.nextKey;
                            }

                            block.gkeyList.Add(gkey.Copy());
                            if (gkey.key != null)
                            {
                                gkey.key.FillKey(table, valueIndex);
                            }

                            block.holder.AddValue(block.countedMap, gkey, table, valueIndex);
                        }
                    }
                    else
                    if (cell.hgOption != InsertOption.never)
                    {
                        cell.tplTextContent = Convert.ToString(cell.GetValueByIndex(valueIndex, table));
                    }

                    cell.align = GroupAlign.none;

                    Console.WriteLine("Inserted hg Line[" + lineIndex + "]cell[" + cellIndex + "] = " + cell.formula);

                    /* update Row Value */
                    if (lineIndex < block.rowCount)
                    {
                        Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, startColIndex + (insertCount /* == 0 ? 0 : insertCount - 1*/) + j,
                                                              block.startRowIndex + lineIndex);

                        cell.WriteCell(tpl, holder, cellRange, table, valueIndex);
                    }
                }
            }
            // Console.WriteLine ("---- End of " + valueIndex);
            // increment next

            nextCloIndex += gCols;
            insertCount  += gCols;
        }
Ejemplo n.º 9
0
        public void InsertOneColumn(TplBlock block, int colIndex, GroupDataHolder holder, DataTable table, int valueIndex, bool hasData)
        {
            if (hasData)
            {
                // block.startRowIndex ;
                Range colRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                      startColIndex + colIndex, block.startRowIndex,
                                                      1, block.rowCount);
                // Insert new ;
                RangeHelper.InsertCopyRange(tplRange.Worksheet, colRange,
                                            1, block.rowCount,
                                            startColIndex + gCols + insertCount, block.startRowIndex,
                                            XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
            }
            // Insert new Col in Template.
            Range tplColRange = RangeHelper.GetRange(tplRange.Worksheet,
                                                     startColIndex + colIndex, block.tplRange.Row,
                                                     1, block.tplRowCount);

            RangeHelper.InsertCopyRange(tplRange.Worksheet, tplColRange,
                                        1, block.tplRowCount,
                                        startColIndex + gCols + insertCount, tplColRange.Row,
                                        XlInsertShiftDirection.xlShiftToRight, tplLastColCount);
            // Refresh Line.TplRange ;
            RefreshLineTplRanges(block, 1);

            block.tplColumCount += 1;
            block.colCount      += 1;

            // Insert cell into exsit lineList.
            for (int lineIndex = 0; lineIndex < block.lineList.Count; lineIndex++)
            {
                TplLine line = block.lineList[lineIndex];

                int cellIndex = startCellIndex + colIndex;

                TplCell cell0 = line.cellList[cellIndex];

                TplCell cell = cell0.Copy();
                cell.lastColIndex += 1;


                line.cellList.Insert(startCellIndex + gCols + insertCount, cell);

                /*
                 * if (cell.useExcelFormula)
                 * {
                 *      cell.tplRange = cell0.tplRange ;
                 * }
                 */
                if (cell.formula != null)
                {
                    for (int keyIndex = 0; keyIndex < cell.formula.keyList.Count; keyIndex++)
                    {
                        GroupValueSearchKey gkey = cell.formula.keyList[keyIndex];
                        if (gkey.rKey == null)
                        {
                            SearchKey key0 = new SearchKey();
                            key0.colName = gkey.valueColName;

                            gkey.rKey = ReusedKey.FindReusedKey(key0);
                        }
                        SearchKey key = gkey.key;
                        while (key != null)
                        {
                            if (IsGroupedColumn(key.colName))
                            {
                                key.keyValue     = RangeHelper.GetColValue(table, valueIndex, key.colName);
                                key.isFixedValue = true;
                            }
                            key = key.nextKey;
                        }

                        block.gkeyList.Add(gkey.Copy());
                        if (gkey.key != null)
                        {
                            gkey.key.FillKey(table, valueIndex);
                        }

                        block.holder.AddValue(block.countedMap, gkey, table, valueIndex);
                    }
                }

                /*
                 * else if (cell.hgOption != InsertOption.never)
                 * {
                 *      // set fixed text
                 *      cell.tplTextContent = Convert.ToString(RangeHelper.GetColValue (table, valueIndex, cell.tplValueColName)) ;
                 * }
                 */

                cell.align = GroupAlign.none;

                Console.WriteLine("Inserted hg Line[" + lineIndex + "]cell[" + cellIndex + "] = " + cell.formula);

                /* update Row Value */
                if (lineIndex < block.rowCount)
                {
                    Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, startColIndex + gCols + insertCount,
                                                          block.startRowIndex + lineIndex);

                    cell.WriteCell(tpl, holder, cellRange, table, valueIndex);
                }
            }
            // Console.WriteLine ("---- End of " + valueIndex);
            // increment next

            nextCloIndex += 1;
            insertCount++;
        }
Ejemplo n.º 10
0
        public int FillBlock(DataTable table)
        {
            int rowIndex = startRowIndex;

            for (int valueIndex = 0; valueIndex < table.Rows.Count; valueIndex++)
            {
                countedMap.Clear();
                // fill key for each line, and count Data.
                // Check is Need Row ;
                if (dColumn != null && !dCloumnsCreated)
                {
                    dColumn.CheckColumn(this, holder, rowIndex,
                                        table, valueIndex);
                }

                // fill key for each line, and count Data.
                for (int j = 0; j < gkeyList.Count; j++)
                {
                    GroupValueSearchKey gkey = gkeyList [j];

                    if (gkey.rKey == null)
                    {
                        SearchKey key = new SearchKey();
                        key.colName = gkey.valueColName;
                        gkey.rKey   = ReusedKey.FindReusedKey(key);
                    }

                    gkey = gkey.Copy();
                    if (gkey.key != null)
                    {
                        gkey.key.FillKey(table, valueIndex);
                    }

                    holder.AddValue(countedMap, gkey, table, valueIndex);
                }

                // fill Data
                for (int j = 0; j < lineList.Count; j++)
                {
                    TplLine line = lineList[j];

                    /*
                     * if (j == 4)
                     *      j = 4 ;
                     */
                    int nl = line.FillLine(holder, rowIndex, table, valueIndex);
                    if (nl > 0)
                    {
                        FillLastLine(j, lastUsedLine, rowIndex - 1, table, lastUsedLineValueIndex);

                        lastUsedLine           = line;
                        lastUsedLineValueIndex = valueIndex;

                        // is LastLine, update current line
                        if (valueIndex + 1 >= table.Rows.Count)
                        {
                            FillLastLine(j, line, rowIndex, table, lastUsedLineValueIndex);
                        }
                    }


                    /*else
                     * {
                     *      // Ensure Each Column is OK.
                     *      if (dColumn != null && lastUsedLine != null && lastUsedLine == line)
                     *      {
                     *              if (! lastUsedLine.containsHGroup)
                     *                      lastUsedLine.UpdateRowData (holder, rowIndex - 1, table, valueIndex);
                     *
                     *              if (updateAllRow)
                     *              {
                     *                      for (int k = 0 ; k <= j ; k ++)
                     *                      {
                     *                              TplLine hLine = lineList [k] ;
                     *                              if (hLine.containsHGroup && hLine.insertedRowList.Count > 0)
                     *                              {
                     *                                      hLine.UpdateRowData(holder,
                     *                                                          hLine.insertedRowList[hLine.insertedRowList.Count - 1],
                     *                                                          table, valueIndex);
                     *                              }
                     *                      }
                     *              }
                     *
                     *      }
                     * }*/
                    rowIndex += nl;
                    rowCount += nl;
                }
            }

            MergeHGroupCells();

            //if the table is custum empty ,ignor the  MergeVGroupCells
            if (table.ExtendedProperties.ContainsKey("TableType") &&
                table.ExtendedProperties["TableType"].ToString() == "CustumEmpty")
            {
                return(rowCount);
            }

            MergeVGroupCells();
            return(rowCount);
        }
Ejemplo n.º 11
0
        public void AddValue(Dictionary <GroupValueSearchKey, bool> map, GroupValueSearchKey gkey,
                             System.Data.DataTable table, int valueIndex)
        {
            if (map.ContainsKey(gkey))
            {
                // ignored.
                return;
            }

            // judge Data is Match
            if (gkey.key != null)
            {
                SearchKey tmpKey = gkey.key;
                while (tmpKey != null)
                {
                    if (tmpKey.rKey == null)
                    {
                        tmpKey.rKey = ReusedKey.FindReusedKey(tmpKey);
                    }

                    if (tmpKey.isFixedValue)
                    {
                        // Compare Fixed value Key only
                        object keyValue = null;

                        keyValue = tmpKey.rKey.GetReusedValue(table, valueIndex);
                        //  RangeHelper.GetColValue (table, valueIndex, tmpKey.colName) ;

                        // Not match, return .
                        if (!Equals(keyValue, tmpKey.keyValue))
                        {
                            return;
                        }
                    }

                    tmpKey = tmpKey.nextKey;
                }

                /*SearchKey copyKey = gkey.key.Copy0 (false) ;
                 * copyKey.FillKey (table, valueIndex);
                 *
                 * // not match.
                 * if (! copyKey.Equals (gkey.key))
                 *      return ;*/
            }

            object lastValue;

            if (!valueList.TryGetValue(gkey, out lastValue))
            {
                lastValue = 0;
                valueList.Add(gkey, lastValue);
            }

            if (gkey.rKey == null)
            {
                SearchKey key = new SearchKey();
                key.colName = gkey.valueColName;
                gkey.rKey   = ReusedKey.FindReusedKey(key);
            }

            valueList [gkey] = CalculateForumla(gkey.formula, lastValue,
                                                gkey.rKey.GetReusedValue(table, valueIndex));

            map[gkey /*.Copy()*/] = true;
        }