wangzelong
2022-09-20 85a3bba2ed29b8cf6f6009f837d01583c5daf9d4
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
using IStation.Application.Report.Helper;
using IStation.Model;
using IStation.Model.Eta;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.rtf.headerfooter;
using Microsoft.AspNetCore.Http;
using System.Text;
 
namespace IStation.Application
{
 
    /// <summary>
    /// 
    /// </summary>
    public class Eta_Month_ReportPdf
    {
        #region 属性
        Document _document;
        PdfWriter _writer;
        BaseFont _baseFont_general = null;//常规字体
        BaseFont _baseFont_spec_char;//特殊字符字体
        Font _fontSize8;
        Font _fontSize9_bold;
        Font _fontSize13_bold;
        Font _fontSize11;
 
        int _currentPage = 0;
 
        /// <summary>
        /// 生成报表
        /// </summary>
        /// <param name="station">泵站信息</param>
        /// <param name="datatime">时间</param>
        /// <param name="pipeList">机泵管路列表</param>
        /// <param name="list">机泵信息列表</param>
        /// <param name="sum">泵站月信息列表</param>
        /// <param name="path">路径</param>
        /// <returns></returns>
        public bool Create4Stream(Station station, Model.EtaSumMultiMonthRecord sum, List<Model.PipeLine> pipeList, List<Model.EtaSumSingleMonthRecord> list, string datatime, string path)
        {
            InitialFont();
            //初始化标题中的LOGO图片
            InitialTitleLogoImage();
 
            MemoryStream strem = new MemoryStream();
            _document = new Document(PageSize.A4);
            _document.SetMargins(-40, -40, 40, 40);
            _writer = PdfWriter.GetInstance(_document, new FileStream(path, FileMode.Create));
            _writer.PageEvent = new CreatHeaderAndFoot();
            CreatestationInfoPage(station, pipeList, sum, list, datatime);//产品信息
            _document.Close();
            return true;
        }
 
        //字体
        private void InitialFont()
        {
            string fileTtc_simsun = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fonts\\simsun.ttc");
            if (!File.Exists(fileTtc_simsun))
            {
                if (File.Exists(@"C:\Windows\Fonts\simsun.ttc"))
                {
                    fileTtc_simsun = @"C:\Windows\Fonts\simsun.ttc";
                }
                else
                {
                    if (File.Exists(@"C:\Windows\Fonts\simsunb.ttc"))
                    {
                        fileTtc_simsun = @"C:\Windows\Fonts\simsunb.ttc";
                    }
                }
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                _baseFont_spec_char = BaseFont.CreateFont(fileTtc_simsun + ",1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//读取ttc字体
                //BaseFont.CreateFont 的第一个参数,在字体文件后不一定需要跟上“,1”。
                //这取决于使用的字体文件是否支持多字体。例如simsun.ttc 包含了“宋体”和“新宋体”两套字体,
                //那么如果要使用这个字体文件,就必须指明使用哪一套字体,序号从0开始。
                //但如果使用的字体文件只有一套字体,则一定不能加“,0”。否则,无论是多加还是少加,都会报错。
                //要想知道字体文件是否是多套字体,只需双击打开字体文件,如果有导航的>>和<<按钮,则是有多套字体,否则就不是。
                //TTC是几个TTF合成的字库,安装后字体列表中会看到两个以上的字体。
            }
            _fontSize8 = new Font(_baseFont_spec_char, 8);
            _fontSize9_bold = new Font(_baseFont_spec_char, 9, Font.BOLD);
            _fontSize13_bold = new Font(_baseFont_spec_char, 13, Font.BOLD);
            _fontSize11 = new Font(_baseFont_spec_char, 11);
        }
 
        #region LOGO图片
        System.Drawing.Image _imgTitleCorpLogo = null;//表头的LOGO
 
        /// <summary>
        /// 
        /// </summary>
        public void InitialTitleLogoImage()
        {
            //如果Data文件夹下有就优先
            string strLogoFullPath = string.Format("{0}\\SelectReportTitleLogo.png", 1);
            if (File.Exists(strLogoFullPath))
            {
                _imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath);
                return;
            }
 
            strLogoFullPath = string.Format("{0}\\CorpLogo.png", 1);
            if (File.Exists(strLogoFullPath))
            {
                _imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath);
                return;
            }
 
