Winform (XtraReport) enables the printing method (reprint) (just self-referential to welcome you to the wrong place heavyweights come to exchange ideas)

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;

[csharp]  view plain  copy
 
 
 
  print ?
  1. using System;  
  2. using System.Drawing;  
  3. using System.Collections;  
  4. using System.ComponentModel;  
  5. using DevExpress.XtraReports.UI;  
  6. using System.Data;  
  7. using Zeda.AssistantClass;  
  8.   
  9. namespace LYWJMIS  
  10. {  
  11.     public partial class MyReport2 : DevExpress.XtraReports.UI.XtraReport  
  12.     {  
  13.         private DataRow drPur;  
  14.   
  15.         public MyReport2()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.         /// <summary>  
  20.         /// constructor arguments  
  21.         /// </summary>  
  22.         /// <param name = "drPur"> PO information </ param>  
  23.         public MyReport2(DataRow drPur)  
  24.             : this()  
  25.         {  
  26.             this.drPur = drPur;  
  27.             string sheetID = string.Empty;  
  28.             if (drPur == null) return;  
  29.             // binding purchase order information  
  30.             BindFormData (Drafur);  
  31.             // get the purchase order ID  
  32.             sheetID = drPur["ID"].ToString();  
  33.             // get the purchase order detail data set  
  34.             DataSet dsDetail = DataService.Instance.GetPurchaseSheetDetailInfoBySheetID(sheetID);  
  35.             // binding purchase order detail information  
  36.             BindTableData(dsDetail);  
  37.         }  
  38.         /// <summary>  
  39.         /// binding purchase order detail information  
  40.         /// </summary>  
  41.         private void BindTableData(DataSet ds)  
  42.         {  
  43.             // each column of the bound data set and a corresponding field XRTable  
  44.             this.xrTableCell1.DataBindings.Add ( "Text", ds,  "DB0137A"); // name DB0137A field name  
  45.             this.xrTableCell2.DataBindings.Add("Text", ds, "DB0152A");//规格  
  46.             this.xrTableCell3.DataBindings.Add("Text", ds, "DB0150A");//单位  
  47.             this.xrTableCell7.DataBindings.Add("Text", ds, "DB0151A");//产地  
  48.             this.xrTableCell8.DataBindings.Add("Text", ds, "DB0168A");//剂型  
  49.             this.xrTableCell9.DataBindings.Add ( "Text", ds,  "DB0183A"); // measurement specifications  
  50.             this.xrTableCell10.DataBindings.Add("Text", ds, "DB0188A", "{0:n2}");//进价  
  51.             this.xrTableCell11.DataBindings.Add("Text", ds, "DB0354A", "{0:f0}");//数量  
  52.             // Set this page Subtotal (Quantity Subtotal)  
  53.             this.xrTableCell23.DataBindings.Add("Text", ds, "DB0354A", "{0:f0}");//数量  
  54.             this.xrTableCell23.Summary = new XRSummary(SummaryRunning.Page, SummaryFunc.Sum, string.Empty);  
  55.             // Bind the total number of  
  56.             this.xrTableCell18.DataBindings.Add("Text", ds, "DB0354A", "{0:f0}");//数量  
  57.             this.xrTableCell18.Summary = new XRSummary(SummaryRunning.Group, SummaryFunc.Sum, string.Empty);  
  58.         }  
  59.        /// <summary>  
  60.         /// binding purchase order detail information  
  61.        /// </summary>  
  62.         private void BindFormData(DataRow dr)  
  63.         {  
  64.             DataSet ds = DataSetOperator.DataRowToDataSet(dr);  
  65.             // XRLabel bind data Method 1:  
  66.             this.txtDB0336A.Text = dr["DB0336A"].ToString();  
  67.             // XRLabel bind data Method 2:  
  68.             this.txtDB0337A.DataBindings.Add(new XRBinding("Text", ds, "DB0337A", "{0:yyyy-MM-dd}"));  
  69.             this.txtDB0005A.Text = dr["DB0005A"].ToString();  
  70.             this.txtDB0339A.Text = dr["DB0339A"].ToString();  
  71.             this.txtDB0345A.DataBindings.Add(new XRBinding("Text", ds, "DB0345A", "{0:n2}"));  
  72.             this.labPrintTime.Text = DateTime.Now.Date.ToString();  
  73.   
  74.         }  
  75.     }  
  76. }  

Call MyReport2 report class Print Preview

 

[csharp]  view plain  copy
 
 
 
  print ?
  1.  private void btnPrintReport_Click(object sender, EventArgs e)  
  2.         {  
  3.             DataRow dr = this.wgcPur.GridView1.GetFocusedDataRow();  
  4.             if (dr == null) return;  
  5.             MyReport2 rep = new MyReport2(dr);  
  6.             // set the paper type to Custom  
  7.             rep.PaperKind = System.Drawing.Printing.PaperKind.Custom;  
  8.             // set the paper size  
  9.             double width = 24.1 * 0.3937008 * Dpi.GetDeviceCapsX();  
  10.             double height = 9.3 * 0.3937008 * Dpi.GetDeviceCapsY();  
  11.             rep.PageSize = new System.Drawing.Size((int)width, (int)height);  
  12.             //Printing preview  
  13.             rep.ShowPreview();  
  14.         }  

 

 

 

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

Guess you like

Origin www.cnblogs.com/LiZhongZhongY/p/11589636.html