public void AppointmentOrdering() { PageDocument report = TestHelper.GetReport("Calendar-AppointmentWrapping.rdlx"); TestingRenderingExtension renderer = new TestingRenderingExtension(); report.Render(renderer, null); // StartTime(string),EndTime(string),Value(string) //2007-12-07,2007-12-09,"Appt#1 Text ..." //2007-12-08,2007-12-09,"Appt#2 Text ..." //2007-12-09,2007-12-09,"Appt#3 Text ..." //2007-12-09,2007-12-11,"Appt#4 Text ..." ICalendar calendar = (ICalendar)renderer.GetReportItem("Calendar1"); Assert.IsNotNull(calendar); Assert.AreEqual(4, calendar.Appointments.Count); CalendarData calendarData = new CalendarData(calendar); Assert.IsNotNull(calendarData); MonthInfo month = calendarData.GetFirstMonth(); Assert.IsNotNull(month); Assert.AreEqual(12, month.Month); Assert.AreEqual(2007, month.Year); ICollection <Appointment> week1Appointments = calendarData.GetAppointmentsInWeek(month, 1); Assert.AreEqual(2, week1Appointments.Count); ICollection <Appointment> week2Appointments = calendarData.GetAppointmentsInWeek(month, 2); Assert.AreEqual(4, week2Appointments.Count); // first week : make sure of the ordering of appointments. int index = 1; foreach (Appointment appointment in week1Appointments) { Assert.AreEqual(string.Format("Appt#{0} Text ...", index), appointment.Value); index++; } // second week : make sure of the ordering of appointments is the same as prior week. index = 1; foreach (Appointment appointment in week1Appointments) { Assert.AreEqual(string.Format("Appt#{0} Text ...", index), appointment.Value); index++; } }
/// <summary> /// Draws the appointments of a specified week. /// </summary> private void RenderAppointments(MonthInfo month, IEnumerable <DayInfo> days, SizeF dayCellSize) { const float ImagePadding = 0.02f; for (int week = 0; week < CalendarData.WeeksInMonth; week++) { DateTime weekStartDate = month.GetDateOfDay(week, CalendarData.FirstDayOfWeek, CalendarData.FirstDayOfWeek); DateTime weekEndDate = month.GetDateOfDay(week, CalendarData.LastDayOfWeek, CalendarData.FirstDayOfWeek, true); CalendarData.AppointmentLayoutHelper layoutHelper = new CalendarData.AppointmentLayoutHelper(CalendarData.FirstDayOfWeek, CalendarData.AppointmentGap); foreach (Appointment appointment in CalendarData.GetAppointmentsInWeek(month, week)) { int apptWeekDaysCount = appointment.GetDurationInPeriod(weekStartDate, weekEndDate); Debug.Assert(apptWeekDaysCount > 0, "The appointment should belong to the rendering week."); DateTime appStartDate = appointment.ArrangeStartDate(weekStartDate); DayInfo appStartDayInfo = DayInfo.FindDayInfo(days, appStartDate); Debug.Assert(appStartDayInfo != null, "Day have to be found in the collection."); SizeF appSize = CalendarData.MeasureAppointment(appointment, weekStartDate, weekEndDate, dayCellSize); float appOffset = layoutHelper.Add(appStartDate, appStartDate.AddDays(apptWeekDaysCount - 1), appSize.Height); RectangleF appointmentRect; if (!_rightToLeft) { appointmentRect = new RectangleF( appStartDayInfo.Bounds.X, appStartDayInfo.Bounds.Y + appStartDayInfo.HeaderSize.Height + appOffset, apptWeekDaysCount * dayCellSize.Width, appSize.Height); } else { appointmentRect = new RectangleF( appStartDayInfo.Bounds.X - ((apptWeekDaysCount - 1) * dayCellSize.Width), appStartDayInfo.Bounds.Y + appStartDayInfo.HeaderSize.Height + appOffset, apptWeekDaysCount * dayCellSize.Width, appSize.Height); } AddActionToInteractivityMap(appointment, appointmentRect); using (BrushEx backcolorBrush = Canvas.CreateSolidBrush(appointment.Backcolor)) { Canvas.FillRectangle(backcolorBrush, appointmentRect); } // draw image! Image img = CalendarData.GetAppointmentImage(appointment); RectangleF appTextRect = new RectangleF(appointmentRect.X, appointmentRect.Y, appointmentRect.Width, appointmentRect.Height); bool drawImage = appointment.StartDate >= weekStartDate && appointment.StartDate <= weekEndDate; if (img != null && drawImage) { var imageStream = new MemoryStream(); img.Save(imageStream, ImageFormat.Png); imageStream.Position = 0; using (ImageEx image = Canvas.CreateImage(new ImageInfo(imageStream, "image/png"))) { float imgHeight = Math.Min(CalendarData.GetAppointmentImageSize(appointment), appointmentRect.Width); float imgWidth = imgHeight; float imgLeft; if (!_rightToLeft) { imgLeft = appointmentRect.X; } else { imgLeft = appointmentRect.Right - imgWidth; } float imgTop = appointmentRect.Y + ImagePadding; //Fix for case 44294 Canvas.PushState(); Canvas.IntersectClip(new RectangleF(imgLeft, imgTop, imgWidth, imgHeight)); SizeF imgSz = CalendarData.GetAppointmentImageRealSize(appointment); Canvas.DrawImage(image, imgLeft, imgTop, imgSz.Width, imgSz.Height); Canvas.PopState(); if (imgHeight == appointmentRect.Width) { appTextRect.Y += imgHeight; appTextRect.Height -= imgHeight; } else { if (!_rightToLeft) { appTextRect.X = appointmentRect.X + imgWidth; } appTextRect.Width = appointmentRect.Width - imgWidth; } } } // HACK: we should consider the issue with drawing string later. the issue comes about in the designer when caledar has small width to fit titles. --SergeyP using (StringFormat sf = Components.Calendar.CalendarData.GetAppointmentFormat(appointment, _rightToLeft)) { TextStyle fontStyle = new TextStyle(appointment.FontFamily, appointment.FontSize, appointment.FontStyle, appointment.FontWeight, appointment.FontDecoration, appointment.FontColor); Canvas.PushState(); var font = fontStyle.CreateFontInfo(); using (BrushEx forecolorBrush = Canvas.CreateSolidBrush(fontStyle.FontColor)) { string value = CalendarData.FormatString(appointment.Value, appointment.Format); Canvas.DrawString(value, font, forecolorBrush, appTextRect, ToEx(sf)); } Canvas.PopState(); } LineStyle borderStyle = new LineStyle(appointment.BorderColor); using (PenEx pen = LineStyle.CreatePen(Canvas, borderStyle)) { pen.Width = 1; // HACK: temporary hack because the width is turned off for appointments DrawRectangle(Canvas, pen, appointmentRect.X, appointmentRect.Y, appointmentRect.Width, appointmentRect.Height); } RenderAction(appointment, Canvas, appointmentRect); } } }