| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 | using System;using System.Collections.Generic;using System.Linq.Expressions;using InABox.Core;namespace Comal.Classes{    public class KanbanDocumentCount : CoreAggregate<Kanban, KanbanDocument, Guid>    {        public override Expression<Func<KanbanDocument, Guid>> Aggregate => x => x.ID;        public override AggregateCalculation Calculation => AggregateCalculation.Count;        public override Dictionary<Expression<Func<KanbanDocument, object>>, Expression<Func<Kanban, object>>> Links =>            new Dictionary<Expression<Func<KanbanDocument, object>>, Expression<Func<Kanban, object>>> ()            {                { KanbanDocument => KanbanDocument.EntityLink.ID, Kanban => Kanban.ID }            };    }    public class KanbaAssignmentDuration : CoreAggregate<Kanban, Assignment, TimeSpan>    {        public override Expression<Func<Assignment, TimeSpan>> Aggregate => x => x.Actual.Duration;        public override AggregateCalculation Calculation => AggregateCalculation.Sum;        public override Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Kanban, object>>> Links =>            new Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Kanban, object>>>()            {                { Assignment => Assignment.Task.ID, Kanban => Kanban.ID }            };    }    public enum KanbanCategory    {        Open,        InProgress,        Waiting,        Complete    }    [UserTracking("Task Management")]    [Caption("Tasks")]    public class Kanban : Entity, IPersistent, IRemotable, IKanban, IScheduleAction, IOneToMany<Schedule>, INumericAutoIncrement<Kanban>,        IOneToMany<Equipment>, ILicense<TaskManagementLicense>, IExportable, IImportable    {        private bool bChanging;        [NullEditor]        public DeliveryLink Delivery { get; set; }        [IntegerEditor(Editable = Editable.Disabled)]        [EditorSequence(-1)]        public int Number { get; set; }        [TextBoxEditor]        [EditorSequence(0)]        public string Title { get; set; }        [EditorSequence(1)]        [Caption("Attached to")]        public JobLink JobLink { get; set; }        [RichTextEditor]        [EditorSequence(2)]        public string Description { get; set; }        [NotesEditor]        [EditorSequence(3)]        public string[] Notes { get; set; }        [NullEditor]        [EditorSequence(4)]        public string Summary { get; set; }        [EditorSequence(5)]        [Caption("Task Type")]        public KanbanTypeLink Type { get; set; }        [DateEditor]        [EditorSequence(6)]        public DateTime DueDate { get; set; }        [EditorSequence(7)]        [Caption("Assigned To")]        public EmployeeLink EmployeeLink { get; set; }        [EditorSequence(8)]        [Caption("Allocated By")]        public EmployeeLink ManagerLink { get; set; }        [DateTimeEditor(Editable = Editable.Hidden)]        [EditorSequence(9)]        public DateTime Completed { get; set; }        [EditorSequence("Other", 1)]        [Caption("Equipment Item")]        public EquipmentLink Equipment { get; set; }        [DateEditor]        [EditorSequence("Other", 2)]        public DateTime StartDate { get; set; }        [DurationEditor]        [EditorSequence("Other", 3)]        public TimeSpan EstimatedTime { get; set; }        [Aggregate(typeof(KanbaAssignmentDuration))]        [EditorSequence("Other", 4)]        public TimeSpan ActualTime { get; set; }        [CheckBoxEditor]        [EditorSequence("Other", 5)]        public bool Private { get; set; }        [EditorSequence("Other", 6)]        [CheckBoxEditor]        public bool Locked { get; set; }        [ComboLookupEditor(typeof(KanbanCategoryLookups))]        [EditorSequence("Other", 7)]        [LoggableProperty]        public string Category { get; set; }        [SecondaryIndex]        [NullEditor]        public DateTime Closed { get; set; }        [NullEditor]        [Aggregate(typeof(KanbanDocumentCount))]        public int Attachments { get; set; }        public Expression<Func<Kanban, int>> AutoIncrementField()        {            return x => x.Number;        }        public Filter<Kanban> AutoIncrementFilter()        {            return null;        }        [NullEditor]        public ScheduleLink ScheduleLink { get; set; }        public static KanbanCategory StringToCategory(string category)        {            return string.Equals(category, "Complete")                ? KanbanCategory.Complete                : string.Equals(category, "Waiting")                    ? KanbanCategory.Waiting                    : string.Equals(category, "In Progress")                        ? KanbanCategory.InProgress                        : KanbanCategory.Open;        }        public static string CategoryToString(KanbanCategory category)        {            return category.Equals(KanbanCategory.Complete)                ? "Complete"                : category.Equals(KanbanCategory.Waiting)                    ? "Waiting"                    : category.Equals(KanbanCategory.InProgress)                        ? "In Progress"                        : "Open";        }        protected override void Init()        {            base.Init();            JobLink = new JobLink();            Equipment = new EquipmentLink();            EmployeeLink = new EmployeeLink();            ManagerLink = new EmployeeLink();            ScheduleLink = new ScheduleLink();            Notes = new string[] { };            StartDate = DateTime.Today;            EstimatedTime = TimeSpan.FromHours(1);            DueDate = DateTime.Today;            Completed = DateTime.MinValue;            Closed = DateTime.MinValue;            Type = new KanbanTypeLink();            Delivery = new DeliveryLink();        }        private bool IsCompleted(object value)        {            if (value == null)                return false;            if (value is DateTime)                return !((DateTime)value).IsEmpty();            return value.Equals("Complete") || value.Equals("Completed");        }        protected override void DoPropertyChanged(string name, object before, object after)        {            base.DoPropertyChanged(name, before, after);            if (bChanging)                return;            bChanging = true;            if (name.Equals("Completed")) // set the completed date            {                Category = IsCompleted(after) ? "Complete" : IsCompleted(Category) ? "In Progress" : Category;            }            else if (name.Equals("Category")) // set the completed date            {                Completed = IsCompleted(after) ? IsCompleted(Completed) ? Completed : DateTime.Now : DateTime.MinValue;            }            else if (name.Equals("Description"))            {                var summary = (string)after;                Summary = CoreUtils.StripHTML(summary);            }            bChanging = false;        }        private class KanbanCategoryLookups : LookupGenerator<object>        {            public KanbanCategoryLookups(object[] items) : base(items)            {                AddValue("Open", "To Do");                AddValue("In Progress", "In Progress");                AddValue("Waiting", "Waiting For Others");                AddValue("Complete", "Completed");            }        }    }}
 |