public Bitmap GetImageForRooster(Rooster rooster, UserPreferences preferences) { var daysAndHours = GetAmountOfDaysAndHours(rooster, preferences); daysAndHours.FirstDateTime = daysAndHours.FirstDateTime.AddHours(-daysAndHours.FirstDateTime.Hour).AddMinutes(-daysAndHours.FirstDateTime.Minute); if (daysAndHours == null) //geen resultaten return null; var days = daysAndHours.CountDays; var hours = daysAndHours.CountHours; var bitmap = new Bitmap(days * DAYWIDTH + HEADERSIZE, hours * HOURHEIGHT + HEADERSIZE); using(var g = Graphics.FromImage(bitmap)) { g.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height); var orangePen = Pens.DarkOrange; //var unEvenBackground = Brushes.LightGray; for (var i = 0; i < hours; i++) { if(i % 2 == 0) g.FillRectangle(Brushes.LightGray, 0, HEADERSIZE + i * HOURHEIGHT, bitmap.Width, HOURHEIGHT); int offset = HEADERSIZE + i * HOURHEIGHT; g.DrawLine(orangePen, 0, offset, bitmap.Width, offset); g.DrawString($"{daysAndHours.FirstHour + i}:00{Environment.NewLine}-{Environment.NewLine}{daysAndHours.FirstHour + i + 1}:00", FONT, Brushes.Black, new RectangleF(0, HEADERSIZE + i * HOURHEIGHT, HEADERSIZE, HOURHEIGHT), FORMAT); } for (var i = 0; i < days; i++) { int offset = HEADERSIZE + i * DAYWIDTH; g.DrawLine(orangePen, offset, 0, offset, bitmap.Height); g.DrawString(daysAndHours.FirstDateTime.AddDays(i).ToString("ddd d MMM"), FONT, Brushes.Black, new RectangleF(HEADERSIZE + i * DAYWIDTH, 0, DAYWIDTH, HEADERSIZE), FORMAT); } StringBuilder sb = new StringBuilder(); foreach(var les in rooster.Lessen) { if (!preferences.IsLesIgnored(les)) { var roosterRectangle = new Rectangle( x: (HEADERSIZE + (les.StartTime - daysAndHours.FirstDateTime).Days * DAYWIDTH) + ROOSTERPADDING / 2, y: HEADERSIZE + (les.StartTime.Hour - daysAndHours.FirstHour) * HOURHEIGHT + (les.StartTime.Minute * HOURHEIGHT / 60) + ROOSTERPADDING / 2, width: DAYWIDTH - ROOSTERPADDING, height: (les.EndTime - les.StartTime).Hours * HOURHEIGHT - ROOSTERPADDING ); g.FillRectangle(Brushes.Orange, roosterRectangle); g.DrawRectangle(orangePen, roosterRectangle); sb.Clear(); GetLesContents(les, sb); g.DrawString(sb.ToString(), FONT, Brushes.Black, new RectangleF(roosterRectangle.X, roosterRectangle.Y, roosterRectangle.Width, roosterRectangle.Height), FORMAT); } } } return bitmap; }
public string FormatRooster(Rooster rooster, UserPreferences preferences) { StringBuilder sb = new StringBuilder(); DateTime prevDate = new DateTime(); bool first = true; foreach (Rooster.Les l in rooster.Lessen) { if (preferences.IsLesIgnored(l)) continue; if (l.StartTime.DayOfYear != prevDate.DayOfYear) { if (!first) sb.AppendLine(); else first = false; sb.AppendLine(l.StartTime.ToString("dddd d MMMM")); prevDate = l.StartTime; } FormatLes(l, sb, preferences); sb.AppendLine(); } return sb.ToString(); }
protected DaysAndHoursForRooster GetAmountOfDaysAndHours(Rooster rooster, UserPreferences preferences) { DaysAndHoursForRooster result = null; foreach(var les in rooster.Lessen) { if (!preferences.IsLesIgnored(les)) { if (result == null) result = new DaysAndHoursForRooster(); var day = GetDayOfYearWithYear(les.StartTime); if (day < result.FirstDay) { result.FirstDay = day; result.FirstDateTime = les.StartTime; } if (day > result.LastDay) result.LastDay = day; if (les.StartTime.Hour < result.FirstHour) result.FirstHour = les.StartTime.Hour; if (les.EndTime.Hour > result.LastHour) result.LastHour = les.EndTime.Hour; } } return result; }
private ReplyKeyboardMarkup KeyboardForResults(UserPreferences preferences) { List<string> lesStrings = new List<string>(); foreach(var lesName in lessen) lesStrings.Add($"{(preferences.IsLesIgnored(lesName) ? ignored : shown)} {lesName}"); return ReplyKeyboardMarkup.GetKeyboardForValues(lesStrings, null, stop); }
private int CountWithoutIgnoredLessen(List<Rooster.Les> lessen, UserPreferences preferences) { if (lessen.Count == 0) return 0; int count = 0; for(var i = 0; i < lessen.Count; i++) if (!preferences.IsLesIgnored(lessen[i])) count++; return count; }