You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using SlnMesnac.LabelPrint.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SlnMesnac.LabelPrint.TaskQueue
|
|
{
|
|
public class TaskHelper
|
|
{
|
|
|
|
#region 单例实现
|
|
private static readonly Lazy<TaskHelper> lazy = new Lazy<TaskHelper>(() => new TaskHelper());
|
|
|
|
public static TaskHelper Instance
|
|
{
|
|
get
|
|
{
|
|
return lazy.Value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 委托事件
|
|
/// <summary>
|
|
/// 清除标签信息
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
public delegate void ClearLabelInfoDataGrid(BaseLabelInfo baseLabelInfo);
|
|
public event ClearLabelInfoDataGrid ClearLabelInfoDataGridEvent;
|
|
#endregion
|
|
|
|
public TaskHelper() { }
|
|
|
|
private List<BaseLabelInfo> labelTask = new List<BaseLabelInfo>();
|
|
|
|
/// <summary>
|
|
/// 添加标签任务
|
|
/// </summary>
|
|
/// <param name="labelInfos"></param>
|
|
public void AddTask(List<BaseLabelInfo> labelInfos)
|
|
{
|
|
if (labelInfos == null) return;
|
|
labelTask.AddRange(labelInfos);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取标签任务,根据时间返回第一个不同的标签
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public BaseLabelInfo GetTask()
|
|
{
|
|
return labelTask.OrderBy(x => x.recordTime).FirstOrDefault();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除标签任务,打印完成后删除队列中的任务
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
public void RemoveTask(BaseLabelInfo item)
|
|
{
|
|
labelTask.Remove(item);
|
|
ClearLabelInfoDataGridEvent?.Invoke(item);
|
|
}
|
|
|
|
}
|
|
}
|