Current.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection.Emit;
  6. using System.Text;
  7. using SqlSugar;
  8. using WCS.Data;
  9. using WCS.Data.Models;
  10. using WCS.Data.Utils;
  11. using WCS.PLC.Model.Equipment;
  12. using WCS.WMSWorkflow;
  13. namespace WCS.PLC
  14. {
  15. public enum TaskTypeEnum
  16. {
  17. TaskType_InStorage = 1,
  18. TaskType_OutStorage = 2,
  19. TaskType_StockTransfer = 3,
  20. TaskType_Carry = 4,
  21. TaskType_Move = 5,
  22. TaskType_TrayExceptionBack = 6
  23. }
  24. public enum SrmModeEnum
  25. {
  26. 远程 = 1,
  27. 半自动 = 2,
  28. 手动 = 3,
  29. 维修 = 4
  30. }
  31. public enum SrmStateFork1Enum
  32. {
  33. 空闲 = 1,
  34. 定位 = 2,
  35. 取货 = 3,
  36. 放货 = 4,
  37. 维护 = 99
  38. }
  39. public enum ComTypeEnum
  40. {
  41. 入库 = 1,
  42. 出库 = 2,
  43. 移库 = 3,
  44. 搬运 = 4,
  45. 移动 = 5,
  46. 托盘异常退回 = 6
  47. }
  48. public enum WkStatus
  49. {
  50. 未下发 = 0,
  51. 未执行 = 1,
  52. 输送机执行 = 2,
  53. RGV上料执行 = 3,
  54. RGV下料执行 = 4,
  55. 堆垛机执行 = 5,
  56. 堆垛机完成 = 6,
  57. RGV执行中 = 7,
  58. RGV移动 = 8,
  59. RGV完成 = 9,
  60. 任务已下发AGV = 10,
  61. AGV取货完成输送中 = 11,
  62. AGV任务完成 = 12,
  63. 熟化房熟化中 = 13,
  64. 熟化房熟化完成=14,
  65. 完成任务 = 99,
  66. 取消任务 = 106,
  67. 手动过账 = 109
  68. }
  69. public class Current: BaseCurrent
  70. {
  71. public static string LED_DEFAULTMESSAGE = "欢迎光临博众精工科技股份有限公司";
  72. /// <summary>
  73. /// 当前任务列表
  74. /// </summary>
  75. public static List<WCS_TASK> TaskSet = new List<WCS_TASK>();
  76. /// <summary>
  77. /// AGV任务列表
  78. /// </summary>
  79. public static List<Middle_AGVTask> AgvTaskSet = new List<Middle_AGVTask>();
  80. /// <summary>
  81. /// 熟化架缓存位信息
  82. /// </summary>
  83. public static List<Middle_CachePostionInfo> AgvCachePostionSet = new List<Middle_CachePostionInfo>();
  84. /// <summary>
  85. /// 需要手动生成任务的工位清单
  86. /// </summary>
  87. public static List<WCS_TASKTIMEPOINT> WCS_TASKTIMEPOINTSet = new List<WCS_TASKTIMEPOINT>();
  88. /// <summary>
  89. /// plc列表
  90. /// </summary>
  91. public static List<WCS_PLC> PlcSet = new List<WCS_PLC>();
  92. /// <summary>
  93. /// 设备路由列表
  94. /// </summary>
  95. public static List<WCS_EQUIPMENTROUTE> EquRouteSet = new List<WCS_EQUIPMENTROUTE>();
  96. /// <summary>
  97. /// 堆垛机出入口输送线列表
  98. /// </summary>
  99. public static List<WCS_SrmOutInInfo> WCS_SrmOutInInfoSet = new List<WCS_SrmOutInInfo>();
  100. /// <summary>
  101. /// 缓存区信息
  102. /// </summary>
  103. public static List<WCS_CacheInfo> WCS_CacheInfoSet = new List<WCS_CacheInfo>();
  104. /// <summary>
  105. /// 系统设置信息
  106. /// </summary>
  107. public static List<WCS_SYSSET> SysSets = new List<WCS_SYSSET>();
  108. /// <summary>
  109. /// RGV对接口列表
  110. /// </summary>
  111. public static List<WCS_RGVOutInInfo> WCS_RGVOutInInfoSet = new List<WCS_RGVOutInInfo>();
  112. /// <summary>
  113. /// WMS接口
  114. /// </summary>
  115. public static IWMS WmsInterface { get; set; }
  116. /// <summary>
  117. /// WCS扩展接口
  118. /// </summary>
  119. public static IWCS WcsInterface { get; set; }
  120. /// <summary>
  121. /// 原料仓库编号
  122. /// </summary>
  123. public static readonly string WareHouseId = "pvchouseyuanmo";
  124. /// <summary>
  125. /// PVC普通立体库
  126. /// </summary>
  127. public static readonly string Pvchouseputong = "pvchouseputong";
  128. public static readonly string PvchouseputongCh = "PVC普通立库";
  129. /// <summary>
  130. /// 仓库
  131. /// </summary>
  132. public static List<string> WareNameList { get; set; }
  133. public static void InitData(string wcssystem)
  134. {
  135. try
  136. {
  137. DeleteLog(30);
  138. WareNameList = new List<string>() { "PVC原膜立库", "PVC普通立库" };
  139. PlcSet = SugarBase.DB.Queryable<WCS_PLC>().Where(v => v.PLC_WCSSYSTEM == wcssystem).ToList();
  140. EquRouteSet = SugarBase.DB.Queryable<WCS_EQUIPMENTROUTE>().ToList();
  141. WCS_SrmOutInInfoSet = SugarBase.DB.Queryable<WCS_SrmOutInInfo>().ToList().Where(v => PlcSet.Any(t => t.PLC_NAME == v.SRMOUTIN_CONVPLCNAME)).ToList();
  142. WCS_RGVOutInInfoSet = SugarBase.DB.Queryable<WCS_RGVOutInInfo>().ToList().Where(v => PlcSet.Any(t => t.PLC_NAME == v.PLCNAME)).ToList();
  143. SysSets = SugarBase.DB.Queryable<WCS_SYSSET>().ToList();
  144. var sysset_wms = SysSets.FirstOrDefault(v => v.SET_TYPE == "WmsInterface" && v.SET_VALUE == "1");
  145. WmsInterface = (IWMS)Activator.CreateInstance(Type.GetType(sysset_wms.SET_NAME));
  146. var sysset_wcs = SysSets.FirstOrDefault(v => v.SET_TYPE == "WcsInterface" && v.SET_VALUE == "1");
  147. WcsInterface = (IWCS)Activator.CreateInstance(Type.GetType(sysset_wcs.SET_NAME));
  148. foreach (var plc in PlcSet)
  149. {
  150. for (int i = 0; i < plc.PLC_INSTANCECOUNT; i++)
  151. {
  152. plc.PlcInstanceSet.Add(null);
  153. }
  154. plc.WCS_DBSet = SugarBase.DB.Queryable<WCS_DBDEFINITION>().Where(v => v.DB_PLCNAME == plc.PLC_NAME).ToList();
  155. plc.WCS_ScannSet = SugarBase.DB.Queryable<WCS_SCANN>().Where(v => v.SCANN_PLCNAME == plc.PLC_NAME).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  156. plc.WCS_EquipmentInfoSet = SugarBase.DB.Queryable<WCS_EQUIPMENTINFO>().Where(v => v.Equ_PlcName == plc.PLC_NAME).OrderBy(v => v.Equ_Sequence).ToList();
  157. foreach (var item in plc.WCS_EquipmentInfoSet)
  158. {
  159. var equDBInfoSet = GetConvDBInfo(plc, item);
  160. if (item.Equ_Type.ToLower().Trim() == EquipmentType.conveyor.ToString())
  161. {
  162. item.EquSignal = new ConvSignal(item.Equ_PlcName, equDBInfoSet);
  163. }
  164. else if (item.Equ_Type.ToLower().Trim() == EquipmentType.srm.ToString())
  165. {
  166. item.EquSignal = new Model.Equipment.SrmSignal(item.Equ_PlcName, equDBInfoSet);
  167. }
  168. else if (item.Equ_Type.ToLower().Trim() == EquipmentType.rgv.ToString())
  169. {
  170. item.EquSignal = new Model.Equipment.RGVSignal(item.Equ_PlcName, equDBInfoSet);
  171. }
  172. }
  173. plc.Init();
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  179. }
  180. }
  181. private static List<ConvDbInfo> GetConvDBInfo(WCS_PLC plc, WCS_EQUIPMENTINFO item)
  182. {
  183. List<ConvDbInfo> equDBInfoSet = new List<ConvDbInfo>();
  184. var dbSet = plc.WCS_DBSet.Where(v => v.DB_PLCNAME == item.Equ_PlcName).ToList();
  185. foreach (var DB in dbSet)
  186. {
  187. if (DB.DB_TYPE == (int)DB_TypeEnum.WCS可读可写DB)
  188. {
  189. if (string.IsNullOrWhiteSpace(item.Equ_ReadWriteDB_Sequence)) continue;
  190. var convdb = new ConvDbInfo();
  191. convdb.DBName = DB.DB_NAME;
  192. convdb.DBType = DB_TypeEnum.WCS可读可写DB;
  193. convdb.DBReadLength = item.Equ_ReadWriteDB_Length;
  194. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  195. int temp_sequence = Convert.ToInt32(item.Equ_ReadWriteDB_Sequence);
  196. if (temp_sequence != 0)
  197. {
  198. int Totallength = temp_sequence * item.Equ_ReadWriteDB_Length;// plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_ReadWriteDB_Sequence) == false && Convert.ToInt32(v.Equ_ReadWriteDB_Sequence) < temp_sequence).Sum(v => v.Equ_ReadWriteDB_Length);
  199. convdb.DBReadIndox = Totallength;
  200. }
  201. equDBInfoSet.Add(convdb);
  202. }
  203. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS只读DB)
  204. {
  205. if (string.IsNullOrWhiteSpace(item.Equ_ReadDB_Sequence)) continue;
  206. var convdb = new ConvDbInfo();
  207. convdb.DBName = DB.DB_NAME;
  208. convdb.DBType = DB_TypeEnum.WCS只读DB;
  209. convdb.DBReadLength = item.Equ_ReadDB_Length;
  210. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  211. int temp_sequence = Convert.ToInt32(item.Equ_ReadDB_Sequence);
  212. if (temp_sequence != 0)
  213. {
  214. int Totallength = temp_sequence * item.Equ_ReadDB_Length;//plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_ReadDB_Sequence) == false && Convert.ToInt32(v.Equ_ReadDB_Sequence) < temp_sequence).Sum(v => v.Equ_ReadDB_Length);
  215. convdb.DBReadIndox = Totallength;
  216. }
  217. equDBInfoSet.Add(convdb);
  218. }
  219. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS状态和故障DB)
  220. {
  221. if (string.IsNullOrWhiteSpace(item.Equ_StatusDB_Sequence)) continue;
  222. var convdb = new ConvDbInfo();
  223. convdb.DBName = DB.DB_NAME;
  224. convdb.DBType = DB_TypeEnum.WCS状态和故障DB;
  225. convdb.DBReadLength = item.Equ_StatusDB_Length;
  226. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  227. int temp_sequence = Convert.ToInt32(item.Equ_StatusDB_Sequence);
  228. if (temp_sequence != 0)
  229. {
  230. int Totallength = temp_sequence * item.Equ_StatusDB_Length;//plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_StatusDB_Sequence) == false && Convert.ToInt32(v.Equ_StatusDB_Sequence) < temp_sequence).Sum(v => v.Equ_StatusDB_Length);
  231. convdb.DBReadIndox = Totallength;
  232. }
  233. equDBInfoSet.Add(convdb);
  234. }
  235. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读取扫码DB)
  236. {
  237. if (string.IsNullOrWhiteSpace(item.Equ_BarCodeDB_Sequence)) continue;
  238. var convdb = new ConvDbInfo();
  239. convdb.DBName = DB.DB_NAME;
  240. convdb.DBType = DB_TypeEnum.WCS读取扫码DB;
  241. convdb.DBReadLength = item.Equ_BarCodeDB_Length;
  242. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  243. int temp_sequence = Convert.ToInt32(item.Equ_BarCodeDB_Sequence);
  244. if (temp_sequence != 0)
  245. {
  246. int Totallength = plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_BarCodeDB_Sequence) == false && Convert.ToInt32(v.Equ_BarCodeDB_Sequence) < temp_sequence).Sum(v => v.Equ_BarCodeDB_Length);
  247. convdb.DBReadIndox = Totallength;
  248. }
  249. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  250. equDBInfoSet.Add(convdb);
  251. }
  252. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读写扩展DB1)
  253. {
  254. if (string.IsNullOrWhiteSpace(item.Equ_ExtendOne_Sequence)) continue;
  255. var convdb = new ConvDbInfo();
  256. convdb.DBName = DB.DB_NAME;
  257. convdb.DBType = DB_TypeEnum.WCS读写扩展DB1;
  258. convdb.DBReadLength = item.Equ_ExtendOne_Length;
  259. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  260. int temp_sequence = Convert.ToInt32(item.Equ_ExtendOne_Sequence);
  261. if (temp_sequence != 0)
  262. {
  263. int Totallength = plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_ExtendOne_Sequence) == false && Convert.ToInt32(v.Equ_ExtendOne_Sequence) < temp_sequence).Sum(v => v.Equ_ExtendOne_Length);
  264. convdb.DBReadIndox = Totallength;
  265. }
  266. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  267. equDBInfoSet.Add(convdb);
  268. }
  269. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读写扩展DB2)
  270. {
  271. if (string.IsNullOrWhiteSpace(item.Equ_ExtendTwo_Sequence)) continue;
  272. var convdb = new ConvDbInfo();
  273. convdb.DBName = DB.DB_NAME;
  274. convdb.DBType = DB_TypeEnum.WCS读写扩展DB2;
  275. convdb.DBReadLength = item.Equ_ExtendTwo_Length;
  276. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  277. int temp_sequence = Convert.ToInt32(item.Equ_ExtendTwo_Sequence);
  278. if (temp_sequence != 0)
  279. {
  280. int Totallength = plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_ExtendTwo_Sequence) == false && Convert.ToInt32(v.Equ_ExtendTwo_Sequence) < temp_sequence).Sum(v => v.Equ_ExtendTwo_Length);
  281. convdb.DBReadIndox = Totallength;
  282. }
  283. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  284. equDBInfoSet.Add(convdb);
  285. }
  286. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读写扩展DB3)
  287. {
  288. if (string.IsNullOrWhiteSpace(item.Equ_ExtendThree_Sequence)) continue;
  289. var convdb = new ConvDbInfo();
  290. convdb.DBName = DB.DB_NAME;
  291. convdb.DBType = DB_TypeEnum.WCS读写扩展DB3;
  292. convdb.DBReadLength = item.Equ_ExtendThree_Length;
  293. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  294. int temp_sequence = Convert.ToInt32(item.Equ_ExtendThree_Sequence);
  295. if (temp_sequence != 0)
  296. {
  297. int Totallength = plc.WCS_EquipmentInfoSet.Where(v => string.IsNullOrWhiteSpace(v.Equ_ExtendThree_Sequence) == false && Convert.ToInt32(v.Equ_ExtendThree_Sequence) < temp_sequence).Sum(v => v.Equ_ExtendThree_Length);
  298. convdb.DBReadIndox = Totallength;
  299. }
  300. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  301. equDBInfoSet.Add(convdb);
  302. }
  303. }
  304. return equDBInfoSet;
  305. }
  306. /// <summary>
  307. /// 删除过期日志
  308. /// </summary>
  309. public static void DeleteLog(int day)
  310. {
  311. string path = string.Format("{0}bin\\Debug\\netcoreapp3.1\\App_Log\\Info\\", AppDomain.CurrentDomain.BaseDirectory);
  312. DeleteLog(day, path);
  313. path = string.Format("{0}bin\\Debug\\netcoreapp3.1\\App_Log\\Error\\", AppDomain.CurrentDomain.BaseDirectory);
  314. DeleteLog(day, path);
  315. path = string.Format("{0}bin\\Debug\\netcoreapp3.1\\App_Log\\Product\\", AppDomain.CurrentDomain.BaseDirectory);
  316. DeleteLog(day, path);
  317. //DeleteAGVLog(day);
  318. }
  319. private static void DeleteLog(int day, string path)
  320. {
  321. try
  322. {
  323. int daycount = -day;
  324. DirectoryInfo folder = new DirectoryInfo(path);
  325. FileInfo[] files = folder.GetFiles("*.log.*");
  326. DateTime dt = DateTime.Now.AddDays(daycount);
  327. DateTime date = new DateTime();
  328. foreach (FileInfo info in files)
  329. {
  330. if (DateTime.TryParse(info.Name.Substring(0, 10), out date))
  331. {
  332. if (date < dt)
  333. {
  334. info.Delete();
  335. }
  336. }
  337. }
  338. }
  339. catch (Exception ex)
  340. {
  341. Log4netHelper.Logger_Error.ErrorFormat(string.Format("路径[{0}]下删除超过[{1}]天的日志失败", path, day));
  342. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  343. }
  344. }
  345. ///// <summary>
  346. ///// 根据箱子尺寸是可用范围获取箱子剁型编号
  347. ///// </summary>
  348. //public static WCS_PalletizingCode IsAvailableRange_BoxSize(List<WCS_PalletizingCode> palletizingCodeSet,string boxSize, int task_no)
  349. //{
  350. // WCS_PalletizingCode palletizingCode = null;
  351. // try
  352. // {
  353. // if (string.IsNullOrWhiteSpace(boxSize))
  354. // throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  355. // string[] boxsizeSet = boxSize.Split('*');
  356. // if (boxsizeSet.Count() < 3)
  357. // throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  358. // decimal length = Convert.ToDecimal(boxsizeSet[0]);
  359. // decimal width = Convert.ToDecimal(boxsizeSet[1]);
  360. // decimal height = Convert.ToDecimal(boxsizeSet[2]);
  361. // palletizingCode = palletizingCodeSet.FirstOrDefault(v => length == v.BoxSizeLength && width == v.BoxSizeWidth && height == v.BoxSizeHeight);
  362. // //palletizingCode = palletizingCodeSet.FirstOrDefault(v => length >= v.BoxSizeLength_Min && length <= v.BoxSizeLength_Max &&
  363. // // width >= v.BoxSizeWidth_Min && width <= v.BoxSizeWidth_Max &&
  364. // // height >= v.BoxSizeHeight_Min && height <= v.BoxSizeHeight_Max);
  365. // }
  366. // catch (Exception ex)
  367. // {
  368. // LogMessageHelper.RecordLogMessage(ex);
  369. // }
  370. // return palletizingCode;
  371. //}
  372. /// <summary>
  373. /// 根据箱子尺寸是可用范围获取箱子剁型编号
  374. /// </summary>
  375. public static WCS_PalletizingCode IsAvailableRange_BoxSize(List<WCS_PalletizingCode> palletizingCodeSet, string boxSize, int task_no)
  376. {
  377. WCS_PalletizingCode palletizingCode = null;
  378. try
  379. {
  380. if (string.IsNullOrWhiteSpace(boxSize))
  381. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  382. string[] boxsizeSet = boxSize.Split('*');
  383. if (boxsizeSet.Count() < 3)
  384. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  385. decimal length = Convert.ToDecimal(boxsizeSet[0]);
  386. decimal width = Convert.ToDecimal(boxsizeSet[1]);
  387. decimal height = Convert.ToDecimal(boxsizeSet[2]);
  388. palletizingCode = palletizingCodeSet.FirstOrDefault(v => length == v.BoxSizeLength && width == v.BoxSizeWidth && height == v.BoxSizeHeight);
  389. //palletizingCode = palletizingCodeSet.FirstOrDefault(v => length >= v.BoxSizeLength_Min && length <= v.BoxSizeLength_Max &&
  390. // width >= v.BoxSizeWidth_Min && width <= v.BoxSizeWidth_Max &&
  391. // height >= v.BoxSizeHeight_Min && height <= v.BoxSizeHeight_Max);
  392. }
  393. catch (Exception ex)
  394. {
  395. LogMessageHelper.RecordLogMessage(ex);
  396. }
  397. return palletizingCode;
  398. }
  399. /// <summary>
  400. ///根据箱子尺寸托盘尺寸是可用范围获取机械手剁型编号
  401. /// </summary>
  402. public static WCS_PalletizingCode IsAvailableRange_SonTraySize(List<WCS_PalletizingCode> palletizingCodeSet, string sonTraySize, string boxSize, int task_no)
  403. {
  404. WCS_PalletizingCode palletizingCode = null;
  405. try
  406. {
  407. if (string.IsNullOrWhiteSpace(boxSize))
  408. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  409. string[] sonTraySizeSet = sonTraySize.Split('*');
  410. if (sonTraySizeSet.Count() < 2)
  411. throw new Exception(string.Format("任务[{0}]子托盘尺寸[{1}]不正确", task_no, sonTraySize));
  412. if (string.IsNullOrWhiteSpace(boxSize))
  413. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  414. string[] boxsizeSet = boxSize.Split('*');
  415. if (boxsizeSet.Count() < 3)
  416. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  417. decimal boxlength = Convert.ToDecimal(boxsizeSet[0]);
  418. decimal boxwidth = Convert.ToDecimal(boxsizeSet[1]);
  419. decimal boxheight = Convert.ToDecimal(boxsizeSet[2]);
  420. decimal length = Convert.ToDecimal(sonTraySizeSet[0]);
  421. decimal width = Convert.ToDecimal(sonTraySizeSet[1]);
  422. palletizingCode = palletizingCodeSet.FirstOrDefault(v => boxlength == v.BoxSizeLength &&
  423. boxwidth == v.BoxSizeWidth &&
  424. boxheight == v.BoxSizeHeight &&
  425. length == v.SonTraySizeLength &&
  426. width == v.SonTraySizeWidth);
  427. //palletizingCode = palletizingCodeSet.FirstOrDefault(v => boxlength >= v.BoxSizeLength_Min && boxlength <= v.BoxSizeLength_Max &&
  428. // boxwidth >= v.BoxSizeWidth_Min && boxwidth <= v.BoxSizeWidth_Max &&
  429. // boxheight >= v.BoxSizeHeight_Min && boxheight <= v.BoxSizeHeight_Max &&
  430. // length >= v.SonTraySizeLength_Min && length <= v.SonTraySizeLength_Max &&
  431. // width >= v.SonTraySizeWidth_Min && width <= v.SonTraySizeWidth_Max);
  432. }
  433. catch (Exception ex)
  434. {
  435. LogMessageHelper.RecordLogMessage(ex);
  436. }
  437. return palletizingCode;
  438. }
  439. }
  440. }