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