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
{
///
/// 公共任务字典
///
public class TaskDictionary
{
private static Dictionary outTaskDic = new Dictionary();
private static Dictionary inTaskDic = new Dictionary();
private static Dictionary otherTaskDic = new Dictionary();
///
/// 写入出库任务
///
///
///
///
public static bool writeOutTask(int dickey, PlcDirectiveDTO plcDirective)
{
try
{
outTaskDic.Add(dickey, plcDirective);
return true;
}
catch (Exception ex)
{
LogHelper.Error("写入出库任务异常", ex);
return false;
}
}
///
/// 写入入库任务
///
///
///
///
public static bool writeInTask(int dickey, PlcDirectiveDTO plcDirective)
{
try
{
inTaskDic.Add(dickey, plcDirective);
return true;
}
catch (Exception ex)
{
LogHelper.Error("写入入库任务异常", ex);
return false;
}
}
///
/// 写入手动、其它任务
///
///
///
///
public static bool writeOtherTask(int dickey, PlcDirectiveDTO plcDirective)
{
try
{
otherTaskDic.Add(dickey, plcDirective);
return true;
}
catch (Exception ex)
{
LogHelper.Error("写入其它任务异常", ex);
return false;
}
}
///
/// 获取当前出库任务
///
///
public static Dictionary getOutTask()
{
Dictionary dictionary = new Dictionary();
PlcDirectiveDTO plcDirectiveDTO = new PlcDirectiveDTO();
if (outTaskDic.Count() == 0 || outTaskDic == null)
return new Dictionary();
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;
}
///
/// 获取当前入库任务
///
///
public static Dictionary getInTask()
{
Dictionary dictionary = new Dictionary();
PlcDirectiveDTO plcDirectiveDTO = new PlcDirectiveDTO();
if (inTaskDic.Count() == 0 || inTaskDic == null)
return new Dictionary();
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;
}
///
/// 获取当前手动、其它任务
///
///
public static Dictionary getOtherTask()
{
Dictionary dictionary = new Dictionary();
PlcDirectiveDTO plcDirectiveDTO = new PlcDirectiveDTO();
if (otherTaskDic.Count() == 0 || otherTaskDic == null)
return new Dictionary();
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;
}
///
/// 获取所有出库任务
///
///
public static Dictionary getOutDictionary()
{
return outTaskDic;
}
///
/// 获取所有入库任务
///
///
public static Dictionary getInDictionary()
{
return inTaskDic;
}
///
/// 获取所有手动其它任务
///
///
public static Dictionary getOtherDictionary()
{
return otherTaskDic;
}
///
/// 根据key移除出库任务
///
///
///
public static bool removeOutTask(int dicKey)
{
return outTaskDic.Remove(dicKey);
}
///
/// 根据key移除入库任务
///
///
///
public static bool removeInTask(int dicKey)
{
return inTaskDic.Remove(dicKey);
}
///
/// 根据key移除其它任务
///
///
///
public static bool removeOtherTask(int dicKey)
{
return otherTaskDic.Remove(dicKey);
}
///
/// 获取字典中的数量
///
///
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;
}
}
}