using BBWY.Client.APIServices; using BBWY.Client.Helpers; using BBWY.Client.Models; using BBWY.Client.Models.FallWare; using BBWY.Controls; using HandyControl.Controls; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing.Printing; using System.IO; using System.Printing; using System.Reflection; using System.Text; using System.Threading.Tasks; 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; using WebSocketSharp; namespace BBWY.Client.Views.FallWare { /// /// SetJDWareBoxWindow.xaml 的交互逻辑 /// public partial class SetJDWareBoxWindow : BWindow { public SetJDWareBoxWindow(JDWareBoxModel model) { InitializeComponent(); JDWareBoxModel = model; PurchaseOrderImage = MyPrintHelper.GetBarcodeImageV2(model.PurchaseOrder, 420, 50); PrewOrderImage = MyPrintHelper.GetBarcodeImageV2(model.PrewOrder, 420, 50); this.DataContext =this; this.Dispatcher.Invoke(() => { tb_printcount.Text = "1"; }); this.UpdateLayout(); } public JDWareBoxModel JDWareBoxModel { get; set; } /// /// 采购单号条形码 /// public BitmapImage PurchaseOrderImage { get; set; } /// /// 预约单号条形码 /// public BitmapImage PrewOrderImage { 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.Portrait;//设置为横向打印 PageOrientation.Landscape Portrait为纵向 PrintDocument document = new PrintDocument(); document.PrinterSettings.PrinterName = printName; var pageWidth = document.DefaultPageSettings.Bounds.Size.Width; var pageHeight = document.DefaultPageSettings.Bounds.Size.Height; //设置纸张大小 //var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth); //var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight); printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight); var printAreaWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth);//打印区宽度 var printAreaHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight);//打印区高度 this.Height = pageHeight+39;//492 this.Width = pageWidth;//227 // this.FontSize = 30; box_margin.Margin = new Thickness(2); //box_margin.Margin = new Thickness(10); //this.jd_box.Arrange(new Rect(new Point((printAreaWidth- pageWidth)/2, (printAreaHeight- pageHeight)/2), new Size(pageWidth, pageHeight))); for (int i = 1; i <= JDWareBoxModel.BoxCount; i++) { this.Dispatcher.Invoke(() => { tb_printcount.Text =i.ToString(); }); this.UpdateLayout(); //刷新界面 printDialog.PrintVisual(this.jd_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(); } } }