Beispiel #1
0
        public int IsNeedNewLine(GroupDataHolder holder, int currentRowIndex, System.Data.DataTable table, int valueRowIndex)
        {
            if (iOption == InsertOption.never)
            {
                return(-1);
            }

            if (valueRowIndex == 0 && (iOption & InsertOption.onfirst) != 0)
            {
                return(0);
            }

            if (valueRowIndex == table.Rows.Count - 1 && (iOption & InsertOption.onLast) != 0)
            {
                return(0);
            }

            if ((iOption & InsertOption.afterChange) == 0 &&
                (iOption & InsertOption.BeforeChange) == 0 &&
                (iOption & InsertOption.always) == 0)
            {
                return(-1);
            }

            for (int i = 0; i < cellList.Count; i++)
            {
                TplCell cell = cellList[i];
                if (cell.align != GroupAlign.hGroup && cell.IsNeedNewCell(holder, iOption, cell.lastColIndex, currentRowIndex, table, valueRowIndex))
                {
                    return(i);
                }
            }
            return(-1);
        }
Beispiel #2
0
        public void WriteCell(ReportSheetTemplate tpl, GroupDataHolder holder, CellRange currentCellRange, DataTable table, int valueRowIndex)
        {
            if (useR1C1Formula)
            {
                currentCellRange.FormulaR1C1 = "=" + tplTextContent;
                return;                  // do noting
            }
            object value = GetValue(holder, table, valueRowIndex);

            if (value == null || value == string.Empty || value == System.DBNull.Value)
            {
                value = tplDefaultContent;
            }

            // update value.
            RangeHelper.UpdateCellValue(tpl, currentCellRange, value, tplFormat);


            if (align == GroupAlign.vGroup)
            {
                lastGroupedValue = GetGroupValue(holder, table, valueRowIndex);
            }

            lastCellRange = currentCellRange;
        }
Beispiel #3
0
        public int FillLine(GroupDataHolder holder, int currentRowIndex, System.Data.DataTable table, int valueRowIndex)
        {
            // Judge Dose Need New Line

            int startIndex = IsNeedNewLine(holder, currentRowIndex, table, valueRowIndex);

            if (startIndex < 0)
            {
                return(0);
            }
            if (startIndex >= 0)
            {
                // Insert New Line
                /* Range newLineRange = */
                RangeHelper.InsertCopyRange(tplRange.Worksheet, tplRange, cellList.Count, 1, colIndex, currentRowIndex, XlInsertShiftDirection.xlShiftDown);

                insertedRowList.Add(currentRowIndex);
            }


            UpdateLine(currentRowIndex, holder, startIndex, table, valueRowIndex, MergeOption.Left, false);
            UpdateLine(currentRowIndex, holder, startIndex, table, valueRowIndex, MergeOption.Up, true);

            return(1);
        }
Beispiel #4
0
        public bool IsNeedNewCell(GroupDataHolder holder, InsertOption nlOption, int currentColIndex, int currentRowIndex, System.Data.DataTable table,
                                  int valueRowIndex)
        {
            if (align == GroupAlign.always)
            {
                return(true);
            }

            if (align == GroupAlign.none)
            {
                return((nlOption & InsertOption.always) != 0);
            }

            object value = GetGroupValue(holder, table, valueRowIndex);

            switch (align)
            {
            case GroupAlign.vGroup:
            case GroupAlign.hGroup:
                if ((nlOption & InsertOption.BeforeChange) != 0)
                {
                    if (valueRowIndex + 1 >= table.Rows.Count)
                    {
                        // last line
                        return(true);
                    }

                    object value1 = GetGroupValue(holder, table, valueRowIndex);

                    object value2 = GetGroupValue(holder, table, valueRowIndex + 1);
                    return(!Equals(value1, value2));
                }
                else
                {
                    if (lastGroupedValue == null || !lastGroupedValue.Equals(value))
                    {
                        lastGroupedValue = value;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

            /*case GroupAlign.hGroup:
             *      // todo: check hGroup Cells. dose need a New Row.
             *      if (value == null)
             *              return true;
             *      bool flag;
             *      if (lastValueMap.TryGetValue(value, out flag))
             *              return false;
             *      else
             *              lastValueMap.Add(value, true);
             *      return true;*/
            default:
                break;
            }
            return(false);
        }
Beispiel #5
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);
 }
Beispiel #6
0
        public void UpdateRowData(GroupDataHolder holder, int currentRowIndex, System.Data.DataTable table, int valueRowIndex)
        {
            int cellColIndex = cellList[0].lastColIndex;

            for (int i = 0; i < cellList.Count; i++)
            {
                TplCell cell = cellList[i];
                if (cell.formula != null)
                {
                    Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, cellColIndex, currentRowIndex);

                    cell.WriteCell(tpl, holder, cellRange, table, valueRowIndex);
                }
                cellColIndex += cell.acrossColumns;
            }
        }
