1
wankeda
2026-01-27 a474060ae47fc4c807120b2a6178e8d8f84c0863
WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -561,9 +561,9 @@
                                return WebResponseContent.Instance.Error("未找到入库单信息");
                            }
                            var allBoxCodesForDetail = BaseDal.Db.Queryable<Dt_StockInfoDetailCP>()
                         .Where(x => x.StockDetailId == dt_StockInfo.Details.FirstOrDefault().Id)
                         .Select(x => x.BoxCode)
                         .ToList();
              .Where(x => dt_StockInfo.Details.Select(d => d.Id).Contains(x.StockDetailId))
              .Select(x => x.BoxCode)
              .ToList();
                            // 2. 获取托盘下的所有箱号
                            var boxCodes = new List<string>();
@@ -640,14 +640,6 @@
                                    .ToList();
                            }
                            // 更新成品入库明细状态
                            if (cpInboundDetails.Any())
                            {
                                foreach (var cpDetail in cpInboundDetails)
                                {
                                    cpDetail.CPOrderDetailStatus = InboundStatusEnum.入库完成.ObjToInt();
                                }
                            }
                            // 4. 查询并更新成品库存明细(如果有单独的成品库存表)
                            List<Dt_StockInfoDetailCP> cpStockDetails = new List<Dt_StockInfoDetailCP>();
@@ -709,7 +701,7 @@
                                // 更新成品入库明细状态
                                if (cpInboundDetails.Any())
                                {
                                    BaseDal.Db.Updateable(cpInboundDetails).ExecuteCommand();
                                    BaseDal.Db.Deleteable(cpInboundDetails).ExecuteCommand();
                                }
                                // 更新成品库存明细状态
@@ -3198,58 +3190,59 @@
                return;
            }
            // 获取打印机名称
            // 获取配置的打印机名称
            string printerName = AppSettings.app("PrinterName");
            PrintUsingSpireSimple(fullPath, printerName);
            if (string.IsNullOrEmpty(printerName))
            {
                Console.WriteLine("✗ 打印失败:未配置打印机名称");
                return;
            }
            Console.WriteLine("所有打印方法都失败");
            // 直接使用配置的打印机名称,不进行任何转换
            PrintUsingConfiguredPrinter(fullPath, printerName.Trim());
        }
        private void PrintUsingSpireSimple(string filePath, string printerName)
        /// <summary>
        /// 只使用配置的打印机进行打印
        /// </summary>
        private void PrintUsingConfiguredPrinter(string filePath, string printerName)
        {
            try
            {
                // 1. 首先验证打印机是否存在
                if (!IsPrinterInstalled(printerName))
                {
                    Console.WriteLine($"✗ 打印机 '{printerName}' 未安装或不存在");
                    Console.WriteLine("\n系统已安装的打印机列表:");
                    foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                    {
                        Console.WriteLine($"  - {printer}");
                    }
                    throw new InvalidOperationException($"打印机 '{printerName}' 未安装");
                }
                // 3. 使用 Spire.PDF 打印
                using (Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument())
                {
                    // 加载文件
                    pdf.LoadFromFile(filePath);
                    // 获取实际的打印机名称
                    string actualPrinterName = GetActualPrinterName(printerName);
                    // 设置打印机名称(只使用配置的名称)
                    pdf.PrintSettings.PrinterName = printerName;
                    Console.WriteLine($"配置的打印机名称: {printerName}");
                    Console.WriteLine($"实际使用的打印机名称: {actualPrinterName}");
                    // 如果找不到实际打印机,使用默认打印机
                    if (!string.IsNullOrEmpty(actualPrinterName) && IsPrinterInstalled(actualPrinterName))
                    {
                        pdf.PrintSettings.PrinterName = actualPrinterName;
                        Console.WriteLine($"✓ 已设置打印机: {actualPrinterName}");
                    }
                    else
                    {
                        Console.WriteLine($"⚠️ 打印机 '{actualPrinterName}' 未找到,使用默认打印机");
                    }
                    Console.WriteLine($"✓ 使用配置的打印机: {printerName}");
                    Console.WriteLine($"✓ 正在打印: {Path.GetFileName(filePath)}");
                    // 直接打印
                    pdf.Print();
                    Console.WriteLine("✓ 打印任务已提交成功");
                    Console.WriteLine("✓ 打印任务已提交");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"✗ Spire.PDF打印失败: {ex.Message}");
                // 输出所有可用打印机,帮助调试
                Console.WriteLine("\n系统所有可用打印机:");
                foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                {
                    Console.WriteLine($"  - {printer}");
                }
                Console.WriteLine($"✗ 打印失败: {ex.Message}");
                throw;
            }
        }