using BBWY.Client.Helpers; using BBWY.Client.Models; using BBWY.Client.Models.FallWare; using System; using System.Collections.Generic; using System.Printing; using System.Reflection; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace BBWY.Client.Views.PackTask { /// /// PrintPackTaskDetail.xaml 的交互逻辑 /// public partial class PrintPackTaskDetail : Window { public PrintPackTaskDetail(PackTaskModel model) { InitializeComponent(); PackTaskModel = model; this.DataContext = this; this.UpdateLayout();//刷新UI } public PackTaskModel PackTaskModel { get; set; } public void PrintBox(string printName) { var localPrintServer = new LocalPrintServer(); if (string.IsNullOrEmpty(printName)) { return; } var printQueue = localPrintServer.GetPrintQueue(printName); if (printQueue.IsInError) { System.Windows.MessageBox.Show("打印机处于错误状态"); return; } MyPrintHelper.SetDefaultPrint(printName);//设置默认打印机 PrintDialog printDialog = new PrintDialog(); printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;//设置为横向打印 PageOrientation.Landscape Portrait为纵向 //设置纸张大小 var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth); var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight); printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight); this.Height = pageHeight + 39;//833 this.Width = pageWidth;//1123 this.FontSize = 30; // box_margin.Margin = new Thickness(50, 50, 50, 50); //box_margin.Margin = new Thickness(10); //this.jd_box.Arrange(new Rect(new Point(0, 0), new Size(pageWidth, pageHeight))); this.UpdateLayout(); //刷新界面 printDialog.PrintVisual(this.print_box, "打印任务"); //var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //string printNames = System.IO.Path.Combine(applicationPath, "printName.init"); //if (File.Exists(printNames)) //{ // File.Delete(printNames); //} //System.IO.File.WriteAllText(printNames, printName); this.Close(); } } }