diff --git a/BBWY.Client/BBWY.Client.csproj b/BBWY.Client/BBWY.Client.csproj index e6f8759e..760a73f2 100644 --- a/BBWY.Client/BBWY.Client.csproj +++ b/BBWY.Client/BBWY.Client.csproj @@ -26,6 +26,7 @@ + @@ -35,6 +36,7 @@ Always + diff --git a/BBWY.Client/BBWYAppSettings.json b/BBWY.Client/BBWYAppSettings.json index e1b3dcff..34888905 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/Extensions/ImageExtensions.cs b/BBWY.Client/Extensions/ImageExtensions.cs new file mode 100644 index 00000000..876fe2bd --- /dev/null +++ b/BBWY.Client/Extensions/ImageExtensions.cs @@ -0,0 +1,47 @@ +using SixLabors.ImageSharp.Memory; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Text; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace BBWY.Client.Extensions +{ + public static class ImageExtensions + { + public static BitmapImage ByteToBitmapImage(this byte[] imageData) + { + BitmapImage bitmapImage = new BitmapImage(); + try + { + + + using (MemoryStream memoryStream = new MemoryStream(imageData)) + { + bitmapImage.BeginInit(); + bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + bitmapImage.StreamSource = memoryStream; + bitmapImage.EndInit(); + bitmapImage.Freeze(); + } + + return bitmapImage; + } + catch (Exception ex) + { + Debug.Print($"转换图片失败:: {ex.Message}"); + } + return bitmapImage; + } + + public static Image ByteToImage(this byte[] imageData) + { + using MemoryStream ms = new MemoryStream(imageData); + Image image = System.Drawing.Image.FromStream(ms); + return image; + } + } +} diff --git a/BBWY.Client/Helpers/MyPrintHelper.cs b/BBWY.Client/Helpers/MyPrintHelper.cs index 57442300..122219b2 100644 --- a/BBWY.Client/Helpers/MyPrintHelper.cs +++ b/BBWY.Client/Helpers/MyPrintHelper.cs @@ -11,9 +11,11 @@ using System.Drawing.Imaging; using System.Drawing.Printing; using System.IO; using System.Linq; +using System.Net.Http; using System.Reflection; using System.Runtime.InteropServices; using System.Text; +using System.Windows; using System.Windows.Media.Imaging; using WebSocketSharp; @@ -40,11 +42,11 @@ namespace BBWY.Client.Helpers //SetBarStander(barCode, ref args, font); break; case BarcodeLabelModel.精简模板: - //font = new Font("宋体", 10, System.Drawing.FontStyle.Regular); - ////SetBar(barCode, ref args, font, 15); + //font = new Font("宋体", 10, System.Drawing.FontStyle.Regular); + ////SetBar(barCode, ref args, font, 15); - //SetBarSimplify(barCode, ref args, font); - //break; + //SetBarSimplify(barCode, ref args, font); + //break; case BarcodeLabelModel.无型号模板: font = new Font("宋体", 10, System.Drawing.FontStyle.Regular); SetBar(barCode, ref args, font, 7); @@ -152,7 +154,7 @@ namespace BBWY.Client.Helpers //args.Graphics.DrawString($"品名: {barCode.BrandName}", font, System.Drawing.Brushes.Black, new PointF(10, 10)); //args.Graphics.DrawString($"规格: {barCode.SkuName}", font, System.Drawing.Brushes.Black, new PointF(10, 40)); - + args.Graphics.DrawString($"规格: {barCode.SkuName}", font, System.Drawing.Brushes.Black, new PointF(10, 10)); args.Graphics.DrawString($"店铺: {barCode.ShopName}", font, System.Drawing.Brushes.Black, new PointF(10, 40)); // g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; @@ -601,10 +603,19 @@ 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); + try + { + 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); + } + catch + { + MessageBox.Show($"生成条码失败,不支持格式: {printStr}"); + } + + return bitmapToBitmapImage(image); } @@ -618,10 +629,21 @@ namespace BBWY.Client.Helpers public static BitmapImage GetBarcodeImageV2(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, width, height); - graphics2.DrawImage(img, 0, 0, width, height); + + + try + { + Graphics graphics2 = Graphics.FromImage(image); + Barcode barcode = new Barcode(); + System.Drawing.Image img = barcode.Encode(TYPE.CODE128, printStr, width, height); + graphics2.DrawImage(img, 0, 0, width, height); + } + catch + { + MessageBox.Show($"生成条码失败,不支持格式: {printStr}"); + } + + return bitmapToBitmapImage(image); } @@ -644,99 +666,12 @@ namespace BBWY.Client.Helpers - ///// - ///// 打印封箱 - ///// - ///// - ///// - ///// - ///// - //public static void PrintSealBoxData(SealBoxModel sealBoxModel, string printName, int boxCount, int printCount) - //{ - // // 100*180 - - // UnitConverHelper unitConverHelper = new UnitConverHelper(); - - // var data = unitConverHelper.MmToPx(100, 180); - // var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - // string printNamePath = $"{applicationPath}/printSealName.init"; - // if (File.Exists(printNamePath)) - // { - // File.Delete(printNamePath); - // } - // File.WriteAllText(printNamePath, printName); - - // var excel = $"{applicationPath}/Resources/ExccelModel/sealbox.xlsx"; - - // var newExccel = $"{applicationPath}/Resources/ExccelModel/newsealbox.xlsx"; - // if (File.Exists(newExccel)) - // { - // File.Delete(newExccel); - // } - // FileStream fs = new FileStream(excel, FileMode.Open, FileAccess.Read); - // XSSFWorkbook wb = new XSSFWorkbook(fs); - // var sheet = wb.GetSheetAt(0); // 得到第一个sheet - - // var nameCell = sheet.GetRow(0).GetCell(0); // name列,第2行 - // var ageCell = sheet.GetRow(3).GetCell(0); // age列,第2行 - - - // XSSFWorkbook wb2 = new XSSFWorkbook(); - // sheet.CopyTo(wb2, "Sheet1", true, false); - // var sheet2 = wb2.GetSheet("Sheet1"); - // var nameCell2 = sheet2.GetRow(0).GetCell(1); - // nameCell2.SetCellValue(sealBoxModel.ShopName); - - // sheet2.GetRow(3).GetCell(1).SetCellValue(sealBoxModel.WareName); - - // StringBuilder sb = new StringBuilder(); - // int totalCount = 0; - // for (int i = 0; i < sealBoxModel.SealBoxSkus.Count; i++) - // { - // var title = sealBoxModel.SealBoxSkus[i].SkuTitle; - // //if (title.Length>5) - // //{ - // // title = title.Substring(0,5); - // //} - // totalCount += sealBoxModel.SealBoxSkus[i].WareHourseSkuCount; - // sheet2.GetRow(i + 6).GetCell(1).SetCellValue($"名称:{title}"); - // sheet2.GetRow(i + 6).GetCell(2).SetCellValue($"SKU:{sealBoxModel.SealBoxSkus[i].SkuId}"); - // sheet2.GetRow(i + 6).GetCell(3).SetCellValue($"数量:{sealBoxModel.SealBoxSkus[i].WareHourseSkuCount}"); - - // } - // sheet2.GetRow(25).GetCell(1).SetCellValue(totalCount); - // sheet2.GetRow(28).GetCell(1).SetCellValue(boxCount); - // FileStream fs1 = new FileStream(newExccel, FileMode.OpenOrCreate, FileAccess.ReadWrite); - // wb2.Write(fs1); - // fs1.Close(); - // fs1.Dispose(); - // Workbook workbook = new Workbook(); - - // workbook.LoadFromFile(newExccel); - - // Worksheet wsheet = workbook.Worksheets[0]; - - // wsheet.PageSetup.PaperSize = PaperSizeType.PaperA4; - // wsheet.PageSetup.Orientation = PageOrientationType.Portrait; - // wsheet.PageSetup.PrintArea = "A1:D31"; - - - - // var print = workbook.PrintDocument; - // print.PrinterSettings.PrinterName = printName; - // print.PrinterSettings.Copies = (short)printCount;//打印份数 - - - - // print.Print(); - //} - /// /// 打印京东箱唛 /// - public static void PrintJDBoxWareData(JDWareBoxModel jDWareBoxModel,string printName) + public static void PrintJDBoxWareData(JDWareBoxModel jDWareBoxModel, string printName) { - + } @@ -749,6 +684,48 @@ namespace BBWY.Client.Helpers SetDefaultPrinter(printName); } + public static void PrintPackDetail(PackTaskModel model,ref PrintPageEventArgs args, Font font) + { + args.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + args.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + var sige = args.Graphics.VisibleClipBounds;// 宽:283 高:511 打印可视化区域 + args.Graphics.TranslateTransform(0, 0);//设置起始位置 + args.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + args.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + + args.Graphics.DrawImage(LoadImage(model.ItemList[0].Logo.Replace("80x80","200x200")), 10, 20, 120, 120); + + + + + } + + private static Image LoadImage(string imageUrl) + { + try + { + using (HttpClient client = new HttpClient()) + { + // 发送 HTTP 请求并获取图片数据 + var uri = new Uri(Uri.EscapeUriString(imageUrl)); + byte[] imageData = client.GetByteArrayAsync(uri).Result; + return imageData.ByteToImage(); + + } + } + catch (Exception ex) + { + // 处理加载图片失败的异常 + Console.WriteLine("加载图片失败:" + ex.Message); + } + return null; + } + + + + + + /// /// 调用win api将指定名称的打印机设置为默认打印机 /// diff --git a/BBWY.Client/Resources/Images/123.bmp b/BBWY.Client/Resources/Images/123.bmp new file mode 100644 index 00000000..10d1b473 Binary files /dev/null and b/BBWY.Client/Resources/Images/123.bmp differ diff --git a/BBWY.Client/Views/PackTask/PackDetailWindow.xaml b/BBWY.Client/Views/PackTask/PackDetailWindow.xaml index 5c25b243..8e55cbcd 100644 --- a/BBWY.Client/Views/PackTask/PackDetailWindow.xaml +++ b/BBWY.Client/Views/PackTask/PackDetailWindow.xaml @@ -539,295 +539,120 @@ - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/BBWY.Client/Views/PackTask/PackDetailWindow.xaml.cs b/BBWY.Client/Views/PackTask/PackDetailWindow.xaml.cs index 177a1fae..cdee28c0 100644 --- a/BBWY.Client/Views/PackTask/PackDetailWindow.xaml.cs +++ b/BBWY.Client/Views/PackTask/PackDetailWindow.xaml.cs @@ -1,13 +1,20 @@ -using BBWY.Client.Helpers; +using BBWY.Client.Extensions; +using BBWY.Client.Helpers; using BBWY.Client.Models; using BBWY.Client.ViewModels.PackTask; using BBWY.Controls; using System; using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Printing; using System.IO; +using System.Linq; +using System.Net.Http; using System.Printing; using System.Reflection; +using System.Security.Policy; using System.Text; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -16,6 +23,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using WebSocketSharp; namespace BBWY.Client.Views.PackTask { @@ -24,20 +32,33 @@ namespace BBWY.Client.Views.PackTask /// public partial class PackDetailWindow : BWindow { + public PackDetailWindow(PackTaskModel model, Action reflashWindow) { InitializeComponent(); var serviceViewModel = this.DataContext as PackDetailViewModel; - //加载数据 - + if (model.Brand.IsNullOrEmpty()) + { + if (!model.BarCodeModel.Brand.IsNullOrEmpty()) + model.Brand = model.BarCodeModel.Brand; + else if (model.CertificateModel != null && model.CertificateModel.Any(c => c.Brand != null)) + model.Brand = model.CertificateModel.FirstOrDefault(c => c.Brand != null)?.Brand; + } + if (model.BrandName.IsNullOrEmpty()) + { + if (!model.BarCodeModel.BrandName.IsNullOrEmpty()) + model.BrandName = model.BarCodeModel.BrandName; + else if (model.CertificateModel != null && model.CertificateModel.Any(c => c.BrandName != null)) + model.BrandName = model.CertificateModel.FirstOrDefault(c => c.BrandName != null)?.BrandName; + } if (model.BarCodeModel != null) { model.BarCodeModel.ShopName = model.ShopName; } serviceViewModel.PackTaskModel = model; - serviceViewModel.PackTaskList = new System.Collections.ObjectModel.ObservableCollection { model}; + serviceViewModel.PackTaskList = new System.Collections.ObjectModel.ObservableCollection { model }; serviceViewModel.FloorDragNumber = model.FloorDragNumber; serviceViewModel.TaskCount = model.SkuCount; serviceViewModel.TaskId = model.TaskId; @@ -47,61 +68,169 @@ namespace BBWY.Client.Views.PackTask serviceViewModel.LoadPackDatas(); if (reflashWindow != null) serviceViewModel.ReflashWindow = reflashWindow; + + // DownloadImags(model.ItemList[0].Logo.Replace("80x80", "500x500")); + LoadImage(model.ItemList[0].Logo.Replace("80x80", "200x200")); + + + + } + //PackTaskModel model = new PackTaskModel(); + + ///// + ///// 图片 + ///// + //public BitmapImage LogoImage { get; set; } + private void BButton_Click(object sender, RoutedEventArgs e) { - //return;//禁用打印 - var localPrintServer = new LocalPrintServer(); + //PrintPackTaskDetail printWindow = new PrintPackTaskDetail(model); + + //if (printWindow==null) + //{ + // MessageBox.Show("页面加载中,请重试!"); + // return; + //} string printName = cbPrintName.Text.Trim(); + PrintBox(printName); + var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string printNames = System.IO.Path.Combine(applicationPath, "printName.init"); + try + { + if (File.Exists(printNames)) + { + File.Delete(printNames); + } + } + catch + { + + + } + + File.WriteAllText(printNames, cbPrintName.Text); + + return; + } + + public void PrintBox(string printName) + { + + //PrintData(1, printName, model); + //return; + + var localPrintServer = new LocalPrintServer(); if (string.IsNullOrEmpty(printName)) { - System.Windows.MessageBox.Show("选择打印机"); return; } - var printQueue = localPrintServer.GetPrintQueue(printName); if (printQueue.IsInError) { System.Windows.MessageBox.Show("打印机处于错误状态"); return; } - MyPrintHelper.SetDefaultPrint(printName);//设置默认打印机 - - - System.Windows.Controls.PrintDialog printDialog = new PrintDialog(); - printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;//设置为横向打印 PageOrientation.Landscape Portrait为纵向 - //设置纸张大小 - + PrintDialog printDialog = new PrintDialog(); + printDialog.PrintTicket.PageOrientation = PageOrientation.ReversePortrait;//设置为横向打印 PageOrientation.Landscape Portrait为纵向 + //设置纸张大小 var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth); var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight); printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight); - //printArea.Height = pageHeight;//833 - //printArea.Width = pageWidth;//1123 - this.printArea.Arrange(new Rect(new Point(0, 0), new Size(printArea.ActualWidth, printArea.ActualHeight))); - - printDialog.PrintVisual(this.printArea, "打印任务"); + print_box.Height = pageHeight; + print_box.Width = pageWidth; + this.print_box.Arrange(new Rect(new System.Windows.Point(0, 0), new System.Windows.Size(pageWidth, pageHeight))); + this.UpdateLayout(); //刷新界面 + printDialog.PrintVisual(this.print_box, "打印任务"); + this.Close(); + } - var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - string printNames = System.IO.Path.Combine(applicationPath, "printName.init"); + private async void LoadImage(string imageUrl) + { try { - if (File.Exists(printNames)) + + + using (HttpClient client = new HttpClient()) { - File.Delete(printNames); + // 发送 HTTP 请求并获取图片数据 + var uri = new Uri(Uri.EscapeUriString(imageUrl)); + byte[] imageData = await client.GetByteArrayAsync(uri); + + + // 创建 BitmapImage 对象并设置图片数据 + + + // 在 UI 线程上更新 Image 控件的 Source 属性 + + var LogoImage = imageData.ByteToBitmapImage(); + + + img_logo.Source = LogoImage; } } - catch + catch (Exception ex) { + // 处理加载图片失败的异常 + Console.WriteLine("加载图片失败:" + ex.Message); + } + } + private void DownloadImags(string url) + { + var client = new HttpClient(); + var uri = new Uri(Uri.EscapeUriString(url)); + byte[] urlContents = client.GetByteArrayAsync(uri).Result; + var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string imagePath = System.IO.Path.Combine(applicationPath, "123.bmp"); + + if (File.Exists(imagePath)) + { + File.Delete(imagePath); } - File.WriteAllText(printNames, cbPrintName.Text); + using (System.IO.FileStream fs = new System.IO.FileStream(imagePath, System.IO.FileMode.CreateNew)) + { + fs.Write(urlContents, 0, urlContents.Length); + } + BitmapImage img = new BitmapImage(new Uri(imagePath)); + img_logo.Source = img; + this.UpdateLayout(); //刷新界面 + } + + private void PrintData(int printCount, string printName, PackTaskModel model) + { + try + { + + PrintDocument document = new PrintDocument(); + document.PrinterSettings.PrinterName = printName;//使用打印机名称,指定特定的打印机进行打印。 + //设置打印页面 + //document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 236, 157); + document.PrintPage += (s, a) => + { + Font font = new Font("宋体", 6, System.Drawing.FontStyle.Regular); + + MyPrintHelper.PrintPackDetail(model, ref a, font); + + }; + document.PrinterSettings.Copies = (short)printCount;//打印份数 + document.Print(); + } + catch (Exception ex) + { + App.Current.Dispatcher.Invoke(() => + { + new TipsWindow($"打印失败,{ex.Message}").Show(); + }); + } } + } } diff --git a/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml b/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml index 775a36d5..439c5191 100644 --- a/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml +++ b/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml @@ -5,11 +5,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:BBWY.Client.Views.PackTask" mc:Ignorable="d" + xmlns:c="clr-namespace:BBWY.Controls;assembly=BBWY.Controls" Title="PrintPackTaskDetail" Height="492" Width="272"> - + - + @@ -17,52 +18,114 @@ - - - - - + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + - - + + - - + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml.cs b/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml.cs index 7b2dd34e..a33f753b 100644 --- a/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml.cs +++ b/BBWY.Client/Views/PackTask/PrintPackTaskDetail.xaml.cs @@ -1,19 +1,19 @@ -using BBWY.Client.Helpers; +using BBWY.Client.Extensions; +using BBWY.Client.Helpers; using BBWY.Client.Models; -using BBWY.Client.Models.FallWare; + using System; -using System.Collections.Generic; + +using System.Drawing.Imaging; + +using System.Net.Http; using System.Printing; -using System.Reflection; -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.Shapes; + namespace BBWY.Client.Views.PackTask { @@ -25,8 +25,11 @@ namespace BBWY.Client.Views.PackTask public PrintPackTaskDetail(PackTaskModel model) { InitializeComponent(); + PackTaskModel = model; - + PackTaskModel.ItemList[0].Logo = PackTaskModel.ItemList[0].Logo.Replace("80*80", "110*110"); + //LoadImage(model.ItemList[0].Logo); + BarcodeImage = MyPrintHelper.GetBarcodeImage(model.SkuId, 300, 60); this.DataContext = this; this.UpdateLayout();//刷新UI @@ -34,7 +37,15 @@ namespace BBWY.Client.Views.PackTask public PackTaskModel PackTaskModel { get; set; } + /// + /// skuid条形码 + /// + public BitmapImage BarcodeImage { get; set; } + /// + /// 图片 + /// + public BitmapImage LogoImage { get; set; } public void PrintBox(string printName) { @@ -53,14 +64,13 @@ namespace BBWY.Client.Views.PackTask MyPrintHelper.SetDefaultPrint(printName);//设置默认打印机 PrintDialog printDialog = new PrintDialog(); - printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;//设置为横向打印 PageOrientation.Landscape Portrait为纵向 + printDialog.PrintTicket.PageOrientation = PageOrientation.ReversePortrait;//设置为横向打印 PageOrientation.Landscape Portrait为纵向 //设置纸张大小 var pageWidth = (int)Math.Ceiling(printDialog.PrintableAreaWidth); var pageHeight = (int)Math.Ceiling(printDialog.PrintableAreaHeight); printDialog.PrintTicket.PageMediaSize = new PageMediaSize(pageWidth, pageHeight); - this.Height = pageHeight + 39;//833 - this.Width = pageWidth;//1123 - this.FontSize = 30; + print_box.Height = pageHeight; + print_box.Width = pageWidth; // box_margin.Margin = new Thickness(50, 50, 50, 50); //box_margin.Margin = new Thickness(10); //this.jd_box.Arrange(new Rect(new Point(0, 0), new Size(pageWidth, pageHeight))); @@ -77,5 +87,48 @@ namespace BBWY.Client.Views.PackTask //System.IO.File.WriteAllText(printNames, printName); this.Close(); } + + + private async void LoadImage(string imageUrl) + { + try + { + + + using (HttpClient client = new HttpClient()) + { + // 发送 HTTP 请求并获取图片数据 + byte[] imageData = await client.GetByteArrayAsync(imageUrl); + + LogoImage= imageData.ByteToBitmapImage(); + // 创建 BitmapImage 对象并设置图片数据 + BitmapImage bitmapImage = new BitmapImage(); + try + { + bitmapImage.BeginInit(); + + bitmapImage.StreamSource = new System.IO.MemoryStream(imageData); + bitmapImage.EndInit(); + bitmapImage.Freeze(); + + } + catch (Exception ex) + { + + } + + // 在 UI 线程上更新 Image 控件的 Source 属性 + Application.Current.Dispatcher.Invoke(() => + { + LogoImage = bitmapImage; + }); + } + } + catch (Exception ex) + { + // 处理加载图片失败的异常 + Console.WriteLine("加载图片失败:" + ex.Message); + } + } } } diff --git a/BBWY.Client/Views/PackTask/WareHouseListControl.xaml b/BBWY.Client/Views/PackTask/WareHouseListControl.xaml index fcfd18e5..247f6eaa 100644 --- a/BBWY.Client/Views/PackTask/WareHouseListControl.xaml +++ b/BBWY.Client/Views/PackTask/WareHouseListControl.xaml @@ -543,7 +543,7 @@