Basket.cs 6.1 KB
using CtuDeviceLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace Mushiny
{
    /// <summary>
    /// ctu背篓
    /// </summary>
    public class Basket
    {
        /// <summary>
        /// 是否是货叉
        /// </summary>
        public bool IsFork { get; set; }
        /// <summary>
        /// 所在层
        /// 1--10
        /// </summary>
        public byte Row { get; set; }
        /// <summary>
        /// 料箱码
        /// </summary>
        public string BoxCode { get; set; }
        /// <summary>
        /// 料箱定位码
        /// </summary>
        public string LocateCode { get; set; } = "";
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; }
        /// <summary>
        /// 屏蔽
        /// </summary>
        public bool Shield { get; set; }
        /// <summary>
        /// 目的地
        /// </summary>
        public string DstName { get; set; }
        /// <summary>
        /// 是否有料箱
        /// </summary>
        public bool IsPutted { get; set; }
        /// <summary>
        /// 检查半成品料箱是否相同
        /// </summary>
        /// <returns></returns>
        public bool CheckCodeEquals()
        {
            if (string.IsNullOrEmpty(BoxCode) || string.IsNullOrEmpty(LocateCode)) return true;
            //D00314
            string str1 = "";
            string str2 = "";
            if (BoxCode.Length == 6)
            {
                str1 = BoxCode.Substring(1);
            }
            //S000000 00159
            if (LocateCode.Length == 12)
            {
                str2 = LocateCode.Substring(7);
            }
            if (str1.Equals(str2))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 检查料箱是否一致
        /// </summary>
        /// <returns></returns>
        public bool CheckCodeIsSame()
        {
            if (string.IsNullOrEmpty(BoxCode) || string.IsNullOrEmpty(LocateCode)) return true;
            //C07 00314
            string str1 = "";
            string pre1 = "";
            string pre2 = "";
            string str2 = "";
            if (BoxCode.Length == 8)
            {
                str1 = BoxCode.Substring(3);
                pre1 = BoxCode.Substring(0, 3);
            }
            //S000000 00159
            if (LocateCode.Length == 12)
            {
                str2 = LocateCode.Substring(7);
                pre2 = LocateCode.Substring(0, 1);
            }
            if (str1.Equals(str2))
            {
                if ("C07".Equals(pre1) && "S".Equals(pre2))
                {
                    return true;
                }
                if ("C13".Equals(pre1) && "M".Equals(pre2))
                {
                    return true;
                }
                if ("C15".Equals(pre1) && "P".Equals(pre2))
                {
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 料箱码转为定位码
        /// </summary>
        /// <param name="boxCode"></param>
        /// <returns></returns>
        public static string BoxCodeToLocateCode(string boxCode)
        {
            if (string.IsNullOrEmpty(boxCode)) return "";
            if (boxCode.StartsWith("D") && boxCode.Length == 6)//半成品料箱
            {
                //D00314
                return $"T000000{boxCode.Substring(1)}";
            }
            else if (boxCode.StartsWith("C") && boxCode.Length == 8)//原材料料箱
            {
                string prefix = boxCode.Substring(0, 3);
                if ("C07".Equals(prefix))
                {
                    //C07 00314
                    return $"S000000{boxCode.Substring(3)}";
                }
                else if ("C13".Equals(prefix))
                {
                    return $"M000000{boxCode.Substring(3)}";
                }
                else if ("C15".Equals(prefix))
                {
                    return $"P000000{boxCode.Substring(3)}";
                }

            }
            return "";
        }
        /// <summary>
        /// 料箱码转为定位码
        /// </summary>
        /// <param name="boxCode"></param>
        /// <returns></returns>
        public static string LocateCodeToBoxCode(string locateCode)
        {
            if (string.IsNullOrEmpty(locateCode)) return "";

            if (locateCode.StartsWith("T"))//半成品
            {
                //T000000 00314
                return $"D{locateCode.Substring(7)}";
            }
            else if (locateCode.StartsWith("S"))
            {
                return $"C07{locateCode.Substring(7)}";
            }
            else if (locateCode.StartsWith("M"))
            {
                return $"C13{locateCode.Substring(7)}";
            }
            else if (locateCode.StartsWith("P"))
            {
                return $"C15{locateCode.Substring(7)}";
            }
            return "";
        }
        public string GetLocateCodeByContainerCode()
        {
            if (string.IsNullOrEmpty(BoxCode)) return "";
            if (BoxCode.StartsWith("D") && BoxCode.Length == 6)//半成品料箱
            {
                //D00314
                return $"T000000{BoxCode.Substring(1)}";
            }
            else if (BoxCode.StartsWith("C") && BoxCode.Length == 8)//原材料料箱
            {
                string prefix = BoxCode.Substring(0, 3);
                if ("C07".Equals(prefix))
                {
                    //C07 00314
                    return $"S000000{BoxCode.Substring(3)}";
                }
                else if ("C13".Equals(prefix))
                {
                    return $"M000000{BoxCode.Substring(3)}";
                }
                else if ("C15".Equals(prefix))
                {
                    return $"P000000{BoxCode.Substring(3)}";
                }

            }
            return "";
        }
    }
}