Пример #1
0
        private void addCommonTaskToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TimeEntry task = (sender as ToolStripMenuItem).Tag as TimeEntry;

            frmChooseDay dayChooser = new frmChooseDay();

            if (dayChooser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                for (DateTime day = dayChooser.SelectedDates.Start; day <= dayChooser.SelectedDates.End; day = day.AddDays(1))
                {
                    AddTimeEntry(new TimeEntry(task.Project, task.Task, task.Employer, new DateTime(day.Year, day.Month, day.Day, task.Start.Hour, task.Start.Minute, 0),
                                               new DateTime(day.Year, day.Month, day.Day, task.Stop.Hour, task.Stop.Minute, 0), task.Comments));
                }
                RefreshEntries();
            }
        }
Пример #2
0
        public static void ReportDailyTask(TimeEntry inputEntry, List <TimeEntry> TimeEntries, SaveFileDialog saveFileDialogReport)
        {
            frmChooseDay chooser = new frmChooseDay();

            chooser.Title          = "Select Days to Include in the Report";
            chooser.SelectionCount = 100;

            if (chooser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StringBuilder result = new StringBuilder();

                for (DateTime day = chooser.SelectedDates.Start; day <= chooser.SelectedDates.End; day = day.AddDays(1))
                {
                    TimeSpan total = new TimeSpan(0);

                    foreach (TimeEntry entry in TimeEntries.Where(e => e.Start.Date == day.Date && e.Project == inputEntry.Project && e.Task == inputEntry.Task && e.Employer == inputEntry.Employer))
                    {
                        total += (entry.Stop - entry.Start);
                    }
                    if (total.TotalHours > 0)
                    {
                        result.AppendLine(day.Date.ToString("d-MMM") + "," + Math.Round(total.TotalHours, 2).ToString());
                    }
                }

                if (saveFileDialogReport.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        File.WriteAllText(saveFileDialogReport.FileName, result.ToString());
                        System.Diagnostics.Process.Start(saveFileDialogReport.FileName);
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }