步步为盈
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.

117 lines
3.7 KiB

2 years ago
using BarcodeLib;
using BBWY.Client.APIServices;
2 years ago
using BBWY.Client.Helpers;
2 years ago
using BBWY.Client.Models;
2 years ago
using BBWY.Client.ViewModels;
2 years ago
using BBWY.Client.ViewModels.PackTask;
using BBWY.Controls;
2 years ago
using HandyControl.Controls;
2 years ago
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
2 years ago
using System.Drawing.Printing;
2 years ago
using System.IO;
using System.Printing;
using System.Reflection;
2 years ago
using System.Runtime.InteropServices;
2 years ago
using System.Runtime.InteropServices.WindowsRuntime;
2 years ago
using System.Text;
2 years ago
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;
namespace BBWY.Client.Views.PackTask
{
/// <summary>
/// ServiceWindow.xaml 的交互逻辑
/// </summary>
public partial class ServiceWindow : BWindow
{
2 years ago
public ServiceWindow(PackTaskModel model,Action reflashWindow)
2 years ago
{
InitializeComponent();
2 years ago
var serviceViewModel= this.DataContext as PackServiceViewModel;
//加载数据
if (model.BarCodeModel!=null)
{
model.BarCodeModel.ShopName= model.ShopName;
}
2 years ago
serviceViewModel.PackTaskModel = model;
serviceViewModel.PackTaskList = new System.Collections.ObjectModel.ObservableCollection<PackTaskModel> { model };
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.LoadPackDatas();
if (reflashWindow != null)
serviceViewModel.ReflashWindow = reflashWindow;
2 years ago
}
2 years ago
private void BButton_Click(object sender, RoutedEventArgs e)
{
var localPrintServer = new LocalPrintServer();
2 years ago
string printName = cbPrintName.Text.Trim();
if (string.IsNullOrEmpty(printName))
{
2 years ago
System.Windows.MessageBox.Show("选择打印机");
2 years ago
return;
}
var printQueue = localPrintServer.GetPrintQueue(printName);
2 years ago
if (printQueue.IsInError)
{
2 years ago
System.Windows.MessageBox.Show("打印机处于错误状态");
2 years ago
return;
}
MyPrintHelper.SetDefaultPrint(printName);//设置默认打印机
2 years ago
this.printArea.Arrange(new Rect(new Point(0, 0), new Size(printArea.ActualWidth, printArea.ActualHeight)));
2 years ago
System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
2 years ago
//设置纸张大小
var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth);
var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight);
printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight);
printDialog.PrintVisual(this.printArea, "打印任务");
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string printNames = System.IO.Path.Combine(applicationPath, "printName.init");
2 years ago
try
{
if (File.Exists(printNames))
{
File.Delete(printNames);
}
}
catch
{
}
2 years ago
File.WriteAllText(printNames, cbPrintName.Text);
}
2 years ago
}
}