using Aucma.Core.PrintTo.Common; using Aucma.Core.PrintTo.Models; using Aucma.Core.PrintTo.Views; using Castle.Core.Internal; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using FastReport; using log4net; using MaterialDesignThemes.Wpf; 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 barCode = BarCode; if (string.IsNullOrEmpty(barCode)) { MessageBox.Show("放行码不能为空!", "系统提醒", MessageBoxButton.OK, MessageBoxImage.Warning); return Task.CompletedTask; } if (PrintNum<=0){ MessageBox.Show("请输入打印数量!", "系统提醒", MessageBoxButton.OK, MessageBoxImage.Warning); return Task.CompletedTask; } //调用打印机 SpecialPrintToView print =new SpecialPrintToView(barCode, PrintNum); print.ShowDialog(); return Task.CompletedTask; } #region 打印机 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 #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 #region 关闭 [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(); } } #endregion } }