using Aucma.Core.PrintTo.Common; using Aucma.Core.PrintTo.Models; using Aucma.Core.PrintTo.Views; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using FastReport; using log4net; using System.Threading.Tasks; using System.Windows; namespace Aucma.Core.PrintTo.ViewModels { public partial class SpecialPrintViewModel : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); public SpecialPrintViewModel(){ PrintNum = 0; } #region 打印 /// /// 打印 /// /// [RelayCommand] public Task Print() { string printer = "ZDesigner ZT411-300dpi ZPL"; string barCode = BarCode; for (int i = 0; i < PrintNum; i++) { //PrintCode(printer, barCode); } return Task.CompletedTask; } private static void PrintCode(string printer,string barCode) { //对接打印机 Report barReport = new Report(); barReport.Load(System.Environment.CurrentDirectory + @"\Report\MaterialBar.frx");//打印报表位置 // 设置打印机和打印选项 barReport.PrintSettings.ShowDialog = false; // 是否打开打印机选择框 barReport.PrintSettings.Printer = printer; // 设置打印机名称 barReport.PrintSettings.Copies = 1; // 设置打印份数 //barReport.PrintSettings.PageRange = "1-3"; // 设置打印页范围 barReport.SetParameterValue("BoxBarData.Order_No", "");//订单码 barReport.SetParameterValue("BoxBarData.Order_Material_Name", "");//物料名称 barReport.SetParameterValue("BoxBarData.Bar_Code", barCode);//二维码 //barReport.Prepare(); //string BarPath = System.Environment.CurrentDirectory + @"\pdf\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; //barReport.Export(new PDFExport(), BarPath); barReport.Print(); } #endregion #region 打印数量 private int printNum; public int PrintNum { get { return printNum; } set { printNum = value; SetProperty(ref printNum, value); } } #endregion #region 打印条码 private string barCode; public string BarCode { get { return barCode; } set { barCode = value; SetProperty(ref barCode, value); } } #endregion [RelayCommand] public void Close(object parameter) { var window = parameter as Window; if (window == null) return; // $"还有【{BarcodesUnprinted.Count}】个条码未打印。确定要退出打印?" if (MessageBox.Show("确定要退出打印吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { //if (printState == PrintState.Printing) MessageBox.Show("请暂停打印后关闭打印界面吗?", "系统提醒"); //printState = PrintState.Stopped; window.Close(); } } } }