private void RenderEvent(HtmlTextWriter output, Event e, Day d) { string displayText = e.Name + " (" + e.Start.ToShortTimeString() + " - " + e.End.ToShortTimeString() + ")"; BeforeEventRenderEventArgs ea = new BeforeEventRenderEventArgs(e); ea.InnerHTML = displayText; ea.ToolTip = displayText; ea.EventClickEnabled = EventClickHandling != EventClickHandlingEnum.Disabled; if (!CssOnly) { ea.DurationBarColor = ColorTranslator.ToHtml(DurationBarColor); ea.BackgroundColor = ColorTranslator.ToHtml(EventBackColor); } DoBeforeEventRender(ea); // 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 Exception("Unexpected time for dayVisibleEnd."); } DateTime realBoxEnd = e.BoxEnd > dayVisibleEnd ? dayVisibleEnd : e.BoxEnd; // top double top = (realBoxStart - dayVisibleStart).TotalHours * (CellHeight * 2) + 1; if (ShowHeader) { top += HeaderHeight; } // height double height = (realBoxEnd - realBoxStart).TotalHours * (CellHeight * 2) - 2; int startDelta = (int)Math.Floor((e.Start - realBoxStart).TotalHours * (CellHeight * 2)); int endDelta = (int)Math.Floor((realBoxEnd - e.End).TotalHours * (CellHeight * 2)); double barHeight = height - startDelta - endDelta; int barTop = startDelta; // It's outside of visible area (for NonBusinessHours set to Hide). // Don't draw it in that case. if (height <= 0) { return; } if (CssOnly) { output.AddStyleAttribute("-moz-user-select", "none"); // prevent text selection in FF output.AddStyleAttribute("-khtml-user-select", "none"); // prevent text selection output.AddStyleAttribute("-webkit-user-select", "none"); // prevent text selection output.AddStyleAttribute("user-select", "none"); // prevent text selection output.AddAttribute("unselectable", "on"); output.AddStyleAttribute("position", "absolute"); output.AddStyleAttribute("left", e.Column.StartsAtPct + "%"); output.AddStyleAttribute("top", top + "px"); output.AddStyleAttribute("width", e.Column.WidthPct + "%"); output.AddStyleAttribute("height", (realBoxEnd - realBoxStart).TotalHours * (CellHeight * 2) + "px"); output.AddAttribute("class", PrefixCssClass("_event")); if (ea.EventClickEnabled && EventClickHandling != EventClickHandlingEnum.Disabled) { if (EventClickHandling == EventClickHandlingEnum.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.AddAttribute("onmouseover", "this.className+=' " + PrefixCssClass("_event_hover") + "';event.cancelBubble=true;"); output.AddAttribute("onmouseout", "if (this.className) { this.className = this.className.replace(' " + PrefixCssClass("_event_hover") + "', ''); } ;event.cancelBubble=true;"); output.RenderBeginTag("div"); // inner output.AddAttribute("class", PrefixCssClass("_event_inner")); output.AddAttribute("unselectable", "on"); output.RenderBeginTag("div"); output.Write(ea.InnerHTML); output.RenderEndTag(); // bar output.AddAttribute("class", PrefixCssClass("_event_bar")); output.AddStyleAttribute("position", "absolute"); output.RenderBeginTag("div"); double barTopPct = (100.0*barTop/height); double barHeightPct = (100.0*barHeight/height); if (barTopPct + barHeightPct > 100) { barHeightPct = 100 - barTopPct; } // bar_inner output.AddAttribute("class", PrefixCssClass("_event_bar_inner")); output.AddStyleAttribute("top", barTopPct + "%"); output.AddStyleAttribute("height", barHeightPct + "%"); output.RenderBeginTag("div"); // bar_inner output.RenderEndTag(); // bar output.RenderEndTag(); output.RenderEndTag(); } else { // MAIN BOX output.AddAttribute("onselectstart", "return false;"); // prevent text selection in IE if (ea.EventClickEnabled && EventClickHandling != EventClickHandlingEnum.Disabled) { if (EventClickHandling == EventClickHandlingEnum.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("cursor", "pointer"); } 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("position", "absolute"); if (!CssOnly) { output.AddStyleAttribute("font-family", EventFontFamily); output.AddStyleAttribute("font-size", EventFontSize); output.AddStyleAttribute("white-space", "no-wrap"); output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBorderColor)); } output.AddStyleAttribute("left", e.Column.StartsAtPct + "%"); output.AddStyleAttribute("top", top + "px"); output.AddStyleAttribute("width", e.Column.WidthPct + "%"); output.AddStyleAttribute("height", (realBoxEnd - realBoxStart).TotalHours * (CellHeight * 2) + "px"); output.RenderBeginTag("div"); // FIX BOX - to fix the outer/inner box differences in Mozilla/IE (to create border) if (ea.EventClickEnabled && EventClickHandling != EventClickHandlingEnum.Disabled) { if (!CssOnly) { output.AddAttribute("onmouseover", "this.style.backgroundColor='" + ColorTranslator.ToHtml(EventHoverColor) + "';event.cancelBubble=true;"); output.AddAttribute("onmouseout", "this.style.backgroundColor='" + ea.BackgroundColor + "';event.cancelBubble=true;"); } } if (ShowToolTip) { output.AddAttribute("title", ea.ToolTip); } output.AddStyleAttribute("margin-top", "1px"); output.AddStyleAttribute("display", "block"); output.AddStyleAttribute("height", height + "px"); if (!CssOnly) { output.AddStyleAttribute("background-color", ea.BackgroundColor); 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"); // blue column if (e.Start > realBoxStart) { } output.AddStyleAttribute("float", "left"); output.AddStyleAttribute("width", "5px"); output.AddStyleAttribute("height", height - startDelta - endDelta + "px"); output.AddStyleAttribute("margin-top", startDelta + "px"); if (!CssOnly) { output.AddStyleAttribute("background-color", ea.DurationBarColor); output.AddStyleAttribute("font-size", "1px"); } output.RenderBeginTag("div"); output.RenderEndTag(); // right border of blue column output.AddStyleAttribute("float", "left"); output.AddStyleAttribute("width", "1px"); if (!CssOnly) { output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(EventBorderColor)); } output.AddStyleAttribute("height", "100%"); output.RenderBeginTag("div"); output.RenderEndTag(); // space output.AddStyleAttribute("float", "left"); output.AddStyleAttribute("width", "2px"); output.AddStyleAttribute("height", "100%"); output.RenderBeginTag("div"); output.RenderEndTag(); // PADDING BOX output.AddStyleAttribute("padding", "1px"); output.RenderBeginTag("div"); output.Write(ea.InnerHTML); // closing the PADDING BOX output.RenderEndTag(); // closing the FIX BOX output.RenderEndTag(); // closing the MAIN BOX output.RenderEndTag(); } }
private void RenderRowHeader(HtmlTextWriter output, Day d) { BeforeHeaderRenderEventArgs ea = new BeforeHeaderRenderEventArgs(); ea.Columns = d.Columns; ea.InnerHTML = d.Name; ea.Name = d.Name; ea.Value = d.Value; ea.DataItem = d.DataItem; while (ea.Columns.Count < HeaderColumns.Count) { ea.Columns.Add(new ResourceColumn(String.Empty)); } DoBeforeResHeaderRender(ea); int height = (d.MaxColumns() * EventHeight); if (!CssOnly) { height -= 1; } output.AddStyleAttribute("width", (RowHeaderWidthResolved) + "px"); if (!CssOnly) { output.AddStyleAttribute("border-right", "1px solid " + ColorTranslator.ToHtml(BorderColor)); output.AddStyleAttribute("border-left", "1px solid " + ColorTranslator.ToHtml(BorderColor)); output.AddStyleAttribute("border-bottom", "1px solid " + ColorTranslator.ToHtml(BorderColor)); output.AddStyleAttribute("background-color", ColorTranslator.ToHtml(HourNameBackColor)); output.AddStyleAttribute("font-family", HeaderFontFamily); output.AddStyleAttribute("font-size", HeaderFontSize); output.AddStyleAttribute("color", ColorTranslator.ToHtml(HeaderFontColor)); output.AddStyleAttribute("cursor", "default"); } output.AddAttribute("unselectable", "on"); output.AddAttribute("resource", d.Value); output.AddAttribute("id", ClientID + "row" + d.Value); output.RenderBeginTag("td"); if (RowHeaderColumns.Count > 0) { if (!CssOnly) { output.Write("<div unselectable='on' style='height:" + height + "px; line-height:" + height + "px; overflow:hidden; width: " + RowHeaderWidthResolved + "px'>"); StringBuilder sb = new StringBuilder(); sb.Append("<table style='width:" + (RowHeaderColumnWidthTotal) + "px; padding: 0px; border-spacing: 0px; table-layout: fixed;'>"); sb.Append("<tr>"); sb.Append("<td style='width:" + RowHeaderColumns[0] + "px; padding: 0px; white-space: nowrap; overflow: hidden;'>"); sb.Append("<div>"); sb.Append(ea.InnerHTML); sb.Append("</div>"); sb.Append("</td>"); for (int i = 1; i < RowHeaderColumns.Count; i++) { string html = null; if (i <= d.Columns.Count) { html = d.Columns[i - 1].InnerHTML; } sb.Append("<td style='width:" + RowHeaderColumns[i] + "px; padding: 0px; white-space: nowrap;overflow: hidden;'>"); sb.Append(html); sb.Append("</td>"); } sb.Append("</tr>"); sb.Append("</table>"); output.Write(sb.ToString()); } else { output.Write("<div unselectable='on' style='height:" + height + "px; line-height:" + height + "px; overflow:hidden; width: " + RowHeaderWidthResolved + "px'>"); StringBuilder sb = new StringBuilder(); sb.Append("<table style='width:" + (RowHeaderColumnWidthTotal) + "px; padding: 0px; border-spacing: 0px; table-layout: fixed;'>"); sb.Append("<tr>"); sb.Append("<td style='width:" + RowHeaderColumns[0] + "px; padding: 0px; overflow: hidden;'>"); sb.Append("<div unselectable='on' style='height:" + height + "px; overflow:hidden; position: relative;' class='" + PrefixCssClass("_rowheader") + "'>"); sb.Append("<div unselectable='on' class='" + PrefixCssClass("_rowheader_inner") + "'>"); sb.Append(ea.InnerHTML); sb.Append("</div>"); sb.Append("</td>"); for (int i = 1; i < RowHeaderColumns.Count; i++) { string html = null; if (i <= d.Columns.Count) { html = d.Columns[i - 1].InnerHTML; } sb.Append("<td style='width:" + RowHeaderColumns[i] + "px; padding: 0px; white-space: nowrap;overflow: hidden;'>"); sb.Append("<div unselectable='on' style='height:" + height + "px; overflow:hidden; position: relative;' class='" + PrefixCssClass("_rowheader") + "'>"); sb.Append("<div unselectable='on' class='" + PrefixCssClass("_rowheader_inner") + "'>"); sb.Append(html); sb.Append("</div>"); sb.Append("</td>"); } sb.Append("</tr>"); sb.Append("</table>"); output.Write(sb.ToString()); } } else { if (!CssOnly) { output.Write("<div unselectable='on' style='margin-left:4px; height:" + height + "px; line-height:" + height + "px; overflow:hidden;'>"); output.Write(ea.InnerHTML); } else { output.Write("<div unselectable='on' style='height:" + height + "px; overflow:hidden; position: relative;' class='" + PrefixCssClass("_rowheader") + "'>"); output.Write("<div unselectable='on' class='" + PrefixCssClass("_rowheader_inner") + "'>"); output.Write(ea.InnerHTML); output.Write("</div>"); } } output.Write("</div>"); 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); } } }
private void RenderRowCells(HtmlTextWriter output, Day d) { if (!CssOnly) { // render all events in the first cell output.AddStyleAttribute("width", "1px"); output.AddStyleAttribute("border-bottom", "1px solid black"); output.AddStyleAttribute("background-color", GetCellColor(d.Start)); output.AddAttribute("valign", "top"); output.AddAttribute("unselectable", "on"); output.RenderBeginTag("td"); RenderEvents(d, output); // td output.RenderEndTag(); } RenderCells(output, d); }
private void RenderEvents(Day d, HtmlTextWriter output) { if (d.events.Count == 0) { output.Write("<div style='height:" + (EventHeight - 1) + "px;position:relative;width:1px;overflow:none;' unselectable='on'><!-- --></div>"); } else { output.AddStyleAttribute("position", "relative"); output.AddStyleAttribute("height", (d.MaxColumns() * EventHeight - 1) + "px"); // output.AddStyleAttribute("overflow", "none"); output.AddAttribute("unselectable", "on"); output.RenderBeginTag("div"); foreach (Event ep in d.events) { RenderEvent(d, ep, output); } // div relative output.RenderEndTag(); } }
private void RenderEvent(Day d, Event p, HtmlTextWriter output) { BeforeEventRenderEventArgs ea = new BeforeEventRenderEventArgs(p); ea.InnerHTML = p.Name; ea.ToolTip = p.Name; ea.EventClickEnabled = EventClickHandling != EventClickHandlingEnum.Disabled; if (!CssOnly) { ea.DurationBarColor = ColorTranslator.ToHtml(DurationBarColor); ea.BackgroundColor = ColorTranslator.ToHtml(EventBackColor); } DoBeforeEventRender(ea); int max = CellCount*CellWidth; int left = (int)Math.Floor((p.BoxStart - d.Start).TotalMinutes * CellWidth / CellDuration); int top = p.Column.Number * EventHeight - 1; int width = (int)Math.Floor((p.BoxEnd - p.BoxStart).TotalMinutes * CellWidth / CellDuration) - 2; int height = EventHeight - 1; int startDelta = (int)Math.Floor((p.Start - p.BoxStart).TotalMinutes * CellWidth / CellDuration - 1); int realWidth = (int)Math.Floor((p.End - p.Start).TotalMinutes * CellWidth / CellDuration); realWidth = realWidth == 0 ? 1 : realWidth; // adjustments if (left > max) // don't render { return; } if (left + width > max - 2) { width = max - left - 2; } if (left < 0) { width += left; left = 0; } width = Math.Max(width, 2); if (!CssOnly) { 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("overflow", "hidden"); output.AddStyleAttribute("border", "1px solid " + ColorTranslator.ToHtml(EventBorderColor)); output.AddStyleAttribute("background-color", ea.BackgroundColor); output.AddStyleAttribute("white-space", "nowrap"); output.AddStyleAttribute("font-family", EventFontFamily); output.AddStyleAttribute("font-size", EventFontSize); if (ea.EventClickEnabled && EventClickHandling != EventClickHandlingEnum.Disabled) { if (EventClickHandling == EventClickHandlingEnum.PostBack) { output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + Page.ClientScript.GetPostBackEventReference(this, "PK:" + p.PK)); } else { output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + String.Format(EventClickJavaScript, p.PK)); } output.AddStyleAttribute("cursor", "pointer"); } else { output.AddStyleAttribute("cursor", "default"); } output.RenderBeginTag("div"); if (DurationBarVisible) { output.Write("<div unselectable='on' style='width:" + realWidth + "px; margin-left: " + startDelta + "px; height:2px; background-color:" + ea.DurationBarColor + "; font-size:1px; position:relative;' ></div>"); output.Write("<div unselectable='on' style='width:" + width + "px; height:1px; background-color:" + ColorTranslator.ToHtml(EventBorderColor) + "; font-size:1px; position:relative;' ></div>"); } output.AddStyleAttribute("display", "block"); output.AddStyleAttribute("padding-left", "1px"); output.AddAttribute("unselectable", "on"); output.RenderBeginTag("div"); output.Write(ea.InnerHTML); output.RenderEndTag(); output.RenderEndTag(); } else { 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("overflow", "hidden"); output.AddAttribute("class", PrefixCssClass("_event")); if (ea.EventClickEnabled && EventClickHandling != EventClickHandlingEnum.Disabled) { if (EventClickHandling == EventClickHandlingEnum.PostBack) { output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + Page.ClientScript.GetPostBackEventReference(this, "PK:" + p.PK)); } else { output.AddAttribute("onclick", "javascript:event.cancelBubble=true;" + String.Format(EventClickJavaScript, p.PK)); } output.AddStyleAttribute("cursor", "pointer"); } else { output.AddStyleAttribute("cursor", "default"); } output.RenderBeginTag("div"); output.AddStyleAttribute("display", "block"); output.AddAttribute("unselectable", "on"); output.AddAttribute("class", PrefixCssClass("_event_inner")); if (!String.IsNullOrEmpty(ea.BackgroundColor)) { output.AddStyleAttribute("background", ea.BackgroundColor); } output.RenderBeginTag("div"); output.Write(ea.InnerHTML); output.RenderEndTag(); if (DurationBarVisible) { output.AddStyleAttribute("position", "absolute"); output.AddAttribute("unselectable", "on"); output.AddAttribute("class", PrefixCssClass("_event_bar")); output.RenderBeginTag("div"); double barLeft = 100.0 * startDelta / width; double barWidth = 100.0 * realWidth / width; output.AddAttribute("class", PrefixCssClass("_event_bar_inner")); output.AddStyleAttribute("left", barLeft + "%"); output.AddStyleAttribute("width", barWidth + "%"); if (!String.IsNullOrEmpty(ea.DurationBarColor)) { output.AddStyleAttribute("background", ea.DurationBarColor); } output.RenderBeginTag("div"); output.RenderEndTag(); output.RenderEndTag(); //output.Write("<div unselectable='on' style='width:" + realWidth + "px; margin-left: " + startDelta + "px; height:2px; background-color:" + ea.DurationBarColor + "; font-size:1px; position:relative;' ></div>"); //output.Write("<div unselectable='on' style='width:" + width + "px; height:1px; background-color:" + ColorTranslator.ToHtml(EventBorderColor) + "; font-size:1px; position:relative;' ></div>"); } output.RenderEndTag(); } }
private void RenderCells(HtmlTextWriter output, Day d) { int cellsToRender = CellCount; for (int i = 0; i < cellsToRender; i++) { DateTime start = d.Start.AddMinutes(i*CellDuration); int thisCellWidth = CellWidth; string back = GetCellColor(start); if (!CssOnly) { if (i == 0) { thisCellWidth = CellWidth - 1; } if (i == cellsToRender - 1) { output.AddStyleAttribute("border-right", "1px solid " + ColorTranslator.ToHtml(BorderColor)); } output.AddStyleAttribute("border-bottom", "1px solid " + ColorTranslator.ToHtml(BorderColor)); output.AddStyleAttribute("background-color", back); } output.AddStyleAttribute("width", thisCellWidth + "px"); if (TimeRangeSelectedHandling != TimeRangeSelectedHandling.Disabled) { if (TimeRangeSelectedHandling == TimeRangeSelectedHandling.PostBack) { output.AddAttribute("onclick", "javascript:" + Page.ClientScript.GetPostBackEventReference(this, "TIME:" + start.ToString("s") + d.Value)); } else { output.AddAttribute("onclick", "javascript:" + String.Format(TimeRangeSelectedJavaScript, start.ToString("s"), d.Value)); } if (!CssOnly) { output.AddAttribute("onmouseover", "this.style.backgroundColor='" + ColorTranslator.ToHtml(HoverColor) + "';"); output.AddAttribute("onmouseout", "this.style.backgroundColor='" + back + "';"); } output.AddStyleAttribute("cursor", "pointer"); } else { output.AddStyleAttribute("cursor", "default"); } output.RenderBeginTag("td"); if (!CssOnly) { output.Write("<div unselectable='on' style='display:block; width:" + (thisCellWidth - 1) + "px; height:" + (d.MaxColumns() * EventHeight - 1) + "px; border-right: 1px solid " + ColorTranslator.ToHtml(HourBorderColor) + ";' ><!-- --></div>"); } else { output.Write("<div unselectable='on' style='display:block; width:" + (thisCellWidth) + "px; height:" + (d.MaxColumns()*EventHeight) + "px;' class='" + PrefixCssClass("_cell") + "'>"); output.Write("</div>"); } output.RenderEndTag(); } }
private void LoadEventsToDays() { _days = new List<Day>(); ArrayList items = (ArrayList)ViewState["Items"]; if (Resources == null) { return; } if (ViewType == ViewTypeEnum.Resources) { foreach (Resource resource in Resources) { Day d = new Day(StartDate, EndDate.AddDays(1), resource.Name, resource.Value, CellDuration); d.Columns = resource.Columns; _days.Add(d); } } else { if (items != null) { foreach (Event e in items) { Day d = new Day(StartDate, EndDate.AddDays(1), e.Name, e.PK, CellDuration); d.Columns = new List<ResourceColumn>(); d.DataItem = new DataItemWrapper(e.Source); _days.Add(d); } } } foreach (Day d in _days) { d.Load(items); } }