Ejemplo n.º 1
0
        public void WriteMapItem(LayoutColumn map, int listIndex, object listItem, int sc, int sr, ref int mr, StringKeyList stringTable, List <Row> prows = null)
        {
            int tws  = map.GetWithdSpan();
            Row row  = null;
            var rows = prows;

            if (prows == null)
            {
                rows = new List <Row>();
                mr++;
                row = GenerateRow(mr, mc, listItem == null, stringTable);
                WriteCell(row.GetFirstChild <Cell>(), listItem == null ? (object)"#" : (object)(listIndex + 1), stringTable);
                rows.Add(row);
                sc = 1;
            }
            var nr = mr;

            foreach (var item in map)
            {
                if (item.Visible)
                {
                    map.GetVisibleIndex(item, out int c, out int r);
                    c += sc; r += sr;
                    if (item.Count > 0)
                    {
                        WriteMapItem(item, listIndex, listItem, c, r, ref mr, stringTable, rows);
                    }
                    else
                    {
                        int rr = nr + r;
                        if (rows.Count <= r)
                        {
                            mr++;
                            row = GenerateRow(rr, mc, listItem == null, stringTable);
                            rows.Add(row);
                        }
                        else
                        {
                            row = rows[r];
                        }

                        object celldata = ((LayoutColumn)item).Text;
                        if (listIndex == -2)
                        {
                            celldata = list.GetCollectedValue((LayoutColumn)item, group);
                        }
                        if (listItem != null)
                        {
                            object val = list.ReadValue(listItem, (ILayoutCell)item);
                            celldata = list.FormatValue(listItem, val, (ILayoutCell)item);
                            if (val is decimal && ((ILayoutCell)item).Format != "p")
                            {
                                celldata = val;
                            }
                            if (prows == null && c == 1 && listItem is Node)
                            {
                                var s = GroupHelper.Level((Node)listItem) * 4;
                                celldata = celldata.ToString().PadLeft(celldata.ToString().Length + s, '-');
                            }
                        }

                        var cellc = (Cell)row.ChildElements.GetItem(c);
                        WriteCell(cellc, celldata, stringTable);
                        if (celldata is decimal)
                        {
                            cellc.StyleIndex = 3;
                        }

                        int ws = map.GetRowWidthSpan(item.Row);
                        int hs = map.GetRowHeightSpan(item.Row, true);
                        if (tws > ws && hs > 1)
                        {
                            mcells.Add(new MergeCell()
                            {
                                Reference = new CellRange(c, rr, c + tws - ws, rr + hs - 1).ToString()
                            });
                        }
                        else if (tws > ws)
                        {
                            mcells.Add(new MergeCell()
                            {
                                Reference = new CellRange(c, rr, c + tws - ws, rr).ToString()
                            });
                        }
                        else if (hs > 1)
                        {
                            mcells.Add(new MergeCell()
                            {
                                Reference = new CellRange(c, rr, c, rr + hs - 1).ToString()
                            });
                        }
                    }
                }
            }
            if (prows == null)
            {
                if (rows.Count > 1)
                {
                    mcells.Add(new MergeCell()
                    {
                        Reference = new CellRange(0, nr, 0, nr + rows.Count - 1).ToString()
                    });
                }
                if (listItem is Node)
                {
                    foreach (var item in rows)
                    {
                        item.OutlineLevel = (byte)(GroupHelper.Level((IGroup)listItem));
                        if (((IGroup)listItem).IsCompaund)
                        {
                            item.Collapsed = !((IGroup)listItem).Expand;
                        }
                        if (item.OutlineLevel > 0)
                        {
                            item.Hidden = !((IGroup)listItem).IsExpanded;
                        }
                    }
                }
                WriteRows(writer, rows);


                if (listItem is Node && map != null)
                {
                    var i = 0;
                    foreach (var item in ((Node)listItem).Nodes)
                    {
                        WriteMapItem(map, i++, item, 0, 0, ref mr, stringTable);
                    }
                }
            }
        }