lixiaojun
2025-02-19 294b81166f21e12247e784d6bf404f5f34b2ee19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
using DevExpress.XtraCharts;
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);
 
            //内容宽度
            float contentWidth = 727F;//内容宽度
            float firstCaptionHeight = 30F;//一级标题高度
 
            //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 = CreateFirstCaption("一、项目概述", contentWidth, firstCaptionHeight, 0F, locationY);
            this.Detail.Controls.Add(labForDescription);
            locationY += firstCaptionHeight;
 
            #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);
                locationY += 30F;
                locationY += 30F * vm.PumpList.Count;
            }
 
            if (vm.WorkingList != null && vm.WorkingList.Count > 0)
            {
                foreach (var working in vm.WorkingList)
                {
                    //XRChart chart = new XRChart();
                    //chart.LocationF = new DevExpress.Utils.PointFloat(0F, locationY);
                    //chart.WidthF = contentWidth;
                    //chart.HeightF = 300F;
 
                    //// 创建一个线系列
                    //Series series = new Series("Series1", ViewType.Spline);
 
                    //// 添加数据点
                    //foreach (var item in working.PumpAnaly.Items[0].RatedCurveQH)
                    //{
                    //    series.Points.Add(new SeriesPoint(item.X, item.Y));
                    //}
 
                    //chart.Series.Add(series);
 
                    //Detail.Controls.Add(chart);
 
                    var accuracyScaleChart = CreateAccuracyScale(working.Accuracy.Scale, 300F, 250F, locationY);
                    Detail.Controls.Add(accuracyScaleChart);
                    var accuracyFlowChart = CreateAccuracyItem(working.Accuracy.Flow?.AvgError ?? 0, 213F, 250F, 300F, locationY);
                    Detail.Controls.Add(accuracyFlowChart);
                    var accuracyPressChart = CreateAccuracyItem(working.Accuracy.Press?.AvgError ?? 0, 213F, 250F, 513F, locationY);
                    Detail.Controls.Add(accuracyPressChart);
 
                    //var chart = new XRChart();
                    //chart.BackColor = System.Drawing.Color.Transparent;
                    //chart.BorderColor = System.Drawing.Color.Black;
                    //chart.Borders = DevExpress.XtraPrinting.BorderSide.None;
                    ////chart.Legend.LegendID = -1;
                    //chart.Legend.Name = "Default Legend";
                    //chart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
                    //chart.LocationFloat = new DevExpress.Utils.PointFloat(20F, locationY);
                    //chart.Name = "xrChart6";
                    //chart.Padding = new DevExpress.XtraPrinting.PaddingInfo(10, 10, 20, 20, 96F);
                    //chart.PaletteRepository.Add("Palette 1", new DevExpress.XtraCharts.Palette("Palette 1", DevExpress.XtraCharts.PaletteScaleMode.Repeat, new DevExpress.XtraCharts.PaletteEntry[] {
                    //new DevExpress.XtraCharts.PaletteEntry(System.Drawing.Color.FromArgb(((int)(((byte)(103)))), ((int)(((byte)(174)))), ((int)(((byte)(197))))), System.Drawing.Color.FromArgb(((int)(((byte)(103)))), ((int)(((byte)(174)))), ((int)(((byte)(197)))))),
                    //new DevExpress.XtraCharts.PaletteEntry(System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(236)))), ((int)(((byte)(240))))), System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(236)))), ((int)(((byte)(240))))))}));
                    //chart.PaletteName = "Palette 1";
 
 
 
                    //var series = new DevExpress.XtraCharts.Series();
                    //series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.False;
                    //series.Name = "Series 1";
                    ////series.SeriesID = 0;
                    //var doughnutSeriesView = new DevExpress.XtraCharts.DoughnutSeriesView();
                    //doughnutSeriesView.HoleRadiusPercent = 45;
                    //doughnutSeriesView.TotalLabel.DXFont = new DevExpress.Drawing.DXFont("Tahoma", 12F, DevExpress.Drawing.DXFontStyle.Bold);
                    //doughnutSeriesView.TotalLabel.Visible = true;
                    //series.View = doughnutSeriesView;
                    //chart.SeriesSerializable = new DevExpress.XtraCharts.Series[] { series };
                    //chart.SizeF = new System.Drawing.SizeF(175F, 185F);
                    //chart.StylePriority.UseBackColor = false;
                    //chart.StylePriority.UsePadding = false;
 
                    //series.Points.Add(new SeriesPoint("误差", 15));
                    //series.Points.Add(new SeriesPoint("其他", 85));
 
                    //doughnutSeriesView.TotalLabel.TextPattern = string.Format("{0:0%}", 0.15);
 
                    //this.Detail.Controls.Add(chart);
 
 
                }
            }
        }
 
        //创建一级标题
        private XRLabel CreateFirstCaption(string caption, float sizeX, float sizeY, float locationX, float locationY)
        {
            var lab = new XRLabel();
            lab.AnchorHorizontal = (DevExpress.XtraReports.UI.HorizontalAnchorStyles.Left | DevExpress.XtraReports.UI.HorizontalAnchorStyles.Right);
            lab.Font = new DevExpress.Drawing.DXFont("Arial", 12F, DevExpress.Drawing.DXFontStyle.Bold);
            lab.LocationFloat = new DevExpress.Utils.PointFloat(locationX, locationY);
            lab.Multiline = true;
            lab.Name = "lab";
            lab.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F);
            lab.SizeF = new System.Drawing.SizeF(sizeX, sizeY);
            lab.StylePriority.UseFont = false;
            lab.StylePriority.UseTextAlignment = false;
            lab.Text = caption;
            lab.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
            return lab;
        }
 
        //创建精度比例
        private XRChart CreateAccuracyScale(SimulationPrintAccuracyScaleViewModel scale, float sizeX, float sizeY, float locationY)
        {
            var chart = new XRChart();
            chart.BackColor = System.Drawing.Color.Transparent;
            chart.BorderColor = System.Drawing.Color.Black;
            chart.Borders = DevExpress.XtraPrinting.BorderSide.All;
            chart.Legend.Name = "Default Legend";
            chart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
            chart.LocationFloat = new DevExpress.Utils.PointFloat(0F, locationY);
            chart.Name = "chart";
            chart.Padding = new DevExpress.XtraPrinting.PaddingInfo(10, 10, 20, 20, 100F);
 
            var series = new DevExpress.XtraCharts.Series();
            series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            series.Name = "Series";
            var doughnutSeriesView = new DevExpress.XtraCharts.DoughnutSeriesView();
            doughnutSeriesView.HoleRadiusPercent = 45;
            doughnutSeriesView.TotalLabel.DXFont = new DevExpress.Drawing.DXFont("Tahoma", 12F, DevExpress.Drawing.DXFontStyle.Bold);
            doughnutSeriesView.TotalLabel.Visible = true;
            series.View = doughnutSeriesView;
            series.Label.LineVisibility = DevExpress.Utils.DefaultBoolean.True;
            series.Label.TextPattern = "{A}:{VP:P1}";
            chart.SeriesSerializable = new DevExpress.XtraCharts.Series[] { series };
            chart.SizeF = new System.Drawing.SizeF(sizeX, sizeY);
            chart.StylePriority.UseBackColor = false;
            chart.StylePriority.UsePadding = false;
 
            if (scale.Items != null && scale.Items.Count > 0)
            {
                foreach (var item in scale.Items)
                {
                    series.Points.Add(new SeriesPoint(item.EvaluateItem, item.EvaluateCount));
                }
            }
            doughnutSeriesView.TotalLabel.TextPattern = string.Format("{0:0%}", (scale.AvgError ?? 0) / 100F);
            return chart;
        }
 
        //创建精度项
        private XRChart CreateAccuracyItem(double value, float sizeX, float sizeY, float locationX, float locationY)
        {
            var chart = new XRChart();
            chart.BackColor = System.Drawing.Color.Transparent;
            chart.BorderColor = System.Drawing.Color.Black;
            chart.Borders = DevExpress.XtraPrinting.BorderSide.All;
            chart.Legend.Name = "Default Legend";
            chart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
            chart.LocationFloat = new DevExpress.Utils.PointFloat(locationX, locationY);
            chart.Name = "chart";
            chart.Padding = new DevExpress.XtraPrinting.PaddingInfo(10, 10, 20, 20, 100F);
            chart.PaletteRepository.Add("Palette 1", new DevExpress.XtraCharts.Palette("Palette 1", DevExpress.XtraCharts.PaletteScaleMode.Repeat, new DevExpress.XtraCharts.PaletteEntry[] {
            new DevExpress.XtraCharts.PaletteEntry(System.Drawing.Color.FromArgb(((int)(((byte)(103)))), ((int)(((byte)(174)))), ((int)(((byte)(197))))), System.Drawing.Color.FromArgb(((int)(((byte)(103)))), ((int)(((byte)(174)))), ((int)(((byte)(197)))))),
            new DevExpress.XtraCharts.PaletteEntry(System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(236)))), ((int)(((byte)(240))))), System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(236)))), ((int)(((byte)(240))))))}));
            chart.PaletteName = "Palette 1";
 
            var series = new DevExpress.XtraCharts.Series();
            series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.False;
            series.Name = "Series";
            var doughnutSeriesView = new DevExpress.XtraCharts.DoughnutSeriesView();
            doughnutSeriesView.HoleRadiusPercent = 45;
            doughnutSeriesView.TotalLabel.DXFont = new DevExpress.Drawing.DXFont("Tahoma", 12F, DevExpress.Drawing.DXFontStyle.Bold);
            doughnutSeriesView.TotalLabel.Visible = true;
            series.View = doughnutSeriesView;
            chart.SeriesSerializable = new DevExpress.XtraCharts.Series[] { series };
            chart.SizeF = new System.Drawing.SizeF(sizeX, sizeY);
            chart.StylePriority.UseBackColor = false;
            chart.StylePriority.UsePadding = false;
 
            var otherValue = 100 - value;
            series.Points.Add(new SeriesPoint("误差", value));
            series.Points.Add(new SeriesPoint("其他", otherValue));
 
            doughnutSeriesView.TotalLabel.TextPattern = string.Format("{0:0%}", value / 100f);
            return chart;
        }
 
 
        // 创建表头单元格
        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;
        }
 
 
 
    }
}