using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace BP.WF.Rpt
{
///
/// 报表导出模板
///
public class RptExportTemplate
{
///
/// 模板最后修改时间
///
public DateTime LastModify { get; set; }
///
/// 导出填充方向
///
public FillDirection Direction { get; set; }
///
/// 导出开始填充的行/列号
///
public int BeginIdx { get; set; }
///
/// 字段与单元格绑定信息集合
///
public List Cells { get; set; }
///
/// 是否有单元格绑定了指定的表单中的字段
///
/// 表单对应FK_MapData
///
public bool HaveCellInMapData(string fk_mapdata)
{
foreach(RptExportTemplateCell cell in Cells)
{
if (cell.FK_MapData == fk_mapdata)
return true;
}
return false;
}
public RptExportTemplateCell GetBeginHeaderCell(FillDirection direction)
{
if (Cells == null || Cells.Count == 0)
return null;
RptExportTemplateCell cell = Cells[0];
if(direction == FillDirection.Vertical)
{
for(int i = 1;i
/// 获取定义的填充明细表NO
///
///
public string GetDtl()
{
foreach(RptExportTemplateCell cell in Cells)
{
if (!string.IsNullOrWhiteSpace(cell.DtlKeyOfEn))
return cell.FK_DtlMapData;
}
return null;
}
}
///
/// 报表导出模板字段与单元格绑定信息对象
///
public class RptExportTemplateCell
{
[XmlIgnore]
private string _cellName;
///
/// 单元格行号
///
public int RowIdx { get; set; }
///
/// 单元格列号
///
public int ColumnIdx { get; set; }
///
/// 获取单元格名称
///
[XmlIgnore]
public string CellName
{
get
{
if (string.IsNullOrWhiteSpace(_cellName))
_cellName = GetCellName(ColumnIdx, RowIdx);
return _cellName;
}
}
///
/// 单元格所属sheet表名
///
public string SheetName { get; set; }
///
/// 字段所属fk_mapdata
///
public string FK_MapData { get; set; }
///
/// 字段英文名
///
public string KeyOfEn { get; set; }
///
/// 明细表字段所属fk_mapdata
///
public string FK_DtlMapData { get; set; }
///
/// 明细表字段英文名
///
public string DtlKeyOfEn { get; set; }
///
/// 获取单元格的显示名称,格式如A1,B2
///
/// 单元格列号
/// 单元格行号
///
public static string GetCellName(int columnIdx, int rowIdx)
{
int[] maxs = new[] { 26, 26 * 26 + 26, 26 * 26 * 26 + (26 * 26 + 26) + 26 };
int col = columnIdx + 1;
int row = rowIdx + 1;
if (col > maxs[2])
throw new Exception("列序号不正确,超出最大值");
int alphaCount = 1;
foreach(int m in maxs)
{
if (m < col)
alphaCount++;
}
switch (alphaCount)
{
case 1:
return (char)(col + 64) + "" + row;
case 2:
return (char)((col / 26) + 64) + "" + (char)((col % 26) + 64) + row;
case 3:
return (char)((col / 26 / 26) + 64) + "" + (char)(((col - col / 26 / 26 * 26 * 26) / 26) + 64) + "" + (char)((col % 26) + 64) + row;
}
return "Unkown";
}
}
public enum FillDirection
{
Vertical = 1,
Horizontal = 2
}
}