Winform (XtraReport) enables the printing method (reprint)
First create a new XtraReport class. According to the report need to design the page layout;
After the layout design is completed, write code to bind data;
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using DevExpress.XtraReports.UI;
- using System.Data;
- using Zeda.AssistantClass;
- namespace LYWJMIS
- {
- public partial class MyReport2 : DevExpress.XtraReports.UI.XtraReport
- {
- private DataRow drPur;
- public MyReport2()
- {
- InitializeComponent();
- }
- /// <summary>
- /// constructor arguments
- /// </summary>
- /// <param name = "drPur"> PO information </ param>
- public MyReport2(DataRow drPur)
- : this()
- {
- this.drPur = drPur;
- string sheetID = string.Empty;
- if (drPur == null) return;
- // binding purchase order information
- BindFormData (Drafur);
- // get the purchase order ID
- sheetID = drPur["ID"].ToString();
- // get the purchase order detail data set
- DataSet dsDetail = DataService.Instance.GetPurchaseSheetDetailInfoBySheetID(sheetID);
- // binding purchase order detail information
- BindTableData(dsDetail);
- }
- /// <summary>
- /// binding purchase order detail information
- /// </summary>
- private void BindTableData(DataSet ds)
- {
- // each column of the bound data set and a corresponding field XRTable
- this.xrTableCell1.DataBindings.Add ( "Text", ds, "DB0137A"); // name DB0137A field name
- this.xrTableCell2.DataBindings.Add("Text", ds, "DB0152A");//规格
- this.xrTableCell3.DataBindings.Add("Text", ds, "DB0150A");//单位
- this.xrTableCell7.DataBindings.Add("Text", ds, "DB0151A");//产地
- this.xrTableCell8.DataBindings.Add("Text", ds, "DB0168A");//剂型
- this.xrTableCell9.DataBindings.Add ( "Text", ds, "DB0183A"); // measurement specifications
- this.xrTableCell10.DataBindings.Add("Text", ds, "DB0188A", "{0:n2}");//进价
- this.xrTableCell11.DataBindings.Add("Text", ds, "DB0354A", "{0:f0}");//数量
- // Set this page Subtotal (Quantity Subtotal)
- this.xrTableCell23.DataBindings.Add("Text", ds, "DB0354A", "{0:f0}");//数量
- this.xrTableCell23.Summary = new XRSummary(SummaryRunning.Page, SummaryFunc.Sum, string.Empty);
- // Bind the total number of
- this.xrTableCell18.DataBindings.Add("Text", ds, "DB0354A", "{0:f0}");//数量
- this.xrTableCell18.Summary = new XRSummary(SummaryRunning.Group, SummaryFunc.Sum, string.Empty);
- }
- /// <summary>
- /// binding purchase order detail information
- /// </summary>
- private void BindFormData(DataRow dr)
- {
- DataSet ds = DataSetOperator.DataRowToDataSet(dr);
- // XRLabel bind data Method 1:
- this.txtDB0336A.Text = dr["DB0336A"].ToString();
- // XRLabel bind data Method 2:
- this.txtDB0337A.DataBindings.Add(new XRBinding("Text", ds, "DB0337A", "{0:yyyy-MM-dd}"));
- this.txtDB0005A.Text = dr["DB0005A"].ToString();
- this.txtDB0339A.Text = dr["DB0339A"].ToString();
- this.txtDB0345A.DataBindings.Add(new XRBinding("Text", ds, "DB0345A", "{0:n2}"));
- this.labPrintTime.Text = DateTime.Now.Date.ToString();
- }
- }
- }
Call MyReport2 report class Print Preview
- private void btnPrintReport_Click(object sender, EventArgs e)
- {
- DataRow dr = this.wgcPur.GridView1.GetFocusedDataRow();
- if (dr == null) return;
- MyReport2 rep = new MyReport2(dr);
- // set the paper type to Custom
- rep.PaperKind = System.Drawing.Printing.PaperKind.Custom;
- // set the paper size
- double width = 24.1 * 0.3937008 * Dpi.GetDeviceCapsX();
- double height = 9.3 * 0.3937008 * Dpi.GetDeviceCapsY();
- rep.PageSize = new System.Drawing.Size((int)width, (int)height);
- //Printing preview
- rep.ShowPreview();
- }
xrTableCell property:
- TextAlignment: setting cell shows alignment of content;
- Text: setting the character cell display;
- Styles-Style: styling unit;
- CanGrow: content setting unit is able to wrap. If set to true, then the content exceeds the length of the cell, will wrap the same time, the cell height is automatically increased;
- CanShrik: setting whether the height of the cell with scalable content;
- Borders: setting the display cell, down, left, and right borders.
XtraReport property:
- PaperKind: Set the type of paper to print the report;
- PageHeight: paper statements set height (unit: pixels). Note: Only when PaperKind = Custom time to set this property, otherwise invalid;
- The PageWidth: set the width of the paper (unit: pixels). Note: Only when PaperKind = Custom time to set this property, otherwise invalid;
- PageColor: set the background color of the report;
- Margins: Set paper margins;
- DefaultPrinterSettingsUsing: print report whether to apply the default printer's default settings (paper type, margins, etc.);
- UseMargins: If the value is true, the property Margins will be out of action;
- UsePaperKind: If the value is true, the property PerperKind, PageHeight, PageWidth would be removed;
- GroupFooter-RepeatEveryPage: If true, the footer of each page will be displayed; if false, then only the first page footer
Reprinted address: http: //blog.csdn.net/ljunqiang/article/details/39498171#comments