Beispiel #1
0
        /// <summary>
        /// Factory method to create a CustomColumnValue from the internal endocding of custom column values in Hansoft.
        /// </summary>
        /// <param name="task">The task that the value belongs to.</param>
        /// <param name="customColumn">The custom column that the value belongs to.</param>
        /// <param name="internalValue">The Hansoft internal value.</param>
        /// <returns>The CustomColumn value corresponding to the given parameters.</returns>
        public static CustomColumnValue FromInternalValue(Task task, HPMProjectCustomColumnsColumn customColumn, string internalValue)
        {
            switch (customColumn.m_Type)
            {
            case EHPMProjectCustomColumnsColumnType.AccumulatedTime:
                return(AccumulatedTimeValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.FloatNumber:
                return(FloatNumberValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.IntegerNumber:
                return(IntegerNumberValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.Hyperlink:
                return(HyperlinkValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.Text:
                return(TextValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.MultiLineText:
                return(MultilineTextValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.DateTime:
                return(DateValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.DateTimeWithTime:
                return(DateTimeValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.DropList:
                return(SingleSelectionValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.MultiSelectionDropList:
                return(MultipleSelectionValue.FromInternalValue(task, customColumn, internalValue));

            case EHPMProjectCustomColumnsColumnType.Resources:
                return(ResourcesValue.FromInternalValue(task, customColumn, internalValue));

            default:
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Factory method to create a CustomColumnValue from a list of user representations (string) of custom column values in Hansoft.
        /// Currently only implemented for MultipleSelection and Resources
        /// </summary>
        /// <param name="task">The task that the value belongs to.</param>
        /// <param name="customColumn">The custom column that the value belongs to.</param>
        /// <param name="internalValue">The list of strings</param>
        /// <returns>The CustomColumn value corresponding to the given parameters.</returns>
        public static CustomColumnValue FromStringList(Task task, HPMProjectCustomColumnsColumn customColumn, IList value)
        {
            switch (customColumn.m_Type)
            {
            case EHPMProjectCustomColumnsColumnType.MultiSelectionDropList:
                return(MultipleSelectionValue.FromStringList(task, customColumn, value));

            case EHPMProjectCustomColumnsColumnType.Resources:
            {
                Project         project   = Project.GetProject(task.MainProjectID);
                List <Resource> resources = new List <Resource>();
                foreach (string rs in value)
                {
                    string trimmed = rs.Trim();
                    User   user    = project.Members.Find(u => u.Name == trimmed);
                    if (user != null)
                    {
                        resources.Add(user);
                    }
                    else
                    {
                        User groupMember = project.Members.Find(u => u.Groups.Find(g => g.Name == trimmed) != null);
                        if (groupMember != null)
                        {
                            Group group = groupMember.Groups.Find(g => g.Name == trimmed);
                            resources.Add(group);
                        }
                    }
                }

                return(ResourcesValue.FromResourceList(task, customColumn, resources));
            }

            default:
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Factory method to create a CustomColumnValue from the end user representation (string) of custom column values in Hansoft.
        /// </summary>
        /// <param name="task">The task that the value belongs to.</param>
        /// <param name="customColumn">The custom column that the value belongs to.</param>
        /// <param name="endUserString">The string value of the custom column as it is displayed in the Hansoft client.</param>
        /// <returns>The CustomColumn value corresponding to the given parameters.</returns>
        /// <returns></returns>
        public static CustomColumnValue FromEndUserString(Task task, HPMProjectCustomColumnsColumn customColumn, string endUserString)
        {
            switch (customColumn.m_Type)
            {
            case EHPMProjectCustomColumnsColumnType.AccumulatedTime:
                return(AccumulatedTimeValue.FromInternalValue(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.FloatNumber:
                return(FloatNumberValue.FromInternalValue(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.IntegerNumber:
                return(IntegerNumberValue.FromInternalValue(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.Hyperlink:
                return(HyperlinkValue.FromInternalValue(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.Text:
                return(TextValue.FromInternalValue(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.MultiLineText:
                return(MultilineTextValue.FromEscapedString(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.DateTime:
                DateTime dt;
                if (!DateTime.TryParse(endUserString, out dt))
                {
                    return(DateValue.FromInternalValue(task, customColumn, endUserString));
                }
                else
                {
                    return(DateValue.FromDateTime(task, customColumn, dt.ToUniversalTime()));
                }

            case EHPMProjectCustomColumnsColumnType.DateTimeWithTime:
                if (!DateTime.TryParse(endUserString, out dt))
                {
                    return(DateValue.FromInternalValue(task, customColumn, endUserString));
                }
                else
                {
                    return(DateTimeValue.FromDateTime(task, customColumn, dt.ToUniversalTime()));
                }

            case EHPMProjectCustomColumnsColumnType.DropList:
                return(SingleSelectionValue.FromName(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.MultiSelectionDropList:
                return(MultipleSelectionValue.FromName(task, customColumn, endUserString));

            case EHPMProjectCustomColumnsColumnType.Resources:
                Project         project   = Project.GetProject(task.MainProjectID);
                List <Resource> resources = new List <Resource>();
                string[]        rStrings  = endUserString.Split(new char[] { ';' });
                foreach (string rs in rStrings)
                {
                    string trimmed = rs.Trim();
                    User   user    = project.Members.Find(u => u.Name == trimmed);
                    if (user != null)
                    {
                        resources.Add(user);
                    }
                    else
                    {
                        User groupMember = project.Members.Find(u => u.Groups.Find(g => g.Name == trimmed) != null);
                        if (groupMember != null)
                        {
                            Group group = groupMember.Groups.Find(g => g.Name == trimmed);
                            resources.Add(group);
                        }
                    }
                }
                return(ResourcesValue.FromResourceList(task, customColumn, resources));

            default:
                return(null);
            }
        }