            //没有就搜索Infomation文件夹
            strLogoFullPath = string.Format("{0}Infomation\\CorpLogo.png", AppDomain.CurrentDomain.BaseDirectory);
            if (File.Exists(strLogoFullPath))
            {
                _imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath);
            }
        }
        #endregion
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        /// <param name="sum"></param>
        /// <param name="pipeList"></param>
        /// <param name="list"></param>
        /// <param name="dateTime"></param>
        public void CreatestationInfoPage(Station station, List<Model.PipeLine> pipeList, Model.EtaSumMultiMonthRecord sum, List<Model.EtaSumSingleMonthRecord> list, string dateTime)
        {
            _document.Open();
            _document.NewPage();
            _currentPage++;
            CreateHaderTable();
            int runcout = 0;
            double qt = 0;
            double dt = 0;
            foreach (var item in list)
            {
                if (item.RunTime > 0)
                    runcout = runcout + 1;
                if (item.Qt > 0)
                    qt += item.Qt;
                if (item.Dt > 0)
                    dt += item.Dt;
            }
            string Qt = "";
            if (qt < 10)
                Qt = Math.Round((double)qt, 3).ToString();
            if (10 < qt && qt < 1000)
                Qt = Math.Round((double)qt, 2).ToString();
            if (qt > 1000)
                Qt = Math.Round((double)qt, 1).ToString();
            string Dt = "";
            if (dt < 10)
                Dt = Math.Round((double)dt, 3).ToString();
            if (10 < dt && dt < 1000)
                Dt = Math.Round((double)dt, 2).ToString();
            if (dt > 1000)
                Dt = Math.Round((double)dt, 1).ToString();
            CreatestationTable(station, sum, runcout, dateTime);
            CreatestationInfoTable(pipeList, list, station.ID);
            PdfPTable table1 = new PdfPTable(3);
            float[] widths = { 80, 140, 300 };
            table1.SetWidths(widths);
            PdfPCell cell = new PdfPCell();
 
            cell = CreateCell2("设备状态:" + station.UseStatus, _fontSize8, 1, 1);
            table1.AddCell(cell);
            _document.Add(table1);
            CreatePropTable();
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void CreatePropTable()
        {
            List<int> _allPartPropList = new List<int>();
            _allPartPropList.Add(10);
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 300, 300 };
            table.SetWidths(widths);
            PdfPCell cell = new PdfPCell();
            int endIndex = 0;
            cell.DisableBorderSide(8);
            cell.AddElement(PropertyTable(38, 0, out endIndex));
            table.AddCell(cell);
            if (endIndex < _allPartPropList.Count && endIndex > -1)
            {
                cell = new PdfPCell();
                cell.DisableBorderSide(4);
                cell.AddElement(PropertyTable(38, endIndex, out endIndex));
                table.AddCell(cell);
            }
            _document.Add(table);
 
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="displayRow"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        public PdfPTable PropertyTable(int displayRow, int startIndex, out int endIndex)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 300, 300 };
            table.SetWidths(widths);
            PdfPCell cell = new PdfPCell();
            int row = 0;//记录循环的行数
            string groupName = string.Empty;
 
            if (row != 0)
            {
                cell = CreateCell2("", _fontSize9_bold, 2, 1, 10, 15);
                table.AddCell(cell);
                row++;
            }
            groupName = "名称";
            cell = CreateCell1("名称", _fontSize9_bold, 2, 1, 13, 15);
            table.AddCell(cell);
            row++;
 
            cell = CreateCell2("名称", _fontSize8, 1, 1, 13, 0, Element.ALIGN_LEFT, Element.ALIGN_LEFT, true);
            cell.PaddingLeft = 8;
            table.AddCell(cell);
            cell = CreateCell2("名称", _fontSize8, 1, 1, 13, 0);
            cell.PaddingLeft = 8;
            table.AddCell(cell);
            row++;
 
            endIndex = -1;
            return table;
        }
 
        private PdfPCell AddPicture(System.Drawing.Image image,
            int colspan, int rowspan,
            float cellHeight,
            int BorderWidthLeft = -1, int BorderWidthRight = -1,
            int BorderWidthTop = -1, int BorderWidthBottom = -1, float fixHeight = -1)
        {
            if (image == null)
                return null;
            PdfPCell cell = new PdfPCell();
            cell.Colspan = colspan;
            cell.Rowspan = rowspan;
            cell.MinimumHeight = cellHeight;
            cell.FixedHeight = cellHeight;
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            if (BorderWidthLeft >= 0)
                cell.BorderWidthLeft = BorderWidthLeft;
            if (BorderWidthLeft >= 0)
                cell.BorderWidthRight = BorderWidthRight;
            if (BorderWidthTop >= 0)
                cell.BorderWidthTop = BorderWidthTop;
            if (BorderWidthBottom >= 0)
                cell.BorderWidthBottom = BorderWidthBottom;
            if (fixHeight > 0)
                cell.FixedHeight = fixHeight;
 
            while (image.Width > 1800)
            {
                image = image.GetThumbnailImage(Convert.ToInt32(image.Width * 0.9), Convert.ToInt32(image.Height * 0.9), () => { return false; }, IntPtr.Zero);
            }
            var imgTextSharp = Image.GetInstance(image, BaseColor.White);
            imgTextSharp.Alignment = Element.ALIGN_MIDDLE;
            cell.Image = imgTextSharp;
            return cell;
        }
 
        /// <summary>
        /// 表头
        /// </summary>
        public void CreateHaderTable()
        {
            PdfPTable table = new PdfPTable(1);
            PdfPCell cell = new PdfPCell();
            cell = CreateCell2("泵站能效月报表", _fontSize13_bold, 1, 1, 50, 0, Element.ALIGN_CENTER);
            cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
            table.AddCell(cell);
 
            _document.Add(table);
        }
 
 
        /// <summary>
        /// 设备信息
        /// </summary>
        //
        public void CreatestationTable(Station station, EtaSumMultiMonthRecord sum, int cout, string datatime)
        {
            PdfPTable table = new PdfPTable(4);
            PdfPCell cell = new PdfPCell();
            float[] widths = new float[] { 60, 60, 60, 60 };
 
            cell = CreateCell2("泵站信息", _fontSize11, 4, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("泵站名称", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(station.Name, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("运行数量" + " (台)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(cout.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("总电能" + " (A)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(sum.Dt.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("总流量" + " (t)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(sum.Qt.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("报告日期", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(datatime, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("使用状态", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(station.UseStatus == eUseStatus.Enable ? "使用中" : "已停用", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            if (station.UseStatus == eUseStatus.Enable)
                cell.BackgroundColor = BaseColor.Green;
            if (station.UseStatus == eUseStatus.Disable)
                cell.BackgroundColor = BaseColor.Gray;
            table.AddCell(cell);
            cell = CreateCell2("地址", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(station.Address, _fontSize11, 3, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
 
            table.SetWidths(widths);
            _document.Add(table);
        }
 
        /// <summary>
        /// 生成机泵列表
        /// </summary>
        /// <param name="list">机泵列表</param>
        /// <param name="pipeList">管路</param>
        /// <param name="stationID">泵站ID</param>
        public void CreatestationInfoTable(List<Model.PipeLine> pipeList, List<Model.EtaSumSingleMonthRecord> list, long stationID)
        {
 
            PdfPTable table = new PdfPTable(5);
            PdfPCell cell = new PdfPCell();
            float[] widths = new float[] { 60, 60, 60, 60, 60 };
            var ProductList = new Service.Product().GetByCorpID(list.FirstOrDefault().CorpID);
            cell = CreateCell2("能效信息", _fontSize11, 5, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            var seviceEnginePump = new Service.Product();
            foreach (var item in list)
            {
                var EnginePumpLine = pipeList?.Find(x => x.ID == item.ObjectID);
                var EnginePump = ProductList.Find(x => x.BelongID == stationID && x.Name == EnginePumpLine.Name);
                var Pump = seviceEnginePump.GetChildPumpByEnginePumpID(EnginePump.CorpID, EnginePump.ID);
                var Motor = seviceEnginePump.GetChildMotorByEnginePumpID(EnginePump.CorpID, EnginePump.ID);
                string EnginePumpName = "";
                if (EnginePump != null)
                    EnginePumpName = EnginePump.Name;
                cell = CreateCell2(EnginePumpName, _fontSize11, 1, 5, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("状态", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                int usetatus = 0;
                if (item.UWPavg < 1)
                    usetatus = 0;
                if (item.UWPavg > 0)
                    usetatus = 1;
                cell = CreateCell2(usetatus == 1 ? "开启" : "未开启", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                if (usetatus == 1)
                    cell.BackgroundColor = BaseColor.Green;
                if (usetatus == 0)
                    cell.BackgroundColor = BaseColor.Gray;
                table.AddCell(cell);
 
                cell = CreateCell2("运行时间" + " (h)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                var runtime = Math.Round((decimal)item.RunTime / 3600, 1);
                cell = CreateCell2(runtime < 1 ? @"/" : runtime.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("泵型号", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                string PumpCode = "";
                if (Pump != null)
                    PumpCode = Pump.Code;
                cell = CreateCell2(PumpCode, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("电机型号", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                string MotorCode = "";
                if (Pump != null)
                    MotorCode = Motor.Code;
                cell = CreateCell2(MotorCode, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("总电能" + " (A)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                string Dt = "";
                if (item.Dt < 10)
                    Dt = Math.Round((double)item.Dt, 3).ToString();
                if (10 < item.Dt && item.Dt < 1000)
                    Dt = Math.Round((double)item.Dt, 2).ToString();
                if (item.Dt > 1000)
                    Dt = Math.Round((double)item.Dt, 1).ToString();
                cell = CreateCell2(item.Dt < 1 ? @"/" : Dt, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("总流量" + " (m³)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                string Qt = "";
                if (item.Qt < 10)
                    Qt = Math.Round((double)item.Qt, 3).ToString();
                if (10 < item.Qt && item.Qt < 1000)
                    Qt = Math.Round((double)item.Qt, 2).ToString();
                if (item.Qt > 1000)
                    Qt = Math.Round((double)item.Qt, 1).ToString();
                cell = CreateCell2(item.Qt < 1 ? @"/" : Qt, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("平均单位能耗" + " \n(kw·h)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                string UWPavg = "";
                if (item.UWPavg < 10)
                    UWPavg = Math.Round((double)item.UWPavg, 3).ToString();
                if (10 < item.UWPavg && item.UWPavg < 1000)
                    UWPavg = Math.Round((double)item.UWPavg, 2).ToString();
                if (item.UWPavg > 1000)
                    UWPavg = Math.Round((double)item.UWPavg, 1).ToString();
                cell = CreateCell2(item.UWPavg < 1 ? @"/" : UWPavg, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                cell = CreateCell2("平均千吨能耗" + " \n(kw·h)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                string wpavg = "";
                if (item.WPavg < 10)
                    wpavg = Math.Round((double)item.WPavg, 3).ToString();
                if (10 < item.WPavg && item.WPavg < 1000)
                    wpavg = Math.Round((double)item.WPavg, 2).ToString();
                if (item.WPavg > 1000)
                    wpavg = Math.Round((double)item.WPavg, 1).ToString();
                cell = CreateCell2(item.WPavg == 0 ? @"/" : wpavg, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
 
                cell = CreateCell2("耗煤" + " (t)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
                var run_coal = item.Pavg + item.BootTimes / 3600f;
                var value = ((run_coal / 10000f) * 2.7978);
                cell = CreateCell2(value == 0 ? "/" : Math.Round((double)value, 5).ToString(), _fontSize11, 3, 1, 40, 0, Element.ALIGN_CENTER);
                table.AddCell(cell);
            }
            table.SetWidths(widths);
            _document.Add(table);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        public void CreateEndTable(EtaMultiRealRecordPure item)
        {
 
            PdfPTable table = new PdfPTable(4);
            PdfPCell cell = new PdfPCell();
            float[] widths = new float[] { 60, 60, 60, 60 };
 
            cell = CreateCell2("※※※※※※※※※※※※※※分割线※※※※※※※※※※※※※※※※", _fontSize11, 4, 1, 30, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("分析信息", _fontSize11, 4, 1, 30, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            string etause = "错误";
            if (item.AnalyStatus == eAnalyStatus.Normal)
                etause = "正常";
            if (item.AnalyStatus == eAnalyStatus.Missing)
                etause = "数据缺失";
            if (item.AnalyStatus == eAnalyStatus.Abnormal)
                etause = "数据异常";
            if (item.AnalyStatus == eAnalyStatus.Unkonw)
                etause = "未知";
            cell = CreateCell2("分析间隔", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(item.Duration.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2("分析状态", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(etause, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
            cell.BackgroundColor = BaseColor.Red;
            if (item.AnalyStatus == eAnalyStatus.Normal)
                cell.BackgroundColor = BaseColor.Green;
            if (item.AnalyStatus == eAnalyStatus.Missing)
                cell.BackgroundColor = BaseColor.Yellow;
            if (item.AnalyStatus == eAnalyStatus.Abnormal)
                cell.BackgroundColor = BaseColor.Orange;
            if (item.AnalyStatus == eAnalyStatus.Unkonw)
                cell.BackgroundColor = BaseColor.Gray;
            table.AddCell(cell);
            cell = CreateCell2("分析结果", _fontSize11, 1, 1, 150, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
            cell = CreateCell2(item.AnalyInfo, _fontSize11, 3, 1, 150, 0, Element.ALIGN_CENTER);
            table.AddCell(cell);
 
            table.SetWidths(widths);
            _document.Add(table);
        }
 
        //    cell.Rowspan = 4;
        //    table.SetWidths(widths);
        //    _document.Add(table);
        //}
 
        ////添加水印
        //public void AddWatermark()
        //{
        //    if (_isPrintCorpWaterMark)
        //    {
 
        //        var waterMarkLogoFile = System.IO.Path.Combine(SPump.GlobeParas.DataFolder, "SelectReportWaterMark.png");
        //        if (System.IO.File.Exists(waterMarkLogoFile))
        //        {
        //            PdfContentByte cb = _writer.DirectContent;
        //            iTextSharp.text.Rectangle psize = _document.PageSize;
        //            float width = psize.Width;
        //            float height = psize.Height;
        //            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(waterMarkLogoFile);
        //            image.ScalePercent(50);
 
        //            //水印的位置
        //            //var i = image.Width;
        //            image.SetAbsolutePosition(width / 2 - image.Width / 4, height / 2 - image.Height / 4);
        //            cb.AddImage(image);
        //        }
 
 
 
        //    }
 
 
 
        //    if (!string.IsNullOrEmpty(RefWaterMarkText))
        //    {
        //        Font font = new Font(Font.FontFamily.UNDEFINED, 30, Font.BOLD, new iTextSharp.text.BaseColor(100, 400, 400, 50));
 
        //        Phrase p = new Phrase(RefWaterMarkText, font);
        //        ColumnText.ShowTextAligned(_writer.DirectContent, Element.ALIGN_CENTER, p, _document.PageSize.Width - 100, _document.PageSize.Height - 100, 0);
 
        //    }
 
 
        //}
 
        //为英文时首字母大写
        private PdfPCell CreateCell1(string name,
       Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = Element.ALIGN_LEFT)
        {
            Paragraph table_t = null;
            PdfPCell cell = new PdfPCell();
            if (font == null)
                font = _fontSize8;
            if (name == null)
            {
                name = "";
            }
 
            table_t = new Paragraph(name, font);
            table_t.Leading = 9;
            cell.Colspan = col;
            cell.Rowspan = row;
            cell.MinimumHeight = rowHeight;
            cell.FixedHeight = rowHeight;
            cell.DisableBorderSide(disableNum);
            cell.Padding = 0;
            cell.PaddingLeft = 3;
            cell.UseAscender = true;
            cell.UseDescender = true;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
            table_t.Alignment = r;
            cell.AddElement(table_t);
 
            return cell;
        }
 
        //绘制文本(可能有特殊字符)
        private PdfPCell CreateCell2(string name,
            Font font = null,
            int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0,
            int r = Element.ALIGN_LEFT, int Paragraph = Element.ALIGN_LEFT, bool b = false, int strLength = 26)
        {
            Paragraph table_t = null;
            PdfPCell cell = new PdfPCell();
            if (font == null)
                font = _fontSize8;
            if (name == null)
            {
                name = "";
            }
            if (name.Length > 27 && b && name.Length > strLength)
            {
                name = name.Substring(0, strLength);
            }
            table_t = new Paragraph(name, font);
            table_t.Alignment = Element.ALIGN_LEFT;
            table_t.Leading = 9;
            cell.Colspan = col;
            cell.Rowspan = row;
            cell.MinimumHeight = rowHeight;
            cell.FixedHeight = rowHeight;
            cell.DisableBorderSide(disableNum);
            cell.Padding = 0;
            cell.PaddingLeft = 3;
            cell.UseAscender = true;
            cell.UseDescender = true;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
            table_t.Alignment = r;
            cell.AddElement(table_t);
 
            return cell;
        }
 
 
        private PdfPCell CreateCell(double value,
            Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = Element.ALIGN_LEFT)
        {
            string value_v = string.Empty;
            Paragraph table_t = null;
            PdfPCell cell = new PdfPCell();
            if (font == null)
                font = _fontSize8;
            if (value >= 0)
            {
                value_v = Math.Round(value, 4).ToString();
            }
            table_t = new Paragraph(value_v, font);
            table_t.Leading = 9;
            cell.Colspan = col;
            cell.Rowspan = row;
 
            cell.MinimumHeight = rowHeight;
            cell.FixedHeight = rowHeight;
            cell.DisableBorderSide(disableNum);
            cell.Padding = 0;
            cell.PaddingLeft = 3;
            cell.UseAscender = true;
            cell.UseDescender = true;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
            table_t.Alignment = r;
            cell.AddElement(table_t);
            return cell;
        }
        //约分 
        private PdfPCell CreateCellReduce(double value,
            Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = Element.ALIGN_LEFT)
        {
            string value_v = string.Empty;
            Paragraph table_t = null;
            PdfPCell cell = new PdfPCell();
            if (font == null)
                font = _fontSize8;
            if (value >= 0)
            {
                value_v = Math.Round(value, 2).ToString();
            }
            table_t = new Paragraph(value_v, font);
            table_t.Leading = 9;
            cell.Colspan = col;
            cell.Rowspan = row;
 
            cell.MinimumHeight = rowHeight;
            cell.FixedHeight = rowHeight;
            cell.DisableBorderSide(disableNum);
            cell.Padding = 0;
            cell.PaddingLeft = 3;
            cell.UseAscender = true;
            cell.UseDescender = true;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
            cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
            table_t.Alignment = r;
            cell.AddElement(table_t);
            return cell;
        }
 
        //画单元格方法
        private PdfPTable CreateTable(int spanNum, float percentage = 100)//建立表格
        {
            PdfPTable table1 = new PdfPTable(spanNum);//将表格分为10列
 
            table1.WidthPercentage = percentage;//表格所占界面的百分比
            return table1;
        }
        /// <summary>
        /// 根据 年 和 月,获取当月第一天
        /// </summary>
        /// <param name="years">年</param>
        /// <param name="months">月</param>
        /// <returns>返回:yyyy-MM-dd 形式</returns>
        public DateTime GetFirstDayByYearMonth(int years, int months)
        {
            DateTime datetime = DateTime.Parse(years + "-" + months + "-" + "15");
            return datetime.AddDays(1 - datetime.Day);
        }
 
        /// <summary>
        /// 根据 年 和 月,获取当月最后一天
        /// </summary>
        /// <param name="years">年</param>
        /// <param name="months">月</param>
        /// <returns>返回:yyyy-MM-dd 形式</returns>
        public DateTime GetLastDayByYearMonth(int years, int months)
        {
            DateTime datetime = DateTime.Parse(years + "-" + months + "-" + "15");
            return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
        }
    }
}
#endregion