Beispiel #1
0
        public DialogResult ShowReport(IWin32Window owner)
        {
            DateTime now       = DateTime.Now;
            DateTime endDate   = DateTime.Now.Date;
            DateTime beginDate = endDate.AddDays(Math.Min(0, -(int)endDate.DayOfWeek + 1));             // Move to Monday of this week

            this.dtpStartDate.Value = beginDate;
            this.dtpEndDate.Value   = endDate;

            this.lvReportData.ListViewItemSorter = new ListViewColumnSorter(0);
            this.lvReportData.Items.Clear();

            var projects = TimeKeeperData.GetActiveProjects();

            projects.Sort();

            this.clbProjects.Visible = false;

            this.clbProjects.Items.Clear();
            this.clbProjects.Items.AddRange(new ListBox.ObjectCollection(this.clbProjects, projects.ToArray()));
            this.clbProjects.Items.Insert(0, new Project {
                ProjectID = 0, Name = "All Projects"
            });

            this.clbProjects.SetItemChecked(0, true);               // Check all the items (the event will fire and check all the other items)

            this.StartPosition = FormStartPosition.CenterParent;
            return(this.ShowDialog(owner));
        }
Beispiel #2
0
        private void btnUpdateReport_Click(object sender, EventArgs e)
        {
            var selectedProjects = new HashSet <long>();

            foreach (Project project in this.clbProjects.CheckedItems)
            {
                if (project.ProjectID != 0)
                {
                    selectedProjects.Add(project.ProjectID);
                }
            }

            try
            {
                var data = TimeKeeperData.GetProjectSummary(this.dtpStartDate.Value, this.dtpEndDate.Value.Date.AddDays(1)).Where(a => selectedProjects.Contains(a.ProjectID));

                this.SuspendLayout();
                this.lvReportData.BeginUpdate();
                this.lvReportData.Items.Clear();
                this.lvReportData.ListViewItemSorter = new ListViewColumnSorter(0);

                long totalTime = 0;

                foreach (var row in data)
                {
                    totalTime += row.TotalMinutes;
                    this.lvReportData.Items.Add(new ListViewItem(new ListViewItem.ListViewSubItem[] {
                        new ListViewItem.ListViewSubItem()
                        {
                            Text = row.ProjectNameFormatted, Tag = null
                        },
                        new ListViewItem.ListViewSubItem()
                        {
                            Text = row.Department, Tag = null
                        },
                        new ListViewItem.ListViewSubItem()
                        {
                            Text = Strings.ReformatLongTime(row.TotalMinutes), Tag = row.TotalMinutesSortable
                        }
                    }, -1));
                }

                this.lvReportData.Sort();

                this.lblTotalTime.Text          = Strings.ReformatLongTime(totalTime);
                this.lblTimeInReportPeriod.Text = Strings.ReformatLongTime(DateTimes.GetWorkingDayCount(this.dtpStartDate.Value.Date, this.dtpEndDate.Value.Date) * 8 * 60);
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error retrieving the report data:\n\n" + ex.Message, "Report Error");
                return;
            }
            finally
            {
                this.lvReportData.EndUpdate();
                this.ResumeLayout();
            }
        }