private void MainForm_Shown(object sender, EventArgs e) { if (setDBConnectionAndLoad()) { var count = Attendant.MaxAttendantsPerDay(_db); for (int x = 1; x <= count; x++) { var style = new ColumnStyle(SizeType.Absolute, 125); scheduleTable.ColumnStyles.Add(style); scheduleTable.ColumnCount++; } if (Properties.Settings.Default.MainFormHeight != 0) { Height = Properties.Settings.Default.MainFormHeight; Width = Properties.Settings.Default.MainFormWidth; Left = Properties.Settings.Default.MainFormX; Top = Properties.Settings.Default.MainFormY; } if (Properties.Settings.Default.StartDate == DateTime.MinValue) { selectToolStripMenuItem_Click(null, EventArgs.Empty); } else { loadByRange(); } } }
private bool loadByRange(DateTime startDate, DateTime endDate) { startDateLabel.Text = startDate.ToShortDateString(); endDateLabel.Text = endDate.ToShortDateString(); var days = _db.Services.Include("AttendantSchedules.Attendant").Where(s => s.Date >= startDate && s.Date <= endDate) .OrderBy(s => s.Date).ThenBy(s => s.AMPM).ToList(); if (!days.Any()) { return(false); } else { scheduleTable.SuspendLayout(); scheduleTable.Controls.Clear(); scheduleTable.RowCount = 1; int row = 0; var font = new Font(scheduleTable.Font, FontStyle.Bold); var additionalDays = _db.AdditionalServices.ToList(); foreach (var day in days) { var newRowStyle = new RowStyle(SizeType.Absolute, 20); scheduleTable.RowStyles.Add(newRowStyle); Color?fontColor = null; if (additionalDays.Any(s => s.Date.Date == day.Date.Date && s.AMPM == day.AMPM)) { fontColor = Color.Blue; } addLabel(day.Date.ToString("MMM d"), 0, row, font, fontColor); addLabel(day.AMPM, 1, row, font, fontColor); for (int x = 1; x <= Attendant.MaxAttendantsPerDay(_db); x++) { var schedule = day.AttendantSchedules.FirstOrDefault(s => s.Position == x); if (schedule != null) { addPerson(schedule, x + 1, row); } else { addLabel("", x + 1, row); } } row++; scheduleTable.RowCount++; } setCellColors(null, false); scheduleTable.ResumeLayout(); distributionDisplay.DisplayCounts(startDate, endDate); return(true); } }