using CrystalDecisions.CrystalReports.Engine; using System; using System.Collections.Generic; using System.Drawing.Printing; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using TradeData; using TradeModel; namespace TradeManage.PrintTemplate { public partial class GoodPrint : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { PrintDocument prtdoc = new PrintDocument(); string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;//获取默认的打印机名 foreach (String strPrinter in PrinterSettings.InstalledPrinters) //在列表框中列出所有的打印机, { printerList.Items.Add(strPrinter); //if (strPrinter == strDefaultPrinter)//把默认打印机设为缺省值 //{ // printerList.SelectedIndex = printerList.Items.IndexOf(strPrinter); //} } //return; //string[] idarr = Request.QueryString["Detail"].ToString().Trim(',').Split(','); //if (!IsPostBack) //{ List gwplist = new List(); GoodWarePrint md = new GoodWarePrint(); if (Session["GoodWarePrint"] != null) gwplist = (List)Session["GoodWarePrint"]; //HuoWuData hwd = new HuoWuData(); //for (int i = 0; i < idarr.Length; i++) //{ // string[] goodstr = idarr[i].ToString().Split('-'); // int total = Convert.ToInt32(goodstr[goodstr.Length - 2].ToString()); // string wareno = goodstr[goodstr.Length - 1].ToString(); // for(int j=0;j gwplist = new List(); if (Session["GoodWarePrint"] != null) gwplist = (List)Session["GoodWarePrint"]; ReportDocument rptSales = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); rptSales.FileName = Server.MapPath("GoodBatch.rpt"); rptSales.SetDataSource(gwplist); //PrintDocument prtdoc = new PrintDocument(); //string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName; // then print, this is the important thing here //rptSales.PrintOptions.PrinterName = printerList.SelectedValue; //rptSales.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize; //rptSales.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Auto; //parameters here depending on your situation. rptSales.PrintToPrinter(1, true, 1, 9999); } } }