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.
231 lines
6.6 KiB
231 lines
6.6 KiB
2 years ago
|
using BBWY.Client.APIServices.QiKu;
|
||
|
using BBWY.Client.Extensions;
|
||
|
using BBWY.Client.Models;
|
||
|
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.SomeArrival
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// PrintSomeArrivalWindow.xaml 的交互逻辑
|
||
|
/// </summary>
|
||
|
public partial class PrintSomeArrivalWindow : BWindow
|
||
|
{
|
||
|
public PrintSomeArrivalWindow(PackTaskAbortService packTaskAbortService, PackTaskModel model, Action reFlashWindow, List<string> shelvesNumberList, List<int> floorNumberList)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
InitPrintList();
|
||
|
this.DataContext = this;
|
||
|
this.model = model;
|
||
|
this.packTaskAbortService = packTaskAbortService;
|
||
|
|
||
|
if (!model.ShelvesNumber.IsNullOrEmpty())
|
||
|
ShelvesNumber = model.ShelvesNumber;
|
||
|
|
||
|
if (model.FloorNumber != null) FloorNumber = model.FloorNumber;
|
||
|
|
||
|
if (model.AbortRemark != null) RemarkMsg = model.AbortRemark;
|
||
|
FloorNumberList = floorNumberList;
|
||
|
ShelvesNumberList = shelvesNumberList;
|
||
|
ReFlashWindow = reFlashWindow;
|
||
|
}
|
||
|
|
||
|
|
||
|
private string remarkMsg;
|
||
|
/// <summary>
|
||
|
/// 货架
|
||
|
/// </summary>
|
||
|
public string RemarkMsg { get => remarkMsg; set { Set(ref remarkMsg, value); } }
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
Action ReFlashWindow;
|
||
|
PackTaskAbortService packTaskAbortService;
|
||
|
|
||
|
private List<int> floorNumberList = new List<int> { 1, 2, 3, 4 };
|
||
|
/// <summary>
|
||
|
/// 层数列表
|
||
|
/// </summary>
|
||
|
public List<int> FloorNumberList { get => floorNumberList; set { Set(ref floorNumberList, value); } }
|
||
|
|
||
|
private int? floorNumber;
|
||
|
/// <summary>
|
||
|
///层数
|
||
|
/// </summary>
|
||
|
public int? FloorNumber { get => floorNumber; set { Set(ref floorNumber, value); } }
|
||
|
|
||
|
|
||
|
private List<string> shelvesNumberList;
|
||
|
/// <summary>
|
||
|
/// 货架列表
|
||
|
/// </summary>
|
||
|
public List<string> ShelvesNumberList { get => shelvesNumberList; set { Set(ref shelvesNumberList, value); } }
|
||
|
|
||
|
private string shelvesNumber;
|
||
|
/// <summary>
|
||
|
/// 货架
|
||
|
/// </summary>
|
||
|
public string ShelvesNumber { get => shelvesNumber; set { Set(ref shelvesNumber, value); } }
|
||
|
|
||
|
|
||
|
|
||
|
private PackTaskModel model;
|
||
|
|
||
|
|
||
|
|
||
|
/// <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, "printName.init");
|
||
|
if (File.Exists(printNames))
|
||
|
{
|
||
|
PrintName = File.ReadAllText(printNames);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (PrintList.Count > 0)
|
||
|
{
|
||
|
PrintName = PrintList[0].ToString();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public void PrintBox()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
if (ShelvesNumber.IsNullOrEmpty() || FloorNumber==null )
|
||
|
{
|
||
|
MessageBox.Show("请输入摆放货架位置");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var res = packTaskAbortService.SaveTaskShelves(model.TaskId, ShelvesNumber, FloorNumber,remarkMsg);
|
||
|
|
||
|
if (res==null||!res.Success)
|
||
|
{
|
||
|
MessageBox.Show(res.Msg ?? "未知错误!");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
model.ShelvesNumber = ShelvesNumber;
|
||
|
model.FloorNumber = FloorNumber;
|
||
|
model.AbortRemark = RemarkMsg;
|
||
|
|
||
|
|
||
|
SomeArrivalWindow window = new SomeArrivalWindow(model);
|
||
|
//window.ShowDialog();
|
||
|
for (int i = 0; i < PrintCount; i++)
|
||
|
{
|
||
|
window.Print(PrintName);
|
||
|
}
|
||
|
this.Close();
|
||
|
|
||
|
ReFlashWindow?.Invoke();
|
||
|
|
||
|
|
||
|
try
|
||
|
{
|
||
|
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, PrintName);
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|