Current.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. /// 车间产线启用禁用配置
  110. /// </summary>
  111. public static List<WCS_AGV_Config> AGVConfig = new List<WCS_AGV_Config>();
  112. /// <summary>
  113. /// RGV对接口列表
  114. /// </summary>
  115. public static List<WCS_RGVOutInInfo> WCS_RGVOutInInfoSet = new List<WCS_RGVOutInInfo>();
  116. /// <summary>
  117. /// 当前扫码口列表
  118. /// </summary>
  119. public static List<WCS_SCANN> WCS_ScanSet = new List<WCS_SCANN>();
  120. /// <summary>
  121. /// WMS接口
  122. /// </summary>
  123. public static IWMS WmsInterface { get; set; }
  124. /// <summary>
  125. /// WCS扩展接口
  126. /// </summary>
  127. public static IWCS WcsInterface { get; set; }
  128. /// <summary>
  129. /// 原料仓库编号
  130. /// </summary>
  131. public static readonly string WareHouseId = "pvchouseyuanmo";
  132. /// <summary>
  133. /// PVC普通立体库
  134. /// </summary>
  135. public static readonly string Pvchouseputong = "pvchouseputong";
  136. public static readonly string PvchouseputongCh = "PVC普通立库";
  137. /// <summary>
  138. /// 仓库
  139. /// </summary>
  140. public static List<string> WareNameList { get; set; }
  141. /// <summary>
  142. /// 锁
  143. /// </summary>
  144. internal static readonly object Locker = new object();
  145. public static void InitData(string wcssystem)
  146. {
  147. try
  148. {
  149. DeleteLog(30);
  150. WareNameList = new List<string>() { "PVC原膜立库", "PVC普通立库" };
  151. PlcSet = SugarBase.DB.Queryable<WCS_PLC>().Where(v => v.PLC_WCSSYSTEM == wcssystem).ToList();
  152. EquRouteSet = SugarBase.DB.Queryable<WCS_EQUIPMENTROUTE>().ToList();
  153. WCS_SrmOutInInfoSet = SugarBase.DB.Queryable<WCS_SrmOutInInfo>().ToList().Where(v => PlcSet.Any(t => t.PLC_NAME == v.SRMOUTIN_CONVPLCNAME)).ToList();
  154. WCS_RGVOutInInfoSet = SugarBase.DB.Queryable<WCS_RGVOutInInfo>().ToList().Where(v => PlcSet.Any(t => t.PLC_NAME == v.PLCNAME)).ToList();
  155. SysSets = SugarBase.DB.Queryable<WCS_SYSSET>().ToList();
  156. AGVConfig = SugarBase.DB.Queryable<WCS_AGV_Config>().ToList();
  157. var sysset_wms = SysSets.FirstOrDefault(v => v.SET_TYPE == "WmsInterface" && v.SET_VALUE == "1");
  158. WmsInterface = (IWMS)Activator.CreateInstance(Type.GetType(sysset_wms.SET_NAME));
  159. var sysset_wcs = SysSets.FirstOrDefault(v => v.SET_TYPE == "WcsInterface" && v.SET_VALUE == "1");
  160. WcsInterface = (IWCS)Activator.CreateInstance(Type.GetType(sysset_wcs.SET_NAME));
  161. foreach (var plc in PlcSet)
  162. {
  163. for (int i = 0; i < plc.PLC_INSTANCECOUNT; i++)
  164. {
  165. plc.PlcInstanceSet.Add(null);
  166. }
  167. plc.WCS_DBSet = SugarBase.DB.Queryable<WCS_DBDEFINITION>().Where(v => v.DB_PLCNAME == plc.PLC_NAME).ToList();
  168. plc.WCS_ScannSet = SugarBase.DB.Queryable<WCS_SCANN>().Where(v => v.SCANN_PLCNAME == plc.PLC_NAME).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  169. plc.WCS_EquipmentInfoSet = SugarBase.DB.Queryable<WCS_EQUIPMENTINFO>().Where(v => v.Equ_PlcName == plc.PLC_NAME).OrderBy(v => v.Equ_Sequence).ToList();
  170. foreach (var item in plc.WCS_EquipmentInfoSet)
  171. {
  172. var equDBInfoSet = GetConvDBInfo(plc, item);
  173. if (item.Equ_Type.ToLower().Trim() == EquipmentType.conveyor.ToString())
  174. {
  175. item.EquSignal = new ConvSignal(item.Equ_PlcName, equDBInfoSet);
  176. }
  177. else if (item.Equ_Type.ToLower().Trim() == EquipmentType.srm.ToString())
  178. {
  179. item.EquSignal = new Model.Equipment.SrmSignal(item.Equ_PlcName, equDBInfoSet);
  180. }
  181. else if (item.Equ_Type.ToLower().Trim() == EquipmentType.rgv.ToString())
  182. {
  183. item.EquSignal = new Model.Equipment.RGVSignal(item.Equ_PlcName, equDBInfoSet);
  184. }
  185. }
  186. plc.Init();
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  192. }
  193. }
  194. private static List<ConvDbInfo> GetConvDBInfo(WCS_PLC plc, WCS_EQUIPMENTINFO item)
  195. {
  196. List<ConvDbInfo> equDBInfoSet = new List<ConvDbInfo>();
  197. var dbSet = plc.WCS_DBSet.Where(v => v.DB_PLCNAME == item.Equ_PlcName).ToList();
  198. foreach (var DB in dbSet)
  199. {
  200. if (DB.DB_TYPE == (int)DB_TypeEnum.WCS可读可写DB)
  201. {
  202. if (string.IsNullOrWhiteSpace(item.Equ_ReadWriteDB_Sequence)) continue;
  203. var convdb = new ConvDbInfo();
  204. convdb.DBName = DB.DB_NAME;
  205. convdb.DBType = DB_TypeEnum.WCS可读可写DB;
  206. convdb.DBReadLength = item.Equ_ReadWriteDB_Length;
  207. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  208. int temp_sequence = Convert.ToInt32(item.Equ_ReadWriteDB_Sequence);
  209. if (temp_sequence != 0)
  210. {
  211. 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);
  212. convdb.DBReadIndox = Totallength;
  213. }
  214. equDBInfoSet.Add(convdb);
  215. }
  216. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS只读DB)
  217. {
  218. if (string.IsNullOrWhiteSpace(item.Equ_ReadDB_Sequence)) continue;
  219. var convdb = new ConvDbInfo();
  220. convdb.DBName = DB.DB_NAME;
  221. convdb.DBType = DB_TypeEnum.WCS只读DB;
  222. convdb.DBReadLength = item.Equ_ReadDB_Length;
  223. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  224. int temp_sequence = Convert.ToInt32(item.Equ_ReadDB_Sequence);
  225. if (temp_sequence != 0)
  226. {
  227. 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);
  228. convdb.DBReadIndox = Totallength;
  229. }
  230. equDBInfoSet.Add(convdb);
  231. }
  232. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS状态和故障DB)
  233. {
  234. if (string.IsNullOrWhiteSpace(item.Equ_StatusDB_Sequence)) continue;
  235. var convdb = new ConvDbInfo();
  236. convdb.DBName = DB.DB_NAME;
  237. convdb.DBType = DB_TypeEnum.WCS状态和故障DB;
  238. convdb.DBReadLength = item.Equ_StatusDB_Length;
  239. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  240. int temp_sequence = Convert.ToInt32(item.Equ_StatusDB_Sequence);
  241. if (temp_sequence != 0)
  242. {
  243. 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);
  244. convdb.DBReadIndox = Totallength;
  245. }
  246. equDBInfoSet.Add(convdb);
  247. }
  248. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读取扫码DB)
  249. {
  250. if (string.IsNullOrWhiteSpace(item.Equ_BarCodeDB_Sequence)) continue;
  251. var convdb = new ConvDbInfo();
  252. convdb.DBName = DB.DB_NAME;
  253. convdb.DBType = DB_TypeEnum.WCS读取扫码DB;
  254. convdb.DBReadLength = item.Equ_BarCodeDB_Length;
  255. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  256. int temp_sequence = Convert.ToInt32(item.Equ_BarCodeDB_Sequence);
  257. if (temp_sequence != 0)
  258. {
  259. 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);
  260. convdb.DBReadIndox = Totallength;
  261. }
  262. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  263. equDBInfoSet.Add(convdb);
  264. }
  265. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读写扩展DB1)
  266. {
  267. if (string.IsNullOrWhiteSpace(item.Equ_ExtendOne_Sequence)) continue;
  268. var convdb = new ConvDbInfo();
  269. convdb.DBName = DB.DB_NAME;
  270. convdb.DBType = DB_TypeEnum.WCS读写扩展DB1;
  271. convdb.DBReadLength = item.Equ_ExtendOne_Length;
  272. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  273. int temp_sequence = Convert.ToInt32(item.Equ_ExtendOne_Sequence);
  274. if (temp_sequence != 0)
  275. {
  276. 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);
  277. convdb.DBReadIndox = Totallength;
  278. }
  279. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  280. equDBInfoSet.Add(convdb);
  281. }
  282. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读写扩展DB2)
  283. {
  284. if (string.IsNullOrWhiteSpace(item.Equ_ExtendTwo_Sequence)) continue;
  285. var convdb = new ConvDbInfo();
  286. convdb.DBName = DB.DB_NAME;
  287. convdb.DBType = DB_TypeEnum.WCS读写扩展DB2;
  288. convdb.DBReadLength = item.Equ_ExtendTwo_Length;
  289. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  290. int temp_sequence = Convert.ToInt32(item.Equ_ExtendTwo_Sequence);
  291. if (temp_sequence != 0)
  292. {
  293. 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);
  294. convdb.DBReadIndox = Totallength;
  295. }
  296. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  297. equDBInfoSet.Add(convdb);
  298. }
  299. else if (DB.DB_TYPE == (int)DB_TypeEnum.WCS读写扩展DB3)
  300. {
  301. if (string.IsNullOrWhiteSpace(item.Equ_ExtendThree_Sequence)) continue;
  302. var convdb = new ConvDbInfo();
  303. convdb.DBName = DB.DB_NAME;
  304. convdb.DBType = DB_TypeEnum.WCS读写扩展DB3;
  305. convdb.DBReadLength = item.Equ_ExtendThree_Length;
  306. //convdb.DBReadIndox = item.Equ_ReadWriteDB_Sequence * item.Equ_ReadWriteDB_Length;
  307. int temp_sequence = Convert.ToInt32(item.Equ_ExtendThree_Sequence);
  308. if (temp_sequence != 0)
  309. {
  310. 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);
  311. convdb.DBReadIndox = Totallength;
  312. }
  313. convdb.ScannSet = plc.WCS_ScannSet.Where(v => v.SCANN_STATIONNO == item.Equ_No).OrderBy(v => v.SCANN_SEQUENCE).ToList();
  314. equDBInfoSet.Add(convdb);
  315. }
  316. }
  317. return equDBInfoSet;
  318. }
  319. /// <summary>
  320. /// 删除过期日志
  321. /// </summary>
  322. public static void DeleteLog(int day)
  323. {
  324. string path = string.Format("{0}bin\\Debug\\netcoreapp3.1\\App_Log\\Info\\", AppDomain.CurrentDomain.BaseDirectory);
  325. DeleteLog(day, path);
  326. path = string.Format("{0}bin\\Debug\\netcoreapp3.1\\App_Log\\Error\\", AppDomain.CurrentDomain.BaseDirectory);
  327. DeleteLog(day, path);
  328. path = string.Format("{0}bin\\Debug\\netcoreapp3.1\\App_Log\\Product\\", AppDomain.CurrentDomain.BaseDirectory);
  329. DeleteLog(day, path);
  330. //DeleteAGVLog(day);
  331. }
  332. private static void DeleteLog(int day, string path)
  333. {
  334. try
  335. {
  336. int daycount = -day;
  337. DirectoryInfo folder = new DirectoryInfo(path);
  338. FileInfo[] files = folder.GetFiles("*.log.*");
  339. DateTime dt = DateTime.Now.AddDays(daycount);
  340. DateTime date = new DateTime();
  341. foreach (FileInfo info in files)
  342. {
  343. if (DateTime.TryParse(info.Name.Substring(0, 10), out date))
  344. {
  345. if (date < dt)
  346. {
  347. info.Delete();
  348. }
  349. }
  350. }
  351. }
  352. catch (Exception ex)
  353. {
  354. Log4netHelper.Logger_Error.ErrorFormat(string.Format("路径[{0}]下删除超过[{1}]天的日志失败", path, day));
  355. Log4netHelper.Logger_Error.ErrorFormat(ex.ToString());
  356. }
  357. }
  358. ///// <summary>
  359. ///// 根据箱子尺寸是可用范围获取箱子剁型编号
  360. ///// </summary>
  361. //public static WCS_PalletizingCode IsAvailableRange_BoxSize(List<WCS_PalletizingCode> palletizingCodeSet,string boxSize, int task_no)
  362. //{
  363. // WCS_PalletizingCode palletizingCode = null;
  364. // try
  365. // {
  366. // if (string.IsNullOrWhiteSpace(boxSize))
  367. // throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  368. // string[] boxsizeSet = boxSize.Split('*');
  369. // if (boxsizeSet.Count() < 3)
  370. // throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  371. // decimal length = Convert.ToDecimal(boxsizeSet[0]);
  372. // decimal width = Convert.ToDecimal(boxsizeSet[1]);
  373. // decimal height = Convert.ToDecimal(boxsizeSet[2]);
  374. // palletizingCode = palletizingCodeSet.FirstOrDefault(v => length == v.BoxSizeLength && width == v.BoxSizeWidth && height == v.BoxSizeHeight);
  375. // //palletizingCode = palletizingCodeSet.FirstOrDefault(v => length >= v.BoxSizeLength_Min && length <= v.BoxSizeLength_Max &&
  376. // // width >= v.BoxSizeWidth_Min && width <= v.BoxSizeWidth_Max &&
  377. // // height >= v.BoxSizeHeight_Min && height <= v.BoxSizeHeight_Max);
  378. // }
  379. // catch (Exception ex)
  380. // {
  381. // LogMessageHelper.RecordLogMessage(ex);
  382. // }
  383. // return palletizingCode;
  384. //}
  385. /// <summary>
  386. /// 根据箱子尺寸是可用范围获取箱子剁型编号
  387. /// </summary>
  388. public static WCS_PalletizingCode IsAvailableRange_BoxSize(List<WCS_PalletizingCode> palletizingCodeSet, string boxSize, int task_no)
  389. {
  390. WCS_PalletizingCode palletizingCode = null;
  391. try
  392. {
  393. if (string.IsNullOrWhiteSpace(boxSize))
  394. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  395. string[] boxsizeSet = boxSize.Split('*');
  396. if (boxsizeSet.Count() < 3)
  397. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  398. decimal length = Convert.ToDecimal(boxsizeSet[0]);
  399. decimal width = Convert.ToDecimal(boxsizeSet[1]);
  400. decimal height = Convert.ToDecimal(boxsizeSet[2]);
  401. palletizingCode = palletizingCodeSet.FirstOrDefault(v => length == v.BoxSizeLength && width == v.BoxSizeWidth && height == v.BoxSizeHeight);
  402. //palletizingCode = palletizingCodeSet.FirstOrDefault(v => length >= v.BoxSizeLength_Min && length <= v.BoxSizeLength_Max &&
  403. // width >= v.BoxSizeWidth_Min && width <= v.BoxSizeWidth_Max &&
  404. // height >= v.BoxSizeHeight_Min && height <= v.BoxSizeHeight_Max);
  405. }
  406. catch (Exception ex)
  407. {
  408. LogMessageHelper.RecordLogMessage(ex);
  409. }
  410. return palletizingCode;
  411. }
  412. /// <summary>
  413. ///根据箱子尺寸托盘尺寸是可用范围获取机械手剁型编号
  414. /// </summary>
  415. public static WCS_PalletizingCode IsAvailableRange_SonTraySize(List<WCS_PalletizingCode> palletizingCodeSet, string sonTraySize, string boxSize, int task_no)
  416. {
  417. WCS_PalletizingCode palletizingCode = null;
  418. try
  419. {
  420. if (string.IsNullOrWhiteSpace(boxSize))
  421. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  422. string[] sonTraySizeSet = sonTraySize.Split('*');
  423. if (sonTraySizeSet.Count() < 2)
  424. throw new Exception(string.Format("任务[{0}]子托盘尺寸[{1}]不正确", task_no, sonTraySize));
  425. if (string.IsNullOrWhiteSpace(boxSize))
  426. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  427. string[] boxsizeSet = boxSize.Split('*');
  428. if (boxsizeSet.Count() < 3)
  429. throw new Exception(string.Format("任务[{0}]箱子尺寸[{1}]不正确", task_no, boxSize));
  430. decimal boxlength = Convert.ToDecimal(boxsizeSet[0]);
  431. decimal boxwidth = Convert.ToDecimal(boxsizeSet[1]);
  432. decimal boxheight = Convert.ToDecimal(boxsizeSet[2]);
  433. decimal length = Convert.ToDecimal(sonTraySizeSet[0]);
  434. decimal width = Convert.ToDecimal(sonTraySizeSet[1]);
  435. palletizingCode = palletizingCodeSet.FirstOrDefault(v => boxlength == v.BoxSizeLength &&
  436. boxwidth == v.BoxSizeWidth &&
  437. boxheight == v.BoxSizeHeight &&
  438. length == v.SonTraySizeLength &&
  439. width == v.SonTraySizeWidth);
  440. //palletizingCode = palletizingCodeSet.FirstOrDefault(v => boxlength >= v.BoxSizeLength_Min && boxlength <= v.BoxSizeLength_Max &&
  441. // boxwidth >= v.BoxSizeWidth_Min && boxwidth <= v.BoxSizeWidth_Max &&
  442. // boxheight >= v.BoxSizeHeight_Min && boxheight <= v.BoxSizeHeight_Max &&
  443. // length >= v.SonTraySizeLength_Min && length <= v.SonTraySizeLength_Max &&
  444. // width >= v.SonTraySizeWidth_Min && width <= v.SonTraySizeWidth_Max);
  445. }
  446. catch (Exception ex)
  447. {
  448. LogMessageHelper.RecordLogMessage(ex);
  449. }
  450. return palletizingCode;
  451. }
  452. }
  453. }