コード例 #1
0
 private void GetSubTasks(Task parentTask, List <TimeEntry> timeEntries, ISelectionFilter filter)
 {
     foreach (var subTask in parentTask.SubTasks)
     {
         if (filter.HasTask(subTask))
         {
             foreach (var timeEntry in subTask.TimeEntries)
             {
                 if (filter.HasTimeEntry(timeEntry))
                 {
                     timeEntries.Add(timeEntry);
                 }
             }
         }
         GetSubTasks(subTask, timeEntries, filter);
     }
 }
コード例 #2
0
        private DataSet CreateXmlData(ISelectionFilter filter)
        {
            var dataSet     = new DataSet();
            var timeEntries = new List <TimeEntry>();

            var customers = filter.Customers;

            foreach (var customer in customers)
            {
                foreach (var project in customer.Projects)
                {
                    if (filter.HasProject(project))
                    {
                        foreach (var task in project.Tasks)
                        {
                            if (filter.HasTask(task))
                            {
                                foreach (var timeEntry in task.TimeEntries)
                                {
                                    if (filter.HasTimeEntry(timeEntry))
                                    {
                                        timeEntries.Add(timeEntry);
                                    }
                                }
                            }
                            GetSubTasks(task, timeEntries, filter);
                        }
                    }
                }
            }

            using (var stream = new StringWriter())
            {
                using (var writer = new XmlTextWriter(stream))
                {
                    writer.WriteStartDocument(true);
                    writer.WriteStartElement("data");

                    foreach (var timeEntry in timeEntries)
                    {
                        writer.WriteStartElement("Table");
                        writer.WriteElementString("StartTime", String.Format("{0} {1}", timeEntry.StartTime.ToShortDateString(), timeEntry.StartTime.ToShortTimeString()));
                        writer.WriteElementString("EndTime", String.Format("{0} {1}", timeEntry.EndTime.ToShortDateString(), timeEntry.EndTime.ToShortTimeString()));
                        writer.WriteElementString("Customer", timeEntry.Task.Project.Customer.Name);
                        writer.WriteElementString("Project", timeEntry.Task.Project.Name);
                        writer.WriteElementString("Task", timeEntry.Task.Name);
                        writer.WriteElementString("Consultant", timeEntry.User.Name);
                        writer.WriteElementString("Billable", timeEntry.Billable.ToString());
                        writer.WriteElementString("Description", timeEntry.Description);
                        writer.WriteElementString("Timespent", timeEntry.TimeSpent.ToString("N2"));
                        writer.WriteElementString("BillableTime", timeEntry.BillableTime.ToString("N2"));
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                    writer.WriteEndDocument();

                    //stream.Position = 0;
                    //var xml = System.Text.Encoding.UTF8.GetString(stream.GetBuffer());
                    var stringReader = new StringReader(stream.ToString());

                    dataSet.ReadXml(stringReader);

                    return(dataSet);
                }
            }
        }