|
|
|
using BBWY.Client.Extensions;
|
|
|
|
using BBWY.Client.Helpers;
|
|
|
|
using BBWY.Client.Models;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Printing;
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BBWY.Client.Views.PackTask
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// PrintPackTaskDetail.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class PrintPackTaskDetail : Window
|
|
|
|
{
|
|
|
|
public PrintPackTaskDetail(PackTaskModel model)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
PackTaskModel = model;
|
|
|
|
PackTaskModel.ItemList[0].Logo = PackTaskModel.ItemList[0].Logo.Replace("80*80", "110*110");
|
|
|
|
//LoadImage(model.ItemList[0].Logo);
|
|
|
|
BarcodeImage = MyPrintHelper.GetBarcodeImage(model.SkuId, 300, 60);
|
|
|
|
this.DataContext = this;
|
|
|
|
|
|
|
|
this.UpdateLayout();//刷新UI
|
|
|
|
}
|
|
|
|
public PackTaskModel PackTaskModel { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// skuid条形码
|
|
|
|
/// </summary>
|
|
|
|
public BitmapImage BarcodeImage { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 图片
|
|
|
|
/// </summary>
|
|
|
|
public BitmapImage LogoImage { 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.ReversePortrait;//设置为横向打印 PageOrientation.Landscape Portrait为纵向
|
|
|
|
//设置纸张大小
|
|
|
|
var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth);
|
|
|
|
var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight);
|
|
|
|
printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight);
|
|
|
|
print_box.Height = pageHeight;
|
|
|
|
print_box.Width = pageWidth;
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void LoadImage(string imageUrl)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
using (HttpClient client = new HttpClient())
|
|
|
|
{
|
|
|
|
// 发送 HTTP 请求并获取图片数据
|
|
|
|
byte[] imageData = await client.GetByteArrayAsync(imageUrl);
|
|
|
|
|
|
|
|
LogoImage= imageData.ByteToBitmapImage();
|
|
|
|
// 创建 BitmapImage 对象并设置图片数据
|
|
|
|
BitmapImage bitmapImage = new BitmapImage();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bitmapImage.BeginInit();
|
|
|
|
|
|
|
|
bitmapImage.StreamSource = new System.IO.MemoryStream(imageData);
|
|
|
|
bitmapImage.EndInit();
|
|
|
|
bitmapImage.Freeze();
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 在 UI 线程上更新 Image 控件的 Source 属性
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
LogoImage = bitmapImage;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
// 处理加载图片失败的异常
|
|
|
|
Console.WriteLine("加载图片失败:" + ex.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|