|
|
@ -9,6 +9,8 @@ using System.Threading.Tasks; |
|
|
|
using System.Windows; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using BBWY.Client.Extensions; |
|
|
|
using System.Reflection; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
namespace BBWY.Client.Views.PackTask |
|
|
|
{ |
|
|
@ -20,21 +22,17 @@ namespace BBWY.Client.Views.PackTask |
|
|
|
public PrintWindow() |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
|
this.Loaded += PrintWindow_Loaded; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
InitPrintList(); |
|
|
|
this.DataContext = this; |
|
|
|
|
|
|
|
private void PrintWindow_Loaded(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
LoadPrints(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取打印机名称
|
|
|
|
/// </summary>
|
|
|
|
private void LoadPrints() |
|
|
|
public void InitPrintList() |
|
|
|
{ |
|
|
|
|
|
|
|
PrintList = new ObservableCollection<string>(); |
|
|
|
var printingNames = PrinterSettings.InstalledPrinters;//获取本机的打印机数据
|
|
|
|
int index = -1; |
|
|
|
int selectIndex = 0; |
|
|
@ -49,12 +47,30 @@ namespace BBWY.Client.Views.PackTask |
|
|
|
{ |
|
|
|
selectIndex = index; |
|
|
|
} |
|
|
|
cbPrints.Items.Add(name); |
|
|
|
PrintList.Add(name); |
|
|
|
} |
|
|
|
try |
|
|
|
{ |
|
|
|
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); |
|
|
|
string printNames = System.IO.Path.Combine(applicationPath, "handPrintBarCerName.init"); |
|
|
|
if (File.Exists(printNames)) |
|
|
|
{ |
|
|
|
PrintName = File.ReadAllText(printNames); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (PrintList.Count > 0) |
|
|
|
{ |
|
|
|
PrintName = PrintList[0].ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (cbPrints.Items.Count > selectIndex) |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
cbPrints.SelectedIndex = selectIndex; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -81,43 +97,59 @@ namespace BBWY.Client.Views.PackTask |
|
|
|
cer.Visibility = Visibility.Collapsed; |
|
|
|
bar.Visibility = Visibility.Visible; |
|
|
|
} |
|
|
|
this.DataContext = this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public CertificateModel[] CertificateModel { get; set; } |
|
|
|
private CertificateModel[] certificateModel; |
|
|
|
public CertificateModel[] CertificateModel { get => certificateModel; set { Set(ref certificateModel, value); } } |
|
|
|
|
|
|
|
public BarCodeModel BarCodeModel { get; set; } |
|
|
|
private BarCodeModel barCodeModel; |
|
|
|
public BarCodeModel BarCodeModel { get=> barCodeModel; set {Set(ref barCodeModel,value); } } |
|
|
|
|
|
|
|
private void BButton_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
int printCount = 0; |
|
|
|
try |
|
|
|
{ |
|
|
|
printCount = Convert.ToInt32(tbCount.Text); |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
new TipsWindow("请输入打印份数", 1).ShowDialog(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
string printName = cbPrints.Text;//选择的要打印的打印机名称
|
|
|
|
|
|
|
|
/// <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; |
|
|
|
|
|
|
|
private void BButton_Click(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
if (BarCodeModel != null) |
|
|
|
{ |
|
|
|
PrintData(printCount, printName,BarCodeModel); |
|
|
|
PrintData(PrintCount, PrintName,BarCodeModel); |
|
|
|
//MyPrintHelper.PrintBarcode(ref args, BarCodeModel, font);
|
|
|
|
} |
|
|
|
if (CertificateModel != null&& CertificateModel.Count()>0) |
|
|
|
{ |
|
|
|
foreach (var cer in CertificateModel) |
|
|
|
{ |
|
|
|
PrintData(printCount, printName,null,cer); |
|
|
|
PrintData(PrintCount, PrintName,null,cer); |
|
|
|
System.Threading.Thread.Sleep(100); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); |
|
|
|
string printNames = System.IO.Path.Combine(applicationPath, "handPrintBarCerName.init"); |
|
|
|
try |
|
|
|
{ |
|
|
|
if (File.Exists(printNames)) |
|
|
|
{ |
|
|
|
File.Delete(printNames); |
|
|
|
} |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
File.WriteAllText(printNames, PrintName); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|