|
|
|
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 = System.Drawing.Printing.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; }
|
|
|
|
|
|
|
|
public string LabelName { get; set; }
|
|
|
|
|
|
|
|
public Dictionary<string, string> Datas { get; set; }
|
|
|
|
|
|
|
|
private void BButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
|
|
//string path = appPath + $"/Resources/LabelNames/{LabelName}.btw";
|
|
|
|
|
|
|
|
int printCount = Convert.ToInt32(tbCount.Text);//份数
|
|
|
|
string printName = cbPrints.Text;//选择的要打印的打印机名称
|
|
|
|
PrintDocument pd = new PrintDocument();
|
|
|
|
PrintDocument document = new PrintDocument();
|
|
|
|
document.PrinterSettings.PrinterName = printName;
|
|
|
|
document.PrintPage += Document_PrintPage;
|
|
|
|
document.PrinterSettings.Copies = (short)printCount;//打印份数
|
|
|
|
document.Print();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Task.Factory.StartNew(() => {
|
|
|
|
// PrintBarCode(path, printCount, printName);
|
|
|
|
//});
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
new TipsWindow("打印失败").ShowDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Document_PrintPage(object sender, PrintPageEventArgs args)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
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();//打印失败提示
|
|
|
|
// }));
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|