ManufacturingItem.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class ManufacturingItem : BaseObject, IPackable
  8. {
  9. private BarcodeType _barcodetype = BarcodeType.Unspecified;
  10. public ManufacturingItem()
  11. {
  12. ID = Guid.NewGuid();
  13. Description = "Completed Item";
  14. Code = "#";
  15. Quantity = 1;
  16. Due = DateTime.Today;
  17. TemplateID = Guid.Empty;
  18. Stages = new PackableList<SetoutStage>();
  19. Attributes = new Dictionary<string, object>();
  20. _barcodetype = BarcodeType.Unspecified;
  21. Purchased = false;
  22. }
  23. [NullEditor]
  24. public Guid ID { get; set; }
  25. [NullEditor]
  26. public string Code { get; set; }
  27. public string Description { get; set; }
  28. public string Group { get; set; }
  29. public string Serial { get; set; }
  30. public int Quantity { get; set; }
  31. // Deprecated - replacing with BarcodeType
  32. public bool GroupedBarcode { get; set; }
  33. [EnumLookupEditor(typeof(BarcodeType))]
  34. public BarcodeType BarcodeType
  35. {
  36. get => _barcodetype == BarcodeType.Unspecified ? GroupedBarcode ? BarcodeType.Grouped : BarcodeType.Individual : _barcodetype;
  37. set => _barcodetype = value;
  38. }
  39. [CheckBoxEditor]
  40. public bool Purchased { get; set; }
  41. [DateEditor]
  42. public DateTime Due { get; set; }
  43. [LookupEditor(typeof(ManufacturingTemplate), "Name->Description")]
  44. public Guid TemplateID { get; set; }
  45. //static FactorySetup setup = null;
  46. //public static Dictionary<object,object> TemplateID_Lookups()
  47. //{
  48. // Dictionary<object, object> result = new Dictionary<object, object>();
  49. // if (setup == null)
  50. // setup = new GlobalConfiguration<FactorySetup>().Load();
  51. // foreach (var template in setup.Templates)
  52. // result[template.ID] = template.Name;
  53. // return result;
  54. //}
  55. public PackableList<SetoutStage> Stages { get; set; }
  56. public Dictionary<string, object> Attributes { get; set; }
  57. public void Pack(FastBinaryWriter writer)
  58. {
  59. writer.Write(ID.ToByteArray());
  60. writer.Write(Description);
  61. writer.Write(Code);
  62. writer.Write(Quantity);
  63. writer.Write(Due.ToBinary());
  64. writer.Write(TemplateID.ToByteArray());
  65. Stages.Pack(writer);
  66. var attributes = new List<string>();
  67. foreach (var key in Attributes.Keys)
  68. attributes.Add(string.Format("{0}={1}", key, Attributes[key]));
  69. writer.Write(string.Join("\n", attributes));
  70. writer.Write((int)BarcodeType);
  71. writer.Write(Serial);
  72. writer.Write(Purchased);
  73. }
  74. public void Unpack(FastBinaryReader reader)
  75. {
  76. ID = new Guid(reader.ReadBytes(16));
  77. Description = reader.ReadString();
  78. Code = reader.ReadString();
  79. Quantity = reader.ReadInt32();
  80. Due = DateTime.FromBinary(reader.ReadInt64());
  81. TemplateID = new Guid(reader.ReadBytes(16));
  82. Stages = new PackableList<SetoutStage>();
  83. Stages.Unpack(reader);
  84. var attributes = reader.ReadString().Split('\n');
  85. foreach (var attribute in attributes.Where(x => x.Contains("=")))
  86. try
  87. {
  88. var comps = attribute.Split('=');
  89. Attributes[comps[0]] = comps[1];
  90. }
  91. catch (Exception e)
  92. {
  93. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  94. }
  95. BarcodeType = (BarcodeType)reader.ReadInt32();
  96. Serial = reader.ReadString();
  97. Purchased = reader.ReadBoolean();
  98. }
  99. }
  100. }