JobRequisitionItem.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.ComponentModel;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. public enum JobRequisitionItemStatus
  9. {
  10. NotChecked,
  11. Reserved,
  12. TreatmentRequired,
  13. OrderRequired,
  14. TreatmentOnOrder,
  15. OnOrder,
  16. Received,
  17. TreatmentReceived,
  18. Cancelled,
  19. Archived
  20. }
  21. public class JobRequisitionItemTotalQtyFormula : IFormula<JobRequisitionItem, double>
  22. {
  23. public Expression<Func<JobRequisitionItem, double>> Value => x => x.Qty;
  24. public Expression<Func<JobRequisitionItem, double>>[] Modifiers => new Expression<Func<JobRequisitionItem, double>>[] { x => x.Dimensions.Value };
  25. public FormulaOperator Operator => FormulaOperator.Multiply;
  26. public FormulaType Type => FormulaType.Virtual;
  27. }
  28. [Caption("Items")]
  29. [UserTracking(typeof(Job))]
  30. public class JobRequisitionItem : DimensionedEntity<StockDimensions>, IRemotable, IPersistent, IOneToMany<JobRequisition>,
  31. ILicense<ProjectManagementLicense>, IJobMaterial
  32. {
  33. [EntityRelationship(DeleteAction.Cascade)]
  34. public JobLink Job { get; set; }
  35. [EntityRelationship(DeleteAction.Cascade)]
  36. public JobRequisitionLink Requisition { get; set; }
  37. [EntityRelationship(DeleteAction.SetNull)]
  38. [EditorSequence(0)]
  39. public ProductLink Product { get; set; }
  40. [EditorSequence(1)]
  41. [MemoEditor]
  42. public string Notes { get; set; }
  43. [EditorSequence(2)]
  44. public ProductStyleLink Style { get; set; }
  45. [EditorSequence(3)]
  46. public double Qty { get; set; }
  47. [NullEditor]
  48. [Obsolete("Replaced with Dimensions", true)]
  49. public double UnitSize { get; set; }
  50. [EditorSequence(4)]
  51. public override StockDimensions Dimensions { get; set; }
  52. [EditorSequence(5)]
  53. public SupplierLink Supplier { get; set; }
  54. [DoubleEditor(Editable = Editable.Hidden)]
  55. [Formula(typeof(JobRequisitionItemTotalQtyFormula))]
  56. public double TotalQty { get; set; }
  57. [EnumLookupEditor(typeof(JobRequisitionItemStatus))]
  58. public JobRequisitionItemStatus Status { get; set; }
  59. [IntegerEditor(Visible = Visible.Default, Editable = Editable.Disabled)] //currently no way to disable editor but we need the columns
  60. public PurchaseOrderItemLink PurchaseOrderItem { get; set; }
  61. protected override void Init()
  62. {
  63. base.Init();
  64. Job = new JobLink();
  65. Requisition = new JobRequisitionLink();
  66. Product = new ProductLink();
  67. //Product.PropertyChanged += Product_PropertyChanged;
  68. //Product.DefaultStyle.PropertyChanged += DefaultStyle_PropertyChanged;
  69. Style = new ProductStyleLink();
  70. Status = JobRequisitionItemStatus.NotChecked;
  71. PurchaseOrderItem = new PurchaseOrderItemLink();
  72. Supplier = new SupplierLink();
  73. Dimensions = new StockDimensions();
  74. }
  75. // private void DefaultStyle_PropertyChanged(object sender, PropertyChangedEventArgs e)
  76. // {
  77. // Style = Product.DefaultStyle;
  78. // }
  79. //private void Product_PropertyChanged(object sender, PropertyChangedEventArgs e)
  80. //{
  81. // if (new Column<Product>(x=>x.UnitSize).IsEqualTo(e.PropertyName))
  82. // UnitSize = Product.UnitSize;
  83. // //else if (e.PropertyName.Equals("DefaultStyle"))
  84. // // Style = Product.DefaultStyle;
  85. //}
  86. private static Column<JobRequisitionItem> dimensions = new Column<JobRequisitionItem>(x => x.Product.Dimensions);
  87. private static Column<JobRequisitionItem> style = new Column<JobRequisitionItem>(x => x.Product.DefaultStyle);
  88. private bool bChanging;
  89. protected override void DoPropertyChanged(string name, object before, object after)
  90. {
  91. if (bChanging)
  92. return;
  93. bChanging = true;
  94. if (dimensions.IsParentOf(name))
  95. {
  96. String col = String.Join(".", name.Split('.').Skip(1));
  97. CoreUtils.SetPropertyValue(this, col, after);
  98. }
  99. else if (dimensions.IsParentOf(name))
  100. {
  101. String col = String.Join(".", name.Split('.').Skip(1));
  102. CoreUtils.SetPropertyValue(this, col, after);
  103. }
  104. bChanging = false;
  105. base.DoPropertyChanged(name, before, after);
  106. }
  107. }
  108. }