ReelParam.cs 4.8 KB
using CodeLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

[Serializable]
public class ReelParam
{ 
    public ReelParam(string wareNo = "", int platew = 0, int plateh = 0,string startPos="",string pos="",  bool _IsNg = false, string ngMsg = "")
    {
        WareCode = wareNo;
        PlateW = platew;
        PlateH = plateh;
        IsNg = _IsNg;
        NgMsg = ngMsg;
        this.StartPos = startPos;
        this.TargetPos = pos;
        codeInfos = new List<CodeInfo>();
        string[] posArray = TargetPos.Split('_');
        if (posArray.Length >=2)
        {
            TargetOutShelf = posArray[0];
            if (TargetOutShelf != "NG")
            {
                if (posArray[1].StartsWith("B"))
                { 
                    TargetLoc =26+ posArray[posArray.Length - 1];
                }
                else
                { 
                    //取最后一位
                    TargetLoc = posArray[posArray.Length - 1];
                }
            }
        }
    }
    /// <summary>
    /// 物品二维码信息
    /// </summary>
    public string WareCode { get; set; }
    /// <summary>
    /// 取料位置
    /// </summary>
    public string StartPos { get; set; }
    /// <summary>
    /// 库位号
    /// </summary>
    public string TargetPos { get; set; }
    /// <summary>
    /// 放料的目标料架
    /// </summary> 
    public string TargetOutShelf { get; set; }


    /// <summary>
    /// 放料的目标位置(服务器通信)
    /// </summary> 
    public string TargetLoc { get; set; }
    public string bitmapfilename = "";
    public List<CodeInfo> codeInfos { get; set; }
    /// <summary>
    /// 料盘高度
    /// </summary>
    public int PlateH { get; set; }
    /// <summary>
    /// 料盘宽度
    /// </summary>
    public int PlateW { get; set; }
    /// <summary>
    /// 是否是入料NG料
    /// </summary>
    public bool IsNg = false;
    /// <summary>
    /// 入料NG消息
    /// </summary>
    public string NgMsg = "";
    /// <summary>
    /// 物料编码
    /// </summary>
    public string PN { get; set; }
    ///// <summary>
    ///// 数量
    ///// </summary>
    //public int QTY { get; set; } = 0;
    ///// <summary>
    ///// 厂家代码
    ///// </summary>
    //public string FC { get; set; }
    ///// <summary>
    ///// 唯一序列号
    ///// </summary>
    //public string RI { get; set; }
    //public string DC { get; set; }
    ///// <summary>
    ///// 批次号
    ///// </summary>
    //public string Batch { get; set; }
    //public string cid { get; set; }
    //public string SubCID { get; set; }



    public bool ReelOnFixture { get; set; } = false;
    public bool IsInStore { get; set; }

    public int HeightPos = 0;
    public string RFID = "";

    public ReelParam clone()
    {
        ReelParam dstobject;
        using (MemoryStream mStream = new MemoryStream())
        {
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(mStream, this);
            mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
            dstobject = (ReelParam)bf.Deserialize(mStream);
            mStream.Close();
        }
        return dstobject;
    }

    public string ToStr()
    {
        if (IsNg)
        {
            return $":NG[{NgMsg}][{StartPos}->{TargetPos}][{WareCode}][{RFID}][{PlateW}x{PlateH}]";
        }
        else
        {

            return $":[{StartPos}->{TargetPos}][{WareCode}][{RFID}][{PlateW}x{PlateH}]";
        }
    }
    bool islog = false;
    /// <summary>
    /// NG口位置,1=左侧,2=右侧
    /// </summary>
    /// <param name="NgPos"></param>
    /// <param name="isInstore"></param>
    public void logresult(int NgPos = 0, bool isInstore = true)
    {
        if (!islog)
        {
            islog = true;
            var datetime = DateTime.Now;
            string countfile = $".\\Logs\\NGLOG_{datetime:yyyyMMdd}.csv";
            Directory.CreateDirectory(".\\Logs\\");
            if (!File.Exists(countfile))
            {
                StreamWriter sw1 = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                sw1.WriteLine($"WareCode,StartPos,TargetPos,TargetOutShelf,TargetLoc,Date,NgMsg");
                sw1.Close();
                sw1.Dispose();
            }
            try
            {
                var sw = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                sw.WriteLine($"{WareCode},{StartPos},{TargetPos},{TargetOutShelf},{TargetLoc},{datetime:yyyy/MM/dd HH:mm:ss},{NgMsg}");
                sw.Close();
                sw.Dispose();
            }
            catch { }

        }       
        
    }
}