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.
180 lines
5.8 KiB
180 lines
5.8 KiB
using BBWY.Client.Helpers;
|
|
using BBWY.Client.Models;
|
|
using BBWY.Controls;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
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.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 - 4, 4);
|
|
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 path = Directory.GetCurrentDirectory()+ $"/Resources/LabelNames/{LabelName}.btw";
|
|
int printCount = Convert.ToInt32(tbCount.Text);
|
|
string printName =cbPrints.Text;
|
|
|
|
PrintBarCode(path,printCount,printName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
new TipsWindow("打印失败").ShowDialog();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印条形码
|
|
/// </summary>
|
|
private void PrintBarCode(string labelPath,int printNums,string PrintName)
|
|
{
|
|
BartenderHelper helper = new BartenderHelper();
|
|
string msg = "";
|
|
helper.BTPrint(labelPath, Datas, out msg, printNums, PrintName);
|
|
if (msg == "OK")
|
|
{
|
|
return;
|
|
}
|
|
new TipsWindow(msg).ShowDialog();//打印失败提示
|
|
|
|
}
|
|
}
|
|
}
|
|
|