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.

213 lines
6.6 KiB
C#

using AUCMA.STORE.Entity.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AUCMA.STORE.Common
{
/// <summary>
/// 公共任务字典
/// </summary>
public class TaskDictionary
{
private static Dictionary<int, PlcDirectiveDTO> outTaskDic = new Dictionary<int, PlcDirectiveDTO>();
private static Dictionary<int, PlcDirectiveDTO> inTaskDic = new Dictionary<int, PlcDirectiveDTO>();
private static Dictionary<int, PlcDirectiveDTO> otherTaskDic = new Dictionary<int, PlcDirectiveDTO>();
/// <summary>
/// 写入出库任务
/// </summary>
/// <param name="dickey"></param>
/// <param name="plcDirective"></param>
/// <returns></returns>
public static bool writeOutTask(int dickey, PlcDirectiveDTO plcDirective)
{
try
{
outTaskDic.Add(dickey, plcDirective);
return true;
}
catch (Exception ex)
{
LogHelper.Error("写入出库任务异常", ex);
return false;
}
}
/// <summary>
/// 写入入库任务
/// </summary>
/// <param name="dickey"></param>
/// <param name="plcDirective"></param>
/// <returns></returns>
public static bool writeInTask(int dickey, PlcDirectiveDTO plcDirective)
{
try
{
inTaskDic.Add(dickey, plcDirective);
return true;
}
catch (Exception ex)
{
LogHelper.Error("写入入库任务异常", ex);
return false;
}
}
/// <summary>
/// 写入手动、其它任务
/// </summary>
/// <param name="dickey"></param>
/// <param name="plcDirective"></param>
/// <returns></returns>
public static bool writeOtherTask(int dickey, PlcDirectiveDTO plcDirective)
{
try
{
otherTaskDic.Add(dickey, plcDirective);
return true;
}
catch (Exception ex)
{
LogHelper.Error("写入其它任务异常", ex);
return false;
}
}
/// <summary>
/// 获取当前出库任务
/// </summary>
/// <returns></returns>
public static Dictionary<int, PlcDirectiveDTO> getOutTask()
{
Dictionary<int, PlcDirectiveDTO> dictionary = new Dictionary<int, PlcDirectiveDTO>();
PlcDirectiveDTO plcDirectiveDTO = new PlcDirectiveDTO();
if (outTaskDic.Count() == 0 || outTaskDic == null)
return new Dictionary<int, PlcDirectiveDTO>();
int dictionarykey = outTaskDic.OrderBy(x => x.Key).ToDictionary(y => y.Key, p => p.Value).FirstOrDefault().Key;
outTaskDic.TryGetValue(dictionarykey, out plcDirectiveDTO);
dictionary.Add(dictionarykey, plcDirectiveDTO);
return dictionary;
}
/// <summary>
/// 获取当前入库任务
/// </summary>
/// <returns></returns>
public static Dictionary<int, PlcDirectiveDTO> getInTask()
{
Dictionary<int, PlcDirectiveDTO> dictionary = new Dictionary<int, PlcDirectiveDTO>();
PlcDirectiveDTO plcDirectiveDTO = new PlcDirectiveDTO();
if (inTaskDic.Count() == 0 || inTaskDic == null)
return new Dictionary<int, PlcDirectiveDTO>();
int dictionarykey = inTaskDic.OrderBy(x => x.Key).ToDictionary(y => y.Key, p => p.Value).FirstOrDefault().Key;
inTaskDic.TryGetValue(dictionarykey, out plcDirectiveDTO);
dictionary.Add(dictionarykey, plcDirectiveDTO);
return dictionary;
}
/// <summary>
/// 获取当前手动、其它任务
/// </summary>
/// <returns></returns>
public static Dictionary<int, PlcDirectiveDTO> getOtherTask()
{
Dictionary<int, PlcDirectiveDTO> dictionary = new Dictionary<int, PlcDirectiveDTO>();
PlcDirectiveDTO plcDirectiveDTO = new PlcDirectiveDTO();
if (otherTaskDic.Count() == 0 || otherTaskDic == null)
return new Dictionary<int, PlcDirectiveDTO>();
int dictionarykey = otherTaskDic.OrderBy(x => x.Key).ToDictionary(y => y.Key, p => p.Value).FirstOrDefault().Key;
otherTaskDic.TryGetValue(dictionarykey, out plcDirectiveDTO);
dictionary.Add(dictionarykey, plcDirectiveDTO);
return dictionary;
}
/// <summary>
/// 获取所有出库任务
/// </summary>
/// <returns></returns>
public static Dictionary<int, PlcDirectiveDTO> getOutDictionary()
{
return outTaskDic;
}
/// <summary>
/// 获取所有入库任务
/// </summary>
/// <returns></returns>
public static Dictionary<int, PlcDirectiveDTO> getInDictionary()
{
return inTaskDic;
}
/// <summary>
/// 获取所有手动其它任务
/// </summary>
/// <returns></returns>
public static Dictionary<int, PlcDirectiveDTO> getOtherDictionary()
{
return otherTaskDic;
}
/// <summary>
/// 根据key移除出库任务
/// </summary>
/// <param name="dicKey"></param>
/// <returns></returns>
public static bool removeOutTask(int dicKey)
{
return outTaskDic.Remove(dicKey);
}
/// <summary>
/// 根据key移除入库任务
/// </summary>
/// <param name="dicKey"></param>
/// <returns></returns>
public static bool removeInTask(int dicKey)
{
return inTaskDic.Remove(dicKey);
}
/// <summary>
/// 根据key移除其它任务
/// </summary>
/// <param name="dicKey"></param>
/// <returns></returns>
public static bool removeOtherTask(int dicKey)
{
return otherTaskDic.Remove(dicKey);
}
/// <summary>
/// 获取字典中的数量
/// </summary>
/// <returns></returns>
public static int dicCount()
{
return outTaskDic.Count();
}
public static int FindKey(int TaskCode)
{
int key = outTaskDic.FirstOrDefault(q => q.Value.pilerTaskCode == TaskCode).Key;
return key;
}
}
}