Files
client/Models/PrintJob.cs

110 lines
2.7 KiB
C#
Raw Normal View History

2026-05-23 18:16:50 +08:00
using CloudPrint.Client.Infrastructure;
namespace CloudPrint.Client.Models;
public enum PrintJobStatus
{
Pending,
Printing,
Completed,
Failed,
Cancelled
}
public sealed class PrintJob : ObservableObject
{
private PrintJobStatus _status = PrintJobStatus.Pending;
private int _progress;
private string _errorMessage = string.Empty;
private int? _windowsJobId;
private string _windowsJobStatus = string.Empty;
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? WindowsJobId
{
get => _windowsJobId;
set => SetProperty(ref _windowsJobId, value);
}
public string WindowsJobStatus
{
get => _windowsJobStatus;
set => SetProperty(ref _windowsJobStatus, value);
}
public PrintJobStatus Status
{
get => _status;
set
{
if (SetProperty(ref _status, value))
{
OnPropertyChanged(nameof(StatusText));
}
}
}
public int Progress
{
get => _progress;
set => SetProperty(ref _progress, Math.Clamp(value, 0, 100));
}
public string ErrorMessage
{
get => _errorMessage;
set => SetProperty(ref _errorMessage, value);
}
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;
}
}