|
@ -1,5 +1,6 @@ |
|
|
using BarcodeLib; |
|
|
using BarcodeLib; |
|
|
using BBWY.Client.APIServices; |
|
|
using BBWY.Client.APIServices; |
|
|
|
|
|
using BBWY.Client.Helpers; |
|
|
using BBWY.Client.ViewModels; |
|
|
using BBWY.Client.ViewModels; |
|
|
using BBWY.Client.ViewModels.PackTask; |
|
|
using BBWY.Client.ViewModels.PackTask; |
|
|
using BBWY.Controls; |
|
|
using BBWY.Controls; |
|
@ -50,9 +51,8 @@ namespace BBWY.Client.Views.PackTask |
|
|
MessageBox.Show("打印机处于错误状态"); |
|
|
MessageBox.Show("打印机处于错误状态"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
//Print(this.printArea, cbPrintName.Text, "打印任务",1);
|
|
|
|
|
|
|
|
|
MyPrintHelper.SetDefaultPrint(printName);//设置默认打印机
|
|
|
|
|
|
|
|
|
this.printArea.Arrange(new Rect(new Point(0, 0), new Size(printArea.ActualWidth, printArea.ActualHeight))); |
|
|
this.printArea.Arrange(new Rect(new Point(0, 0), new Size(printArea.ActualWidth, printArea.ActualHeight))); |
|
|
|
|
|
|
|
|
PrintDialog printDialog = new PrintDialog(); |
|
|
PrintDialog printDialog = new PrintDialog(); |
|
@ -76,99 +76,7 @@ namespace BBWY.Client.Views.PackTask |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打印
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="document">流文档</param>
|
|
|
|
|
|
/// <param name="printer">打印机名称</param>
|
|
|
|
|
|
/// <param name="description">打印描述</param>
|
|
|
|
|
|
/// <param name="copyCount">打印个数</param>
|
|
|
|
|
|
public static void Print(Visual document, string printer, string description, int copyCount) |
|
|
|
|
|
{ |
|
|
|
|
|
var localPrintServer = new LocalPrintServer(); |
|
|
|
|
|
var printQueue = localPrintServer.GetPrintQueue(printer); |
|
|
|
|
|
if (printQueue.IsInError) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new Exception("打印机处于错误状态"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var printDialog = new PrintDialog |
|
|
|
|
|
{ |
|
|
|
|
|
PrintQueue = printQueue, //打印队列
|
|
|
|
|
|
PrintTicket = { CopyCount = copyCount } //打印个数
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//设置纸张大小
|
|
|
|
|
|
var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth); //小标签:114
|
|
|
|
|
|
var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight); //小标签:227
|
|
|
|
|
|
printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight); |
|
|
|
|
|
|
|
|
|
|
|
//设置纸张边距
|
|
|
|
|
|
var paperSize = GetPaperSize(printer); //小标签:118*246
|
|
|
|
|
|
//var offsetX = (int)Math.Ceiling((paperSize.Width - pageWidth) / 2f);
|
|
|
|
|
|
//var offsetY = (int)Math.Ceiling((paperSize.Height - pageHeight) / 2f);
|
|
|
|
|
|
//document.PagePadding = new Thickness(offsetX, offsetY, offsetX, offsetY);
|
|
|
|
|
|
|
|
|
|
|
|
//打印
|
|
|
|
|
|
var paginator = ((IDocumentPaginatorSource)document).DocumentPaginator; |
|
|
|
|
|
printDialog.PrintDocument(paginator, description); |
|
|
|
|
|
|
|
|
|
|
|
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); |
|
|
|
|
|
string printNames = System.IO.Path.Combine(applicationPath, "printName.init"); |
|
|
|
|
|
File.WriteAllText(printNames, printer); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static object GetPaperSize(string printer) |
|
|
|
|
|
{ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public interface IDocumentRenderer |
|
|
|
|
|
{ |
|
|
|
|
|
void Render(FlowDocument doc, object data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class CommonDocumentRenderer : IDocumentRenderer |
|
|
|
|
|
{ |
|
|
|
|
|
public void Render(FlowDocument doc, object data) |
|
|
|
|
|
{ |
|
|
|
|
|
var model = data as PrintModel; |
|
|
|
|
|
if (model == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentException("data is not PrintModel"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var type = typeof(PrintModel); |
|
|
|
|
|
var properties = type.GetProperties(); |
|
|
|
|
|
foreach (var property in properties) |
|
|
|
|
|
{ |
|
|
|
|
|
//文本赋值
|
|
|
|
|
|
if (doc.FindName(property.Name) is TextBlock textBlock) |
|
|
|
|
|
{ |
|
|
|
|
|
textBlock.Text = property.GetValue(model)?.ToString(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class PrintModel |
|
|
|
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批号
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string BatchNumber { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 订单号
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string OrderNumber { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 物料代码
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string MaterialNumber { get; set; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|