Exemple #1
0
        public MatrixTable CreateMatrixTable(TableFormat format, System.Data.DataTable source)
        {
            Soway.Data.DS.Tree.ITreeFactory <MatrixHeader, MatrixHeader> fac =
                new Soway.Data.DS.Tree.ITreeFactory <MatrixHeader, MatrixHeader>(

                    (ob1, ob2) =>
            {
                return(Soway.Data.DS.Tree.TeeNodeCompareResult.Child);
            });
            Soway.Data.DS.Tree.Tree <MatrixHeader> colHeaders = new Soway.Data.DS.Tree.Tree <MatrixHeader>();
            Soway.Data.DS.Tree.Tree <MatrixHeader> rowHeaders = new Soway.Data.DS.Tree.Tree <MatrixHeader>();
            MatrixTable table = new MatrixTable();

            //生成列头
            MakeTableHeader(format.Colums, source, table.ColHeaders, colHeaders);
            MakeTableHeader(format.Rows, source, table.RowHeaders, rowHeaders);


            foreach (DataRow row in source.Rows)
            {
                DataRect rect = new DataRect();
                //1 得到列头
                List <object> cols = new List <object>();
                foreach (var colfmt in format.Colums)
                {
                    cols.Add(row[colfmt.SourceColumn]);
                }
                //2 得到行头
                List <object> rows = new List <object>();
                foreach (var colfmt in format.Rows)
                {
                    rows.Add(row[colfmt.SourceColumn]);
                }
                //3 得到数据
                foreach (var dtfmt in format.ValueCell)
                {
                    rect.Cells.Add(new Cell()
                    {
                        Value = row[dtfmt.SourceColumn]
                    });
                }
                rect.ColHeaderIndex = fac.AddArrayToLeaf(colHeaders, GetFmtArry(format.Colums, cols.ToArray())) - 1;
                rect.RowHeaderIndex = fac.AddArrayToLeaf(rowHeaders, GetFmtArry(format.Rows, rows.ToArray())) - 1;
                table.Cells.Add(rect);
            }

            //计算汇总
            var colBottom = fac.GetBottomNodes(colHeaders);
            var rowBottom = fac.GetBottomNodes(rowHeaders);

            foreach (var node in rowHeaders)
            {
                if (node.Data.StaticCell != null)
                {
                    int    colIndex       = 0;
                    int    RowHeaderIndex = GetTreeNodeIndex(node, rowHeaders);// fac.AddArrayToLeaf(rowHeaders, GetFmtArry(format.Colums, GetObjsToParent(node))) - 1;
                    string CalScope       = GetCalScope(node, rowBottom, RowHeaderIndex);


                    for (colIndex = 0; colIndex < colBottom.Count; colIndex++)
                    {
                        DataRect staticRect = new DataRect();
                        staticRect.ColHeaderIndex = colIndex;
                        staticRect.RowHeaderIndex = RowHeaderIndex;

                        foreach (var staticCell in node.Data.StaticCell.StaticsCells)
                        {
                            staticRect.Cells.Add(new Cell()
                            {
                                Value        = node.Data.StaticCell.Name + colIndex,
                                IsCalculate  = true,
                                CalDirection = CalDirection.Column,
                                CalScope     = CalScope,
                                Expression   = staticCell.StaticType
                            });
                        }

                        table.Cells.Add(staticRect);
                    }
                }
            }
            foreach (var node in colHeaders)
            {
                if (node.Data.StaticCell != null)
                {
                    int    RowHeaderIndex = 0;
                    int    ColIndex       = GetTreeNodeIndex(node, colHeaders);// fac.AddArrayToLeaf(rowHeaders, GetFmtArry(format.Colums, GetObjsToParent(node))) - 1;
                    string CalScope       = GetCalScope(node, colBottom, ColIndex);
                    for (RowHeaderIndex = 0; RowHeaderIndex < rowBottom.Count; RowHeaderIndex++)
                    {
                        DataRect staticRect = new DataRect();
                        staticRect.ColHeaderIndex = ColIndex;
                        staticRect.RowHeaderIndex = RowHeaderIndex;
                        foreach (var staticCell in node.Data.StaticCell.StaticsCells)
                        {
                            staticRect.Cells.Add(new Cell()
                            {
                                Value        = node.Data.StaticCell.Name + RowHeaderIndex,
                                CalDirection = CalDirection.Row,
                                CalScope     = CalScope,
                                IsCalculate  = true,
                                Expression   = staticCell.StaticType
                            });
                        }

                        table.Cells.Add(staticRect);
                    }
                }
            }
            foreach (var colnode in colBottom)
            {
            }

            if (format.Colums.Count == 0 && format.Rows.Count == 0)
            {
            }
            return(table);
        }
Exemple #2
0
        public List <Cell> GetCells(MatrixTable table, int colStart = 0, int rowStart = 0)
        {
            List <Cell> result     = new List <Cell>();
            int         currentcol = colStart;
            int         currentrow = rowStart;
            int         lastCol    = colStart;
            int         lastRow    = rowStart;

            for (int i = 0; i < table.ColHeaders.Count; i++)//cols in table.ColHeaders)
            {
                var cols = table.ColHeaders[i];
                currentcol = colStart + table.RowHeaders.Count;
                foreach (var col in cols)
                {
                    var cell = new Cell()
                    {
                        ColSpan = col.Span,
                        Column  = currentcol,
                        RowSpan = 1,
                        Row     = currentrow,
                        Value   = col.Value
                    };
                    if (col.MegerToParent == false)
                    {
                        result.Add(cell);
                    }
                    else
                    {
                        var parent = result.FirstOrDefault(p => p.Column == currentcol && p.ColSpan == col.Span && p.Row < currentrow);
                        if (parent != null)
                        {
                            parent.RowSpan++;
                        }
                    }
                    currentcol += col.Span;
                }
                currentrow++;
            }

            currentcol = colStart;
            foreach (var rows in table.RowHeaders)
            {
                currentrow = rowStart + table.ColHeaders.Count;
                foreach (var row in rows)
                {
                    var cell = new Cell()
                    {
                        ColSpan = 1,
                        Column  = currentcol,
                        Row     = currentrow,
                        RowSpan = row.Span,
                        Value   = row.Value
                    };
                    if (row.MegerToParent == false)
                    {
                        result.Add(cell
                                   );
                    }
                    else
                    {
                        var parent = result.FirstOrDefault(p => p.Row == currentrow && p.RowSpan == row.Span &&
                                                           p.Column < currentcol);
                        if (parent != null)
                        {
                            parent.ColSpan++;
                        }
                    }

                    currentrow += row.Span;
                }
                currentcol++;
            }
            currentrow = rowStart + table.ColHeaders.Count;
            currentcol = colStart + table.RowHeaders.Count;
            foreach (var cells in table.Cells)
            {
                foreach (var cell in cells.Cells)
                {
                    result.Add(new Cell()
                    {
                        ColSpan     = 1,
                        RowSpan     = 1,
                        Column      = cell.Column + currentcol + cells.ColHeaderIndex,
                        IsCalculate = cell.IsCalculate,
                        CalScope    = cell.CalDirection == CalDirection.Column ?
                                      cell.GetScopeFromOffSet(currentrow)
                        :(cell.CalDirection == CalDirection.Row?
                          cell.GetScopeFromOffSet(currentcol) :""),
                        Expression = cell.Expression,

                        CalDirection = cell.CalDirection,
                        Row          = cell.Row + currentrow + cells.RowHeaderIndex,

                        Value = cell.Value
                    });
                }
            }
            return(result);
        }