diff --git a/BBWY.Client/GlobalContext.cs b/BBWY.Client/GlobalContext.cs index 7cc3b287..6d76bbda 100644 --- a/BBWY.Client/GlobalContext.cs +++ b/BBWY.Client/GlobalContext.cs @@ -9,7 +9,7 @@ namespace BBWY.Client { ShopServiceGroupList = new List(); ShopServiceGroupLowerList = new List(); - ClientVersion = "10122"; + ClientVersion = "10123"; } private User user; diff --git a/BBWY.Client/Helpers/MyPrintHelper.cs b/BBWY.Client/Helpers/MyPrintHelper.cs index 12515e17..6296a880 100644 --- a/BBWY.Client/Helpers/MyPrintHelper.cs +++ b/BBWY.Client/Helpers/MyPrintHelper.cs @@ -9,6 +9,7 @@ using System.Drawing.Printing; using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Windows.Media.Imaging; using WebSocketSharp; @@ -618,5 +619,19 @@ namespace BBWY.Client.Helpers } } + + public static void SetDefaultPrint(string printName) + { + SetDefaultPrinter(printName); + } + + /// + /// 调用win api将指定名称的打印机设置为默认打印机 + /// + /// + /// + [DllImport("winspool.drv")] + public static extern bool SetDefaultPrinter(string Name); + } } diff --git a/BBWY.Client/Models/PackTask/PackTaskModel.cs b/BBWY.Client/Models/PackTask/PackTaskModel.cs index ce5db38a..252775e4 100644 --- a/BBWY.Client/Models/PackTask/PackTaskModel.cs +++ b/BBWY.Client/Models/PackTask/PackTaskModel.cs @@ -103,7 +103,16 @@ namespace BBWY.Client.Models // qualityViewModel.TaskId = TaskId; qualityViewModel.OrderId = OrderId; qualityViewModel.SkuId = SkuId; - qualityViewModel.SearchSku(this); + try + { + qualityViewModel.SearchSku(this); + } + catch (Exception ex) + { + System.Windows.MessageBox.Show(ex.Message); + + } + //qualityViewModel.LoadPackDatas(); //qualityViewModel.SetAllFees = new Action>((feesItem, packUsers) => //{ diff --git a/BBWY.Client/ViewModels/QualityTask/QualityViewModel.cs b/BBWY.Client/ViewModels/QualityTask/QualityViewModel.cs index f645f141..452efd6a 100644 --- a/BBWY.Client/ViewModels/QualityTask/QualityViewModel.cs +++ b/BBWY.Client/ViewModels/QualityTask/QualityViewModel.cs @@ -552,28 +552,43 @@ namespace BBWY.Client.ViewModels request.PreCompeteTime = competeTime; - var competeRes = packPurchaseTaskService.CompeteQualityTask(request); - if (competeRes == null) - { - MessageBox.Show("网络异常"); - return; - } - if (!competeRes.Success) - { - MessageBox.Show(competeRes.Msg); - return; - } - BatchPrintWindow batchPrint = new BatchPrintWindow(); + try + { + var competeRes = packPurchaseTaskService.CompeteQualityTask(request); + if (competeRes == null) + { + MessageBox.Show("网络异常"); + return; + } + if (!competeRes.Success) + { + MessageBox.Show(competeRes.Msg); + return; + } + BatchPrintWindow batchPrint = new BatchPrintWindow(); + + batchPrint.SetData(GoodProductQuantity, + PurchaseSkuList.Where(p => p.IsNeedCer && p.CerDTO.Id > 0).Select(p => p.CerDTO).ToArray() + , BarCodeModel); + batchPrint.ShowDialog(); + + if (ReflashWindow != null) ReflashWindow(); + var window = obj as BWindow; + App.Current.Dispatcher.Invoke(new Action(() => { - batchPrint.SetData(GoodProductQuantity, - PurchaseSkuList.Where(p => p.IsNeedCer && p.CerDTO.Id > 0).Select(p => p.CerDTO).ToArray() - , BarCodeModel); - batchPrint.ShowDialog(); + window.Close(); + })); + + } + catch (Exception ex) + { + + System.Windows.MessageBox.Show(ex.Message); + } + - if (ReflashWindow != null) ReflashWindow(); - var window = obj as BWindow; - window.Close(); + } diff --git a/BBWY.Client/Views/PackTask/ServiceWindow.xaml.cs b/BBWY.Client/Views/PackTask/ServiceWindow.xaml.cs index cd1668ac..f51f2957 100644 --- a/BBWY.Client/Views/PackTask/ServiceWindow.xaml.cs +++ b/BBWY.Client/Views/PackTask/ServiceWindow.xaml.cs @@ -1,5 +1,6 @@ using BarcodeLib; using BBWY.Client.APIServices; +using BBWY.Client.Helpers; using BBWY.Client.ViewModels; using BBWY.Client.ViewModels.PackTask; using BBWY.Controls; @@ -50,9 +51,8 @@ namespace BBWY.Client.Views.PackTask MessageBox.Show("打印机处于错误状态"); return; } - //Print(this.printArea, cbPrintName.Text, "打印任务",1); - - + + MyPrintHelper.SetDefaultPrint(printName);//设置默认打印机 this.printArea.Arrange(new Rect(new Point(0, 0), new Size(printArea.ActualWidth, printArea.ActualHeight))); PrintDialog printDialog = new PrintDialog(); @@ -76,99 +76,7 @@ namespace BBWY.Client.Views.PackTask - /// - /// 打印 - /// - /// 流文档 - /// 打印机名称 - /// 打印描述 - /// 打印个数 - public static void Print(Visual document, string printer, string description, int copyCount) - { - var localPrintServer = new LocalPrintServer(); - var printQueue = localPrintServer.GetPrintQueue(printer); - if (printQueue.IsInError) - { - throw new Exception("打印机处于错误状态"); - } - - var printDialog = new PrintDialog - { - PrintQueue = printQueue, //打印队列 - PrintTicket = { CopyCount = copyCount } //打印个数 - }; - - //设置纸张大小 - var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth); //小标签:114 - var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight); //小标签:227 - printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight); - - //设置纸张边距 - var paperSize = GetPaperSize(printer); //小标签:118*246 - //var offsetX = (int)Math.Ceiling((paperSize.Width - pageWidth) / 2f); - //var offsetY = (int)Math.Ceiling((paperSize.Height - pageHeight) / 2f); - //document.PagePadding = new Thickness(offsetX, offsetY, offsetX, offsetY); - - //打印 - var paginator = ((IDocumentPaginatorSource)document).DocumentPaginator; - printDialog.PrintDocument(paginator, description); - - var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - string printNames = System.IO.Path.Combine(applicationPath, "printName.init"); - File.WriteAllText(printNames, printer); - - } - - private static object GetPaperSize(string printer) - { - return null; - } - - public interface IDocumentRenderer - { - void Render(FlowDocument doc, object data); - } - - public class CommonDocumentRenderer : IDocumentRenderer - { - public void Render(FlowDocument doc, object data) - { - var model = data as PrintModel; - if (model == null) - { - throw new ArgumentException("data is not PrintModel"); - } - - var type = typeof(PrintModel); - var properties = type.GetProperties(); - foreach (var property in properties) - { - //文本赋值 - if (doc.FindName(property.Name) is TextBlock textBlock) - { - textBlock.Text = property.GetValue(model)?.ToString(); - } - } - } - } - - public class PrintModel - { - /// - /// 批号 - /// - public string BatchNumber { get; set; } - - /// - /// 订单号 - /// - public string OrderNumber { get; set; } - - /// - /// 物料代码 - /// - public string MaterialNumber { get; set; } - } + } }