private void SetEventDetails(SavedEvent @event) { DateAndTime currDate = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime()); DateAndTime eventStartDate = @event.ActivationDate; DateAndTime eventEndDate = @event.DeactivationDate; Exp_Start_Date.SetText(TimeAndDateUtility.ConvertDate_String(@event.ActivationDate.Date, true)); Exp_Start_Time.SetText(TimeAndDateUtility.ConvertTime_String(@event.ActivationDate.Time)); Exp_End_Date.SetText(TimeAndDateUtility.ConvertDate_String(@event.DeactivationDate.Date, true)); Exp_End_Time.SetText(TimeAndDateUtility.ConvertTime_String(@event.DeactivationDate.Time)); Created_Date.SetText( $"{TimeAndDateUtility.ConvertDate_String(@event.CreatedDate.Date, true)} {TimeAndDateUtility.ConvertTime_String(@event.CreatedDate.Time)}"); Completion_Date.SetText( @event.Completed && @event.CompletedDate != null && @event.CompletedDate.Date != null && @event.CompletedDate.Time != null ? $"{TimeAndDateUtility.ConvertDate_String(@event.CompletedDate.Date, true)} {TimeAndDateUtility.ConvertTime_String(@event.CompletedDate.Time)}" : DASH); Event_Status.SetText( @event.Completed ? "Complete" : TimeAndDateUtility.IsBeforeRange(eventStartDate, currDate) ? "Upcoming" : TimeAndDateUtility.IsWithinRange(eventStartDate, currDate, eventEndDate) ? "In Progress" : "Overdue"); Event_Status.SetBackColor( @event.Completed ? Color.DarkGreen : TimeAndDateUtility.IsBeforeRange(eventStartDate, currDate) ? Color.DarkGray : TimeAndDateUtility.IsWithinRange(eventStartDate, currDate, eventEndDate) ? Color.DarkBlue : Color.DarkRed); User_Title.SetText(@event.Title); User_Comment.SetText(!string.IsNullOrEmpty(@event.Comment) ? @event.Comment : NO_COMMENT); }
private void UpdateEventDetails() { try { string id = ((SavedEvent)Todays_Events.SelectedIndex())?.Id; if (!string.IsNullOrEmpty(id)) { SavedEvent @event = _events.GetEvent(id); if (@event != null) { DateAndTime currDate = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime()); SetEventDetails(@event); ToggleViewButtons(true, TimeAndDateUtility.IsBeforeRange(@event.ActivationDate, currDate)); } } } catch (Exception) { // Log } }
private void TodaysEventsListBox_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Font font; Brush brush = Brushes.Black; Brush selectedBrush = new SolidBrush(Color.White); int index = e.Index; int status = -1; string title = string.Empty; ListBox lb = (ListBox)sender; Graphics g = e.Graphics; if (index > -1) { SavedEvent @event = null; try { @event = (SavedEvent)lb.Items[index]; } catch (Exception) { /*Something happened*/ } if (@event != null) { DateAndTime currDate = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime()); DateAndTime eventStartDate = @event.ActivationDate; DateAndTime eventEndDate = @event.DeactivationDate; status = @event.Completed ? 4 : TimeAndDateUtility.IsBeforeRange(eventStartDate, currDate) ? 1 : TimeAndDateUtility.IsWithinRange(eventStartDate, currDate, eventEndDate) ? 2 : 3; title = @event.Title; } } switch (status) { case 1: font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold); brush = Brushes.DarkSlateGray; break; case 2: font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Italic); brush = Brushes.DarkSlateBlue; break; case 3: font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular); brush = Brushes.DarkRed; break; case 4: font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold | FontStyle.Italic); brush = Brushes.DarkGreen; break; default: font = e.Font; brush = Brushes.Black; break; } if (lb.SelectedIndex == index) { g.FillRectangle(Brushes.Blue, e.Bounds); g.DrawString(title, font, selectedBrush, e.Bounds, StringFormat.GenericDefault); } else { g.FillRectangle(Brushes.White, e.Bounds); g.DrawString(title, font, brush, e.Bounds, StringFormat.GenericDefault); } }