コード例 #1
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        /// <summary>
        /// Add new task.
        /// </summary>
        /// <param name="task">The task to add.</param>
        public static void Add(UserTask task)
        {
            XmlElement existing = db.Doc.GetElementById(task.ID);

            if (existing == null)
            {
                //
                // <yyyymmdd></yyyymmdd>
                //
                string date = "nodate";

                if (task.DueDate != null)
                {
                    date = FormatHelpers.DateString((DateTime)task.DueDate);
                }

                XmlNode existingDate = db.Doc.SelectSingleNode("/db/" + date);

                //
                // <t />
                //
                XmlElement tsk = db.Doc.CreateElement(TaskTag);

                tsk.SetAttribute(XmlDatabase.IdAttribute, task.ID);
                tsk.SetAttribute(SubjectAttribute, task.Subject);

                if (task.StartDate != null)
                {
                    tsk.SetAttribute(StartDateAttribute, FormatHelpers.DateTimeToShortString(task.StartDate.Value));
                }
                else
                {
                    tsk.SetAttribute(StartDateAttribute, "");
                }

                tsk.SetAttribute(ReminderAttribute, FormatHelpers.DateTimeToString(task.Reminder));
                tsk.SetAttribute(IsReminderEnabledAttribute, FormatHelpers.BoolToString(task.IsReminderEnabled));
                tsk.SetAttribute(StatusAttribute, ((byte)task.Status).ToString());
                tsk.SetAttribute(PriorityAttribute, ((byte)task.Priority).ToString());
                tsk.SetAttribute(ProgressAttribute, task.Progress.ToString());
                tsk.SetAttribute(CategoryAttribute, task.CategoryID);
                tsk.SetAttribute(OwnerAttribute, task.Owner);
                tsk.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(task.ReadOnly));
                tsk.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(task.Private));
                tsk.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(task.LastModified));

                if (existingDate == null)
                {
                    XmlElement elem = db.Doc.CreateElement(date);
                    elem.AppendChild(tsk);

                    if (task.DueDate != null)
                    {
                        db.Doc.SmartInsert(elem, (DateTime)task.DueDate, date);
                    }
                    else
                    {
                        db.Doc.DocumentElement.PrependChild(elem);
                    }
                }
                else
                {
                    existingDate.AppendChild(tsk);
                }
            }
        }
コード例 #2
0
ファイル: TaskDatabase.cs プロジェクト: mingslogar/dimension4
        /// <summary>
        /// Get all tasks tagged with the specified date.
        /// </summary>
        /// <param name="dueDate">the date tasks should be returned for</param>
        public static UserTask[] GetTasks(DateTime?dueDate)
        {
            //
            // <yyyymmdd></yyyymmdd>
            //
            string datestring = "nodate";

            if (dueDate != null)
            {
                datestring = FormatHelpers.DateString((DateTime)dueDate);
            }

            XmlNode existingDate = db.Doc.SelectSingleNode("/db/" + datestring);

            if (existingDate != null)
            {
                XmlNodeList tsks = existingDate.ChildNodes;

                int count = tsks.Count;

                if (count != 0)
                {
                    UserTask[] tasks = new UserTask[count];

                    for (int i = 0; i < count; i++)
                    {
                        //
                        // <t />
                        //
                        XmlNode node = tsks.Item(i);
                        XmlAttributeCollection attribs = node.Attributes;

                        tasks[i]         = new UserTask(false);
                        tasks[i].ID      = attribs[XmlDatabase.IdAttribute].Value;
                        tasks[i].DueDate = dueDate;

                        if (attribs[StartDateAttribute].Value == "")
                        {
                            tasks[i].StartDate = null;
                        }
                        else
                        {
                            tasks[i].StartDate = FormatHelpers.ParseShortDateTime(attribs[StartDateAttribute].Value);
                        }

                        tasks[i].Subject           = attribs[SubjectAttribute].Value;
                        tasks[i].Reminder          = FormatHelpers.ParseDateTime(attribs[ReminderAttribute].Value);
                        tasks[i].IsReminderEnabled = FormatHelpers.ParseBool(attribs[IsReminderEnabledAttribute].Value);
                        tasks[i].Status            = (UserTask.StatusPhase) byte.Parse(attribs[StatusAttribute].Value);
                        tasks[i].Priority          = (Priority)byte.Parse(attribs[PriorityAttribute].Value);
                        tasks[i].Progress          = double.Parse(attribs[ProgressAttribute].Value);
                        tasks[i].CategoryID        = attribs[CategoryAttribute].Value;
                        tasks[i].Owner             = attribs[OwnerAttribute].Value;
                        tasks[i].ReadOnly          = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value);
                        tasks[i].Private           = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value);
                        tasks[i].LastModified      = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value);
                    }

                    return(tasks);
                }

                return(null);
            }

            return(null);
        }