2026-05-28 23:26:37 +08:00
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2026-05-23 18:16:50 +08:00
|
|
|
|
|
|
|
|
namespace CloudPrint.Client.Models;
|
|
|
|
|
|
|
|
|
|
public enum PrintJobStatus
|
|
|
|
|
{
|
|
|
|
|
Pending,
|
|
|
|
|
Printing,
|
|
|
|
|
Completed,
|
|
|
|
|
Failed,
|
|
|
|
|
Cancelled
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 23:26:37 +08:00
|
|
|
public sealed partial class PrintJob : ObservableObject
|
2026-05-23 18:16:50 +08:00
|
|
|
{
|
2026-05-28 23:26:37 +08:00
|
|
|
[ObservableProperty]
|
|
|
|
|
private int? windowsJobId;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string windowsJobStatus = string.Empty;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[NotifyPropertyChangedFor(nameof(StatusText))]
|
|
|
|
|
private PrintJobStatus status = PrintJobStatus.Pending;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string errorMessage = string.Empty;
|
|
|
|
|
|
|
|
|
|
private int progress;
|
2026-05-23 18:16:50 +08:00
|
|
|
|
|
|
|
|
public int Id { get; init; }
|
|
|
|
|
public string JobNo { get; init; } = string.Empty;
|
|
|
|
|
public int PrinterId { get; set; }
|
|
|
|
|
public string PrinterName { get; set; } = string.Empty;
|
|
|
|
|
public int OrderItemId { get; init; }
|
|
|
|
|
public int FileId { get; init; }
|
|
|
|
|
public string FileName { get; init; } = string.Empty;
|
|
|
|
|
public string FilePath { get; set; } = string.Empty;
|
|
|
|
|
public int Copies { get; init; } = 1;
|
|
|
|
|
public bool Color { get; init; }
|
|
|
|
|
public bool Duplex { get; init; }
|
|
|
|
|
public string PageRange { get; init; } = "all";
|
|
|
|
|
public DateTime? StartedAt { get; set; }
|
|
|
|
|
public DateTime? CompletedAt { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Progress
|
|
|
|
|
{
|
2026-05-28 23:26:37 +08:00
|
|
|
get => progress;
|
|
|
|
|
set => SetProperty(ref progress, Math.Clamp(value, 0, 100));
|
2026-05-23 18:16:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string StatusText => Status switch
|
|
|
|
|
{
|
|
|
|
|
PrintJobStatus.Pending => "待打印",
|
|
|
|
|
PrintJobStatus.Printing => "打印中",
|
|
|
|
|
PrintJobStatus.Completed => "已完成",
|
|
|
|
|
PrintJobStatus.Failed => "失败",
|
|
|
|
|
PrintJobStatus.Cancelled => "已取消",
|
|
|
|
|
_ => "未知"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public void MarkPrinting()
|
|
|
|
|
{
|
|
|
|
|
StartedAt ??= DateTime.Now;
|
|
|
|
|
Status = PrintJobStatus.Printing;
|
|
|
|
|
Progress = Math.Max(Progress, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkCompleted()
|
|
|
|
|
{
|
|
|
|
|
Status = PrintJobStatus.Completed;
|
|
|
|
|
Progress = 100;
|
|
|
|
|
CompletedAt = DateTime.Now;
|
|
|
|
|
ErrorMessage = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkFailed(string message)
|
|
|
|
|
{
|
|
|
|
|
Status = PrintJobStatus.Failed;
|
|
|
|
|
ErrorMessage = message;
|
|
|
|
|
CompletedAt = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkCancelled()
|
|
|
|
|
{
|
|
|
|
|
Status = PrintJobStatus.Cancelled;
|
|
|
|
|
CompletedAt = DateTime.Now;
|
|
|
|
|
}
|
2026-05-28 23:26:37 +08:00
|
|
|
}
|