| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | using System;using System.Collections.Generic;using System.Linq;using InABox.Core;namespace Comal.Classes{    public class ManufacturingItem : BaseObject, IPackable    {        private BarcodeType _barcodetype = BarcodeType.Unspecified;        public ManufacturingItem()        {            ID = Guid.NewGuid();            Description = "Completed Item";            Code = "#";            Quantity = 1;            Due = DateTime.Today;            TemplateID = Guid.Empty;            Stages = new PackableList<SetoutStage>();            Attributes = new Dictionary<string, object>();            _barcodetype = BarcodeType.Unspecified;            Purchased = false;        }        [NullEditor]        public Guid ID { get; set; }        [NullEditor]        public string Code { get; set; }        public string Description { get; set; }        public string Group { get; set; }        public string Serial { get; set; }        public int Quantity { get; set; }        // Deprecated - replacing with BarcodeType        public bool GroupedBarcode { get; set; }        [EnumLookupEditor(typeof(BarcodeType))]        public BarcodeType BarcodeType        {            get => _barcodetype == BarcodeType.Unspecified ? GroupedBarcode ? BarcodeType.Grouped : BarcodeType.Individual : _barcodetype;            set => _barcodetype = value;        }        [CheckBoxEditor]        public bool Purchased { get; set; }        [DateEditor]        public DateTime Due { get; set; }        [LookupEditor(typeof(ManufacturingTemplate), "Name->Description")]        public Guid TemplateID { get; set; }        //static FactorySetup setup = null;         //public static Dictionary<object,object> TemplateID_Lookups()        //{        //    Dictionary<object, object> result = new Dictionary<object, object>();        //    if (setup == null)        //        setup = new GlobalConfiguration<FactorySetup>().Load();        //    foreach (var template in setup.Templates)        //        result[template.ID] = template.Name;        //    return result;        //}        public PackableList<SetoutStage> Stages { get; set; }        public Dictionary<string, object> Attributes { get; set; }        public void Pack(FastBinaryWriter writer)        {            writer.Write(ID.ToByteArray());            writer.Write(Description);            writer.Write(Code);            writer.Write(Quantity);            writer.Write(Due.ToBinary());            writer.Write(TemplateID.ToByteArray());            Stages.Pack(writer);            var attributes = new List<string>();            foreach (var key in Attributes.Keys)                attributes.Add(string.Format("{0}={1}", key, Attributes[key]));            writer.Write(string.Join("\n", attributes));            writer.Write((int)BarcodeType);            writer.Write(Serial);            writer.Write(Purchased);        }        public void Unpack(FastBinaryReader reader)        {            ID = new Guid(reader.ReadBytes(16));            Description = reader.ReadString();            Code = reader.ReadString();            Quantity = reader.ReadInt32();            Due = DateTime.FromBinary(reader.ReadInt64());            TemplateID = new Guid(reader.ReadBytes(16));            Stages = new PackableList<SetoutStage>();            Stages.Unpack(reader);            var attributes = reader.ReadString().Split('\n');            foreach (var attribute in attributes.Where(x => x.Contains("=")))                try                {                    var comps = attribute.Split('=');                    Attributes[comps[0]] = comps[1];                }                catch (Exception e)                {                    Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));                }            BarcodeType = (BarcodeType)reader.ReadInt32();            Serial = reader.ReadString();            Purchased = reader.ReadBoolean();        }    }}
 |