private async void ViewEventsActivated(object sender, EventArgs e) { if (isRecurring) { List <RecurringEvent> EventList = await Task.Run(() => recurringEventRepository.GetRecurringEvents(Instances.User.ID)); lv_events.Items.Clear(); foreach (RecurringEvent events in EventList) { string EndDateText = (events.EndDate == DateTime.MinValue) ? "Never ends" : events.EndDate.ToString(); ListViewItem eventListViewItem = new ListViewItem(new string[] { events.Name, events.ContactName, events.TypeName, events.Location, events.Note, events.CreatedDate.ToString(), events.Status, EndDateText }); eventListViewItem.Tag = events; lv_events.Items.Add(eventListViewItem); } } else { List <Event> eventsList = await Task.Run(() => eventRepository.GetUserEvents(Instances.User.ID)); lv_events.Items.Clear(); foreach (Event events in eventsList) { ListViewItem eventListViewItem = new ListViewItem(new string[] { events.Name, events.TypeName, events.Location, events.ContactName, events.CreatedDate.ToString(), events.Note }); eventListViewItem.Tag = events; lv_events.Items.Add(eventListViewItem); } } }
private void ShowEventsForDate(DateTime d) { pl_events.Controls.OfType <Panel>().ToList().ForEach(p => p.Dispose()); pl_events.VerticalScroll.Maximum = 0; pl_events.AutoScroll = false; pl_events.HorizontalScroll.Maximum = 0; pl_events.HorizontalScroll.Visible = false; pl_events.AutoScroll = true; RecurringEventRepository recurringEventRepository = RecurringEventRepository.Instance; List <RecurringEvent> events = recurringEventRepository.GetRecurringEvents(Instances.User.ID); List <RecurringEvent> newList = new List <RecurringEvent>(); events.ForEach(e => { switch (e.Status) { case "Daily": newList.Add(e); break; case "Weekly": if (e.CreatedDate.DayOfWeek == d.DayOfWeek) { newList.Add(e); } break; case "Monthly": if (e.CreatedDate.Day == d.Day) { newList.Add(e); } break; case "Yearly": if (e.CreatedDate.Month == d.Month && e.CreatedDate.Day == d.Day) { newList.Add(e); } break; } }); newList = newList.OrderBy(e => e.CreatedDate.TimeOfDay).ToList(); if (newList.Count == 0) { newList.Add(new RecurringEvent()); } int now = 0; newList.ForEach(e => { Panel p = new Panel(); p.Width = pl_events.Width; p.Height = 40; p.Location = new Point(0, now); now += p.Height; Label name = new Label(); name.TextAlign = ContentAlignment.MiddleLeft; string nameText = ""; if (e.ID > 0) { nameText = e.Name; if (e.Type) { nameText += " at "; } else { nameText += " by "; } nameText += e.CreatedDate.ToString("HH:mm"); } else { nameText = d.Date == DateTime.Now.Date ? "No events for today!" : "No events for this day!"; name.TextAlign = ContentAlignment.MiddleCenter; } name.Text = nameText; name.ForeColor = Color.FromArgb(109, 116, 129); name.Font = new Font("Roboto", 10F, FontStyle.Regular, GraphicsUnit.Point, 204); name.Location = new Point(0, 0); name.Size = new Size(p.Width, p.Height); name.Padding = new Padding(15, 0, 0, 0); p.Controls.Add(name); Panel b = new Panel(); b.Width = p.Width; b.Height = 1; b.Location = new Point(0, 0); b.BackColor = Color.FromArgb(228, 232, 241); p.Controls.Add(b); b.BringToFront(); pl_events.Controls.Add(p); }); Panel line = new Panel(); line.Width = pl_events.Width; line.Height = 1; line.Location = new Point(0, now); line.BackColor = Color.FromArgb(228, 232, 241); pl_events.Controls.Add(line); line.BringToFront(); }
private async void DoRecurringEvent() { EventRepository transactionRepository = EventRepository.Instance; RecurringEventRepository recurringEventRepository = RecurringEventRepository.Instance; if (Instances.User == null) { return; } List <RecurringEvent> recurringEvents = recurringEventRepository.GetRecurringEvents(Instances.User.ID); foreach (RecurringEvent recurringEvent in recurringEvents) { if (Instances.User == null) { return; } if (DateTime.Now > recurringEvent.EndDate && recurringEvent.EndDate != DateTime.MinValue) { continue; } DateTime accTime = Instances.User.LastAccessDate; DateTime nowTime = DateTime.Now; int days = (nowTime - accTime).Days; DateTime recTime = Instances.User.LastAccessDate; TimeSpan ts = new TimeSpan( recurringEvent.CreatedDate.Hour, recurringEvent.CreatedDate.Minute, recurringEvent.CreatedDate.Second ); recTime = recTime.Date + ts; for (int i = 0; i <= days; i++) { if (recurringEvent.Status.Equals("Weekly")) { if (recTime.DayOfWeek != recurringEvent.CreatedDate.DayOfWeek) { recTime = recTime.AddDays(1); continue; } } if (recurringEvent.Status.Equals("Monthly")) { if (recTime.Day != recurringEvent.CreatedDate.Day) { recTime = recTime.AddDays(1); continue; } } if (recurringEvent.Status.Equals("Yearly")) { string recTimeString = recTime.ToString("dd/MM"); string createdDateString = recurringEvent.CreatedDate.ToString("dd/MM"); if (!recTimeString.Equals(createdDateString)) { recTime = recTime.AddDays(1); continue; } } if (recTime > accTime && recTime <= nowTime && recTime > recurringEvent.CreatedDate) { if (Instances.User == null) { return; } await Task.Run(() => transactionRepository.AddEvent(new Event { Name = recurringEvent.Name, UserID = recurringEvent.UserID, ContactID = recurringEvent.ContactID, Type = recurringEvent.Type, Location = recurringEvent.Location, Note = recurringEvent.Note, CreatedDate = recTime })); bw_recurring.ReportProgress(1, "New event has been added!"); } recTime = recTime.AddDays(1); } } }