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

111 lines
3.7 KiB

using BBWY.Client.APIServices;
using BBWY.Client.Helpers;
using BBWY.Client.Models;
using BBWY.Client.Models.FallWare;
using BBWY.Controls;
using HandyControl.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.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;
using WebSocketSharp;
namespace BBWY.Client.Views.FallWare
{
/// <summary>
/// SetJDWareBoxWindow.xaml 的交互逻辑
/// </summary>
public partial class SetJDWareBoxWindow : BWindow
{
public SetJDWareBoxWindow(JDWareBoxModel model)
{
JDWareBoxModel = model;
InitializeComponent();
PurchaseOrderImage= MyPrintHelper.GetBarcodeImageV2(model.PurchaseOrder, 420, 50);
PrewOrderImage = MyPrintHelper.GetBarcodeImageV2(model.PrewOrder, 350, 50);
this.DataContext =this;
}
public JDWareBoxModel JDWareBoxModel { get; set; }
/// <summary>
/// 采购单号条形码
/// </summary>
public BitmapImage PurchaseOrderImage { get; set; }
/// <summary>
/// 预约单号条形码
/// </summary>
public BitmapImage PrewOrderImage { get; set; }
public int PrintCount { get; set; } = 1;
public void PrintBox(string printName)
{
var localPrintServer = new LocalPrintServer();
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.Landscape;//设置为横向打印 PageOrientation.Landscape Portrait为纵向
for (int i = 1; i <= JDWareBoxModel.BoxCount; i++)
{
PrintCount = i;
//设置纸张大小
var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth);
var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight);
printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight);
this.Height = pageHeight + 39;
this.Width = pageWidth;
this.FontSize = 30;
this.jd_box.Arrange(new Rect(new Point(0, 0), new Size(pageWidth-100, pageHeight-200)));
//794 429 Width="478" Height="440"
//this.jd_box.Arrange(new Rect(new Point((pageWidth - jd_box.DesiredSize.Width) / 2, (pageHeight - jd_box.DesiredSize.Height) / 2), new Size(jd_box.DesiredSize.Width, jd_box.DesiredSize.Height)));
printDialog.PrintVisual(this.jd_box, "打印任务");
}
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string printNames = System.IO.Path.Combine(applicationPath, "printName.init");
if (File.Exists(printNames))
{
File.Delete(printNames);
}
System.IO.File.WriteAllText(printNames, printName);
this.Close();
}
}
}