using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace UIControl
{
    [Serializable]
    public class CItem
    {
        public Boolean Active { get; set; }
        public Boolean PLCWriteNo { get; set; }
        public Boolean PLCWriteSize { get; set; }
        public Boolean Delete { get; set; }
        /// 
        /// 어떠한 포트에서 픽업 되었는지
        /// 
        public int iPort { get; set; }
        /// 
        /// 출력 포트
        /// 
        public int oPort { get; set; }
        public Boolean ExistError { get; set; }
        /// 
        /// 배출여부
        /// 
        public int ErrorOut { get; set; }
        /// 
        /// 크기는 어떠한지(7 or 13)
        /// 
        public string Size { get; set; }
        /// 
        /// 존번호 0~10
        /// 
        public int ZoneIndex { get; set; }
        /// 
        /// 피커에의해서 드랍된 시간
        /// 
        public DateTime DropTime { get; set; }
        /// 
        /// 차수별 일련번호
        /// 
        public UInt16 Seq { get; set; }
        public DateTime BarcodeStart { get; set; }
        public DateTime BarcodeEnd { get; set; }
        /// 
        /// 바코드 처리가 완료디었는가?
        /// 종료일자가 설정되면 처리완료로 합니다.
        /// 201028
        /// 
        public Boolean BarcodeProcess
        {
            get
            {
                if (BarcodeEnd.Year == 1982) return false;
                else if (BarcodeEnd <= BarcodeStart) return false;
                else return true;
            }
        }
        public DateTime PlcStartTime { get; set; }
        public DateTime PlcEndTime { get; set; }
        public DateTime ZoneIntime { get; set; }
        /// 
        /// 컨베이어에 들어온 시간 
        /// 피커에서 드랍되면 dropTime 과 동일하며, 외부에서 들어오면 센서가 최초 감지한 시간이 된다
        /// 
        public DateTime InTime { get; set; }
        public DateTime OutTime { get; set; }
        public Rectangle Rect { get; set; }
        /// 
        /// jobhistory에 연결되는 데이터 키
        /// 
        public string JGUID { get; set; }
        /// 
        /// 바코드 데이터와 연결되는 키값
        /// 
        public string BGUID { get; set; }
        public string RID { get; set; }
        public string SID { get; set; }
        public string VLOT { get; set; }
        public string BarcodeRaw { get; set; }
        public string BarcodeMsg { get; set; }
        public Boolean Processing { get; set; }
        public Boolean Complete { get; set; }
        public string GUID { get; private set; }
        public int Qty { get; set; }
        public int QtyAcc { get; set; }
        public int QtyMax { get; set; }
        public List UnloaderMsg { get; set; }
        /// 
        /// 바코드의 완료여부, timeout 혻은 설정 되었을때 적용
        /// 
        public Boolean BarcodeDone { get; set; }
        public Boolean hasBarcode
        {
            get
            {
                return !string.IsNullOrEmpty(RID);
            }
        }
        /// 
        /// 지정한 문자가 포함되어잇다면 true 반환
        /// 
        /// 
        /// 
        public Boolean CheckMessage(string msg)
        {
            if (UnloaderMsg == null || UnloaderMsg.Count < 1) return false;
            foreach (var item in UnloaderMsg)
                if (item.Contains(msg)) return true;
            return false;
        }
        public void AddMessage(string msg)
        {
            if (this.UnloaderMsg.Contains(msg) == false)
                UnloaderMsg.Add(msg);
        }
        public void ClearMessage()
        {
            this.UnloaderMsg.Clear();
        }
        public CItem()
        {
            ExistError = false;
            Active = true;
            Complete = false;
            PLCWriteNo = false;
            PLCWriteSize = false;
            Qty = 0;
            QtyAcc = 0; //200913    누계
            QtyMax = 0; //200913    최대값
            UnloaderMsg = new List();
            ErrorOut = 0;
            this.GUID = Guid.NewGuid().ToString();
            BGUID = string.Empty;
            JGUID = string.Empty;
            VLOT = string.Empty;
            Seq = 0;
            SID = string.Empty;
            BarcodeRaw = string.Empty;
            BarcodeMsg = string.Empty;
            RID = string.Empty;
            Rect = Rectangle.Empty;
            Delete = false;
            Processing = false;
            DropTime = DateTime.Parse("1982-11-23");
            BarcodeStart = DateTime.Parse("1982-11-23");
            BarcodeEnd = DateTime.Parse("1982-11-23");
            PlcStartTime = DateTime.Parse("1982-11-23");
            PlcEndTime = DateTime.Parse("1982-11-23");
            InTime = DateTime.Parse("1982-11-23");
            OutTime = DateTime.Parse("1982-11-23");
            ZoneIntime = DateTime.Parse("1982-11-23");
            ZoneIndex = -1;
            oPort = -1;
            iPort = -1;
            Size = string.Empty;
        }
        public CItem Clone()
        {
            var item = new CItem();
            item.Qty = Qty;
            item.Seq = Seq;//0;
            item.SID = SID;// string.Empty;
            item.VLOT = VLOT;
            item.BarcodeRaw = BarcodeRaw;//string.Empty;
            item.BarcodeMsg = BarcodeMsg;//string.Empty;
            item.RID = RID;//string.Empty;
            item.Rect = Rect;//Rectangle.Empty;
            item.Delete = Delete;//DropTime;//;
            item.ExistError = ExistError;
            item.DropTime = DropTime;// DateTime.Parse("1982-11-23");
            item.BarcodeStart = BarcodeStart;// DateTime.Parse("1982-11-23");
            item.BarcodeEnd = BarcodeEnd;//DropTime;//.Parse("1982-11-23");
            item.PlcStartTime = PlcStartTime;//DateTime.Parse("1982-11-23");
            item.PlcEndTime = PlcEndTime;// DateTime.Parse("1982-11-23");
            item.InTime = InTime;//DropTime;//.Parse("1982-11-23");
            item.OutTime = OutTime;//DateTime.Parse("1982-11-23");
            item.ZoneIntime = ZoneIntime;//DateTime.Parse("1982-11-23");
            item.ZoneIndex = ZoneIndex;
            item.oPort = oPort;
            item.iPort = iPort;
            item.Size = Size;
            return item;
        }
    }
}