| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | using System;using System.Linq;using InABox.Core;namespace Comal.Classes{    [Caption("Labour")]    public class JobBillOfMaterialsActivity : Entity, IRemotable, IPersistent, IJobActivity, IOneToMany<Job>,        IOneToMany<JobBillOfMaterials>, ISequenceable, ILicense<ProjectManagementLicense>,        IProblems<ManagedProblem>    {                [NullEditor]        public long Sequence { get; set; }                [EntityRelationship(DeleteAction.Cascade)]        [Editable(Editable.Hidden)]        public JobLink JobLink { get; set; }                [EntityRelationship(DeleteAction.Cascade)]        [Editable(Editable.Hidden)]        public JobBillOfMaterialsLink BillOfMaterials { get; set; }                [EditorSequence(1)]        [EntityRelationship(DeleteAction.SetNull)]        [RequiredColumn]        public AssignmentActivityLink ActivityLink { get; set; }                [EditorSequence(2)]        [RequiredColumn]        [DurationEditor(Summary = Summary.Sum)]        public TimeSpan Duration { get; set; }                [EditorSequence(3)]        [CurrencyEditor]        public double HourlyCost { get; set; }        [EditorSequence(4)]        [CurrencyEditor(Summary = Summary.Sum)]        public double TotalCost { get; set; }                [EditorSequence(5)]        [RequiredColumn]        public JobScopeLink Scope { get; set; }                private class JobITPLookup : LookupDefinitionGenerator<JobITP, JobBillOfMaterialsItem>        {            public override Filter<JobITP> DefineFilter(JobBillOfMaterialsItem[] items)            {                if (items.Length == 1)                    return new Filter<JobITP>(x => x.Job.ID).IsEqualTo(items.First().Job.ID);                return LookupFactory.DefineFilter<JobITP>();            }            public override Columns<JobBillOfMaterialsItem> DefineFilterColumns()                => Columns.None<JobBillOfMaterialsItem>().Add(x => x.Job.ID);        }        [EditorSequence(6)]        [EntityRelationship(DeleteAction.SetNull)]        [LookupDefinition(typeof(JobITPLookup))]        public JobITPLink ITP { get; set; }                [EditorSequence("Issues", 1)]        public ManagedProblem Problem { get; set; }                private bool bChanging;                protected override void DoPropertyChanged(string name, object? before, object? after)        {            if (bChanging)                return;            try            {                bChanging = true;                if (name.Equals(nameof(Duration)) && after is TimeSpan duration)                    TotalCost = HourlyCost * duration.TotalHours;                                else if (name.Equals(nameof(HourlyCost)) && after is double cost)                    TotalCost = cost * Duration.TotalHours;                else if (name.Equals(nameof(TotalCost)) && after is double total)                {                    if (Duration == TimeSpan.Zero)                        Duration = TimeSpan.FromHours(1.0);                    HourlyCost = total / Duration.TotalHours;                }            }            finally            {                bChanging = false;            }            base.DoPropertyChanged(name, before, after);        }    }}
 |