Beispiel #7
0
        private int IsNeedNewCol(int currentRowIndex, GroupDataHolder holder, System.Data.DataTable table, int valueIndex)
        {
            object [] vList = new object[groupColList.Count];
            if (lastUsedTable != table)
            {
                lastUsedTable = table;
                // Clear to -1 ;
                for (int i = 0; i < groupColIndexList.Count; i++)
                {
                    groupColIndexList [i] = table.Columns.IndexOf(groupColList [i]);
                }
            }
            for (int i = 0; i < groupColList.Count; i++)
            {
                /* string colName = groupColList [i] ;  */

                vList[i] = RangeHelper.GetColValue(table, valueIndex, groupColIndexList[i]);
            }

            for (int i = 0; i < lastValueMap.Count; i++)
            {
                object[] lvList = lastValueMap [i];

                if (CompareArray(vList, lvList))
                {
                    return(-1);
                }
            }

            // Save new value list
            lastValueMap.Add(vList);

            /* for (int i = 0; i < cellList.Count; i++)
             * {
             *      TplCell cell = cellList[i];
             *      if (cell.align != GroupAlign.hGroup)
             *              continue ;
             *      if (! cell.IsNeedNewCell(holder, InsertOption.afterChange, cell.lastColIndex, currentRowIndex, table, valueIndex))
             *              index = i ;
             *
             * }
             */
            return(0);
        }
Beispiel #8
0
        public int CheckColumn(TplBlock block, GroupDataHolder holder, int currentRowIndex, System.Data.DataTable table, int valueIndex)
        {
            // if grouped Value changed.
            // if value has be inserted.
            // Insert Cell At EachLine
            // Update TplLine Info.
            int startIndex = IsNeedNewCol(currentRowIndex, holder, table, valueIndex);

            if (startIndex < 0)
            {
                return(0);
            }
            // Console.WriteLine("---- Start of " + valueIndex);


            InsertColumn(block, holder, table, valueIndex, true);

            return(1);
        }
Beispiel #9
0
        private void UpdateLine(int currentRowIndex, GroupDataHolder holder, int startIndex, DataTable table, int valueRowIndex, MergeOption mo, bool updateMergeOnly)
        {
            int cellColIndex = cellList[0].lastColIndex;

            for (int i = 0; i < cellList.Count; i++)
            {
                TplCell cell = cellList[i];

                int merge = 0;

                if (cell.mOption == mo &&
                    (                // merge before.
                        i < startIndex ||
                        // merge after. next line is new line
                        (i >= startIndex && (iOption & InsertOption.BeforeChange) != 0) ||
                        // ignore group align option.
                        cell.align == GroupAlign.none))
                // do Merge
                {
                    Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, cellColIndex, currentRowIndex);

                    merge = cell.DoMerge(currentRowIndex, cellRange);
                }

                if (merge == 0 && !updateMergeOnly)
                {
                    if (cell.formula == null)
                    {
                        Range cellRange = RangeHelper.GetCell(tplRange.Worksheet, cellColIndex, currentRowIndex);

                        cell.WriteCell(tpl, holder, cellRange, table, valueRowIndex);
                    }
                }

                /*
                 * else
                 *      // todo: Remove this noused line?
                 *      cell.lastGroupedValue = cell.GetValue(holder, table, valueRowIndex);
                 */
                cellColIndex += cell.acrossColumns;
            }
        }
Beispiel #10
0
        public void CheckEachColumn(TplBlock block, GroupDataHolder holder, int currentRowIndex, System.Data.DataTable table, int valueIndex)
        {
            for (int i = 0; i < gCols; i++)
            {
                bool colInserted = false;
                // Check each cell in this columns
                for (int j = 0; j < block.lineList.Count; j++)
                {
                    TplLine line = block.lineList [j];
                    TplCell cell = line.cellList [startCellIndex + i];
                    if (cell.align != GroupAlign.hGroup)
                    {
                        continue;
                    }

                    if (!colInserted)
                    {
                        bool needNew = cell.IsNeedNewCell(holder, cell.hgOption, 0, currentRowIndex, table, valueIndex);

                        if (needNew)
                        {
                            InsertOneColumn(block, i, holder, table, valueIndex, false);
                            colInserted = true;
                        }
                    }
                    else
                    {
                        if ((cell.hgOption & InsertOption.BeforeChange) != 0)
                        {
                            continue;
                        }

                        // set last grouped value
                        cell.lastGroupedValue = cell.GetGroupValue(holder, table, valueIndex);
                    }
                }
            }
        }
Beispiel #11
0
        public object GetValue(GroupDataHolder holder, System.Data.DataTable table, int rowIndex)
        {
            object lastValue = 0;

            for (int i = 0; i < keyList.Count; i++)
            {
                GroupValueSearchKey gkey = keyList [i];
                if (gkey.key != null)
                {
                    gkey.key.FillKey(table, rowIndex);
                }

                object value = holder.GetValue(gkey, null);

                /*
                 * Console.WriteLine ("row ["+ rowIndex + "] Get value for gkey: " + gkey );
                 * Console.WriteLine ("row [" + rowIndex + "] = [" + value + "]") ;
                 */
                lastValue = Calculate(formulaName, lastValue, value);
            }

            return(lastValue);
        }
Beispiel #12
0
        public object GetValue(GroupDataHolder holder, DataTable table, int rowIndex)
        {
            if (formula != null)
            {
                return(formula.GetValue(holder, table, rowIndex));
            }

            if (hgOption != InsertOption.never)             //  && align == GroupAlign.hGroup)
            {
                // if this cell is hg col and not use formula, use text content as value;
                return(tplTextContent);
            }

            object value = GetValueByIndex(rowIndex, table);

            if (value == null)
            {
                return(tplTextContent);
            }
            else
            {
                return(value);
            }
        }
Beispiel #13
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;
        }
Beispiel #14
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++;
        }