Esempio n. 1
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();
            }
        }