public void RegisterScheduler(string title, string details, DateTime datetime, Color color, bool repeatDaily) { var data = new SchedulerElementData(RetrieveId(), title, details, datetime, color, repeatDaily); _dataDict.Add(data.Id, data); CreateSchedulerElement(data); SaveDb(); }
private void CreateSchedulerElement(SchedulerElementData data) { var element = new SchedulerElement(); element.Id = data.Id; element.titleLabel.Text = data.Title; element.detailsLabel.Text = data.Details; element.dateLabel.Text = $"{ data.Time.ToString("MM/dd/yyyy @ hh:mm") } { (data.RepeatDaily ? "[Repeat daily]" : string.Empty) }"; element.SetColor(data.Color); var margin = 6; if (_controlDict.Count >= 4) { margin = _scrollMargin; } element.Size = new Size(mainContainer.Size.Width - margin, element.Size.Height); var lastElement = (Control)null; if (mainContainer.Controls.Count > 0) { lastElement = mainContainer.Controls[mainContainer.Controls.Count - 1]; } element.Parent = mainContainer; if (lastElement != null) { element.Location = new Point(0, lastElement.Location.Y + lastElement.Size.Height); } else { element.Location = new Point(); } _controlDict.Add(data.Id, element); var notif = new SchedulerNotification(data); if (notif.GetMinuteToWait() <= 0) { if (data.RepeatDaily) { data.Time = data.Time.AddDays(1); element.Repeat($"{ data.Time.ToString("MM/dd/yyyy @ hh:mm") } [Repeat daily]"); SaveDb(); } else { notif.Notified = true; element.SetCompleted(); } } _notifications.Add(notif); if (_controlDict.Count >= 4) { foreach (var ctrl in _controlDict.Values) { ctrl.Size = new Size(mainContainer.Size.Width - _scrollMargin, element.Size.Height); } } }
public SchedulerNotification(SchedulerElementData data) { SchedulerData = data; Notified = false; }