using System; using System.ComponentModel; using System.Linq; using System.Linq.Expressions; using InABox.Core; namespace Comal.Classes { public enum JobRequisitionItemStatus { NotChecked, Reserved, TreatmentRequired, OrderRequired, TreatmentOnOrder, OnOrder, Received, TreatmentReceived, Cancelled, Archived } public class JobRequisitionItemTotalQtyFormula : IFormula { public Expression> Value => x => x.Qty; public Expression>[] Modifiers => new Expression>[] { x => x.Dimensions.Value }; public FormulaOperator Operator => FormulaOperator.Multiply; public FormulaType Type => FormulaType.Virtual; } [Caption("Items")] [UserTracking(typeof(Job))] public class JobRequisitionItem : DimensionedEntity, IRemotable, IPersistent, IOneToMany, ILicense, IJobMaterial { [EntityRelationship(DeleteAction.Cascade)] public JobLink Job { get; set; } [EntityRelationship(DeleteAction.Cascade)] public JobRequisitionLink Requisition { get; set; } [EntityRelationship(DeleteAction.SetNull)] [EditorSequence(0)] public ProductLink Product { get; set; } [EditorSequence(1)] [MemoEditor] public string Notes { get; set; } [EditorSequence(2)] public ProductStyleLink Style { get; set; } [EditorSequence(3)] public double Qty { get; set; } [NullEditor] [Obsolete("Replaced with Dimensions", true)] public double UnitSize { get; set; } [EditorSequence(4)] [RequiredColumn] public override StockDimensions Dimensions { get; set; } [EditorSequence(5)] public SupplierLink Supplier { get; set; } [DoubleEditor(Editable = Editable.Hidden)] [Formula(typeof(JobRequisitionItemTotalQtyFormula))] public double TotalQty { get; set; } [EnumLookupEditor(typeof(JobRequisitionItemStatus))] public JobRequisitionItemStatus Status { get; set; } [IntegerEditor(Visible = Visible.Default, Editable = Editable.Disabled)] //currently no way to disable editor but we need the columns public PurchaseOrderItemLink PurchaseOrderItem { get; set; } protected override void Init() { base.Init(); Job = new JobLink(); Requisition = new JobRequisitionLink(); Product = new ProductLink(); //Product.PropertyChanged += Product_PropertyChanged; //Product.DefaultStyle.PropertyChanged += DefaultStyle_PropertyChanged; Style = new ProductStyleLink(); Status = JobRequisitionItemStatus.NotChecked; PurchaseOrderItem = new PurchaseOrderItemLink(); Supplier = new SupplierLink(); Dimensions = new StockDimensions(); } // private void DefaultStyle_PropertyChanged(object sender, PropertyChangedEventArgs e) // { // Style = Product.DefaultStyle; // } //private void Product_PropertyChanged(object sender, PropertyChangedEventArgs e) //{ // if (new Column(x=>x.UnitSize).IsEqualTo(e.PropertyName)) // UnitSize = Product.UnitSize; // //else if (e.PropertyName.Equals("DefaultStyle")) // // Style = Product.DefaultStyle; //} private static Column dimensions = new Column(x => x.Product.Dimensions); private static Column style = new Column(x => x.Product.DefaultStyle); private bool bChanging; protected override void DoPropertyChanged(string name, object before, object after) { if (bChanging) return; bChanging = true; if (dimensions.IsParentOf(name)) { String col = String.Join(".", name.Split('.').Skip(1)); CoreUtils.SetPropertyValue(this, col, after); } else if (dimensions.IsParentOf(name)) { String col = String.Join(".", name.Split('.').Skip(1)); CoreUtils.SetPropertyValue(this, col, after); } bChanging = false; base.DoPropertyChanged(name, before, after); } } }