private void renderEvent(HtmlTextWriter output, Event e, Day d)
        {
            string displayTime = e.booking.Startdatetime.ToShortTimeString() + " - " + e.booking.Enddatetime.ToShortTimeString();
            string displayTitle = " " + e.booking.Title;
            string displayPersonnumber = " " + e.booking.Personnumber;
            string displayType = " (" + e.booking.Bookingtype + ")";
            string displayNote = " " + e.booking.Note ;

            string displayMobilephone = " ";
            if (!String.IsNullOrEmpty(e.booking.Mobilephone))
                displayMobilephone += "tel: " + e.booking.Mobilephone;
            else if (!String.IsNullOrEmpty(e.booking.Homephone))
                displayMobilephone += "tel: " + e.booking.Homephone;
            else if (!String.IsNullOrEmpty(e.booking.Workphone))
                displayMobilephone += "tel: " + e.booking.Workphone;
            else
                displayMobilephone += "tel: -";

            string displayFreecarddate = " F: " + e.booking.Freecarddate;

            Color eventLeftBarColor = EventLeftBarColor;
            Color eventBackColor = EventBackColor;
            Color eventFreecardExpiredColor = Color.Black;
            Color eventCancellednoteColor = Color.Red;

            try
            {
                DateTime freecarddate = DateTime.Parse(e.booking.Freecarddate);
                if ((freecarddate == DateTime.MinValue) || (freecarddate == DateTime.MaxValue))
                    throw new Exception("Frikortsdatumet existerar inte eller är inte giltigt");
                if ((freecarddate < e.booking.Startdatetime) && (!e.booking.Cancelled))
                {
                    eventLeftBarColor = EventFreecardExpiredBackColor;
                    eventFreecardExpiredColor = EventFreecardExpiredBackColor;
                }
            }
            catch (Exception exception)
            {
            }

            if (e.booking.Arrived)
                eventLeftBarColor = EventArrivedBackColor;
            if (e.booking.Notshown)
                eventLeftBarColor = EventNotShownBackColor;
            if (e.booking.Cancelled)
            {
                eventBackColor = Color.LightGray;
                eventLeftBarColor = Color.Black;
                displayNote = " Återbud:" + e.booking.Cancellednote;
            }

            // real box dimensions and position
            DateTime dayVisibleStart = new DateTime(d.date.Year, d.date.Month, d.date.Day, visibleStart.Hour, 0, 0);
            DateTime realBoxStart = e.BoxStart < dayVisibleStart ? dayVisibleStart : e.BoxStart;

            DateTime dayVisibleEnd;
            if (visibleEnd.Day == 1)
                dayVisibleEnd = new DateTime(d.date.Year, d.date.Month, d.date.Day, visibleEnd.Hour, 0, 0);
            else if (visibleEnd.Day == 2)
                dayVisibleEnd = new DateTime(d.date.Year, d.date.Month, d.date.Day, visibleEnd.Hour, 0, 0).AddDays(1);
            else
                throw new ArgumentOutOfRangeException("Unexpected time for dayVisibleEnd.");

            DateTime realBoxEnd = e.BoxEnd > dayVisibleEnd ? dayVisibleEnd : e.BoxEnd;

            // top
            double top = (realBoxStart - dayVisibleStart).TotalHours * HourHeight + 1;
            if (ShowHeader)
                top += this.HeaderHeight;

            // height
            double height = ((realBoxEnd - realBoxStart).TotalHours * HourHeight - 2);

            // It's outside of visible area (for NonBusinessHours set to Hide).
            // Don't draw it in that case.
            if (height <= 0)
            {
                return;
            }

            // MAIN BOX
            output.AddAttribute("onselectstart", "return false;"); // prevent text selection in IE

            if (EventClickHandling == UserActionHandling.PostBack)
            {
                output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + Page.ClientScript.GetPostBackEventReference(this, "PK:" + e.PK));
            }
            else
            {
                output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + String.Format(JavaScriptEventAction, e.PK));
            }

            //To get some more space to the right
            int newColumnWidth = e.Column.WidthPct - 1;

            output.AddStyleAttribute("-moz-user-select", "none"); // prevent text selection in FF
            output.AddStyleAttribute("-khtml-user-select", "none"); // prevent text selection
            output.AddStyleAttribute("user-select", "none"); // prevent text selection
            output.AddStyleAttribute("cursor", "pointer");
            //output.AddStyleAttribute("cursor", "hand");
            output.AddStyleAttribute("position", "absolute");
            output.AddStyleAttribute("font-family", EventFontFamily);
            output.AddStyleAttribute("font-size", EventFontSize);
            output.AddStyleAttribute("white-space", "no-wrap");
            output.AddStyleAttribute("left", e.Column.StartsAtPct + "%");
            output.AddStyleAttribute("top", top + "px");
            output.AddStyleAttribute("width", newColumnWidth + "%");
            output.AddStyleAttribute("height", (realBoxEnd - realBoxStart).TotalHours * HourHeight + "px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBorderColor));

            output.RenderBeginTag("div");
            //output.Write(divMain.BeginTag());

            // FIX BOX - to fix the outer/inner box differences in Mozilla/IE (to create border)
            //            DivWriter divFix = new DivWriter();
            output.AddAttribute("onmouseover", "this.style.backgroundColor='" + ColorTranslator.ToHtml(EventHoverColor) + "';event.cancelBubble=true;");
            output.AddAttribute("onmouseout", "this.style.backgroundColor='" + ColorTranslator.ToHtml(eventBackColor) + "';event.cancelBubble=true;");

            if (ShowToolTip)
            {
                output.AddAttribute("title", displayTime + displayTitle + displayType +displayNote + "( " + displayMobilephone + displayFreecarddate + " )");
            }

            output.AddStyleAttribute("margin-top", "1px");
            output.AddStyleAttribute("display", "block");
            output.AddStyleAttribute("height", height + "px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(eventBackColor));
            output.AddStyleAttribute("border-left", "1px solid " + ColorTranslator.ToHtml(EventBorderColor));
            output.AddStyleAttribute("border-right", "1px solid " + ColorTranslator.ToHtml(EventBorderColor));
            output.AddStyleAttribute("overflow", "hidden");
            output.RenderBeginTag("div");
            //            output.Write(divFix.BeginTag());

            // blue column
            if (e.Start > realBoxStart)
            {

            }

            int startDelta = (int) Math.Floor((e.Start - realBoxStart).TotalHours * HourHeight);
            int endDelta = (int) Math.Floor((realBoxEnd - e.End).TotalHours * HourHeight);

            //            DivWriter divBlue = new DivWriter();
            output.AddStyleAttribute("float", "left");
            output.AddStyleAttribute("width", "7px");
            output.AddStyleAttribute("height", height - startDelta - endDelta + "px");
            output.AddStyleAttribute("margin-top", startDelta + "px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(eventLeftBarColor));
            output.AddStyleAttribute("font-size", "1px");
            output.RenderBeginTag("div");
            output.RenderEndTag();
            //            output.Write(divBlue.BeginTag());
            //            output.Write(divBlue.EndTag());

            // right border of blue column
            //            DivWriter divBorder = new DivWriter();
            output.AddStyleAttribute("float", "left");
            output.AddStyleAttribute("width", "1px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBorderColor));
            output.AddStyleAttribute("height", "100%");
            output.RenderBeginTag("div");
            output.RenderEndTag();
            //            output.Write(divBorder.BeginTag());
            //            output.Write(divBorder.EndTag());

            // space
            //            DivWriter divSpace = new DivWriter();
            output.AddStyleAttribute("float", "left");
            output.AddStyleAttribute("width", "2px");
            output.AddStyleAttribute("height", "100%");
            output.RenderBeginTag("div");
            output.RenderEndTag();
            //            output.Write(divSpace.BeginTag());
            //            output.Write(divSpace.EndTag());

            // PADDING BOX
            //            DivWriter divPadding = new DivWriter();
            output.AddStyleAttribute("padding", "1px");
            output.RenderBeginTag("div");
            //            output.Write(divPadding.BeginTag());

            if (Days < 5)
            {
                //output.Write("<div id='sensitivePartOne'>");
                output.Write("<span id='sensitiveTitle' style='font-weight:bold; '>" + displayTitle + "</span>");
                output.Write("<span id='sensitivePersonnumber'>" + displayPersonnumber + "</span>");
                //output.Write("</div>");

                output.Write(displayType);

                //output.Write("<div id='sensitivePartTwo'>");
                if (e.booking.Cancelled)
                    output.Write("<span id='sensitiveNote' style='color:" + ColorTranslator.ToHtml(eventCancellednoteColor) + ";font-weight:bold; '>" + displayNote + "</span>");
                else
                    output.Write("<span id='sensitiveNote' style='font-weight:bold; '>" + displayNote + "</span>");

                output.Write("<span id='sensitiveMobilephone' style='font-size:12px;font-family:" + EventFontFamily + "; '>" + " (" + displayMobilephone + "</span>");

                output.Write("<span id='sensitiveFreecarddate' style='color:" + ColorTranslator.ToHtml(eventFreecardExpiredColor) + ";font-size:12px;font-family:" + EventFontFamily + "; '>" + displayFreecarddate + "</span>");

                output.Write("<span id='sensitiveEnd' style='font-size:12px;font-family:" + EventFontFamily + "; '>" + ")" + "</span>");
                //output.Write("</div>");
            }
            else
            {
                output.Write("<span id='sensitiveTitle' style='font-size:10px;font-family:" + EventFontFamily + "; '>" + displayTitle + "</span>");

                output.Write("<span style='font-size:10px;font-family:" + EventFontFamily + "; '>" + displayType + "</span>");
            }

            // closing the PADDING BOX
            output.RenderEndTag();
            //            output.Write(divPadding.EndTag());

            // closing the FIX BOX
            output.RenderEndTag();
            //            output.Write(divFix.EndTag());

            // closing the MAIN BOX
            //            output.Write(divMain.EndTag());
            output.RenderEndTag();
        }
Example #2
0
        private void renderEvent(HtmlTextWriter output, Event e, Day d)
        {
            string displayTextPopup = e.Name + " (" + e.Start.ToShortTimeString() + " - " + e.End.ToShortTimeString() + ")" + ":" + e.Owner;
            string displayText      = e.Name + ": " + e.Owner;

            // real box dimensions and position
            DateTime dayVisibleStart = new DateTime(d.Start.Year, d.Start.Month, d.Start.Day, visibleStart.Hour, 0, 0);
            DateTime realBoxStart    = e.BoxStart < dayVisibleStart ? dayVisibleStart : e.BoxStart;

            DateTime dayVisibleEnd;

            if (visibleEnd.Day == 1)
            {
                dayVisibleEnd = new DateTime(d.Start.Year, d.Start.Month, d.Start.Day, visibleEnd.Hour, 0, 0);
            }
            else if (visibleEnd.Day == 2)
            {
                dayVisibleEnd = new DateTime(d.Start.Year, d.Start.Month, d.Start.Day, visibleEnd.Hour, 0, 0).AddDays(1);
            }
            else
            {
                throw new ArgumentOutOfRangeException("Unexpected time for dayVisibleEnd.");
            }

            DateTime realBoxEnd = e.BoxEnd > dayVisibleEnd ? dayVisibleEnd : e.BoxEnd;

            // top
            double top = (realBoxStart - dayVisibleStart).TotalHours * HourHeight + 1;

            if (ShowHeader)
            {
                top += this.HeaderHeight;
            }

            // height
            double height = ((realBoxEnd - realBoxStart).TotalHours * HourHeight - 2);

            // It's outside of visible area (for NonBusinessHours set to Hide).
            // Don't draw it in that case.
            if (height <= 0)
            {
                return;
            }

            // MAIN BOX
            output.AddAttribute("onselectstart", "return false;"); // prevent text selection in IE

            if (EventClickHandling == UserActionHandling.PostBack)
            {
                output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + Page.ClientScript.GetPostBackEventReference(this, "PK:" + e.PK));
            }
            else
            {
                output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + String.Format(EventClickJavaScript, e.PK));
            }

            output.AddStyleAttribute("-moz-user-select", "none");   // prevent text selection in FF
            output.AddStyleAttribute("-khtml-user-select", "none"); // prevent text selection
            output.AddStyleAttribute("user-select", "none");        // prevent text selection
            output.AddStyleAttribute("cursor", "pointer");
            //output.AddStyleAttribute("cursor", "hand");
            output.AddStyleAttribute("position", "absolute");
            output.AddStyleAttribute("font-family", EventFontFamily);
            output.AddStyleAttribute("font-size", EventFontSize);
            output.AddStyleAttribute("white-space", "no-wrap");
            output.AddStyleAttribute("left", e.Column.StartsAtPct + "%");
            output.AddStyleAttribute("top", top + "px");
            output.AddStyleAttribute("width", e.Column.WidthPct + "%");
            output.AddStyleAttribute("height", (realBoxEnd - realBoxStart).TotalHours * HourHeight + "px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBorderColor));
            output.RenderBeginTag("div");
            //output.Write(divMain.BeginTag());

            // FIX BOX - to fix the outer/inner box differences in Mozilla/IE (to create border)
//            DivWriter divFix = new DivWriter();
            output.AddAttribute("onmouseover", "this.style.backgroundColor='" + ColorTranslator.ToHtml(EventHoverColor) + "';event.cancelBubble=true;");
            output.AddAttribute("onmouseout", "this.style.backgroundColor='" + ColorTranslator.ToHtml(EventBackColor) + "';event.cancelBubble=true;");

            if (ShowToolTip)
            {
                output.AddAttribute("title", displayTextPopup);
            }

            output.AddStyleAttribute("margin-top", "1px");
            output.AddStyleAttribute("display", "block");
            output.AddStyleAttribute("height", height + "px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBackColor));
            output.AddStyleAttribute("border-left", "1px solid " + ColorTranslator.ToHtml(EventBorderColor));
            output.AddStyleAttribute("border-right", "1px solid " + ColorTranslator.ToHtml(EventBorderColor));
            output.AddStyleAttribute("overflow", "hidden");
            output.RenderBeginTag("div");
//            output.Write(divFix.BeginTag());

            // blue column
            if (e.Start > realBoxStart)
            {
            }

            int startDelta = (int)Math.Floor((e.Start - realBoxStart).TotalHours * HourHeight);
            int endDelta   = (int)Math.Floor((realBoxEnd - e.End).TotalHours * HourHeight);

//            DivWriter divBlue = new DivWriter();
            output.AddStyleAttribute("float", "left");
            output.AddStyleAttribute("width", "5px");
            output.AddStyleAttribute("height", height - startDelta - endDelta + "px");
            output.AddStyleAttribute("margin-top", startDelta + "px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(DurationBarColor));
            output.AddStyleAttribute("font-size", "1px");
            output.RenderBeginTag("div");
            output.RenderEndTag();
//            output.Write(divBlue.BeginTag());
//            output.Write(divBlue.EndTag());

            // right border of blue column
//            DivWriter divBorder = new DivWriter();
            output.AddStyleAttribute("float", "left");
            output.AddStyleAttribute("width", "1px");
            output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBorderColor));
            output.AddStyleAttribute("height", "100%");
            output.RenderBeginTag("div");
            output.RenderEndTag();
//            output.Write(divBorder.BeginTag());
//            output.Write(divBorder.EndTag());

            // space
//            DivWriter divSpace = new DivWriter();
            output.AddStyleAttribute("float", "left");
            output.AddStyleAttribute("width", "2px");
            output.AddStyleAttribute("height", "100%");
            output.RenderBeginTag("div");
            output.RenderEndTag();
//            output.Write(divSpace.BeginTag());
//            output.Write(divSpace.EndTag());

            // PADDING BOX
//            DivWriter divPadding = new DivWriter();
            output.AddStyleAttribute("padding", "1px");
            output.RenderBeginTag("div");
//            output.Write(divPadding.BeginTag());

            output.Write(displayText); // e.BoxStart - dayVisibleStart

            // closing the PADDING BOX
            output.RenderEndTag();
//            output.Write(divPadding.EndTag());

            // closing the FIX BOX
            output.RenderEndTag();
//            output.Write(divFix.EndTag());

            // closing the MAIN BOX
//            output.Write(divMain.EndTag());
            output.RenderEndTag();
        }
        private void loadEventsToDays()
        {
            if (EndDate < StartDate)
                throw new ArgumentException("EndDate must be equal to or greater than StartDate.");

            int dayCount = (int)(EndDate - StartDate).TotalDays + 1;
            days = new Day[dayCount];

            for (int i = 0; i < days.Length; i++)
            {
                days[i] = new Day(StartDate.AddDays(i));

                if (items != null)
                    days[i].Load(items);

            }
        }