Ejemplo n.º 1
0
        private static void MakeTableHeader(List <CellFormat> fomatcells,
                                            System.Data.DataTable source,
                                            List <List <SingleCell> > headers,
                                            Soway.Data.DS.Tree.Tree <MatrixHeader> tableHeaders)
        {
            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);
            });
            if (fomatcells.Count > 0)
            {
                //按列区分出表格的列
                var sourceTable = source.DefaultView.ToTable(true, fomatcells.Select(p => p.SourceColumn).ToArray());
                //生成列表的树
                foreach (DataRow row in sourceTable.Rows)
                {
                    fac.AddArrayToLeaf(tableHeaders, GetFmtArry(fomatcells, row.ItemArray));
                }

                foreach (var node in tableHeaders)
                {
                    var objs = GetObjsToParent(node);
                    if (fomatcells[node.Level].StaticFormats.Count > 0)
                    {
                        foreach (var staticcell in fomatcells[node.Level].StaticFormats)
                        {
                            objs[node.Level] = staticcell.Name;
                            fac.AddArrayToLeaf(tableHeaders, GetFmtArry(fomatcells, objs, staticcell));
                        }
                    }
                }

                int level = -1;
                List <SingleCell> cells = null;
                foreach (var node in tableHeaders)
                {
                    if (node.Level > level)
                    {
                        level = node.Level;
                        cells = new List <SingleCell>();
                        headers.Add(cells);
                    }
                    var cell = new SingleCell()
                    {
                        Value = node.Data.Value.ToString(),
                        Span  = node.Width
                    };
                    if (node.Data.Value == ReportEmptyValue.Value)
                    {
                        cell.MegerToParent = true;
                    }
                    cells.Add(cell);
                }
            }
        }
Ejemplo n.º 2
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);
        }