DevExpress.XtraReport動態報表的製作
阿新 • • 發佈:2019-01-05
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
namespace DL698AmmeterTest.form
{
public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
private string _changShang;//廠商
private string _sn;//型號
private string _type;//型別
private string _songJianRen;//送檢人
private string _ceShiDanWei;//測試單位
private string _ceShiRen;//測試人
private TestPlan _testPlan;//測試計劃(批次)
private List<TestItem> _listTI;//測試項
private List<Ammeter> _listAmmeter;//測試結果
private ReportOptions ro = new ReportOptions();
public XtraReport1()
{
InitializeComponent();
}
public XtraReport1(TestPlan testPlan, List<TestItem> listTI, List<Ammeter> listAmmeter)
{
InitializeComponent();
this._testPlan = testPlan;
if (listTI != null && listTI.Count > 0)
{
this._listTI = listTI;
}
else
{
this._listTI = new List<TestItem>();
}
if (listAmmeter != null && listAmmeter.Count > 0)
{
this._listAmmeter = listAmmeter;
}
else
{
this._listAmmeter = new List<Ammeter>();
}
}
//設定標題
public void setTitle()
{
this.xrLabelTitle.Text = this._testPlan.Test_name;
}
public void setFoot()
{
}
public void setBody()
{
Int64 planid = this._testPlan.Id;
foreach (Ammeter ammeter in this._listAmmeter)
{
//建立panel1,並將label及表頭加入
XRPanel xrPanel1 = new XRPanel();
xrPanel1.Location = new Point(0, getY());
xrPanel1.Size = new Size(PageWidth - Margins.Left - Margins.Right, 42);
this.Detail.Controls.Add(xrPanel1);
XRLabel xrLabel1 = new XRLabel();
xrLabel1.Text = "電能表號:";
xrLabel1.Location = new Point(0, 8);
xrLabel1.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.13), 25);
xrLabel1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel1);
//填寫表號的label
XRLabel xrLabel2 = new XRLabel();
xrLabel2.Location = new Point(xrLabel1.Location.X + xrLabel1.Width, 8);
xrLabel2.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.2), 25);
xrLabel2.Text = ammeter.Ammeter_adc_id;
xrLabel2.Font = new Font("宋體", 10, FontStyle.Underline);
xrLabel2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel2);
XRLabel xrLabel3 = new XRLabel();
xrLabel3.Text = "送檢單位:";
xrLabel3.Location = new Point(xrLabel2.Location.X + xrLabel2.Width, 8);
xrLabel3.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.13), 25);
xrLabel3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel3);
//填寫送檢單位的label
XRLabel xrLabel4 = new XRLabel();
xrLabel4.Location = new Point(xrLabel3.Location.X + xrLabel3.Width, 8);
xrLabel4.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.23), 25);
xrLabel4.Text = this._testPlan.Comsumer_name;
xrLabel4.Font = new Font("宋體", 10, FontStyle.Underline);
xrLabel4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel4);
XRLabel xrLabel5 = new XRLabel();
xrLabel5.Text = "測試日期:";
xrLabel5.Location = new Point(xrLabel4.Location.X + xrLabel4.Width, 8);
xrLabel5.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.13), 25);
xrLabel5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel5);
//
XRLabel xrLabel6 = new XRLabel();
xrLabel6.Location = new Point(xrLabel5.Location.X + xrLabel5.Width, 8);
xrLabel6.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.18), 25);
xrLabel6.Text = this._testPlan.Test_time.Year + "年" + this._testPlan.Test_time.Month + "月" + this._testPlan.Test_time.Day + "日";
xrLabel6.Font = new Font("宋體", 10, FontStyle.Underline);
xrLabel6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel6);
//panel2,裝表格
XRPanel xrPanel2 = new XRPanel();
xrPanel2.Location = new Point(0, xrPanel1.Location.Y + 25);
xrPanel2.Size = new Size(xrPanel1.Width, 42);
this.Detail.Controls.Add(xrPanel2);
List<TestResult> listTr = ro.findByPlanIDAndAmmeterAdc_TestResult(planid, ammeter.Ammeter_adc_id);
List<TestData> listTd = new List<TestData>();
XRTable xrTable1 = new XRTable();
xrTable1.BorderWidth = 1;
xrTable1.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTable1.Location = new Point(0, 8);
// xrTable1.Size = new Size(xrPanel2.Width, 25*(listTr.Count+2)/3);
xrTable1.Size = new Size(xrPanel2.Width, 25);
//第一行,表頭
XRTableRow xrTableRow1 = new XRTableRow();
XRTableCell xrTableCell1 = new XRTableCell();
XRTableCell xrTableCell2 = new XRTableCell();
XRTableCell xrTableCell3 = new XRTableCell();
xrTableRow1.Size = new Size(xrTable1.Width, 25);
xrTableRow1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTable1.Rows.Add(xrTableRow1);
//第一行,第一列
xrTableCell1.Size = new Size(Convert.ToInt32(xrTableRow1.Width * 0.4), 25);
xrTableCell1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell1.Font = new Font("宋體", 10, FontStyle.Bold);
xrTableCell1.Width = Convert.ToInt32(xrTableRow1.Width * 0.4);
xrTableCell1.Text = "抄收資料項";
//第一行,第二列
//XRTableCell xrTableCell2 = new XRTableCell();
xrTableCell2.Size = new Size(Convert.ToInt32(xrTableRow1.Width * 0.3), 25);
xrTableCell2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell2.Font = new Font("宋體", 10, FontStyle.Bold);
xrTableCell2.Width = Convert.ToInt32(xrTableRow1.Width * 0.3);
xrTableCell2.Text = "抄收實時資料";
//第一行,第三列
//XRTableCell xrTableCell3 = new XRTableCell();
xrTableCell3.Size = new Size(Convert.ToInt32(xrTableRow1.Width * 0.3), 25);
xrTableCell3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell3.Font = new Font("宋體", 10, FontStyle.Bold);
xrTableCell3.Width = Convert.ToInt32(xrTableRow1.Width * 0.3);
xrTableCell3.Text = "抄收凍結資料";
xrTableRow1.Cells.Add(xrTableCell1);
xrTableRow1.Cells.Add(xrTableCell2);
xrTableRow1.Cells.Add(xrTableCell3);
foreach (TestItem testItem in this._listTI)
{
TestData td = new TestData();
td.Test_item = testItem.Name;
td.Result1 = "電能表沒有該功能";
td.Result2 = "電能表沒有該功能";
listTd.Add(td);
foreach (TestResult testResult in listTr)
{
if (testItem.Id == testResult.Test_item_id)
{
foreach (TestData td1 in listTd)
{
if (td1.Test_item == testItem.Name)
{
if (testResult.Type.Substring(0,2)=="01")
{
td1.Result1 = "通過";
}
else if (testResult.Type.Substring(0,2) == "02")
{
td1.Result2 = "通過";
}
}
}
}
}
}
foreach (TestData testData in listTd)
{
xrTable1.Height = xrTable1.Height + 25;
XRTableRow xrTableRow2 = new XRTableRow();
xrTableRow2.Size = xrTableRow1.Size;
XRTableCell xrTableCell4 = new XRTableCell();
xrTableCell4.Size = xrTableCell1.Size;
xrTableCell4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrTableCell4.Width = xrTableCell1.Width;
xrTableCell4.Text = testData.Test_item;
xrTableRow2.Cells.Add(xrTableCell4);
XRTableCell xrTableCell5 = new XRTableCell();
xrTableCell5.Size = xrTableCell2.Size;
xrTableCell5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrTableCell5.Width = xrTableCell2.Width;
xrTableCell5.Text = testData.Result1;
xrTableRow2.Cells.Add(xrTableCell5);
XRTableCell xrTableCell6 = new XRTableCell();
xrTableCell6.Size = xrTableCell3.Size;
xrTableCell6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrTableCell6.Width = xrTableCell3.Width;
xrTableCell6.Text = testData.Result2;
xrTableRow2.Cells.Add(xrTableCell6);
//xrTable1.Rows.AddRange(new XRTableRow[] { xrTableRow2 });
xrTable1.Rows.Add(xrTableRow2);
}
xrPanel2.Controls.Add(xrTable1);
//panel3,裝表底
XRPanel xrPanel3 = new XRPanel();
xrPanel3.Location = new Point(0, xrPanel2.Location.Y + xrPanel2.Height + 10);
xrPanel3.Size = new Size(xrPanel2.Width, 150);
XRLabel xrLabel8 = new XRLabel();
xrLabel8.Text = "(具體的抄收資料報文、解析資料作為附錄)";
xrLabel8.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrLabel8.Location = new Point(0, 0);
xrLabel8.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.6), 25);
xrPanel3.Controls.Add(xrLabel8);
XRLabel xrLabel9 = new XRLabel();
xrLabel9.Text = "測試人員:";
xrLabel9.Location = new Point(308, 33);
xrLabel9.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.2), 25);
xrLabel9.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel3.Controls.Add(xrLabel9);
XRLabel xrLabel10 = new XRLabel();
xrLabel10.Text = "測試單位: (蓋章有效)";
xrLabel10.Location = new Point(308, 75);
xrLabel10.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.3), 25);
xrLabel10.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel3.Controls.Add(xrLabel10);
XRLabel xrLabel11 = new XRLabel();
xrLabel11.Text = "日 期:";
xrLabel11.Location = new Point(308, 117);
xrLabel11.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrLabel11.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.3), 25);
xrPanel3.Controls.Add(xrLabel11);
this.Detail.Controls.Add(xrPanel3);
XRPageBreak xrPageBreak0 = new XRPageBreak();
Detail.Controls.Add(xrPageBreak0);
xrPageBreak0.Location = new Point(0, xrPanel3.Location.Y + xrPanel3.Height + 10);
//附抄收資料結果
//sql:select t1.id , t1.ammeter_id,t1.result,t1.plant_id, t2.name as test_item,t1.happen_time from test_result as t1 join test_item as t2 on t1.test_item=t2.id
//SELECT t1.ID, t1.AMMETER_ID, t1.RESULT, t1.PLANT_ID, t2.NAME AS Test_Item, t1.HAPPEN_TIME FROM TEST_RESULT AS t1 INNER JOINTEST_ITEM AS t2 ON t1.TEST_ITEM = t2.ID WHERE (t1.PLANT_ID = 1) AND (t1.AMMETER_ID = '000000000011')
//panel4,裝附加資訊
XRPanel xrPanel4 = new XRPanel();
xrPanel4.Location = new Point(0, xrPageBreak0.Location.Y);
xrPanel4.Size = new Size(xrPanel3.Width, 42);
this.Detail.Controls.Add(xrPanel4);
List<TestResult> listResultData = ro.findTestResult1(planid, ammeter.Ammeter_adc_id);
XRLabel xrLabelf = new XRLabel();
xrLabelf.Text = "附表:";
xrLabelf.Location = new Point(0, 0);
xrLabelf.Size = new Size(83, 25);
xrLabelf.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel4.Controls.Add(xrLabelf);
int pages = 0;
if (listResultData.Count % 34 == 0)
{
pages = listResultData.Count / 34;
}
else
{
pages = listResultData.Count / 34 + 1;
}
int num = 0;
int tablex = 0;
int tabley = 30;
int n = 0;
for (int p = 1; p <= pages; p++)
{
XRTable xrTable3 = new XRTable();
xrTable3.Location = new Point(tablex, tabley);
//xrTable3.Size = new Size(xrPanel4.Width, 25 * (listResultData.Count + 6) / 7);
xrTable3.Size = new Size(xrPanel4.Width, 25);
xrTable3.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTable3.BorderWidth = 1;
xrTable3.Font = new Font("宋體", 8);
xrPanel4.Controls.Add(xrTable3);
XRTableRow xrTableRow3 = new XRTableRow();
xrTableRow3.Size = new Size(xrTable3.Width, 25);
//xrTable3.Rows.Add(xrTableRow3);
XRTableCell xrTableCell_3 = new XRTableCell();
xrTableCell_3.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.05), 25);
//xrTableCell_3.Size = new Size(83, 25);
// xrTableCell_3.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
xrTableCell_3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_3.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_3.Text = "編號";
xrTableRow3.Cells.Add(xrTableCell_3);
XRTableCell xrTableCell_4 = new XRTableCell();
xrTableCell_4.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.15), 25);
//xrTableCell_4.Size = new Size(165, 25);
//xrTableCell_4.Width = Convert.ToInt32(xrTableRow3.Width * 0.2);
xrTableCell_4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_4.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_4.Text = "電能表編號";
xrTableRow3.Cells.Add(xrTableCell_4);
XRTableCell xrTableCell_5 = new XRTableCell();
xrTableCell_5.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
//xrTableCell_5.Size = new Size(83, 25);
//xrTableCell_5.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
xrTableCell_5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_5.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_5.Text = "抄收結果";
xrTableRow3.Cells.Add(xrTableCell_5);
//XRTableCell xrTableCell_6 = new XRTableCell();
//xrTableCell_6.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.1), 25);
////xrTableCell_6.Size = new Size(83, 25);
//// xrTableCell_6.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
//xrTableCell_6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
//xrTableCell_6.Font = new Font("宋體", 10, FontStyle.Bold);
//xrTableCell_6.Text = "計劃批次";
//xrTableRow3.Cells.Add(xrTableCell_6);
XRTableCell xrTableCell_7 = new XRTableCell();
xrTableCell_7.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
//xrTableCell_7.Size = new Size(165, 25);
//xrTableCell_7.Width = Convert.ToInt32(xrTableRow3.Width * 0.2);
xrTableCell_7.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_7.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_7.Text = "測試專案";
xrTableRow3.Cells.Add(xrTableCell_7);
XRTableCell xrTableCell_8 = new XRTableCell();
xrTableCell_8.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
//xrTableCell_8.Size = new Size(165, 25);
//xrTableCell_8.Width = Convert.ToInt32(xrTableRow3.Width * 0.2);
xrTableCell_8.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_8.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_8.Text = "測試時間";
xrTableRow3.Cells.Add(xrTableCell_8);
XRTableCell xrTableCell_9 = new XRTableCell();
//xrTableCell_9.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.1), 25);
//xrTableCell_9.Size = new Size(83, 25);
xrTableCell_9.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
xrTableCell_9.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
xrTableCell_9.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_9.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_9.Text = "型別";
xrTableRow3.Cells.Add(xrTableCell_9);
xrTable3.Height = xrTable3.Height + 25;
xrTable3.Rows.Add(xrTableRow3);
int pagestemp = 0;
if (p * 34 > listResultData.Count)
{
pagestemp = listResultData.Count;
}
else
{
pagestemp = p * 34;
}
for (int j = n; j < pagestemp; j++)
{
num++;
n++;
TestResult tr2 = listResultData[j];
xrTable3.Height = xrTable3.Height + 25;
XRTableRow xrTableRow_3 = new XRTableRow();
xrTableRow_3.Size = xrTableRow3.Size;
// xrTable3.Rows.Add(xrTableRow_3);
xrTableRow_3.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableRow_3.BorderWidth = 1;
XRTableCell xrTableCell_31 = new XRTableCell();
xrTableCell_31.Size = xrTableCell_3.Size;
xrTableCell_31.Width = xrTableCell_3.Width;
xrTableCell_31.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_31.Text = num.ToString();
xrTableCell_31.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_31.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_31);
XRTableCell xrTableCell_41 = new XRTableCell();
xrTableCell_41.Size = xrTableCell_4.Size;
xrTableCell_41.Width = xrTableCell_4.Width;
xrTableCell_41.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_41.Text = tr2.Ammeter_id;
xrTableCell_41.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_41.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_41);
XRTableCell xrTableCell_51 = new XRTableCell();
xrTableCell_51.Size = xrTableCell_5.Size;
xrTableCell_51.Width = xrTableCell_5.Width;
xrTableCell_51.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_51.Text = tr2.Result;
xrTableCell_51.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_51.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_51);
//XRTableCell xrTableCell_61 = new XRTableCell();
//xrTableCell_61.Size = xrTableCell_6.Size;
//xrTableCell_61.Width = xrTableCell_6.Width;
//xrTableCell_61.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
//xrTableCell_61.Text = tr2.Plan_id.ToString();
//xrTableCell_61.Borders = DevExpress.XtraPrinting.BorderSide.All;
//xrTableCell_61.BorderWidth = 1;
//xrTableRow_3.Cells.Add(xrTableCell_61);
XRTableCell xrTableCell_71 = new XRTableCell();
xrTableCell_71.Size = xrTableCell_7.Size;
xrTableCell_71.Width = xrTableCell_7.Width;
xrTableCell_71.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_71.Text = tr2.Test_item_string;
xrTableCell_71.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_71.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_71);
XRTableCell xrTableCell_81 = new XRTableCell();
xrTableCell_81.Size = xrTableCell_8.Size;
xrTableCell_81.Width = xrTableCell_8.Width;
xrTableCell_81.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_81.Text = tr2.Happen_time.ToString();
xrTableCell_81.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_81.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_81);
XRTableCell xrTableCell_91 = new XRTableCell();
xrTableCell_91.Size = xrTableCell_9.Size;
xrTableCell_91.Width = xrTableCell_9.Width;
xrTableCell_91.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_91.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_91.BorderWidth = 1;
if (tr2.Type.Equals("0100"))
{
xrTableCell_91.Text = "實時";
}
else if (tr2.Type.Equals("0200"))
{
xrTableCell_91.Text = "凍結(5min)";
}
else if (tr2.Type.Equals("0201"))
{
xrTableCell_91.Text = "凍結(15min)";
}
else if (tr2.Type.Equals("0202"))
{
xrTableCell_91.Text = "凍結(30min)";
}
else if (tr2.Type.Equals("0203"))
{
xrTableCell_91.Text = "凍結(60min)";
}
else if (tr2.Type.Equals("0204"))
{
xrTableCell_91.Text = "凍結(24h)";
}
else if (tr2.Type.Equals("0205"))
{
xrTableCell_91.Text = "凍結(1mon)";
}
xrTableRow_3.Cells.Add(xrTableCell_91);
xrTable3.Rows.Add(xrTableRow_3);
}
if (p == pages)
{
}
else
{
XRPageBreak xrPageBreak3 = new XRPageBreak();
Detail.Controls.Add(xrPageBreak3);
xrPageBreak3.Location = new Point(0, xrTable3.Location.Y + xrTable3.Height + 10);
tablex = 0;
tabley = xrTable3.Location.Y + xrTable3.Height + 60;
}
}
XRPageBreak xrPageBreak1 = new XRPageBreak();
Detail.Controls.Add(xrPageBreak1);
xrPageBreak1.Location = new Point(0, xrPanel4.Location.Y + xrPanel4.Height + 10);
}
}
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
setBody();
}
private void ReportHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
setTitle();
}
//得到最後一個控制元件的位置X
public int getX()
{
XRControlCollection ce = this.Detail.Controls;
XRControl obj = ce[ce.Count - 1];
return obj.Location.X;
}
//得到最後一個控制元件的位置Y
public int getY()
{
XRControlCollection ce = this.Detail.Controls;
int y = 8;
//for (int i = ce.Count - 1; i >= 0; i--)
//{
// XRControl obj = ce[i];
// if (obj.ToString() == "DevExpress.XtraReports.UI.XRPanel")
// {
// y = obj.Location.Y + obj.Size.Height+10;
// break;
// }
// //if (obj.ToString() == "DevExpress.XtraReports.UI.XRPageBreak")
// //{
// // y = obj.Location.Y;
// // break;
// //}
//}
if (ce != null && ce.Count > 0)
{
XRControl obj = ce[ce.Count - 1];
y = obj.Location.Y + obj.Size.Height + 10;
}
return y;
}
public int getHeadY()
{
XRControlCollection ce = this.Detail.Controls;
int y = 8;
for (int i = ce.Count - 1; i >= 0; i--)
{
XRControl obj = ce[i];
if (obj.ToString() == "DevExpress.XtraReports.UI.XRPanel")
{
y = obj.Location.Y + 25;
break;
}
//if (obj.ToString() == "DevExpress.XtraReports.UI.XRPageBreak")
//{
// y = obj.Location.Y;
// break;
//}
}
return y;
}
public int getXrPanel4Height(XRControl xrc)
{
XRControlCollection ce = xrc.Controls;
int y = 0;
for (int i = 0; i < ce.Count; i++)
{
y = y + ce[i].Location.Y + ce[i].Height;
}
return y + xrc.Location.Y;
}
}
}
在這資料就不上傳了,請大家根據需要自己更改資料來源
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
namespace DL698AmmeterTest.form
{
public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
private string _changShang;//廠商
private string _sn;//型號
private string _type;//型別
private string _songJianRen;//送檢人
private string _ceShiDanWei;//測試單位
private string _ceShiRen;//測試人
private TestPlan _testPlan;//測試計劃(批次)
private List<TestItem> _listTI;//測試項
private List<Ammeter> _listAmmeter;//測試結果
private ReportOptions ro = new ReportOptions();
public XtraReport1()
{
InitializeComponent();
}
public XtraReport1(TestPlan testPlan, List<TestItem> listTI, List<Ammeter> listAmmeter)
{
InitializeComponent();
this._testPlan = testPlan;
if (listTI != null && listTI.Count > 0)
{
this._listTI = listTI;
}
else
{
this._listTI = new List<TestItem>();
}
if (listAmmeter != null && listAmmeter.Count > 0)
{
this._listAmmeter = listAmmeter;
}
else
{
this._listAmmeter = new List<Ammeter>();
}
}
//設定標題
public void setTitle()
{
this.xrLabelTitle.Text = this._testPlan.Test_name;
}
public void setFoot()
{
}
public void setBody()
{
Int64 planid = this._testPlan.Id;
foreach (Ammeter ammeter in this._listAmmeter)
{
//建立panel1,並將label及表頭加入
XRPanel xrPanel1 = new XRPanel();
xrPanel1.Location = new Point(0, getY());
xrPanel1.Size = new Size(PageWidth - Margins.Left - Margins.Right, 42);
this.Detail.Controls.Add(xrPanel1);
XRLabel xrLabel1 = new XRLabel();
xrLabel1.Text = "電能表號:";
xrLabel1.Location = new Point(0, 8);
xrLabel1.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.13), 25);
xrLabel1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel1);
//填寫表號的label
XRLabel xrLabel2 = new XRLabel();
xrLabel2.Location = new Point(xrLabel1.Location.X + xrLabel1.Width, 8);
xrLabel2.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.2), 25);
xrLabel2.Text = ammeter.Ammeter_adc_id;
xrLabel2.Font = new Font("宋體", 10, FontStyle.Underline);
xrLabel2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel2);
XRLabel xrLabel3 = new XRLabel();
xrLabel3.Text = "送檢單位:";
xrLabel3.Location = new Point(xrLabel2.Location.X + xrLabel2.Width, 8);
xrLabel3.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.13), 25);
xrLabel3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel3);
//填寫送檢單位的label
XRLabel xrLabel4 = new XRLabel();
xrLabel4.Location = new Point(xrLabel3.Location.X + xrLabel3.Width, 8);
xrLabel4.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.23), 25);
xrLabel4.Text = this._testPlan.Comsumer_name;
xrLabel4.Font = new Font("宋體", 10, FontStyle.Underline);
xrLabel4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel4);
XRLabel xrLabel5 = new XRLabel();
xrLabel5.Text = "測試日期:";
xrLabel5.Location = new Point(xrLabel4.Location.X + xrLabel4.Width, 8);
xrLabel5.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.13), 25);
xrLabel5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel5);
//
XRLabel xrLabel6 = new XRLabel();
xrLabel6.Location = new Point(xrLabel5.Location.X + xrLabel5.Width, 8);
xrLabel6.Size = new Size(Convert.ToInt32(xrPanel1.Width * 0.18), 25);
xrLabel6.Text = this._testPlan.Test_time.Year + "年" + this._testPlan.Test_time.Month + "月" + this._testPlan.Test_time.Day + "日";
xrLabel6.Font = new Font("宋體", 10, FontStyle.Underline);
xrLabel6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel1.Controls.Add(xrLabel6);
//panel2,裝表格
XRPanel xrPanel2 = new XRPanel();
xrPanel2.Location = new Point(0, xrPanel1.Location.Y + 25);
xrPanel2.Size = new Size(xrPanel1.Width, 42);
this.Detail.Controls.Add(xrPanel2);
List<TestResult> listTr = ro.findByPlanIDAndAmmeterAdc_TestResult(planid, ammeter.Ammeter_adc_id);
List<TestData> listTd = new List<TestData>();
XRTable xrTable1 = new XRTable();
xrTable1.BorderWidth = 1;
xrTable1.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTable1.Location = new Point(0, 8);
// xrTable1.Size = new Size(xrPanel2.Width, 25*(listTr.Count+2)/3);
xrTable1.Size = new Size(xrPanel2.Width, 25);
//第一行,表頭
XRTableRow xrTableRow1 = new XRTableRow();
XRTableCell xrTableCell1 = new XRTableCell();
XRTableCell xrTableCell2 = new XRTableCell();
XRTableCell xrTableCell3 = new XRTableCell();
xrTableRow1.Size = new Size(xrTable1.Width, 25);
xrTableRow1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTable1.Rows.Add(xrTableRow1);
//第一行,第一列
xrTableCell1.Size = new Size(Convert.ToInt32(xrTableRow1.Width * 0.4), 25);
xrTableCell1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell1.Font = new Font("宋體", 10, FontStyle.Bold);
xrTableCell1.Width = Convert.ToInt32(xrTableRow1.Width * 0.4);
xrTableCell1.Text = "抄收資料項";
//第一行,第二列
//XRTableCell xrTableCell2 = new XRTableCell();
xrTableCell2.Size = new Size(Convert.ToInt32(xrTableRow1.Width * 0.3), 25);
xrTableCell2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell2.Font = new Font("宋體", 10, FontStyle.Bold);
xrTableCell2.Width = Convert.ToInt32(xrTableRow1.Width * 0.3);
xrTableCell2.Text = "抄收實時資料";
//第一行,第三列
//XRTableCell xrTableCell3 = new XRTableCell();
xrTableCell3.Size = new Size(Convert.ToInt32(xrTableRow1.Width * 0.3), 25);
xrTableCell3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell3.Font = new Font("宋體", 10, FontStyle.Bold);
xrTableCell3.Width = Convert.ToInt32(xrTableRow1.Width * 0.3);
xrTableCell3.Text = "抄收凍結資料";
xrTableRow1.Cells.Add(xrTableCell1);
xrTableRow1.Cells.Add(xrTableCell2);
xrTableRow1.Cells.Add(xrTableCell3);
foreach (TestItem testItem in this._listTI)
{
TestData td = new TestData();
td.Test_item = testItem.Name;
td.Result1 = "電能表沒有該功能";
td.Result2 = "電能表沒有該功能";
listTd.Add(td);
foreach (TestResult testResult in listTr)
{
if (testItem.Id == testResult.Test_item_id)
{
foreach (TestData td1 in listTd)
{
if (td1.Test_item == testItem.Name)
{
if (testResult.Type.Substring(0,2)=="01")
{
td1.Result1 = "通過";
}
else if (testResult.Type.Substring(0,2) == "02")
{
td1.Result2 = "通過";
}
}
}
}
}
}
foreach (TestData testData in listTd)
{
xrTable1.Height = xrTable1.Height + 25;
XRTableRow xrTableRow2 = new XRTableRow();
xrTableRow2.Size = xrTableRow1.Size;
XRTableCell xrTableCell4 = new XRTableCell();
xrTableCell4.Size = xrTableCell1.Size;
xrTableCell4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrTableCell4.Width = xrTableCell1.Width;
xrTableCell4.Text = testData.Test_item;
xrTableRow2.Cells.Add(xrTableCell4);
XRTableCell xrTableCell5 = new XRTableCell();
xrTableCell5.Size = xrTableCell2.Size;
xrTableCell5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrTableCell5.Width = xrTableCell2.Width;
xrTableCell5.Text = testData.Result1;
xrTableRow2.Cells.Add(xrTableCell5);
XRTableCell xrTableCell6 = new XRTableCell();
xrTableCell6.Size = xrTableCell3.Size;
xrTableCell6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrTableCell6.Width = xrTableCell3.Width;
xrTableCell6.Text = testData.Result2;
xrTableRow2.Cells.Add(xrTableCell6);
//xrTable1.Rows.AddRange(new XRTableRow[] { xrTableRow2 });
xrTable1.Rows.Add(xrTableRow2);
}
xrPanel2.Controls.Add(xrTable1);
//panel3,裝表底
XRPanel xrPanel3 = new XRPanel();
xrPanel3.Location = new Point(0, xrPanel2.Location.Y + xrPanel2.Height + 10);
xrPanel3.Size = new Size(xrPanel2.Width, 150);
XRLabel xrLabel8 = new XRLabel();
xrLabel8.Text = "(具體的抄收資料報文、解析資料作為附錄)";
xrLabel8.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrLabel8.Location = new Point(0, 0);
xrLabel8.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.6), 25);
xrPanel3.Controls.Add(xrLabel8);
XRLabel xrLabel9 = new XRLabel();
xrLabel9.Text = "測試人員:";
xrLabel9.Location = new Point(308, 33);
xrLabel9.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.2), 25);
xrLabel9.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel3.Controls.Add(xrLabel9);
XRLabel xrLabel10 = new XRLabel();
xrLabel10.Text = "測試單位: (蓋章有效)";
xrLabel10.Location = new Point(308, 75);
xrLabel10.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.3), 25);
xrLabel10.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel3.Controls.Add(xrLabel10);
XRLabel xrLabel11 = new XRLabel();
xrLabel11.Text = "日 期:";
xrLabel11.Location = new Point(308, 117);
xrLabel11.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrLabel11.Size = new Size(Convert.ToInt32(xrPanel3.Width * 0.3), 25);
xrPanel3.Controls.Add(xrLabel11);
this.Detail.Controls.Add(xrPanel3);
XRPageBreak xrPageBreak0 = new XRPageBreak();
Detail.Controls.Add(xrPageBreak0);
xrPageBreak0.Location = new Point(0, xrPanel3.Location.Y + xrPanel3.Height + 10);
//附抄收資料結果
//sql:select t1.id , t1.ammeter_id,t1.result,t1.plant_id, t2.name as test_item,t1.happen_time from test_result as t1 join test_item as t2 on t1.test_item=t2.id
//SELECT t1.ID, t1.AMMETER_ID, t1.RESULT, t1.PLANT_ID, t2.NAME AS Test_Item, t1.HAPPEN_TIME FROM TEST_RESULT AS t1 INNER JOINTEST_ITEM AS t2 ON t1.TEST_ITEM = t2.ID WHERE (t1.PLANT_ID = 1) AND (t1.AMMETER_ID = '000000000011')
//panel4,裝附加資訊
XRPanel xrPanel4 = new XRPanel();
xrPanel4.Location = new Point(0, xrPageBreak0.Location.Y);
xrPanel4.Size = new Size(xrPanel3.Width, 42);
this.Detail.Controls.Add(xrPanel4);
List<TestResult> listResultData = ro.findTestResult1(planid, ammeter.Ammeter_adc_id);
XRLabel xrLabelf = new XRLabel();
xrLabelf.Text = "附表:";
xrLabelf.Location = new Point(0, 0);
xrLabelf.Size = new Size(83, 25);
xrLabelf.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
xrPanel4.Controls.Add(xrLabelf);
int pages = 0;
if (listResultData.Count % 34 == 0)
{
pages = listResultData.Count / 34;
}
else
{
pages = listResultData.Count / 34 + 1;
}
int num = 0;
int tablex = 0;
int tabley = 30;
int n = 0;
for (int p = 1; p <= pages; p++)
{
XRTable xrTable3 = new XRTable();
xrTable3.Location = new Point(tablex, tabley);
//xrTable3.Size = new Size(xrPanel4.Width, 25 * (listResultData.Count + 6) / 7);
xrTable3.Size = new Size(xrPanel4.Width, 25);
xrTable3.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTable3.BorderWidth = 1;
xrTable3.Font = new Font("宋體", 8);
xrPanel4.Controls.Add(xrTable3);
XRTableRow xrTableRow3 = new XRTableRow();
xrTableRow3.Size = new Size(xrTable3.Width, 25);
//xrTable3.Rows.Add(xrTableRow3);
XRTableCell xrTableCell_3 = new XRTableCell();
xrTableCell_3.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.05), 25);
//xrTableCell_3.Size = new Size(83, 25);
// xrTableCell_3.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
xrTableCell_3.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_3.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_3.Text = "編號";
xrTableRow3.Cells.Add(xrTableCell_3);
XRTableCell xrTableCell_4 = new XRTableCell();
xrTableCell_4.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.15), 25);
//xrTableCell_4.Size = new Size(165, 25);
//xrTableCell_4.Width = Convert.ToInt32(xrTableRow3.Width * 0.2);
xrTableCell_4.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_4.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_4.Text = "電能表編號";
xrTableRow3.Cells.Add(xrTableCell_4);
XRTableCell xrTableCell_5 = new XRTableCell();
xrTableCell_5.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
//xrTableCell_5.Size = new Size(83, 25);
//xrTableCell_5.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
xrTableCell_5.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_5.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_5.Text = "抄收結果";
xrTableRow3.Cells.Add(xrTableCell_5);
//XRTableCell xrTableCell_6 = new XRTableCell();
//xrTableCell_6.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.1), 25);
////xrTableCell_6.Size = new Size(83, 25);
//// xrTableCell_6.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
//xrTableCell_6.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
//xrTableCell_6.Font = new Font("宋體", 10, FontStyle.Bold);
//xrTableCell_6.Text = "計劃批次";
//xrTableRow3.Cells.Add(xrTableCell_6);
XRTableCell xrTableCell_7 = new XRTableCell();
xrTableCell_7.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
//xrTableCell_7.Size = new Size(165, 25);
//xrTableCell_7.Width = Convert.ToInt32(xrTableRow3.Width * 0.2);
xrTableCell_7.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_7.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_7.Text = "測試專案";
xrTableRow3.Cells.Add(xrTableCell_7);
XRTableCell xrTableCell_8 = new XRTableCell();
xrTableCell_8.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
//xrTableCell_8.Size = new Size(165, 25);
//xrTableCell_8.Width = Convert.ToInt32(xrTableRow3.Width * 0.2);
xrTableCell_8.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_8.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_8.Text = "測試時間";
xrTableRow3.Cells.Add(xrTableCell_8);
XRTableCell xrTableCell_9 = new XRTableCell();
//xrTableCell_9.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.1), 25);
//xrTableCell_9.Size = new Size(83, 25);
xrTableCell_9.Size = new Size(Convert.ToInt32(xrTableRow3.Width * 0.2), 25);
xrTableCell_9.Width = Convert.ToInt32(xrTableRow3.Width * 0.1);
xrTableCell_9.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_9.Font = new Font("宋體", 8, FontStyle.Bold);
xrTableCell_9.Text = "型別";
xrTableRow3.Cells.Add(xrTableCell_9);
xrTable3.Height = xrTable3.Height + 25;
xrTable3.Rows.Add(xrTableRow3);
int pagestemp = 0;
if (p * 34 > listResultData.Count)
{
pagestemp = listResultData.Count;
}
else
{
pagestemp = p * 34;
}
for (int j = n; j < pagestemp; j++)
{
num++;
n++;
TestResult tr2 = listResultData[j];
xrTable3.Height = xrTable3.Height + 25;
XRTableRow xrTableRow_3 = new XRTableRow();
xrTableRow_3.Size = xrTableRow3.Size;
// xrTable3.Rows.Add(xrTableRow_3);
xrTableRow_3.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableRow_3.BorderWidth = 1;
XRTableCell xrTableCell_31 = new XRTableCell();
xrTableCell_31.Size = xrTableCell_3.Size;
xrTableCell_31.Width = xrTableCell_3.Width;
xrTableCell_31.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_31.Text = num.ToString();
xrTableCell_31.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_31.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_31);
XRTableCell xrTableCell_41 = new XRTableCell();
xrTableCell_41.Size = xrTableCell_4.Size;
xrTableCell_41.Width = xrTableCell_4.Width;
xrTableCell_41.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_41.Text = tr2.Ammeter_id;
xrTableCell_41.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_41.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_41);
XRTableCell xrTableCell_51 = new XRTableCell();
xrTableCell_51.Size = xrTableCell_5.Size;
xrTableCell_51.Width = xrTableCell_5.Width;
xrTableCell_51.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_51.Text = tr2.Result;
xrTableCell_51.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_51.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_51);
//XRTableCell xrTableCell_61 = new XRTableCell();
//xrTableCell_61.Size = xrTableCell_6.Size;
//xrTableCell_61.Width = xrTableCell_6.Width;
//xrTableCell_61.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
//xrTableCell_61.Text = tr2.Plan_id.ToString();
//xrTableCell_61.Borders = DevExpress.XtraPrinting.BorderSide.All;
//xrTableCell_61.BorderWidth = 1;
//xrTableRow_3.Cells.Add(xrTableCell_61);
XRTableCell xrTableCell_71 = new XRTableCell();
xrTableCell_71.Size = xrTableCell_7.Size;
xrTableCell_71.Width = xrTableCell_7.Width;
xrTableCell_71.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_71.Text = tr2.Test_item_string;
xrTableCell_71.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_71.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_71);
XRTableCell xrTableCell_81 = new XRTableCell();
xrTableCell_81.Size = xrTableCell_8.Size;
xrTableCell_81.Width = xrTableCell_8.Width;
xrTableCell_81.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_81.Text = tr2.Happen_time.ToString();
xrTableCell_81.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_81.BorderWidth = 1;
xrTableRow_3.Cells.Add(xrTableCell_81);
XRTableCell xrTableCell_91 = new XRTableCell();
xrTableCell_91.Size = xrTableCell_9.Size;
xrTableCell_91.Width = xrTableCell_9.Width;
xrTableCell_91.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
xrTableCell_91.Borders = DevExpress.XtraPrinting.BorderSide.All;
xrTableCell_91.BorderWidth = 1;
if (tr2.Type.Equals("0100"))
{
xrTableCell_91.Text = "實時";
}
else if (tr2.Type.Equals("0200"))
{
xrTableCell_91.Text = "凍結(5min)";
}
else if (tr2.Type.Equals("0201"))
{
xrTableCell_91.Text = "凍結(15min)";
}
else if (tr2.Type.Equals("0202"))
{
xrTableCell_91.Text = "凍結(30min)";
}
else if (tr2.Type.Equals("0203"))
{
xrTableCell_91.Text = "凍結(60min)";
}
else if (tr2.Type.Equals("0204"))
{
xrTableCell_91.Text = "凍結(24h)";
}
else if (tr2.Type.Equals("0205"))
{
xrTableCell_91.Text = "凍結(1mon)";
}
xrTableRow_3.Cells.Add(xrTableCell_91);
xrTable3.Rows.Add(xrTableRow_3);
}
if (p == pages)
{
}
else
{
XRPageBreak xrPageBreak3 = new XRPageBreak();
Detail.Controls.Add(xrPageBreak3);
xrPageBreak3.Location = new Point(0, xrTable3.Location.Y + xrTable3.Height + 10);
tablex = 0;
tabley = xrTable3.Location.Y + xrTable3.Height + 60;
}
}
XRPageBreak xrPageBreak1 = new XRPageBreak();
Detail.Controls.Add(xrPageBreak1);
xrPageBreak1.Location = new Point(0, xrPanel4.Location.Y + xrPanel4.Height + 10);
}
}
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
setBody();
}
private void ReportHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
setTitle();
}
//得到最後一個控制元件的位置X
public int getX()
{
XRControlCollection ce = this.Detail.Controls;
XRControl obj = ce[ce.Count - 1];
return obj.Location.X;
}
//得到最後一個控制元件的位置Y
public int getY()
{
XRControlCollection ce = this.Detail.Controls;
int y = 8;
//for (int i = ce.Count - 1; i >= 0; i--)
//{
// XRControl obj = ce[i];
// if (obj.ToString() == "DevExpress.XtraReports.UI.XRPanel")
// {
// y = obj.Location.Y + obj.Size.Height+10;
// break;
// }
// //if (obj.ToString() == "DevExpress.XtraReports.UI.XRPageBreak")
// //{
// // y = obj.Location.Y;
// // break;
// //}
//}
if (ce != null && ce.Count > 0)
{
XRControl obj = ce[ce.Count - 1];
y = obj.Location.Y + obj.Size.Height + 10;
}
return y;
}
public int getHeadY()
{
XRControlCollection ce = this.Detail.Controls;
int y = 8;
for (int i = ce.Count - 1; i >= 0; i--)
{
XRControl obj = ce[i];
if (obj.ToString() == "DevExpress.XtraReports.UI.XRPanel")
{
y = obj.Location.Y + 25;
break;
}
//if (obj.ToString() == "DevExpress.XtraReports.UI.XRPageBreak")
//{
// y = obj.Location.Y;
// break;
//}
}
return y;
}
public int getXrPanel4Height(XRControl xrc)
{
XRControlCollection ce = xrc.Controls;
int y = 0;
for (int i = 0; i < ce.Count; i++)
{
y = y + ce[i].Location.Y + ce[i].Height;
}
return y + xrc.Location.Y;
}
}
}
在這資料就不上傳了,請大家根據需要自己更改資料來源