Exemplo n.º 1
0
 internal void Add(CalendarEvent ev)
 {
     calendarEvents.Add(ev);
     arrangeColumns();
 }
        private void RenderEvent(CalendarDay calendarDay, CalendarEvent calendarEvent, HtmlTextWriter output)
        {
            var max = CellCount * Configuration.CellWidth;

            var dayVisibleStart = new DateTime(calendarDay.StartDate.Year,
                                               calendarDay.StartDate.Month,
                                               calendarDay.StartDate.Day,
                                               GetVisibleStart.Hour,
                                               0,
                                               0);
            var realBoxStart = calendarEvent.Start < dayVisibleStart ? dayVisibleStart : calendarEvent.Start;

            DateTime dayVisibleEnd;

            switch (GetVisibleEnd.Day)
            {
            case 1:
                dayVisibleEnd = new DateTime(calendarDay.StartDate.Year,
                                             calendarDay.StartDate.Month,
                                             calendarDay.StartDate.Day,
                                             GetVisibleEnd.Hour + 1,
                                             0,
                                             0);
                break;

            default:
                dayVisibleEnd =
                    new DateTime(calendarDay.StartDate.Year, calendarDay.StartDate.Month, calendarDay.StartDate.Day, GetVisibleEnd.Hour, 0, 0)
                    .AddDays(1);
                break;
            }

            var realBoxEnd = calendarEvent.End > dayVisibleEnd ? dayVisibleEnd : calendarEvent.End;

            var left   = (int)Math.Floor((realBoxStart - dayVisibleStart).TotalMinutes * Configuration.CellWidth / Configuration.CellDuration);
            var top    = calendarEvent.Column.Number * Configuration.EventHeight - 1;
            var width  = (int)Math.Floor((realBoxEnd - realBoxStart).TotalMinutes * Configuration.CellWidth / Configuration.CellDuration) - 3;
            var height = Configuration.EventHeight - 1;

            if (left > max)
            {
                return;
            }

            if (left + width > max - 2)
            {
                width = max - left - 2;
            }

            if (left < 0)
            {
                width += left;
                left   = 0;
            }

            width = Math.Max(width, 2);
            output.AddAttribute("unselectable", "on");
            output.AddStyleAttribute("position", "absolute");
            output.AddStyleAttribute("left", left + "px");
            output.AddStyleAttribute("top", top + "px");
            output.AddStyleAttribute("width", width + "px");
            output.AddStyleAttribute("height", height + "px");
            output.AddStyleAttribute("border", "1px solid " + Configuration.EventBorderColor);

            var eventBackColor = Configuration.EventBackColor;

            if (!string.IsNullOrEmpty(calendarEvent.LegacyFreeBusyStatus))
            {
                switch (calendarEvent.LegacyFreeBusyStatus)
                {
                case "OOF":
                    eventBackColor = Configuration.EventBackColor_OOF;
                    break;

                case "Tentative":
                    eventBackColor = Configuration.EventBackColor_Tentative;
                    break;

                case "Free":
                    eventBackColor = Configuration.EventBackColor_Free;
                    break;

                default:
                    eventBackColor = Configuration.EventBackColor;
                    break;
                }
            }

            output.AddStyleAttribute("background-color", eventBackColor);
            output.AddStyleAttribute("white-space", "nowrap");
            output.AddStyleAttribute("overflow", "hidden");
            output.AddStyleAttribute("display", "block");
            output.AddStyleAttribute("padding-left", "1px");
            output.RenderBeginTag("div");

            output.AddStyleAttribute("font-family", Configuration.EventFontFamily);
            output.AddStyleAttribute("font-size", Configuration.EventFontSize);
            output.RenderBeginTag("div");

            output.Write(calendarEvent.Name.Length < Configuration.MaxEventTextLenght
                ? calendarEvent.Name
                : calendarEvent.Name.Substring(0, 22) + "...");
            output.Write(calendarEvent.Name);
            if (!string.IsNullOrEmpty(calendarEvent.Location))
            {
                output.Write("<br/><strong>{0}</strong>", calendarEvent.Location);
            }

            output.RenderEndTag();
            output.RenderEndTag();
        }