Exemplo n.º 1
0
        /// <summary>
        /// Generates an item in a list of upcoming events in a repeater control.
        /// </summary>
        /// <param name="container">A reference to the containing <see cref="RepeaterItem"/> control.</param>
        private void BuildItemTemplate(Control container)
        {
            // event date
            Literal date = new Literal();

            date.DataBinding += new EventHandler(
                delegate
            {
                CPCalendarItem item = (container as RepeaterItem).DataItem as CPCalendarItem;
                if (item != null)
                {
                    date.Text = string.Format("<tr{0}><td class=\"date\">{1}</td>", item.IsImmediate ? "class=\"alert\"" : null, string.Format(_dateFormat, item.Date));
                }
            });
            container.Controls.Add(date);
            // event title and link
            Literal html = new Literal()
            {
                Text = "<td class=\"event\">"
            };

            container.Controls.Add(html);
            HyperLink link = new HyperLink();

            link.DataBinding += new EventHandler(
                delegate
            {
                CPCalendarItem item = (container as RepeaterItem).DataItem as CPCalendarItem;
                if (item != null)
                {
                    link.Text    = HttpUtility.HtmlEncode((_view == RemindersView.Full) ? item.Description : item.Title);
                    link.ToolTip = item.Description;
                    string url   = PageUrlManager.GetCalendarItemDisplayUrl(item);
                    if (!string.IsNullOrEmpty(url))
                    {
                        link.NavigateUrl = string.Format("{0}?ItemID={1}", url, PageUrlManager.GetCalendarItemID(item));
                    }
                }
            });
            container.Controls.Add(link);
            html = new Literal()
            {
                Text = "</td></tr>"
            };
            container.Controls.Add(html);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <returns></returns>
        public static SPCalendarItem ToSPCalendarItem <T>(this T item) where T : CPCalendarItem
        {
            // set start date to end date for statement reviews and doing business reviews
            DateTime startDate;

            switch (item.CalendarItemType)
            {
            case CPCalendarItemType.StatementReview:
            case CPCalendarItemType.DoingBusinessReview:
                startDate = item.EndDate;
                break;

            default:
                startDate = item.StartDate;
                break;
            }
            if (item.StartDate == DateTime.MinValue || item.EndDate == DateTime.MinValue)
            {
                return(null);                // invalid dates will throw an ArgumentOutOfRangeException later
            }
            SPCalendarItem calItem = new SPCalendarItem()
            {
                StartDate     = startDate,
                CalendarType  = (int)SPCalendarType.Gregorian,
                Description   = item.Description,
                EndDate       = item.EndDate,
                hasEndDate    = item.HasEndDate,
                IsAllDayEvent = item.IsAllDayEvent,
                IsRecurrence  = item.IsRecurrence,
                ItemID        = PageUrlManager.GetCalendarItemID(item),
                Title         = item.Title
            };
            // set calendar item link destinations
            string url = PageUrlManager.GetCalendarItemDisplayUrl(item);

            if (!string.IsNullOrEmpty(url))
            {
                calItem.DisplayFormUrl = url;
            }
            calItem.BackgroundColorClassName = string.Format("{0} {1}", calItem.BackgroundColorClassName, item.CalendarItemType).Trim();
            return(calItem);
        }