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.
178 lines
5.2 KiB
178 lines
5.2 KiB
using BBWY.Client.APIServices;
|
|
using BBWY.Client.Models.APIModel;
|
|
using BBWY.Client.Models.PackTask;
|
|
using BBWY.Controls;
|
|
using NPOI.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Drawing.Printing;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
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;
|
|
|
|
namespace BBWY.Client.Views.SealBox
|
|
{
|
|
/// <summary>
|
|
/// SealBoxPrintDetailsWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class SealBoxPrintDetailsWindow : BWindow
|
|
{
|
|
public SealBoxPrintDetailsWindow(SealBoxModel sealBox, SealBoxService sealBoxService)
|
|
{
|
|
InitializeComponent();
|
|
InitPrintList();
|
|
SealBoxModel = sealBox.Copy();
|
|
this.DataContext = this;
|
|
this.sealBoxService = sealBoxService;
|
|
}
|
|
/// <summary>
|
|
/// 打印机列表
|
|
/// </summary>
|
|
public ObservableCollection<string> PrintList { get; set; }
|
|
public void InitPrintList()
|
|
{
|
|
//TaskImage = MyPrintHelper.GetBarcodeImage(TaskId.ToString(), 300, 60);
|
|
|
|
//BarcodeImage = MyPrintHelper.GetBarcodeImage(SkuId, 300, 60);
|
|
|
|
|
|
|
|
|
|
PrintList = new ObservableCollection<string>();
|
|
var printingNames = PrinterSettings.InstalledPrinters;//获取本机的打印机数据
|
|
int index = -1;
|
|
int selectIndex = 0;
|
|
foreach (string name in printingNames)
|
|
{
|
|
if (name == "Microsoft XPS Document Writer" || name == "Microsoft Print to PDF" || name == "Fax")
|
|
{
|
|
continue;
|
|
}
|
|
index++;
|
|
if (name.Contains("Deli"))
|
|
{
|
|
selectIndex = index;
|
|
}
|
|
PrintList.Add(name);
|
|
}
|
|
try
|
|
{
|
|
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
string printNames = System.IO.Path.Combine(applicationPath, "printName.init");
|
|
if (File.Exists(printNames))
|
|
{
|
|
PrintName = File.ReadAllText(printNames);
|
|
}
|
|
else
|
|
{
|
|
if (PrintList.Count > 0)
|
|
{
|
|
PrintName = PrintList[0].ToString();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public string PrintName { get; set; }
|
|
public int PrintCount { get; set; } = 1;
|
|
|
|
|
|
/// <summary>
|
|
/// 封箱sku列表
|
|
/// </summary>
|
|
public SealBoxModel SealBoxModel { get; set; }
|
|
|
|
public string ShopName { get; set; }
|
|
public string WareName { get; set; }
|
|
|
|
public long SealBoxId { get; set; }
|
|
|
|
SealBoxService sealBoxService;
|
|
private void BButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
|
|
int limitIndex = 15;//单页限制数量
|
|
|
|
|
|
|
|
|
|
var res = sealBoxService.WareCompetePrintSealBox(SealBoxModel.SealBoxId);
|
|
|
|
if (res ==null|| !res.Success)
|
|
{
|
|
MessageBox.Show(res?.Msg);
|
|
return;
|
|
}
|
|
|
|
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
for (int i = 0; i < PrintCount; i++)//打印份数
|
|
{
|
|
again:
|
|
if (SealBoxModel.SealBoxSkus.Count > limitIndex)
|
|
{
|
|
PrintBox(SealBoxModel.SealBoxSkus.GetRange(0, limitIndex));
|
|
|
|
SealBoxModel.SealBoxSkus.RemoveRange(0, limitIndex);
|
|
goto again;
|
|
}
|
|
else
|
|
{
|
|
PrintBox(SealBoxModel.SealBoxSkus);
|
|
}
|
|
}
|
|
App.Current.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
this.Close();
|
|
}));
|
|
|
|
|
|
});
|
|
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);
|
|
}
|
|
File.WriteAllText(printNames, PrintName);
|
|
}
|
|
catch
|
|
{
|
|
|
|
|
|
}
|
|
}
|
|
|
|
public void PrintBox(List<WareSealBoxSku> sealBoxSkus)
|
|
{
|
|
App.Current.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
SealBoxPolicyDetailsWindow policyDetailsWindow = new SealBoxPolicyDetailsWindow(sealBoxSkus, SealBoxModel.ShopName, SealBoxModel.WareName, SealBoxModel.SealBoxId, SealBoxModel.AcceptUserName);
|
|
//policyDetailsWindow.Show();
|
|
policyDetailsWindow.PrintBox(PrintName);
|
|
}));
|
|
|
|
}
|
|
}
|
|
}
|
|
|