|
|
|
using BBWY.Client.Helpers;
|
|
|
|
using BBWY.Client.Models;
|
|
|
|
using BBWY.Controls;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Drawing.Printing;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
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.Interop;
|
|
|
|
using System.Windows.Media;
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
|
namespace BBWY.Client.Views.PackTask
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// PrintWindow.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class PrintWindow : BWindow
|
|
|
|
{
|
|
|
|
public PrintWindow()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
cbPrints.Items.Add(name);
|
|
|
|
}
|
|
|
|
if (cbPrints.Items.Count>selectIndex)
|
|
|
|
{
|
|
|
|
cbPrints.SelectedIndex = selectIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 加载预览打印数据
|
|
|
|
/// </summary>
|
|
|
|
public void LoadData()
|
|
|
|
{
|
|
|
|
if (CertificateModel==null)
|
|
|
|
{
|
|
|
|
cer.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cer.Visibility = Visibility.Visible;
|
|
|
|
bar.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
|
|
CertificateModel data = new CertificateModel
|
|
|
|
{
|
|
|
|
Brand = CertificateModel.Brand,
|
|
|
|
BrandName = CertificateModel.BrandName,
|
|
|
|
ExcuteStander = CertificateModel.ExcuteStander,
|
|
|
|
FactoryNumber = CertificateModel.FactoryNumber,
|
|
|
|
IsLogo =CertificateModel.IsLogo,
|
|
|
|
LabelModel = CertificateModel.LabelModel,
|
|
|
|
ProductAdress = CertificateModel.ProductAdress,
|
|
|
|
Id = CertificateModel.Id,
|
|
|
|
ProductDate = CertificateModel.ProductDate,
|
|
|
|
ProductNo = CertificateModel.ProductNo,
|
|
|
|
ProductShop = CertificateModel.ProductShop,
|
|
|
|
Shader = CertificateModel.Shader,
|
|
|
|
SkuId = CertificateModel.SkuId,
|
|
|
|
Reseller = CertificateModel.Reseller
|
|
|
|
|
|
|
|
};
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (data.ExcuteStander.Contains(","))//有逗号就拆分
|
|
|
|
{
|
|
|
|
var excutes = data.ExcuteStander.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
for (int i = 0; i < excutes.Count(); i++)
|
|
|
|
{
|
|
|
|
if (i % 2 == 0 && i > 0)//间隔两个换行
|
|
|
|
{
|
|
|
|
sb.Append("\r\n");
|
|
|
|
}
|
|
|
|
sb.Append(excutes[i]).Append(" ");
|
|
|
|
}
|
|
|
|
sb.Remove(sb.Length - 3, 3);
|
|
|
|
data.ExcuteStander = sb.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.DataContext = data;
|
|
|
|
if (data.IsLogo == 0)
|
|
|
|
{
|
|
|
|
is3c.Visibility = Visibility.Collapsed;
|
|
|
|
no3c.Visibility = Visibility.Visible;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is3c.Visibility = Visibility.Visible;
|
|
|
|
no3c.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (BarCodeModel == null)
|
|
|
|
{
|
|
|
|
bar.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bar.Visibility = Visibility.Visible;
|
|
|
|
cer.Visibility = Visibility.Collapsed;
|
|
|
|
this.DataContext = BarCodeModel;
|
|
|
|
if (BarCodeModel.LabelModel == BarcodeLabelModel.barsimplify)
|
|
|
|
{//精简版
|
|
|
|
jingjian.Visibility = Visibility.Visible;
|
|
|
|
biaozhun.Visibility = Visibility.Collapsed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jingjian.Visibility = Visibility.Collapsed;
|
|
|
|
biaozhun.Visibility = Visibility.Visible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public CertificateModel CertificateModel { get; set; }
|
|
|
|
|
|
|
|
public BarCodeModel BarCodeModel { get; set; }
|
|
|
|
|
|
|
|
private void BButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
|
|
|
|
int printCount = Convert.ToInt32(tbCount.Text);
|
|
|
|
string printName = cbPrints.Text;//选择的要打印的打印机名称
|
|
|
|
Task.Factory.StartNew(() => {
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PrintDocument pd = new PrintDocument();
|
|
|
|
PrintDocument document = new PrintDocument();
|
|
|
|
document.PrinterSettings.PrinterName = printName;
|
|
|
|
document.PrintPage += Document_PrintPage;
|
|
|
|
document.PrinterSettings.Copies = (short)printCount;//打印份数
|
|
|
|
document.Print();
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
App.Current.Dispatcher.Invoke(() => {
|
|
|
|
new TipsWindow("打印失败").ShowDialog();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Document_PrintPage(object sender, PrintPageEventArgs args)
|
|
|
|
{
|
|
|
|
//RectangleF bounds = new RectangleF(0, 0, 236, 157);
|
|
|
|
//args.Graphics.SetClip(bounds);//设置打印区域
|
|
|
|
|
|
|
|
Font font = new Font("宋体", 6, System.Drawing.FontStyle.Regular);
|
|
|
|
if (BarCodeModel != null)
|
|
|
|
{
|
|
|
|
MyPrintHelper.PrintBarcode(ref args, BarCodeModel, font);
|
|
|
|
}
|
|
|
|
if (CertificateModel !=null)
|
|
|
|
{
|
|
|
|
MyPrintHelper.PrintCertificate(ref args, CertificateModel, font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 打印条形码
|
|
|
|
/// </summary>
|
|
|
|
//private void PrintBarCode(string labelPath,int printNums,string PrintName)
|
|
|
|
//{
|
|
|
|
// BartenderHelper helper = new BartenderHelper();
|
|
|
|
// string msg = "";
|
|
|
|
// // File.AppendAllText("c:/1.txt", $"{PrintName}开始打印{printNums}份,{labelPath}");
|
|
|
|
// helper.BTPrint(labelPath, Datas, out msg, printNums, PrintName);
|
|
|
|
// // File.AppendAllText("c:/1.txt", "结束打印");
|
|
|
|
// //File.AppendAllText("c:/1.txt", msg);
|
|
|
|
// if (msg == "OK")
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// App.Current.Dispatcher.Invoke(new Action(() => {
|
|
|
|
// new TipsWindow(msg).ShowDialog();//打印失败提示
|
|
|
|
// }));
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|