步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
9.3 KiB

using BBWY.Client.Extensions;
using BBWY.Client.Helpers;
2 years ago
using BBWY.Client.Models;
using BBWY.Client.ViewModels.PackTask;
using BBWY.Client.Views.PackagingTask;
2 years ago
using BBWY.Controls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
2 years ago
using System.IO;
using System.Linq;
using System.Net.Http;
2 years ago
using System.Printing;
using System.Reflection;
using System.Security.Policy;
2 years ago
using System.Text;
using System.Threading.Tasks;
2 years ago
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;
2 years ago
namespace BBWY.Client.Views.PackTask
{
/// <summary>
/// PackDetailWindow.xaml 的交互逻辑
/// </summary>
public partial class PackDetailWindow : BWindow
{
2 years ago
public PackDetailWindow(PackTaskModel model, Action reflashWindow)
{
InitializeComponent();
var serviceViewModel = this.DataContext as PackDetailViewModel;
if (model.Brand.IsNullOrEmpty())
{
if (model.BarCodeModel != null && !model.BarCodeModel.Brand.IsNullOrEmpty())
model.Brand = model.BarCodeModel.Brand;
else if (model.CertificateModel != null && model.CertificateModel.Any(c => c.Brand != null))
model.Brand = model.CertificateModel.FirstOrDefault(c => c.Brand != null)?.Brand;
}
if (model.BrandName.IsNullOrEmpty())
{
if (model.BarCodeModel != null && !model.BarCodeModel.BrandName.IsNullOrEmpty())
model.BrandName = model.BarCodeModel.BrandName;
else if (model.CertificateModel != null && model.CertificateModel.Any(c => c.BrandName != null))
model.BrandName = model.CertificateModel.FirstOrDefault(c => c.BrandName != null)?.BrandName;
}
2 years ago
if (model.BarCodeModel != null)
{
model.BarCodeModel.ShopName = model.ShopName;
}
serviceViewModel.PackTaskModel = model;
serviceViewModel.PackTaskList = new System.Collections.ObjectModel.ObservableCollection<PackTaskModel> { model };
2 years ago
serviceViewModel.FloorDragNumber = model.FloorDragNumber;
serviceViewModel.TaskCount = model.SkuCount;
serviceViewModel.TaskId = model.TaskId;
serviceViewModel.OrderId = model.OrderId;
serviceViewModel.SkuId = model.SkuId;
serviceViewModel.PackUserName = model.PackUser?.Replace("\r\n", ",")?.Replace("\n", ",")?.Replace("\r", ",");
serviceViewModel.ProcessComboName = model.FeesItemResponse?.ProcessComboName;
serviceViewModel.PackCompletionOverTime = model.PackCompletionOverTime;
serviceViewModel.ConsumableNameList = model.FeesItemResponse?.ConsumableList?.Select(c =>
{
return $"{c.ItemName}";
})?.ToList();
serviceViewModel.PackerFee = model.FeesItemResponse?.PackFees * (model.FeesItemResponse?.PackerDiscount ?? 0.85m);
2 years ago
serviceViewModel.LoadPackDatas();
if (reflashWindow != null)
serviceViewModel.ReflashWindow = reflashWindow;
// DownloadImags(model.ItemList[0].Logo.Replace("80x80", "500x500"));
LoadImage(model.ItemList[0].Logo.Replace("80x80", "200x200"));
2 years ago
}
//PackTaskModel model = new PackTaskModel();
///// <summary>
///// 图片
///// </summary>
//public BitmapImage LogoImage { get; set; }
2 years ago
private void BButton_Click(object sender, RoutedEventArgs e)
{
//PrintPackTaskDetail printWindow = new PrintPackTaskDetail(model);
//if (printWindow==null)
//{
// MessageBox.Show("页面加载中,请重试!");
// return;
//}
//string printName = cbPrintName.Text.Trim();
//PrintBox(printName);
//var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//string printNames = System.IO.Path.Combine(applicationPath, "printName.init");
//try
//{
// if (File.Exists(printNames))
// {
// File.Delete(printNames);
// }
//}
//catch
//{
//}
//File.WriteAllText(printNames, cbPrintName.Text);
//var serviceViewModel = this.DataContext as PackDetailViewModel;
//serviceViewModel?.ReflashWindow?.Invoke();
return;
}
public void PrintBox(string printName)
{
//PrintData(1, printName, model);
//return;
var localPrintServer = new LocalPrintServer();
2 years ago
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为纵向 //设置纸张大小
2 years ago
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;
this.print_box.Arrange(new Rect(new System.Windows.Point(0, 0), new System.Windows.Size(pageWidth, pageHeight)));
this.UpdateLayout(); //刷新界面
printDialog.PrintVisual(this.print_box, "打印任务");
this.Close();
}
2 years ago
private async void LoadImage(string imageUrl)
{
2 years ago
try
{
using (HttpClient client = new HttpClient())
2 years ago
{
// 发送 HTTP 请求并获取图片数据
var uri = new Uri(Uri.EscapeUriString(imageUrl));
byte[] imageData = await client.GetByteArrayAsync(uri);
// 创建 BitmapImage 对象并设置图片数据
// 在 UI 线程上更新 Image 控件的 Source 属性
var LogoImage = imageData.ByteToBitmapImage();
img_logo.Source = LogoImage;
2 years ago
}
}
catch (Exception ex)
2 years ago
{
// 处理加载图片失败的异常
Console.WriteLine("加载图片失败:" + ex.Message);
}
}
private void DownloadImags(string url)
{
var client = new HttpClient();
var uri = new Uri(Uri.EscapeUriString(url));
byte[] urlContents = client.GetByteArrayAsync(uri).Result;
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string imagePath = System.IO.Path.Combine(applicationPath, "123.bmp");
if (File.Exists(imagePath))
{
File.Delete(imagePath);
2 years ago
}
using (System.IO.FileStream fs = new System.IO.FileStream(imagePath, System.IO.FileMode.CreateNew))
{
fs.Write(urlContents, 0, urlContents.Length);
}
BitmapImage img = new BitmapImage(new Uri(imagePath));
img_logo.Source = img;
this.UpdateLayout(); //刷新界面
}
private void PrintData(int printCount, string printName, PackTaskModel model)
{
try
{
PrintDocument document = new PrintDocument();
document.PrinterSettings.PrinterName = printName;//使用打印机名称,指定特定的打印机进行打印。
//设置打印页面
//document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 236, 157);
document.PrintPage += (s, a) =>
{
Font font = new Font("宋体", 6, System.Drawing.FontStyle.Regular);
MyPrintHelper.PrintPackDetail(model, ref a, font);
2 years ago
};
document.PrinterSettings.Copies = (short)printCount;//打印份数
document.Print();
2 years ago
}
catch (Exception ex)
{
App.Current.Dispatcher.Invoke(() =>
{
new TipsWindow($"打印失败,{ex.Message}").Show();
});
2 years ago
}
2 years ago
}
private void BButton_Click_1(object sender, RoutedEventArgs e)
{
var serviceViewModel = this.DataContext as PackDetailViewModel;
serviceViewModel.UpLoadPackCommand.Execute(this);
}
2 years ago
}
}