|
|
|
using BBWY.Client.Models;
|
|
|
|
using BBWY.Client.Views.PackTask;
|
|
|
|
using BBWY.Client.Views.SplitTask;
|
|
|
|
using BBWY.Controls;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Drawing.Printing;
|
|
|
|
using System.IO;
|
|
|
|
using System.Printing;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text;
|
|
|
|
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;
|
|
|
|
|
|
|
|
namespace BBWY.Client.Views.PackagingTask
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// PrintPackDetailWindow.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class PrintPackDetailWindow : BWindow
|
|
|
|
{
|
|
|
|
public PrintPackDetailWindow(PackDetailWindow printWindow)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
InitPrintList();
|
|
|
|
this.DataContext = this;
|
|
|
|
this.printWindow = printWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
private PackTaskModel model;
|
|
|
|
PackDetailWindow printWindow;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 打印机列表
|
|
|
|
/// </summary>
|
|
|
|
public ObservableCollection<string> PrintList { get; set; }
|
|
|
|
public string PrintName { get; set; }
|
|
|
|
public int PrintCount { get => printCount; set { Set(ref printCount, value); } }
|
|
|
|
private int printCount = 1;
|
|
|
|
|
|
|
|
|
|
|
|
public void InitPrintList()
|
|
|
|
{
|
|
|
|
|
|
|
|
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, "printPackDetailName.init");
|
|
|
|
if (File.Exists(printNames))
|
|
|
|
{
|
|
|
|
PrintName = File.ReadAllText(printNames);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PrintList.Count > 0)
|
|
|
|
{
|
|
|
|
PrintName = PrintList[0].ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void BButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (PrintName.IsNullOrEmpty())
|
|
|
|
{
|
|
|
|
MessageBox.Show("请选择打印设备");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(PrintName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var localPrintServer = new LocalPrintServer();
|
|
|
|
var printQueue = localPrintServer.GetPrintQueue(PrintName);
|
|
|
|
if (printQueue.IsInError)
|
|
|
|
{
|
|
|
|
System.Windows.MessageBox.Show("打印机处于错误状态");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < PrintCount; i++)
|
|
|
|
{
|
|
|
|
printWindow.PrintBox(PrintName);
|
|
|
|
}
|
|
|
|
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
string printNames = System.IO.Path.Combine(applicationPath, "printPackDetailName.init");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (File.Exists(printNames))
|
|
|
|
{
|
|
|
|
File.Delete(printNames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
File.WriteAllText(printNames, PrintName);
|
|
|
|
this.Close();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|