using DevExpress.XtraReports.UI;
|
using System;
|
using System.Collections;
|
using System.ComponentModel;
|
using System.Drawing;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class SimulationCommonReport : DevExpress.XtraReports.UI.XtraReport
|
{
|
public SimulationCommonReport()
|
{
|
InitializeComponent();
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(SimulationPrintViewModel vm)
|
{
|
//A4设置 827 1169
|
this.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A4;
|
this.Margins = new DevExpress.Drawing.DXMargins(50, 50, 50, 50);
|
|
//727 1069
|
|
#region 页眉
|
|
var labForCorp = new XRLabel();
|
labForCorp.Name = "页眉";
|
labForCorp.Text = "杭州科维节能技术股份有限公司";
|
labForCorp.Multiline = true;
|
labForCorp.LocationFloat = new DevExpress.Utils.PointFloat(482F, 16F);
|
labForCorp.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F);
|
labForCorp.SizeF = new System.Drawing.SizeF(236F, 24F);
|
labForCorp.StylePriority.UseTextAlignment = false;
|
labForCorp.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
|
this.TopMargin.Controls.Add(labForCorp);
|
|
#endregion
|
|
#region 页脚
|
|
var pageForCurrentNum = new XRPageInfo();
|
pageForCurrentNum.LocationFloat = new DevExpress.Utils.PointFloat(617F, 10.00001F);
|
pageForCurrentNum.Name = "页脚";
|
pageForCurrentNum.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F);
|
pageForCurrentNum.SizeF = new System.Drawing.SizeF(100F, 23F);
|
pageForCurrentNum.StylePriority.UseTextAlignment = false;
|
pageForCurrentNum.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
|
pageForCurrentNum.TextFormatString = "第{0}页";
|
this.BottomMargin.Controls.Add(pageForCurrentNum);
|
|
#endregion
|
|
#region 标题
|
|
float locationY = 0F;
|
var labForTitle = new XRLabel();
|
labForTitle.AnchorHorizontal = ((DevExpress.XtraReports.UI.HorizontalAnchorStyles)((DevExpress.XtraReports.UI.HorizontalAnchorStyles.Left | DevExpress.XtraReports.UI.HorizontalAnchorStyles.Right)));
|
labForTitle.Font = new DevExpress.Drawing.DXFont("Arial", 15F, DevExpress.Drawing.DXFontStyle.Bold);
|
labForTitle.LocationFloat = new DevExpress.Utils.PointFloat(0F, 0F);
|
labForTitle.Multiline = true;
|
labForTitle.Name = "labTitle";
|
labForTitle.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 96F);
|
labForTitle.SizeF = new System.Drawing.SizeF(727F, 50F);
|
labForTitle.StylePriority.UseFont = false;
|
labForTitle.StylePriority.UseTextAlignment = false;
|
labForTitle.Text = $"{vm.Project.Name}项目节能报告";
|
labForTitle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
|
this.Detail.Controls.Add(labForTitle);
|
locationY += 50F;
|
|
#endregion
|
|
#region 一、项目概述
|
|
var labForDescription = new XRLabel();
|
labForDescription.AnchorHorizontal = (DevExpress.XtraReports.UI.HorizontalAnchorStyles.Left | DevExpress.XtraReports.UI.HorizontalAnchorStyles.Right);
|
labForDescription.Font = new DevExpress.Drawing.DXFont("Arial", 12F, DevExpress.Drawing.DXFontStyle.Bold);
|
labForDescription.LocationFloat = new DevExpress.Utils.PointFloat(0F, locationY);
|
labForDescription.Multiline = true;
|
labForDescription.Name = "labForDescription";
|
labForDescription.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F);
|
labForDescription.SizeF = new System.Drawing.SizeF(727F, 25F);
|
labForDescription.StylePriority.UseFont = false;
|
labForDescription.StylePriority.UseTextAlignment = false;
|
labForDescription.Text = "一、项目概述";
|
labForDescription.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
|
this.Detail.Controls.Add(labForDescription);
|
locationY += 25F;
|
|
#endregion
|
|
#region 项目概述内容
|
|
var labForDescriptionContent = new XRLabel();
|
labForDescriptionContent.AnchorHorizontal = (DevExpress.XtraReports.UI.HorizontalAnchorStyles.Left | DevExpress.XtraReports.UI.HorizontalAnchorStyles.Right);
|
labForDescriptionContent.Font = new DevExpress.Drawing.DXFont("Arial", 10F);
|
labForDescriptionContent.LocationFloat = new DevExpress.Utils.PointFloat(0F, locationY);
|
labForDescriptionContent.Multiline = true;
|
labForDescriptionContent.Name = "labForDescriptionContent";
|
labForDescriptionContent.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 96F);
|
labForDescriptionContent.SizeF = new System.Drawing.SizeF(727F, 100F);
|
labForDescriptionContent.StylePriority.UseFont = false;
|
labForDescriptionContent.StylePriority.UseTextAlignment = false;
|
labForDescriptionContent.Text = $" {vm.Project.Description}";
|
labForDescriptionContent.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
|
this.Detail.Controls.Add(labForDescriptionContent);
|
locationY += 100F;
|
|
#endregion
|
|
//二、水泵明细
|
var labForPumpList = new XRLabel();
|
labForPumpList.AnchorHorizontal = (DevExpress.XtraReports.UI.HorizontalAnchorStyles.Left | DevExpress.XtraReports.UI.HorizontalAnchorStyles.Right);
|
labForPumpList.Font = new DevExpress.Drawing.DXFont("Arial", 12F, DevExpress.Drawing.DXFontStyle.Bold);
|
labForPumpList.LocationFloat = new DevExpress.Utils.PointFloat(0F, locationY);
|
labForPumpList.Multiline = true;
|
labForPumpList.Name = "labForPumpList";
|
labForPumpList.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F);
|
labForPumpList.SizeF = new System.Drawing.SizeF(727F, 25F);
|
labForPumpList.StylePriority.UseFont = false;
|
labForPumpList.StylePriority.UseTextAlignment = false;
|
labForPumpList.Text = "二、水泵明细";
|
labForPumpList.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
|
this.Detail.Controls.Add(labForPumpList);
|
locationY += 25F;
|
|
//水泵明细内容
|
if (vm.PumpList != null && vm.PumpList.Count > 0)
|
{
|
// 创建 XRTable
|
var tableForPumpList = new XRTable();
|
tableForPumpList.LocationF = new DevExpress.Utils.PointFloat(0F, locationY);
|
tableForPumpList.SizeF = new SizeF(727F, 30F); // 设置大小
|
|
// 创建表头行
|
XRTableRow headerRowPumpList = new XRTableRow();
|
headerRowPumpList.BackColor = Color.LightGray; // 设置背景颜色
|
|
// 添加表头列
|
headerRowPumpList.Cells.Add(CreateTableCell("名称", 100));
|
headerRowPumpList.Cells.Add(CreateTableCell("编码", 100));
|
headerRowPumpList.Cells.Add(CreateTableCell("额定流量", 100));
|
headerRowPumpList.Cells.Add(CreateTableCell("额定扬程", 100));
|
headerRowPumpList.Cells.Add(CreateTableCell("额定功率", 100));
|
headerRowPumpList.Cells.Add(CreateTableCell("额定转速", 100));
|
|
// 将表头行添加到表格
|
tableForPumpList.Rows.Add(headerRowPumpList);
|
|
//遍历水泵
|
foreach (var pump in vm.PumpList)
|
{
|
// 创建数据行
|
var dataRow = new XRTableRow();
|
dataRow.Cells.Add(new XRTableCell()
|
{
|
Text = pump.Name,
|
WidthF = 100F,
|
TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter,
|
Borders = DevExpress.XtraPrinting.BorderSide.All
|
});
|
dataRow.Cells.Add(new XRTableCell()
|
{
|
Text = pump.Code,
|
WidthF = 100F,
|
TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter,
|
Borders = DevExpress.XtraPrinting.BorderSide.All
|
});
|
dataRow.Cells.Add(new XRTableCell()
|
{
|
Text = pump.RatedQ.ToString(),
|
WidthF = 100F,
|
TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter,
|
Borders = DevExpress.XtraPrinting.BorderSide.All
|
});
|
dataRow.Cells.Add(new XRTableCell()
|
{
|
Text = pump.RatedH.ToString(),
|
WidthF = 100F,
|
TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter,
|
Borders = DevExpress.XtraPrinting.BorderSide.All
|
});
|
dataRow.Cells.Add(new XRTableCell()
|
{
|
Text = pump.RatedP.ToString(),
|
WidthF = 100F,
|
TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter,
|
Borders = DevExpress.XtraPrinting.BorderSide.All
|
});
|
dataRow.Cells.Add(new XRTableCell()
|
{
|
Text = pump.RatedN.ToString(),
|
WidthF = 100F,
|
TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter,
|
Borders = DevExpress.XtraPrinting.BorderSide.All
|
});
|
tableForPumpList.Rows.Add(dataRow);
|
}
|
|
// 将表格添加到Detail
|
this.Detail.Controls.Add(tableForPumpList);
|
}
|
|
|
|
|
|
|
}
|
|
// 创建表头单元格
|
private XRTableCell CreateTableCell(string text, int width)
|
{
|
XRTableCell cell = new XRTableCell();
|
cell.Text = text;
|
cell.Width = width;
|
cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter; // 文本居中
|
cell.Borders = DevExpress.XtraPrinting.BorderSide.All; // 设置边框
|
return cell;
|
}
|
|
// 创建数据绑定单元格
|
private XRTableCell CreateTableCellWithBinding(string dataMember, int width)
|
{
|
XRTableCell cell = new XRTableCell();
|
cell.DataBindings.Add(new XRBinding("Text", null, dataMember)); // 绑定数据字段
|
cell.Width = width;
|
cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft; // 文本左对齐
|
cell.Borders = DevExpress.XtraPrinting.BorderSide.All; // 设置边框
|
return cell;
|
}
|
|
|
|
}
|
}
|