Esempio n. 1
0
        public bool UpdateTaskAttributes(Task task, UIExtension.UpdateType type, bool newTask)
        {
            if (!task.IsValid())
            {
                return(false);
            }

            UInt32 taskID = task.GetID();

            if (newTask)
            {
                Title         = task.GetTitle();
                AllocTo       = String.Join(", ", task.GetAllocatedTo());
                HasIcon       = task.HasIcon();
                Id            = taskID;
                IsParent      = task.IsParent();
                TaskTextColor = task.GetTextDrawingColor();
                DrawBorder    = true;
                IsLocked      = task.IsLocked(true);

                Task.TimeUnits units = Task.TimeUnits.Unknown;
                TimeEstimate = task.GetTimeEstimate(ref units, false);
                TimeEstUnits = units;

                StartDate = task.GetStartDate(false);
                IsDone    = (task.IsDone() || task.IsGoodAsDone());

                m_PrevDueDate = task.GetDueDate(false);
                EndDate       = (IsDone ? task.GetDoneDate() : m_PrevDueDate);
            }
            else
            {
                if (task.IsAttributeAvailable(Task.Attribute.Title))
                {
                    Title = task.GetTitle();
                }

                if (task.IsAttributeAvailable(Task.Attribute.DueDate))
                {
                    m_PrevDueDate = task.GetDueDate(false);                     // always

                    if (!IsDone)
                    {
                        EndDate = m_PrevDueDate;
                    }
                }

                if (task.IsAttributeAvailable(Task.Attribute.DoneDate))
                {
                    bool wasDone = IsDone;
                    IsDone = (task.IsDone() || task.IsGoodAsDone());

                    if (IsDone)
                    {
                        if (!wasDone)
                        {
                            m_PrevDueDate = EndDate;
                        }

                        EndDate = task.GetDoneDate();
                    }
                    else if (wasDone && !IsDone)
                    {
                        EndDate = m_PrevDueDate;
                    }
                }

                if (task.IsAttributeAvailable(Task.Attribute.TimeEstimate))
                {
                    Task.TimeUnits units = Task.TimeUnits.Unknown;
                    TimeEstimate = task.GetTimeEstimate(ref units, false);
                    TimeEstUnits = units;
                }

                if (task.IsAttributeAvailable(Task.Attribute.StartDate))
                {
                    StartDate = task.GetStartDate(false);
                }

                if (task.IsAttributeAvailable(Task.Attribute.AllocatedTo))
                {
                    AllocTo = String.Join(", ", task.GetAllocatedTo());
                }

                if (task.IsAttributeAvailable(Task.Attribute.Icon))
                {
                    HasIcon = task.HasIcon();
                }

                TaskTextColor = task.GetTextDrawingColor();
                IsLocked      = task.IsLocked(true);
            }

            UpdateOriginalDates();

            return(true);
        }
        public void UpdateTasks(TaskList tasks, UIExtension.UpdateType type)
        {
            Task           task = tasks.GetFirstTask();
            SampleListItem item = new SampleListItem();

            System.Collections.Generic.List <String> attrib = new System.Collections.Generic.List <String>();
            System.Collections.Generic.List <String> value  = new System.Collections.Generic.List <String>();

            if (tasks.IsAttributeAvailable(Task.Attribute.Title))
            {
                attrib.Add("Title");
                value.Add(task.GetTitle());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.DoneDate))
            {
                attrib.Add("Done Date");
                value.Add(task.GetDoneDateString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.DueDate))
            {
                attrib.Add("Due Date");
                value.Add(task.GetDueDateString(false));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.StartDate))
            {
                attrib.Add("Start Date");
                value.Add(task.GetStartDateString(false));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Priority))
            {
                attrib.Add("Priority");
                value.Add(task.GetPriority(false).ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Color))
            {
                attrib.Add("Color");
                value.Add(task.GetColor().ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.AllocatedTo))
            {
                attrib.Add("Alloc To");
                value.Add(task.FormatAllocatedTo(", "));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.AllocatedBy))
            {
                attrib.Add("Alloc By");
                value.Add(task.GetAllocatedBy());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Status))
            {
                attrib.Add("Status");
                value.Add(task.GetStatus());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Category))
            {
                attrib.Add("Category");
                value.Add(task.FormatCategory(", "));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Percent))
            {
                attrib.Add("Percent");
                value.Add(task.GetPercentDone(false).ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.TimeEstimate))
            {
                attrib.Add("Time Estimate");

                Task.TimeUnits units = Task.TimeUnits.Hours;
                value.Add(task.GetTimeEstimate(ref units, false).ToString() + units);
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.TimeSpent))
            {
                attrib.Add("Time Spent");

                Task.TimeUnits units = Task.TimeUnits.Hours;
                value.Add(task.GetTimeSpent(ref units, false).ToString() + units);
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.FileLink))
            {
                attrib.Add("File Link");
                value.Add(task.FormatFileLink(", "));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Comments))
            {
                attrib.Add("Comments");
                value.Add(task.GetComments());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Flag))
            {
                attrib.Add("Flag");
                value.Add(task.IsFlagged(false).ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.CreationDate))
            {
                attrib.Add("Creation Date");
                value.Add(task.GetCreationDateString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.CreatedBy))
            {
                attrib.Add("Created By");
                value.Add(task.GetCreatedBy());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Risk))
            {
                attrib.Add("Risk");
                value.Add(task.GetRisk(false).ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.ExternalId))
            {
                attrib.Add("External ID");
                value.Add(task.GetExternalID());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Cost))
            {
                attrib.Add("Cost");
                value.Add(task.GetCost(false).ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Dependency))
            {
                attrib.Add("Dependency");
                value.Add(task.FormatDependency(", "));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Recurrence))
            {
                attrib.Add("Recurrence");
                //value.Add(task.GetRecurrence());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Version))
            {
                attrib.Add("Version");
                value.Add(task.GetVersion());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Position))
            {
                attrib.Add("Position");
                value.Add(task.GetPositionString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Id))
            {
                attrib.Add("ID");
                value.Add(task.GetID().ToString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.LastModifiedDate))
            {
                attrib.Add("Last Modified");
                //value.Add(task.GetLastModifiedString());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Icon))
            {
                attrib.Add("Icon");
                value.Add(task.GetIcon());
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.Tags))
            {
                attrib.Add("Tag");
                value.Add(task.FormatTag(", "));
            }

            if (tasks.IsAttributeAvailable(Task.Attribute.CustomAttribute))
            {
                attrib.Add("Custom Attribute");
                //value.Add(task.GetCustomAttributeData());
            }

            item.Attrib = String.Join(",", attrib.ToArray());
            item.Value  = String.Join(",", value.ToArray());
            item.Tasks  = task.GetID().ToString();

            switch (type)
            {
            case UIExtension.UpdateType.Edit: item.Type = "Edit"; break;

            case UIExtension.UpdateType.New: item.Type = "Add Task"; break;

            case UIExtension.UpdateType.Delete: item.Type = "Move Tasks"; break;

            case UIExtension.UpdateType.All: item.Type = "All"; break;

            case UIExtension.UpdateType.Unknown: item.Type = "Unknown"; break;
            }

            m_Items.Add(item);
            m_ListView.Items.Refresh();
        }
        public bool UpdateTaskAttributes(Task task,
                                         UIExtension.UpdateType type,
                                         System.Collections.Generic.HashSet <UIExtension.TaskAttribute> attribs)
        {
            if (!task.IsValid())
            {
                return(false);
            }

            UInt32 taskID = task.GetID();

            if (attribs != null)
            {
                if (attribs.Contains(UIExtension.TaskAttribute.Title))
                {
                    Title = task.GetTitle();
                }

                if (attribs.Contains(UIExtension.TaskAttribute.DueDate))
                {
                    m_PrevDueDate = task.GetDueDate(false);                     // always

                    if (!IsDone)
                    {
                        EndDate = CheckGetEndOfDay(m_PrevDueDate);
                    }
                }

                if (attribs.Contains(UIExtension.TaskAttribute.DoneDate))
                {
                    bool wasDone = IsDone;
                    IsDone = (task.IsDone() || task.IsGoodAsDone());

                    if (IsDone)
                    {
                        if (!wasDone)
                        {
                            m_PrevDueDate = CheckGetEndOfDay(EndDate);
                        }

                        EndDate = CheckGetEndOfDay(task.GetDoneDate());
                    }
                    else if (wasDone && !IsDone)
                    {
                        EndDate = CheckGetEndOfDay(m_PrevDueDate);
                    }
                }

                if (attribs.Contains(UIExtension.TaskAttribute.TimeEstimate))
                {
                    Task.TimeUnits units = Task.TimeUnits.Unknown;
                    TimeEstimate = task.GetTimeEstimate(ref units, false);
                    TimeEstUnits = units;
                }

                if (attribs.Contains(UIExtension.TaskAttribute.StartDate))
                {
                    StartDate = task.GetStartDate(false);
                }

                if (attribs.Contains(UIExtension.TaskAttribute.AllocTo))
                {
                    AllocTo = String.Join(", ", task.GetAllocatedTo());
                }

                if (attribs.Contains(UIExtension.TaskAttribute.Icon))
                {
                    HasIcon = task.HasIcon();
                }

                TaskTextColor = task.GetTextDrawingColor();
                IsLocked      = task.IsLocked(true);
            }
            else
            {
                Title         = task.GetTitle();
                AllocTo       = String.Join(", ", task.GetAllocatedTo());
                HasIcon       = task.HasIcon();
                Id            = taskID;
                IsParent      = task.IsParent();
                TaskTextColor = task.GetTextDrawingColor();
                DrawBorder    = true;
                IsLocked      = task.IsLocked(true);

                Task.TimeUnits units = Task.TimeUnits.Unknown;
                TimeEstimate = task.GetTimeEstimate(ref units, false);
                TimeEstUnits = units;

                StartDate = task.GetStartDate(false);
                IsDone    = (task.IsDone() || task.IsGoodAsDone());

                m_PrevDueDate = CheckGetEndOfDay(task.GetDueDate(false));
                EndDate       = (IsDone ? CheckGetEndOfDay(task.GetDoneDate()) : m_PrevDueDate);
            }

            UpdateOriginalDates();

            return(true);
        }