149 lines
4.2 KiB
C#
149 lines
4.2 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using DevExpress.XtraPrinting;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace BS.Shared.Core
|
|
{
|
|
public static class ReportUtils
|
|
{
|
|
public static void InvokeActionOnEveryCell(XRTable table, Action<XRTableCell, int> action)
|
|
{
|
|
if(table != null && action != null)
|
|
{
|
|
for(var rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++)
|
|
{
|
|
var row = table.Rows[rowIndex];
|
|
for(var cellIndex = 0; cellIndex < row.Cells.Count; cellIndex++)
|
|
{
|
|
var cell = row.Cells[cellIndex];
|
|
action(cell, cellIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void InvokeActionOnEveryRow(XRTable table, Action<XRTableRow, int> action)
|
|
{
|
|
if(table != null && action != null)
|
|
{
|
|
for(var rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++)
|
|
{
|
|
var row = table.Rows[rowIndex];
|
|
action(row, rowIndex);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void InvokeActionOnEveryCellOfRow(XRTableRow row, Action<XRTableCell, int> action)
|
|
{
|
|
if(row != null && action != null)
|
|
{
|
|
for(var i = 0; i < row.Cells.Count; i++)
|
|
{
|
|
var cell = row.Cells[i];
|
|
action(cell, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static decimal[] GetColumnSumsOfTable(XRTable table, int limit, int indexOfFirstColumn)
|
|
{
|
|
var result = new decimal[limit];
|
|
var counter = indexOfFirstColumn;
|
|
|
|
while(counter < limit)
|
|
{
|
|
for(var i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
var currentCell = table.Rows[i].Cells[counter];
|
|
|
|
var cellText = currentCell.Text ?? string.Empty;
|
|
|
|
if(cellText.EndsWith("%"))
|
|
{
|
|
cellText = cellText.TrimEnd('%');
|
|
}
|
|
|
|
if(decimal.TryParse(cellText, out var value))
|
|
{
|
|
result[counter] += value;
|
|
}
|
|
}
|
|
|
|
counter++;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static void AddCellToRow(XRTableRow row)
|
|
{
|
|
var cell = new XRTableCell();
|
|
|
|
row.Cells.Add(cell);
|
|
}
|
|
|
|
public static void AddCellToRow(XRTableRow row, string text)
|
|
{
|
|
var cell = new XRTableCell
|
|
{
|
|
Text = text
|
|
};
|
|
|
|
row.Cells.Add(cell);
|
|
}
|
|
|
|
public static void AddCellToRow(XRTableRow row, string text, string cellName)
|
|
{
|
|
var cell = new XRTableCell
|
|
{
|
|
Text = text,
|
|
Name = cellName
|
|
};
|
|
|
|
row.Cells.Add(cell);
|
|
}
|
|
|
|
public static void AddCellToRow(XRTableRow row, string text, string cellName, float widthF)
|
|
{
|
|
var cell = new XRTableCell
|
|
{
|
|
Text = text,
|
|
Name = cellName,
|
|
WidthF = widthF
|
|
};
|
|
|
|
row.Cells.Add(cell);
|
|
}
|
|
|
|
public static void AddCellToRow(XRTableRow row, string text, string cellName, float widthF, TextAlignment textAlignment)
|
|
{
|
|
var cell = new XRTableCell
|
|
{
|
|
Text = text,
|
|
TextAlignment = textAlignment,
|
|
Name = cellName,
|
|
WidthF = widthF,
|
|
BackColor = Color.White
|
|
};
|
|
|
|
row.Cells.Add(cell);
|
|
}
|
|
|
|
public static void AddCellToRow(XRTableRow row, string text, string cellName, float widthF, TextAlignment textAlignment, Color backColor)
|
|
{
|
|
var cell = new XRTableCell
|
|
{
|
|
Text = text,
|
|
TextAlignment = textAlignment,
|
|
Name = cellName,
|
|
WidthF = widthF,
|
|
BackColor = backColor
|
|
};
|
|
|
|
row.Cells.Add(cell);
|
|
}
|
|
}
|
|
}
|