From fa119808140c5fd7ada76a5b0db467e21b6f0eca Mon Sep 17 00:00:00 2001 From: "506583276@qq.com" <506583276@qq.com> Date: Sun, 28 May 2023 13:31:56 +0800 Subject: [PATCH] 1 --- BBWY.Client/APIServices/PackTaskService.cs | 2 + BBWY.Client/BBWYAppSettings.json | 2 +- BBWY.Client/Helpers/MyPrintHelper.cs | 30 ++ BBWY.Client/Models/PackTask/BarCodeModel.cs | 6 + .../PackTask/PackServiceViewModel.cs | 128 ++++- .../Views/PackTask/FeesExcelControl.xaml.cs | 2 +- .../Views/PackTask/MinBarcodeControl.xaml | 74 +++ .../Views/PackTask/MinBarcodeControl.xaml.cs | 70 +++ BBWY.Client/Views/PackTask/MinCerControl.xaml | 159 ++++++ .../Views/PackTask/MinCerControl.xaml.cs | 51 ++ BBWY.Client/Views/PackTask/ServiceWindow.xaml | 455 ++++++++++-------- .../Views/PackTask/ServiceWindow.xaml.cs | 138 +++++- 12 files changed, 892 insertions(+), 225 deletions(-) create mode 100644 BBWY.Client/Views/PackTask/MinBarcodeControl.xaml create mode 100644 BBWY.Client/Views/PackTask/MinBarcodeControl.xaml.cs create mode 100644 BBWY.Client/Views/PackTask/MinCerControl.xaml create mode 100644 BBWY.Client/Views/PackTask/MinCerControl.xaml.cs diff --git a/BBWY.Client/APIServices/PackTaskService.cs b/BBWY.Client/APIServices/PackTaskService.cs index fc3b76c0..43d2c788 100644 --- a/BBWY.Client/APIServices/PackTaskService.cs +++ b/BBWY.Client/APIServices/PackTaskService.cs @@ -410,6 +410,8 @@ namespace BBWY.Client.APIServices /// public List DeletedPackServices { get; set; } + public List DelPackServices { get; set; } + //public PersonTaskModel[] PersonTaskModels { get; set; } //public IncreateMemberModel[] IncreateMembers { get; set; } diff --git a/BBWY.Client/BBWYAppSettings.json b/BBWY.Client/BBWYAppSettings.json index 34888905..e1b3dcff 100644 --- a/BBWY.Client/BBWYAppSettings.json +++ b/BBWY.Client/BBWYAppSettings.json @@ -5,5 +5,5 @@ "JOSApiHost": "", "1688ApiHost": "", "QKApiHost": "http://localhost:8080" - // "QKApiHost": "http://qiku.qiyue666.com" + //"QKApiHost": "http://qiku.qiyue666.com" } \ No newline at end of file diff --git a/BBWY.Client/Helpers/MyPrintHelper.cs b/BBWY.Client/Helpers/MyPrintHelper.cs index 45e6e6ff..12515e17 100644 --- a/BBWY.Client/Helpers/MyPrintHelper.cs +++ b/BBWY.Client/Helpers/MyPrintHelper.cs @@ -10,6 +10,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; +using System.Windows.Media.Imaging; using WebSocketSharp; namespace BBWY.Client.Helpers @@ -588,5 +589,34 @@ namespace BBWY.Client.Helpers } + + + + public static BitmapImage GetBarcodeImage(string printStr,int width,int height) + { + Bitmap image = new Bitmap(width, height); + Graphics graphics2 = Graphics.FromImage(image); + Barcode barcode = new Barcode(); + System.Drawing.Image img = barcode.Encode(TYPE.CODE128, printStr, 500, 60); + graphics2.DrawImage(img, 0, 0, width, height); + return bitmapToBitmapImage(image); + } + + static BitmapImage bitmapToBitmapImage(Bitmap bitmap) + { + using (var stream = new MemoryStream()) + { + bitmap.Save(stream, ImageFormat.Png); + stream.Position = 0; + BitmapImage reslut = new BitmapImage(); + reslut.BeginInit(); + reslut.CacheOption = BitmapCacheOption.OnLoad; + reslut.StreamSource = stream; + reslut.EndInit(); + reslut.Freeze(); + return reslut; + } + } + } } diff --git a/BBWY.Client/Models/PackTask/BarCodeModel.cs b/BBWY.Client/Models/PackTask/BarCodeModel.cs index 0c09a043..9131979a 100644 --- a/BBWY.Client/Models/PackTask/BarCodeModel.cs +++ b/BBWY.Client/Models/PackTask/BarCodeModel.cs @@ -1,4 +1,6 @@ using BBWY.Client.Models.PackTask; +using System.Drawing; +using System.Windows.Media.Imaging; namespace BBWY.Client.Models { @@ -61,5 +63,9 @@ namespace BBWY.Client.Models /// 模板标签 /// public BarcodeLabelModel LabelModel { get => labelModel; set { Set(ref labelModel, value); } } + + + + } } diff --git a/BBWY.Client/ViewModels/PackTask/PackServiceViewModel.cs b/BBWY.Client/ViewModels/PackTask/PackServiceViewModel.cs index 17eba481..fd65bdd3 100644 --- a/BBWY.Client/ViewModels/PackTask/PackServiceViewModel.cs +++ b/BBWY.Client/ViewModels/PackTask/PackServiceViewModel.cs @@ -1,6 +1,7 @@ using AutoMapper; using AutoMapper.Internal; using BBWY.Client.APIServices; +using BBWY.Client.Helpers; using BBWY.Client.Models; using BBWY.Client.Models.APIModel.Request; using BBWY.Client.Models.APIModel.Response.PackTask; @@ -9,12 +10,16 @@ using BBWY.Client.Views.PackTask; using BBWY.Common.Models; using GalaSoft.MvvmLight.Command; using Microsoft.Extensions.Logging; +using NPOI.Util; using Org.BouncyCastle.Asn1.Crmf; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Drawing.Printing; +using System.IO; using System.Linq; +using System.Reflection; using System.Reflection.Metadata.Ecma335; using System.Runtime.CompilerServices; using System.Text; @@ -22,6 +27,7 @@ using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; +using System.Windows.Media.Imaging; namespace BBWY.Client.ViewModels.PackTask { @@ -29,6 +35,30 @@ namespace BBWY.Client.ViewModels.PackTask { + + + private BitmapImage barcodeImage; + /// + /// 任务Id条形码 + /// + public BitmapImage BarcodeImage { get => barcodeImage; set { Set(ref barcodeImage, value); } } + + private BitmapImage taskImage; + /// + /// 任务Id条形码 + /// + public BitmapImage TaskImage { get => taskImage; set { Set(ref taskImage, value); } } + + private string printName; + + public string PrintName { get => printName; set { Set(ref printName, value); } } + + private ObservableCollection printList; + /// + /// 打印机列表 + /// + public ObservableCollection PrintList { get => printList; set { Set(ref printList, value); } } + private ObservableCollection packTaskList; /// /// 动态数据表 @@ -51,6 +81,9 @@ namespace BBWY.Client.ViewModels.PackTask public ICommand SetAllCountCommand { get; set; } + + public ICommand PrintCommand { get; set; } + readonly PackTaskService packTaskService; readonly ConsumableService consumableService; readonly PackDetailService packDetailService; @@ -85,6 +118,56 @@ namespace BBWY.Client.ViewModels.PackTask /// public List LoadList = new List(); + + + public void InitPrintList() + { + TaskImage = MyPrintHelper.GetBarcodeImage(TaskId.ToString(),300,60); + + BarcodeImage = MyPrintHelper.GetBarcodeImage(SkuId, 300, 60); + + + PrintList = new ObservableCollection(); + var printingNames = 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; + } + PrintList.Add(name); + } + try + { + var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string printNames = Path.Combine(applicationPath, "printName.init"); + if (File.Exists(printNames)) + { + PrintName = File.ReadAllText(printNames); + } + else + { + if (PrintList.Count > 0) + { + PrintName = PrintList[0].ToString(); + } + } + } + catch (Exception) + { + + + } + + } + public PackServiceViewModel(PackTaskService packTaskService, ConsumableService consumableService, PackServiceService packServiceService, PackDetailService packDetailService, BatchPurchaseService batchPurchaseService)//, long taskId { //TaskId = taskId; @@ -162,8 +245,6 @@ namespace BBWY.Client.ViewModels.PackTask } - - AddIncreateServiceCommand = new RelayCommand(AddIncreateService); AddPackServiceCommand = new RelayCommand(AddPackService); AddConsumableCommand = new RelayCommand(AddConsumable); @@ -185,6 +266,16 @@ namespace BBWY.Client.ViewModels.PackTask /// public void LoadPackDatas() { + try + { + InitPrintList(); + } + catch (Exception) + { + + + } + LoadList = new List(); Task task = Task.Factory.StartNew(() => { @@ -257,7 +348,7 @@ namespace BBWY.Client.ViewModels.PackTask } LoadList.AddRange(IncreateList); LoadList.AddRange(PackList); - Discount =res.Data.Discount.ToString(); + Discount = res.Data.Discount.ToString(); } }); @@ -519,11 +610,27 @@ namespace BBWY.Client.ViewModels.PackTask uploadService.PackServiceIds = string.Join(",", PackServiceMembers.Select(a => a.PackServiceId)); uploadService.PackServiceNos = string.Join(",", PackServiceMembers.Select(a => a.PackServiceCount)); - var orgIds = LoadList.Select(p => p.SelectId).ToList(); - var nowIds = PackServiceMembers.Select(p => p.PackServiceId).ToList(); + //var orgIds = LoadList.Select(p => p.SelectId).ToList(); + //var nowIds = PackServiceMembers.Select(p => p.PackServiceId).ToList(); //var add = nowIds.Except(orgIds); - var del = orgIds.Except(nowIds).ToList(); + + foreach (var item in LoadList) + { + if (!PackServiceMembers.Any(p => p.UserId == item.SelectUserId && p.PackServiceId == item.SelectId)) + { + delDatas.Add(new PersonTaskModel + { + + TaskId = taskId, + PackUserId = item.SelectUserId, + ServiceId = item.SelectId + }); + } + } + + + //var del = orgIds.Except(nowIds).ToList(); foreach (var PackServiceMember in PackServiceMembers) { @@ -539,10 +646,13 @@ namespace BBWY.Client.ViewModels.PackTask }); } uploadService.AddPackServices = addDatas; - uploadService.DeletedPackServices = del; + uploadService.DelPackServices = delDatas; + //uploadService.DeletedPackServices = del; + + //uploadService.DeletedPackServices uploadService.SkuId = SkuId; - uploadService.OrderId= OrderId; - uploadService.AllFees = Convert.ToDecimal(AllFees.ToString("0.00")); + uploadService.OrderId = OrderId; + uploadService.AllFees = Convert.ToDecimal(AllFees.ToString("0.00")); uploadService.SingleFees = singleFees; uploadService.IncreaseFees = Convert.ToDecimal((IncreateFees).ToString("0.00")); uploadService.PackFees = Convert.ToDecimal((PackFees).ToString("0.00")); diff --git a/BBWY.Client/Views/PackTask/FeesExcelControl.xaml.cs b/BBWY.Client/Views/PackTask/FeesExcelControl.xaml.cs index bdf2db2d..f1d413b8 100644 --- a/BBWY.Client/Views/PackTask/FeesExcelControl.xaml.cs +++ b/BBWY.Client/Views/PackTask/FeesExcelControl.xaml.cs @@ -137,7 +137,7 @@ namespace BBWY.Client.Views.PackTask [:Header:] - + diff --git a/BBWY.Client/Views/PackTask/MinBarcodeControl.xaml b/BBWY.Client/Views/PackTask/MinBarcodeControl.xaml new file mode 100644 index 00000000..7dc25ac8 --- /dev/null +++ b/BBWY.Client/Views/PackTask/MinBarcodeControl.xaml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/PackTask/MinBarcodeControl.xaml.cs b/BBWY.Client/Views/PackTask/MinBarcodeControl.xaml.cs new file mode 100644 index 00000000..19029991 --- /dev/null +++ b/BBWY.Client/Views/PackTask/MinBarcodeControl.xaml.cs @@ -0,0 +1,70 @@ +using BBWY.Client.Models; +using System; +using System.Collections.Generic; +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.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BBWY.Client.Views.PackTask +{ + /// + /// MinBarcodeControl.xaml 的交互逻辑 + /// + public partial class MinBarcodeControl : UserControl + { + public MinBarcodeControl() + { + InitializeComponent(); + } + + /// + /// + /// + public BarCodeModel model + { + get { return (BarCodeModel)GetValue(modelProperty); } + set + { + SetValue(modelProperty, value); + } + } + + + public static readonly DependencyProperty modelProperty = + DependencyProperty.Register("model", typeof(BarCodeModel), typeof(MinBarcodeControl), new PropertyMetadata(ChangedProperty)); + + private static void ChangedProperty(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + + + } + + public BitmapImage BarcodeImage + { + get { return (BitmapImage)GetValue(BarcodeImageProperty); } + set + { + SetValue(BarcodeImageProperty, value); + } + } + + + public static readonly DependencyProperty BarcodeImageProperty = + DependencyProperty.Register("BarcodeImage", typeof(BitmapImage), typeof(MinBarcodeControl), new PropertyMetadata(ChangedProperty1)); + + private static void ChangedProperty1(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + + + } + + + } +} diff --git a/BBWY.Client/Views/PackTask/MinCerControl.xaml b/BBWY.Client/Views/PackTask/MinCerControl.xaml new file mode 100644 index 00000000..ed8f2037 --- /dev/null +++ b/BBWY.Client/Views/PackTask/MinCerControl.xaml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BBWY.Client/Views/PackTask/MinCerControl.xaml.cs b/BBWY.Client/Views/PackTask/MinCerControl.xaml.cs new file mode 100644 index 00000000..f1ee53e2 --- /dev/null +++ b/BBWY.Client/Views/PackTask/MinCerControl.xaml.cs @@ -0,0 +1,51 @@ +using BBWY.Client.Models; +using System; +using System.Collections.Generic; +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.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BBWY.Client.Views.PackTask +{ + /// + /// MinCerControl.xaml 的交互逻辑 + /// + public partial class MinCerControl : UserControl + { + public MinCerControl() + { + InitializeComponent(); + } + + /// + /// + /// + public CertificateModel model + { + get { return (CertificateModel)GetValue(modelProperty); } + set + { + SetValue(modelProperty, value); + } + } + public static readonly DependencyProperty modelProperty = + DependencyProperty.Register("model", typeof(CertificateModel), typeof(MinCerControl), new PropertyMetadata(ChangedProperty)); + + private static void ChangedProperty(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + //var control = d as CerControl; + //var data = e.NewValue as CertificateModel; + //if (data != null) + //{ + // control.SetData(data); + //} + } + } +} diff --git a/BBWY.Client/Views/PackTask/ServiceWindow.xaml b/BBWY.Client/Views/PackTask/ServiceWindow.xaml index eac79660..44edf693 100644 --- a/BBWY.Client/Views/PackTask/ServiceWindow.xaml +++ b/BBWY.Client/Views/PackTask/ServiceWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:BBWY.Client.Views.PackTask" mc:Ignorable="d" - Title="TipsWindow" Height="820" Width="1560" + Title="TipsWindow" Height="844" Width="350" xmlns:c="clr-namespace:BBWY.Controls;assembly=BBWY.Controls" xmlns:b="http://schemas.microsoft.com/xaml/behaviors" xmlns:ctr="clr-namespace:BBWY.Client.Converters" @@ -227,230 +227,240 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + - - - + + - + - - - + + + - - + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + - - - - - + + + + - - - - - - - - - + + + + + + + + + - - + + - - - - - + + + + - - - - - + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - + + + + - - + + + + + + + + + + + - + + + + + + + - + + - - + - + + /// 打印 + /// + /// 流文档 + /// 打印机名称 + /// 打印描述 + /// 打印个数 + 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; } + } + } }