private bool GetTimesheetDetailListViewItem(TimesheetDate timesheetDate, out ListViewItem timesheetDetailListViewItem, bool createIfNotExists) { int itemCount = m_listView.Items.Count; if (itemCount == 0) { timesheetDetailListViewItem = createIfNotExists ? CreateTimesheetDetailListViewItem(timesheetDate) : null; return(false); } else { foreach (ListViewItem listViewItem in m_listView.Items) { if (listViewItem.Tag is TimesheetDate) { TimesheetDate timeheetDateToCheck = (TimesheetDate)listViewItem.Tag; if (timeheetDateToCheck.Equals(timesheetDate)) { timesheetDetailListViewItem = listViewItem; return(true); } } } // If we get here there is no ListViewItem associated with the timesheetDate in the ListView... timesheetDetailListViewItem = createIfNotExists ? CreateTimesheetDetailListViewItem(timesheetDate) : null; return(false); } }
private void UpdateTimesheetDetailListViewItem(TimesheetDate timesheetDate) { const string noExistsError = "UpdateTimesheetDateListViewItem() failed in an attempt " + "to update the Timesheet's Detail ListItem in the ListView because it does not exist; " + "use InsertDayTypesListViewItem() instead."; ListViewItem listViewItem; if (!GetTimesheetDetailListViewItem(timesheetDate, out listViewItem)) { throw new InvalidOperationException(noExistsError); } else { listViewItem.StateImageIndex = timesheetDate.Timesheet.TimesheetSent ? DefaultImageList.Instance.GetLockedIconIndex() : -1; listViewItem.ImageIndex = DefaultImageList.Instance.GetCalendarIconIndex(); listViewItem.Text = Dates.GetMMDDYYYY(timesheetDate.Date); listViewItem.SubItems[1].Text = timesheetDate.Date.DayOfWeek.ToString(); listViewItem.SubItems[2].Text = timesheetDate.DayType.Name; listViewItem.SubItems[3].Text = timesheetDate.BillableHours.ToString(); listViewItem.SubItems[4].Text = timesheetDate.GetFormattedRatePerHour(); listViewItem.SubItems[5].Text = timesheetDate.GetFormattedInvoiceAmount(); listViewItem.SubItems[6].Text = timesheetDate.Notes; } }
protected override void Initialize() { base.Initialize(); TimesheetDate timesheetDate = this.Tag; // Text... StringBuilder stringBuilder = new StringBuilder(Dates.GetYYYYMMDD(timesheetDate.Date, '-')); stringBuilder.AppendFormat(" ({0})", timesheetDate.GetFormattedInvoiceAmount()); this.Text = stringBuilder.ToString(); }
// Events // -------------------------------------------------------------------------- #region Events protected void OnListViewMouseDoubleClick(object sender, MouseEventArgs e) { if (m_listView.SelectedIndices.Count > 0) { TimesheetDate timesheetDate = (TimesheetDate)m_listView.SelectedItems[0].Tag; if (!timesheetDate.IsValidDate || timesheetDate.Timesheet.TimesheetSent) { // If the Timesheet has been sent, or, if it is an invali date, do not allow updates. return; } else { TimesheetDateEditForm form = new TimesheetDateEditForm(timesheetDate); if (form.ShowDialog(this) == DialogResult.OK) { if (form.ValuesChanged) { if (this.TimesheetDetailUpdatingEvent != null) { TimesheetDetailEventArgs args = new TimesheetDetailEventArgs(this.Timesheet); this.TimesheetDetailUpdatingEvent(this, args); } // Suspend the changed events because we're going to make the calls to update our // Timesheet and Timesheet detail manually. timesheetDate.SuspendChangedEvent(true); timesheetDate.BillableHours = form.BillableHours; timesheetDate.DayType = form.DayType; timesheetDate.Notes = form.Notes; timesheetDate.SuspendChangedEvent(false); UpdateTimesheetDetailListViewItem(timesheetDate); ResizeTimesheetDetailListViewColumns(); if (this.TimesheetDetailUpdatedEvent != null) { TimesheetDetailEventArgs args = new TimesheetDetailEventArgs(this.Timesheet); this.TimesheetDetailUpdatedEvent(this, args); } } } } } #endregion // Events }
/// <summary> /// This member creates ListViewItems for Timsheets. /// </summary> /// <param name="timesheet">The Timesheet from which the ListViewItems will be created.</param> /// <returns>A ListViewItem object.</returns> private ListViewItem CreateTimesheetDetailListViewItem(TimesheetDate timesheetDate) { ListViewItem listViewItem = new ListViewItem(Dates.GetMMDDYYYY(timesheetDate.Date)); Timesheet timesheet = timesheetDate.Timesheet; if (timesheet.IsSplitTimesheet) { if (timesheetDate.IsWeekday) { listViewItem.ForeColor = (timesheetDate.IsValidDate && timesheetDate.BillableHours == 0) ? Color.DarkRed : Color.Red; } else { listViewItem.ForeColor = Color.Red; } } else { if (timesheetDate.IsValidDate) { if (timesheetDate.IsWeekday && timesheetDate.BillableHours == 0) { listViewItem.ForeColor = Color.DarkRed; } } } listViewItem.Font = (timesheetDate.IsValidDate) ? listViewItem.Font : new Font(listViewItem.Font, FontStyle.Strikeout); listViewItem.StateImageIndex = timesheetDate.Timesheet.TimesheetSent ? DefaultImageList.Instance.GetLockedIconIndex() : -1; listViewItem.ImageIndex = DefaultImageList.Instance.GetCalendarIconIndex(); listViewItem.SubItems.Add(timesheetDate.Date.DayOfWeek.ToString()); listViewItem.SubItems.Add(timesheetDate.DayType.Name); listViewItem.SubItems.Add(timesheetDate.BillableHours.ToString()); listViewItem.SubItems.Add(timesheetDate.GetFormattedRatePerHour()); listViewItem.SubItems.Add(timesheetDate.GetFormattedInvoiceAmount()); listViewItem.SubItems.Add(timesheetDate.Notes); listViewItem.Tag = timesheetDate; return(listViewItem); }
public TimesheetDateEditForm(TimesheetDate timesheetDate) { InitializeComponent(); this.TimesheetDate = timesheetDate; this.Text = string.Format("Edit {0}", Dates.GetYYYYMMDD(this.TimesheetDate.Date)); InitializeBillableHours(); InitializeInvoiceAmount(); InitializeDayTypes(); m_defaultWorkDayHours.Text = Configuration.Instance.MiscellaneousConfiguration.DefaultWorkDayHours.ToString("0.0"); m_notes.Text = this.TimesheetDate.Notes; m_clearNotes.Click += new EventHandler( delegate(object sender, EventArgs e) { m_notes.Text = string.Empty; }); m_ok.Click += new EventHandler( delegate(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); }); m_cancel.Click += new EventHandler( delegate(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); }); m_zero.Click += new EventHandler( delegate(object sender, EventArgs e) { m_billableHours.SelectedIndex = 0; }); m_defaultWorkDayHours.Click += new EventHandler( delegate(object sender, EventArgs e) { int index = m_billableHours.FindStringExact(m_defaultWorkDayHours.Text); m_billableHours.SelectedIndex = index; }); }
/// <summary> /// This function returns the DISTINCT Rates used by the given timesheet. /// </summary> /// <param name="timesheet">The Timesheet whose Rates are to be returned.</param> /// <returns>An Enumerable collection distinct Rates used by this Timesheet.</returns> static public IEnumerable <Rate> GetRates(Timesheet timesheet) { lock (m_syncRoot) { Configuration.Configuration config = Configuration.Configuration.Instance; IEnumerable <Rate> rates = config.RatesConfiguration.Rates; List <Rate> filteredRates = new List <Rate>(); for (int i = 0; i < timesheet.Dates.Count(); i++) { TimesheetDate timesheetDate = timesheet[i]; if (timesheetDate.IsValidDate) { filteredRates.Add(timesheetDate.Rate); } } return(filteredRates.Distinct().OrderBy(p => p.EffectiveDate)); } }
private void AddTimesheetDateTreeNodeDetailNodes(TimesheetDateTreeNode timesheetDateTreeNode, TimesheetDate timesheetDate, Color foreColor) { TreeNodeEx treeNode = null; int imageIndex = DefaultImageList.Instance.GetPropertyIconIndex(); // DayType Name... treeNode = new TimesheetDateDetailTreeNode(timesheetDate.DayType.Name, imageIndex); treeNode.ForeColor = foreColor; timesheetDateTreeNode.Nodes.Add(treeNode); // Billable Hours... treeNode = new TimesheetDateDetailTreeNode(string.Format("Billable Hours: {0}", timesheetDate.GetFormattedBillableHours()), imageIndex); treeNode.ForeColor = foreColor; timesheetDateTreeNode.Nodes.Add(treeNode); // Rate Per Hour... treeNode = new TimesheetDateDetailTreeNode(string.Format("Rate Per Hour: {0}", timesheetDate.GetFormattedRatePerHour()), imageIndex); treeNode.ForeColor = foreColor; timesheetDateTreeNode.Nodes.Add(treeNode); }
// Timesheet Detail ListView Members // -------------------------------------------------------------------------- #region Timesheet Detail ListView Members private void InsertTimesheetDateListViewItem(TimesheetDate timesheetDate) { ListViewItem timesheetDateListViewItem = CreateTimesheetDetailListViewItem(timesheetDate); m_listView.Items.Add(timesheetDateListViewItem); }
private bool GetTimesheetDetailListViewItem(TimesheetDate timesheetDate, out ListViewItem timesheetDetailListViewItem) { return(GetTimesheetDetailListViewItem(timesheetDate, out timesheetDetailListViewItem, false)); }
// Abstract Overrides // -------------------------------------------------------------------------- #region Abstract Overrides protected override bool UpdateWorkbook() { Excel.Application excelApplication = ExcelGenerator.GetExcelApplication(); TimesheetConfiguration timesheetConfiguration = Configuration.Configuration.Instance.TimesheetConfiguration; PersonalConfiguration personalConfiguration = Configuration.Configuration.Instance.PersonalConfiguration; ExcelCell cell = null; // Notes and remarks cell ExcelCell notesAndRemarksCell = Helpers.Excel.ToCell(timesheetConfiguration.NotesAndRemarksCell); // Timesheet name... cell = Helpers.Excel.ToCell(timesheetConfiguration.NameCell); excelApplication.Cells[cell.Row, cell.Column].Value = personalConfiguration.Name; // From date... cell = Helpers.Excel.ToCell(timesheetConfiguration.StartDateCell); excelApplication.Cells[cell.Row, cell.Column].Value = this.Timesheet.StartDate.Date; // Timesheet project description... cell = Helpers.Excel.ToCell(timesheetConfiguration.ProjectDescriptionCell); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetConfiguration.ProjectDescription; // Billable hours... // ------------------------------------------------------------------- string hourCellString = string.Empty; DayOfWeek dayOfWeek; TimesheetDate timesheetDate = null; // Monday... hourCellString = timesheetConfiguration.MondayHourCell; dayOfWeek = DayOfWeek.Monday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } // Tuesday... hourCellString = timesheetConfiguration.TuesdayHourCell; dayOfWeek = DayOfWeek.Tuesday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } // Wednesday... hourCellString = timesheetConfiguration.WednesdayHourCell; dayOfWeek = DayOfWeek.Wednesday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } // Thursday... hourCellString = timesheetConfiguration.ThursdayHourCell; dayOfWeek = DayOfWeek.Thursday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } // Friday... hourCellString = timesheetConfiguration.FridayHourCell; dayOfWeek = DayOfWeek.Friday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } // Saturday... hourCellString = timesheetConfiguration.SaturdayHourCell; dayOfWeek = DayOfWeek.Saturday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } // Sunday... hourCellString = timesheetConfiguration.SundayHourCell; dayOfWeek = DayOfWeek.Sunday; cell = Helpers.Excel.ToCell(hourCellString); timesheetDate = this.Timesheet.Dates.First(p => p.Date.DayOfWeek == dayOfWeek); excelApplication.Cells[cell.Row, cell.Column].Value = timesheetDate.BillableHours; if (timesheetDate.HasNotes) { AddNote(excelApplication, timesheetDate.Date, timesheetDate.Notes, notesAndRemarksCell); } return(true); }
public TimesheetDateTreeNode(TimesheetDate timesheetDate, int imageIndex = 0) { this.ImageIndex = imageIndex; this.Tag = timesheetDate; Initialize(); }
public TimesheetDateChangedEventArgs(TimesheetDate timesheetDate) { this.TimesheetDate = timesheetDate; }
/// <summary> /// This member creates ListViewItems for Timsheets. /// </summary> /// <param name="timesheet">The Timesheet from which the ListViewItems will be created.</param> /// <returns>A ListViewItem object.</returns> private ListViewItem CreateTimesheetDetailListViewItem(TimesheetDate timesheetDate) { ListViewItem listViewItem = new ListViewItem(Dates.GetMMDDYYYY(timesheetDate.Date)); Timesheet timesheet = timesheetDate.Timesheet; if (timesheet.IsSplitTimesheet) { if (timesheetDate.IsWeekday) { listViewItem.ForeColor = (timesheetDate.IsValidDate && timesheetDate.BillableHours == 0) ? Color.DarkRed : Color.Red; } else { listViewItem.ForeColor = Color.Red; } } else { if (timesheetDate.IsValidDate) { if (timesheetDate.IsWeekday && timesheetDate.BillableHours == 0) { listViewItem.ForeColor = Color.DarkRed; } } } listViewItem.Font = (timesheetDate.IsValidDate) ? listViewItem.Font : new Font(listViewItem.Font, FontStyle.Strikeout); listViewItem.StateImageIndex = timesheetDate.Timesheet.TimesheetSent ? DefaultImageList.Instance.GetLockedIconIndex() : -1; listViewItem.ImageIndex = DefaultImageList.Instance.GetCalendarIconIndex(); listViewItem.SubItems.Add(timesheetDate.Date.DayOfWeek.ToString()); listViewItem.SubItems.Add(timesheetDate.DayType.Name); listViewItem.SubItems.Add(timesheetDate.BillableHours.ToString()); listViewItem.SubItems.Add(timesheetDate.GetFormattedRatePerHour()); listViewItem.SubItems.Add(timesheetDate.GetFormattedInvoiceAmount()); listViewItem.SubItems.Add(timesheetDate.Notes); listViewItem.Tag = timesheetDate; return listViewItem; }
private bool GetTimesheetDetailListViewItem(TimesheetDate timesheetDate, out ListViewItem timesheetDetailListViewItem, bool createIfNotExists) { int itemCount = m_listView.Items.Count; if (itemCount == 0) { timesheetDetailListViewItem = createIfNotExists ? CreateTimesheetDetailListViewItem(timesheetDate) : null; return false; } else { foreach (ListViewItem listViewItem in m_listView.Items) { if (listViewItem.Tag is TimesheetDate) { TimesheetDate timeheetDateToCheck = (TimesheetDate)listViewItem.Tag; if (timeheetDateToCheck.Equals(timesheetDate)) { timesheetDetailListViewItem = listViewItem; return true; } } } // If we get here there is no ListViewItem associated with the timesheetDate in the ListView... timesheetDetailListViewItem = createIfNotExists ? CreateTimesheetDetailListViewItem(timesheetDate) : null; return false; } }
private bool GetTimesheetDetailListViewItem(TimesheetDate timesheetDate, out ListViewItem timesheetDetailListViewItem) { return GetTimesheetDetailListViewItem(timesheetDate, out timesheetDetailListViewItem, false); }