LabelParam.cs 6.3 KB
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
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;

namespace DeviceLibrary
{
    [Serializable]
    public class ReelParam
    {
        /// <summary>
        /// 创建新出入库信息
        /// </summary>
        /// <param name="wareNo">二维码内容</param>
        /// <param name="platew">宽度</param>
        /// <param name="plateh">高度</param>
        /// <param name="IsNg">是否是入库NG料</param>
        /// <param name="ngMsg">NG消息</param>
        public ReelParam(string wareNo = "", int platew = 0, int plateh = 0, bool _IsNg = false, string ngMsg = "")
        {
            UID = databaseProc.Current.GetID();
            ReeID = WareCode;
            WareCode = wareNo;
            PlateW = platew;
            PlateH = plateh;
            PlateRawH = plateh;
            IsNg = _IsNg;
            NgMsg = ngMsg;

            PN = "PN";
        }
        public long UID = 0;
        string _WareCode;
        /// <summary>
        /// 物品二维码信息
        /// </summary>
        public string WareCode
        {
            get => _WareCode;
            set
            {
                _WareCode = value;
            }
        }
        public string bitmapfilename = "";
        public string ReeID { get; set; }
        public string PN { get; set; }
        public string Algo { get; set; }
        /// <summary>
        /// 点料数量
        /// </summary>
        public int QTY { get; set; } = 0;
        public int OrgQTY { get; set; } = 0;
        public int CurrentStringNum = 0;
        public List<CodeInfo> codeInfos { get; set; }
        /// <summary>
        /// 料盘高度
        /// </summary>
        public int PlateH { get; set; }
        public int PlateRawH { get; set; }
        /// <summary>
        /// 料盘宽度
        /// </summary>
        public int PlateW { get; set; }
        /// <summary>
        /// 是否是入料NG料
        /// </summary>
        public bool IsNg
        {
            get;set;
        }
        /// <summary>
        /// 入料NG消息
        /// </summary>
        public string NgMsg = "";

        /// <summary>
        /// 贴标状态
        /// </summary>
        public string LabelState = "None";

        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()
        {
            //var ngStr = IsNg ? "[NG]" : $"[{ReelDest}]";
            var countStr = QTY > 0 ? $"[{QTY}]" : "";
            return $"[{PlateW}x{PlateH}]{countStr}[{ReeID}]";
        }
        public string ToDetailStr()
        {
            return $"{DateTime.Now:HH:mm:ss},{ReeID},{PN},{PlateW}x{PlateH},{CurrentStringNum},{NgMsg},{QTY},{WareCode}";
        }
        public string ToSortStr()
        {
            return $"{PN},{PlateW}inch,{NgMsg},{QTY}";
        }
        bool islog = false;
        public void logresult(string xrayfile = "", string resultfile = "")
        {
            if (!islog)
            {
                islog = true;
                var datetime = DateTime.Now;
                string countfile = $"\\LogData\\{datetime:yyyyMMdd_HHmmss}_{QTY}.csv";
                Directory.CreateDirectory("\\LogData\\");
                if (!File.Exists(countfile))
                {
                    StreamWriter sw1 = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                    sw1.WriteLine($"ReelId,Quantity,DateCode,XFile,Operator");
                    sw1.Close();
                    sw1.Dispose();
                }

                var sw = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                //var sw = File.Open(countfile, FileMode.Append, FileAccess.Write);
                // string s = $"\r\n{ReeID},{PN},{PlateW}x{PlateH},{ReelDest},{NgMsg},{QTY},{WareCode}";
                //var b = Encoding.GetEncoding("gb2312").GetBytes(s);
                //sw.Write(b, 0, b.Length);
                sw.WriteLine($"{ReeID},{QTY},{datetime:yyyy/MM/dd HH:mm:ss},{xrayfile},");
                sw.Close();
                sw.Dispose();
            }
            databaseProc.Current.InsertOrUpdateRI(UID, PN, ReeID, IsNg, NgMsg, QTY, LabelState, Algo, WareCode, xrayfile, resultfile);
            
        }
        /*
        public void logresult(string xrayfile="",string resultfile="")
        {
            if (!islog)
            {
                islog = true;
                string countfile = $"\\XrayLogs\\CountResult-{DateTime.Now:yyyy-MM-dd}.csv";
                Directory.CreateDirectory("\\XrayLogs\\");
                if (!File.Exists(countfile))
                {
                    StreamWriter sw1 = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                    sw1.WriteLine($"Date,ReeID,PN,NgMsg,QTY,Algo,XrayFile,ResultFile");
                    sw1.Close();
                    sw1.Dispose();
                }

                var sw = new StreamWriter(countfile, true, Encoding.GetEncoding("GB2312"));
                //var sw = File.Open(countfile, FileMode.Append, FileAccess.Write);
                // string s = $"\r\n{ReeID},{PN},{PlateW}x{PlateH},{ReelDest},{NgMsg},{QTY},{WareCode}";
                //var b = Encoding.GetEncoding("gb2312").GetBytes(s);
                //sw.Write(b, 0, b.Length);
                sw.WriteLine($"{DateTime.Now:yyyy-mm-dd HH:mm:ss},{ReeID},{PN},{NgMsg},{QTY},{Algo},{xrayfile},{resultfile}");
                sw.Close();
                sw.Dispose();
            }
            databaseProc.Current.InsertOrUpdateRI(UID, PN, ReeID, IsNg, NgMsg, QTY, LabelState, Algo, WareCode,xrayfile,resultfile);
        }*/
        public string GetImgName()
        {
            string timeName = "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
            return PN + "-" + ReeID + "-" + timeName;
        }

    }
}