liulb@mesnac.com 1 year ago
parent ad4260bd09
commit a13a01868b

@ -36,18 +36,16 @@ namespace Aucma.Core.PrintTo.ViewModels
public PrintToDevViewModel(string productCode, string materialCode, string materialName, int printAmount, string? barCode = null) public PrintToDevViewModel(string productCode, string materialCode, string materialName, int printAmount, string? barCode = null)
{ {
_orderBomInfoServices = App.ServiceProvider.GetService<IOrderBomInfoServices>();
ProductCode = productCode; ProductCode = productCode;
MaterialName = materialName; MaterialName = materialName;
PrintAmount = printAmount; PrintAmount = printAmount;
_orderBomInfoServices = App.ServiceProvider.GetService<IOrderBomInfoServices>();
MaxProgress = 100;
Progress = 0; Progress = 0;
//PrintProgress = $"[100/4] B23060512345678910001";
State = "Green"; State = "Green";
ErrorNum = 0; ErrorNum = 0;
printState = PrintState.Printing; printState = PrintState.Printing;
isPrint=true; isPrint=true;
//StopOrStart = "暂停"; SuspendEnabled = "False";
OperateEnabled = "True"; OperateEnabled = "True";
// 非阻塞打印 // 非阻塞打印
Task.Run(async () => Task.Run(async () =>
@ -149,38 +147,19 @@ namespace Aucma.Core.PrintTo.ViewModels
[RelayCommand] [RelayCommand]
public void StartOperate() public void StartOperate()
{ {
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => printState = PrintState.Printing;
{ SuspendEnabled = "True";
if (printState == PrintState.Completetd) OperateEnabled = "False";
State = "Green";
if (isPrint)//首次打印
{ {
isPrint = false; isPrint = false;
StopOrStart = "已完成"; // 非阻塞打印
MessageBox.Show("打印已完成", "系统提醒"); Task.Run(async () =>
return; {
await Print();
});
} }
//if (isPrint&& printState == PrintState.Printing)
//{
// if (MessageBox.Show("确定要暂停打印吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
// {
// isPrint = false;
// printState = PrintState.Paused;
// StopOrStart = "继续";
// }
//}
//else
//{
// if (MessageBox.Show("确定要继续打印吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
// {
// isPrint = true;
// printState = PrintState.Printing;
// State = "Green";
// StopOrStart = "暂停";
// }
//}
}));
} }
#region 暂停 #region 暂停
@ -205,7 +184,7 @@ namespace Aucma.Core.PrintTo.ViewModels
{ {
var window = parameter as Window; var window = parameter as Window;
if (window == null) return; if (window == null) return;
isPrint = true;
if (printState == PrintState.Completetd) if (printState == PrintState.Completetd)
{ {
WeakReferenceMessenger.Default.Send<string>("Refresh");//刷新窗口 WeakReferenceMessenger.Default.Send<string>("Refresh");//刷新窗口
@ -239,27 +218,28 @@ namespace Aucma.Core.PrintTo.ViewModels
var boxList = await _orderBomInfoServices.QueryAsync(d => d.ParentId == orderNo&&d.MaterialName.Contains("箱体")); var boxList = await _orderBomInfoServices.QueryAsync(d => d.ParentId == orderNo&&d.MaterialName.Contains("箱体"));
if (boxList.Count == 0) if (boxList.Count == 0)
{ {
MaxProgress = boxList.Count;
MessageBox.Show("无法查询打印条码数据", "系统提醒"); MessageBox.Show("无法查询打印条码数据", "系统提醒");
return; return;
} }
var list = await _orderBomInfoServices.QueryAsync(d => d.ParentId == orderNo && d.MaterialName.Contains("内胆")); var list = await _orderBomInfoServices.QueryAsync(d => d.ParentId == orderNo && d.MaterialName.Contains("内胆"));
if (list.Count == 0) if (list.Count == 0)
{ {
MaxProgress = list.Count;
MessageBox.Show("无法查询打印条码数据", "系统提醒"); MessageBox.Show("无法查询打印条码数据", "系统提醒");
return; return;
} }
list.ForEach(d => BarcodesUnprinted.Enqueue(d)); list.ForEach(d => BarcodesUnprinted.Enqueue(d));
await Print(printer);
} }
#endregion #endregion
#region 打印 #region 打印
public Task Print(string printer) public Task Print()
{ {
try try
{ {
string printer = Appsettings.app("Printer", "PrinterName");
int printNum = BarcodesUnprinted.Count;//打印数 int printNum = BarcodesUnprinted.Count;//打印数
int i = 0; int i = 0;
MaxProgress = printNum; MaxProgress = printNum;
@ -269,6 +249,7 @@ namespace Aucma.Core.PrintTo.ViewModels
if (printState == PrintState.Paused) if (printState == PrintState.Paused)
{ {
SetPaused(); SetPaused();
Thread.Sleep(1 * 1000);
continue; continue;
} }
if (printState == PrintState.Completetd) break; if (printState == PrintState.Completetd) break;
@ -276,7 +257,6 @@ namespace Aucma.Core.PrintTo.ViewModels
{ {
var item = BarcodesUnprinted.Peek(); var item = BarcodesUnprinted.Peek();
////对接打印机 ////对接打印机
//Report barReport = new Report(); //Report barReport = new Report();
//barReport.Load(System.Environment.CurrentDirectory + @"\Report\MaterialBar.frx");//打印报表位置 //barReport.Load(System.Environment.CurrentDirectory + @"\Report\MaterialBar.frx");//打印报表位置
@ -286,7 +266,7 @@ namespace Aucma.Core.PrintTo.ViewModels
//barReport.PrintSettings.Printer = printer; // 设置打印机名称 //barReport.PrintSettings.Printer = printer; // 设置打印机名称
//barReport.PrintSettings.Copies = 1; // 设置打印份数 //barReport.PrintSettings.Copies = 1; // 设置打印份数
// //barReport.PrintSettings.PageRange = "1-3"; // 设置打印页范围 // //barReport.PrintSettings.PageRange = "1-3"; // 设置打印页范围
//barReport.SetParameterValue("BoxBarData.Id", item);
//barReport.SetParameterValue("BoxBarData.Order_No", orderNo);//订单码 //barReport.SetParameterValue("BoxBarData.Order_No", orderNo);//订单码
//barReport.SetParameterValue("BoxBarData.Order_Material_Name", materialName);//物料名称 //barReport.SetParameterValue("BoxBarData.Order_Material_Name", materialName);//物料名称
//barReport.SetParameterValue("BoxBarData.Bar_Code", barCode);//二维码 //barReport.SetParameterValue("BoxBarData.Bar_Code", barCode);//二维码
@ -300,13 +280,13 @@ namespace Aucma.Core.PrintTo.ViewModels
if (item.MaterialName.Contains("箱体")) if (item.MaterialName.Contains("箱体"))
{ {
Console.WriteLine(item.MaterialName); Console.WriteLine(item.MaterialName);
PrintProgress = $"[{printNum}/{i}] B{DateTime.Now.ToString("yyMMdd")}1234567890000{i + 1}"; PrintProgress = $"[{printNum}/{i}] B{DateTime.Now.ToString("yyMMdd")}item.MaterialCode{i + 1}";
Console.WriteLine($"B{DateTime.Now.ToString("yyMMdd")}{item.MaterialCode}{i + 1}"); Console.WriteLine($"B{DateTime.Now.ToString("yyMMdd")}{item.MaterialCode}{i + 1}");
} }
if (item.MaterialName.Contains("内胆")) if (item.MaterialName.Contains("内胆"))
{ {
Console.WriteLine(item.MaterialName); Console.WriteLine(item.MaterialName);
PrintProgress = $"[{printNum}/{i}] B{DateTime.Now.ToString("yyMMdd")}{item.MaterialCode}0000{i + 1}"; PrintProgress = $"[{printNum}/{i}] L{DateTime.Now.ToString("yyMMdd")}{item.MaterialCode}0000{i + 1}";
Console.WriteLine($"L{DateTime.Now.ToString("yyMMdd")}{item.MaterialCode}0000{i + 1}"); Console.WriteLine($"L{DateTime.Now.ToString("yyMMdd")}{item.MaterialCode}0000{i + 1}");
} }
BarcodesPrinted.Enqueue(BarcodesUnprinted.Dequeue()); BarcodesPrinted.Enqueue(BarcodesUnprinted.Dequeue());
@ -330,6 +310,10 @@ namespace Aucma.Core.PrintTo.ViewModels
log.Error($"打印出错:{ex.Message}"); log.Error($"打印出错:{ex.Message}");
return Task.FromResult(false); return Task.FromResult(false);
} }
finally
{
isPrint = true;
}
} }
#endregion #endregion
@ -343,8 +327,10 @@ namespace Aucma.Core.PrintTo.ViewModels
printState = PrintState.Paused; printState = PrintState.Paused;
State = "yellow"; State = "yellow";
//StopOrStart = "继续";
isPrint = false; isPrint = false;
SuspendEnabled = "False";
OperateEnabled = "True";
} }
#endregion #endregion

Loading…
Cancel
Save