JobRequisitionItem.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. [RequiredColumn]
  52. public override StockDimensions Dimensions { get; set; }
  53. [EditorSequence(5)]
  54. public SupplierLink Supplier { get; set; }
  55. [DoubleEditor(Editable = Editable.Hidden)]
  56. [Formula(typeof(JobRequisitionItemTotalQtyFormula))]
  57. public double TotalQty { get; set; }
  58. [EnumLookupEditor(typeof(JobRequisitionItemStatus))]
  59. public JobRequisitionItemStatus Status { get; set; }
  60. [IntegerEditor(Visible = Visible.Default, Editable = Editable.Disabled)] //currently no way to disable editor but we need the columns
  61. public PurchaseOrderItemLink PurchaseOrderItem { get; set; }
  62. protected override void Init()
  63. {
  64. base.Init();
  65. Job = new JobLink();
  66. Requisition = new JobRequisitionLink();
  67. Product = new ProductLink();
  68. //Product.PropertyChanged += Product_PropertyChanged;
  69. //Product.DefaultStyle.PropertyChanged += DefaultStyle_PropertyChanged;
  70. Style = new ProductStyleLink();
  71. Status = JobRequisitionItemStatus.NotChecked;
  72. PurchaseOrderItem = new PurchaseOrderItemLink();
  73. Supplier = new SupplierLink();
  74. Dimensions = new StockDimensions();
  75. }
  76. // private void DefaultStyle_PropertyChanged(object sender, PropertyChangedEventArgs e)
  77. // {
  78. // Style = Product.DefaultStyle;
  79. // }
  80. //private void Product_PropertyChanged(object sender, PropertyChangedEventArgs e)
  81. //{
  82. // if (new Column<Product>(x=>x.UnitSize).IsEqualTo(e.PropertyName))
  83. // UnitSize = Product.UnitSize;
  84. // //else if (e.PropertyName.Equals("DefaultStyle"))
  85. // // Style = Product.DefaultStyle;
  86. //}
  87. private static Column<JobRequisitionItem> dimensions = new Column<JobRequisitionItem>(x => x.Product.Dimensions);
  88. private static Column<JobRequisitionItem> style = new Column<JobRequisitionItem>(x => x.Product.DefaultStyle);
  89. private bool bChanging;
  90. protected override void DoPropertyChanged(string name, object before, object after)
  91. {
  92. if (bChanging)
  93. return;
  94. bChanging = true;
  95. if (dimensions.IsParentOf(name))
  96. {
  97. String col = String.Join(".", name.Split('.').Skip(1));
  98. CoreUtils.SetPropertyValue(this, col, after);
  99. }
  100. else if (dimensions.IsParentOf(name))
  101. {
  102. String col = String.Join(".", name.Split('.').Skip(1));
  103. CoreUtils.SetPropertyValue(this, col, after);
  104. }
  105. bChanging = false;
  106. base.DoPropertyChanged(name, before, after);
  107. }
  108. }
  109. }