这几天一直在做几个报表,这个报表与之前不同的是现在报表的列头要求是活的,根据用户添加的数据来动态决定,也就是实现动态报
表。刚开始想用交叉表来实现,后来发现客户给的报表样张中报表中有些数据用交叉表是实现不了的;后来由于直接用工具画图的方法
在这里不合适,所以就选择用代码来动态的拼接生成相应的报表文件来实现相应的操作; 以下也就是在生成动态报表表头时的所用到的
一些代码;这里要说明一点的是,在这中间有报表要求画成斜线而报表工具中没有,最后无奈之下用了个现成的图片放上去拼接成报表
头了;如下图:
List<SecYearCareerMoniDangerDto> MoniUnitlst = JsonUtility.DeserializeByNewton<List<SecYearCareerMoniDangerDto>>
(Request["postData"]);
List<SecYearCareerMoniDangerDto> lstNew = new List<SecYearCareerMoniDangerDto>();
if (MoniUnitlst != null &&MoniUnitlst.Count>0)
{
foreach (SecYearCareerMoniDangerDto oldDdto in MoniUnitlst)
{
bool flag = true;
foreach (SecYearCareerMoniDangerDto dangerDto in lstNew)
{
if (dangerDto.careerDangerClass == oldDdto.careerDangerClass
List<SecYearCareerMoniDangerDto> lstNew = new List<SecYearCareerMoniDangerDto>();
if (MoniUnitlst != null &&MoniUnitlst.Count>0)
{
foreach (SecYearCareerMoniDangerDto oldDdto in MoniUnitlst)
{
bool flag = true;
foreach (SecYearCareerMoniDangerDto dangerDto in lstNew)
{
if (dangerDto.careerDangerClass == oldDdto.careerDangerClass
&&dangerDto.careerDanger==oldDdto.careerDanger)
{
flag = false;
break;
}
}
if (flag)
{
SecYearCareerMoniDangerDto newDto = new SecYearCareerMoniDangerDto();
newDto.CurrentYear = oldDdto.secYearCareerMoniUnit_currentYear;
newDto.careerDangerClass = oldDdto.careerDangerClass;
newDto.careerDangerClass_cnName = oldDdto.careerDangerClass_cnName;
newDto.careerDanger = oldDdto.careerDanger;
newDto.careerDanger_cnName = oldDdto.careerDanger_cnName;
newDto.monitorCount = oldDdto.monitorCount;
newDto.monitorUnit = oldDdto.secYearCareerMoniUnit_monitorUnit;
newDto.remark = oldDdto.secYearCareerMoniUnit_remark;
lstNew.Add(newDto);
}
}
}
这是在做stimulsoft report中的拼接报表中数据用到的一些代码,以上含义是从得到的一些集合中过滤掉危害类别和危害因素相同的数
{
flag = false;
break;
}
}
if (flag)
{
SecYearCareerMoniDangerDto newDto = new SecYearCareerMoniDangerDto();
newDto.CurrentYear = oldDdto.secYearCareerMoniUnit_currentYear;
newDto.careerDangerClass = oldDdto.careerDangerClass;
newDto.careerDangerClass_cnName = oldDdto.careerDangerClass_cnName;
newDto.careerDanger = oldDdto.careerDanger;
newDto.careerDanger_cnName = oldDdto.careerDanger_cnName;
newDto.monitorCount = oldDdto.monitorCount;
newDto.monitorUnit = oldDdto.secYearCareerMoniUnit_monitorUnit;
newDto.remark = oldDdto.secYearCareerMoniUnit_remark;
lstNew.Add(newDto);
}
}
}
这是在做stimulsoft report中的拼接报表中数据用到的一些代码,以上含义是从得到的一些集合中过滤掉危害类别和危害因素相同的数
据,分别对应以上的careerDangerClass和这个字段careerDanger。以上主要指的注意的用法就是怎么样去过滤掉集合中有重复条件的数
据。我们可以使用foreach遍历,在这之前要先新建一个和这个数据具有相同类型的集合,使用两个遍历,在遍历最初集合时加上遍历新
建的集合在这个种判断如果满足条件做相应的操作。如果不满足就把相应的数据加入到新建的集合中去;
List<SecYearCareerMoniDangerDto> lstData = new List<SecYearCareerMoniDangerDto>();
foreach (SecYearCareerMoniDangerDto dangerDto in MoniUnitlst)
{
for (int i = 0; i < lstNew.Count; i++)
{
if (dangerDto.careerDangerClass == lstNew[i].careerDangerClass && dangerDto.careerDanger ==
foreach (SecYearCareerMoniDangerDto dangerDto in MoniUnitlst)
{
for (int i = 0; i < lstNew.Count; i++)
{
if (dangerDto.careerDangerClass == lstNew[i].careerDangerClass && dangerDto.careerDanger ==
lstNew[i].careerDanger)
{
SecYearCareerMoniDangerDto newDangerDto = null;
foreach (SecYearCareerMoniDangerDto newDto in lstData)
{
if (newDto.monitorUnit == dangerDto.secYearCareerMoniUnit_monitorUnit)
{
newDangerDto = newDto;
break;
}
{
SecYearCareerMoniDangerDto newDangerDto = null;
foreach (SecYearCareerMoniDangerDto newDto in lstData)
{
if (newDto.monitorUnit == dangerDto.secYearCareerMoniUnit_monitorUnit)
{
newDangerDto = newDto;
break;
}
}
if (newDangerDto == null)
{
newDangerDto = new SecYearCareerMoniDangerDto();
newDangerDto.monitorUnit = dangerDto.secYearCareerMoniUnit_monitorUnit;
newDangerDto.remark =dangerDto.secYearCareerMoniUnit_remark;
newDangerDto.GetType().GetProperty("udf" + (i + 1)).SetValue(newDangerDto,
if (newDangerDto == null)
{
newDangerDto = new SecYearCareerMoniDangerDto();
newDangerDto.monitorUnit = dangerDto.secYearCareerMoniUnit_monitorUnit;
newDangerDto.remark =dangerDto.secYearCareerMoniUnit_remark;
newDangerDto.GetType().GetProperty("udf" + (i + 1)).SetValue(newDangerDto,
dangerDto.monitorCount + "", null);
lstData.Add(newDangerDto);
}
else
{
newDangerDto.GetType().GetProperty("udf" + (i + 1)).SetValue(newDangerDto,
lstData.Add(newDangerDto);
}
else
{
newDangerDto.GetType().GetProperty("udf" + (i + 1)).SetValue(newDangerDto,
dangerDto.monitorCount + "", null);
}
break;
}
}
}
这个和上面的代码实现的功能差不多,在这里注意newDangerDto.GetType().GetProperty("udf" + (i + 1)).SetValue(newDangerDto,
}
break;
}
}
}
这个和上面的代码实现的功能差不多,在这里注意newDangerDto.GetType().GetProperty("udf" + (i + 1)).SetValue(newDangerDto,
dangerDto.monitorCount + "", null);这行代码的使用,得到对应实体的字段,再为字段赋相应的值。
转载于:https://blog.51cto.com/zhjjzhjj/772051