Beispiel #1
0
        public void Create(ReportFormat format)
        {
            DateTime dateIndex = StartDate.Date;

            DataTable data = new DataTable();
            data.Columns.Add("Date", typeof(DateTime));
            data.Columns.Add("Client", typeof(string));
            data.Columns.Add("Comments", typeof(string));
            data.Columns.Add("Hours", typeof(decimal));

            DataColumn[] primaryKey = new DataColumn[] { data.Columns[0], data.Columns[1], data.Columns[2] };
            data.PrimaryKey = primaryKey;

            string filename = String.Empty;
            while (dateIndex <= EndDate.Date)
            {
                filename = Constants.DataPath + dateIndex.ToString("yyyy-MM-dd") + ".xml";
                if (File.Exists(filename))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(filename);

                    foreach (XmlNode node in xml.DocumentElement.ChildNodes)
                    {
                        TimeSlice timeSlice = new TimeSlice(node);
                        DataRow row = data.Rows.Find(new object[] { dateIndex, timeSlice.Client, timeSlice.Notes });
                        decimal hours = 0;
                        if (row == null)
                        {
                            row = data.NewRow();
                            row["Client"] = timeSlice.Client;
                            row["Comments"] = timeSlice.Notes;
                            row["Date"] = timeSlice.StartTime.Date;
                            data.Rows.Add(row);
                        }
                        else
                        {
                            hours = Convert.ToDecimal(row[3]);
                        }

                        row["Hours"] = hours + (Convert.ToDecimal(timeSlice.EndTime.Subtract(timeSlice.StartTime).TotalHours) * (1 + Fluff));
                    }
                }

                dateIndex = dateIndex.AddDays(1);
            }

            List<object> postMungeData = new List<object>();
            foreach (DataRow row in data.Rows)
                postMungeData.Add(new { Client = row["Client"], Comments = row["Comments"], Date = row["Date"], Hours = row["Hours"] });

            StreamWriter writer = null;
            try
            {
                writer = new StreamWriter(Filename);
                writer.Write(format.Create(postMungeData));
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }
Beispiel #2
0
        private void Stop(string client, string notes, DateTime dateStarted)
        {
            TimeSlice timeSlice = new TimeSlice(client, notes, dateStarted);
            timeSlice.Save();

            DateStarted = null;
            GoButton.Content = "Start";
            ClientComboBox.IsEnabled = true;
            NotesTextBox.Text = "";
            SystemTrayIcon.Text = "Slacking off";

            GoButton.Background = (System.Windows.Media.Brush)Application.Current.Resources["StartButtonBrush"];
        }