コード例 #1
0
 public Rooster(Rooster FullWeek, DateTime? restrictToDate = null)
 {
     RoosterFor = FullWeek.RoosterFor;
     foreach (var les in FullWeek.Lessen)
         if (restrictToDate == null || !restrictToDate.HasValue || les.StartTime.DayOfYear == restrictToDate.Value.DayOfYear)
             Lessen.Add(les);
 }
コード例 #2
0
 protected override void FormatLes(Rooster.Les l, StringBuilder sb, UserPreferences preferences)
 {
     if (sb == null) throw new ArgumentException("You must provide a StringBuilder object!", nameof(sb));
     if (l.HasLokalen && l.HasKlassen)
         sb.Append($"{l.StartTime.ToString(TIMEFORMAT)} - {l.EndTime.ToString(TIMEFORMAT)} {l.Omschrijving} ({l.GetLokalen()} - {l.GetKlassen()})");
     else if (l.HasLokalen || l.HasKlassen)
     {
         var klasOrLokaalDisplay = (!l.HasKlassen ? l.GetLokalen() : l.GetKlassen());
         sb.Append($"{l.StartTime.ToString(TIMEFORMAT)} - {l.EndTime.ToString(TIMEFORMAT)} {l.Omschrijving} ({klasOrLokaalDisplay})");
     }
     else
         sb.Append($"{l.StartTime.ToString(TIMEFORMAT)} - {l.EndTime.ToString(TIMEFORMAT)} {l.Omschrijving}");
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 protected virtual void FormatLes(Rooster.Les l, StringBuilder sb, UserPreferences preferences)
 {
     if (sb == null) throw new ArgumentException("You must provide a StringBuilder object!", nameof(sb));
     if(l.HasLokalen && l.HasDocenten)
     {
         string docentDisplay = preferences.ShowFullDocentNamen ? l.GetDocentenByNaam() : l.GetDocentenByCode();
         sb.Append($"{l.StartTime.ToString(TIMEFORMAT)} - {l.EndTime.ToString(TIMEFORMAT)} {l.Omschrijving} ({l.GetLokalen()} - {docentDisplay})");
     }
     else if (l.HasLokalen || l.HasDocenten)
     {
         string lokaalOrDocentDisplay = (!l.HasDocenten ? (l.GetLokalen()) : preferences.ShowFullDocentNamen ? l.GetDocentenByNaam() : l.GetDocentenByCode());
         sb.Append($"{l.StartTime.ToString(TIMEFORMAT)} - {l.EndTime.ToString(TIMEFORMAT)} {l.Omschrijving} ({lokaalOrDocentDisplay})");
     }
     else
         sb.Append($"{l.StartTime.ToString(TIMEFORMAT)} - {l.EndTime.ToString(TIMEFORMAT)} {l.Omschrijving}");
 }
コード例 #5
0
 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();
 }
コード例 #6
0
 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;
 }
コード例 #7
0
 protected abstract void GetLesContents(Rooster.Les les, StringBuilder sb);
コード例 #8
0
 protected override void GetLesContents(Rooster.Les les, StringBuilder sb)
 {
     sb.AppendLine(les.Omschrijving);
     if (les.HasKlassen)
         sb.AppendLine(les.GetKlassen());
     if (les.HasLokalen)
         sb.AppendLine(les.GetLokalen());
 }
コード例 #9
0
 public static Rooster operator +(Rooster a, Rooster b)
 {
     var rooster = new Rooster()
     {
         Lessen = new List<Les>(),
         RoosterFor = a.RoosterFor
     };
     int lesCountA = a.Lessen.Count, lesCountB = b.Lessen.Count;
     int x = 0, y = 0; //x Iterator voor a, y iterator voor b
     while(x != lesCountA || y != lesCountB)
     {
         if (x == lesCountA) //Als X alle lessen verwerkt heeft, en Y nog niet
             rooster.Lessen.Add(b.Lessen[y++]);
         else if (y == lesCountB) //Als Y alle lessen verwerkt heeft en X nog niet
             rooster.Lessen.Add(a.Lessen[x++]);
         else if (a.Lessen[x].StartTime > b.Lessen[y].StartTime) //Beide hebben nog niet verwerkte lessen
             rooster.Lessen.Add(b.Lessen[y++]);
         else
             rooster.Lessen.Add(a.Lessen[x++]);
     }
     return rooster;
 }
コード例 #10
0
 public string FormatLes(Rooster.Les l, UserPreferences preferences)
 {
     StringBuilder sb = new StringBuilder();
     FormatLes(l, sb, preferences);
     return sb.ToString();
 }