Ejemplo n.º 1
0
        private void CreateItem(TaskRow taskRow, ref StringBuilder sb)
        {
            DateTime workingDate = ColumnStartDate;

            // define the row
            TableRow tr = new TableRow();

            tr.CssClass = "p1-ganttTaskRow";
            tr.Height   = new Unit("20px");


            // set the link/title for the row
            tr.Cells.Add(GetRowTitle(taskRow.Title, taskRow.TitleAction));

            // Generate the correct backgrounds
            TableCell td = null;

            for (int x = 0; x < DaysGenerated; x++)
            {
                td          = new TableCell();
                workingDate = ColumnStartDate.AddDays(x);
                if (workingDate == DateTime.Today)
                {
                    td.CssClass = "p1-GT";
                }
                else if (workingDate.DayOfWeek == DayOfWeek.Saturday || workingDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    td.CssClass = "p1-GNWD";
                }
                else
                {
                    td.CssClass = "p1-GWD";
                }
                tr.Cells.Add(td);
            }
            foreach (TaskRowItem tri in taskRow.Items)
            {
                if (tri.StartDate > ColumnEndDate)
                {
                    continue;
                }
                if (tri.EndDate < ColumnStartDate)
                {
                    continue;
                }
                // determine the starting cell and ending cell in the cells collection
                int startingColumn = tri.StartDate.Subtract(ColumnStartDate).Days + 1;
                if (startingColumn < 0)
                {
                    startingColumn = 1;
                    tr.Cells[startingColumn].Controls.Add(new LiteralControl(string.Format(itemImgMiddle, tri.ToolTip)));
                }
                else if (startingColumn >= 1)
                {
                    tr.Cells[startingColumn].Controls.Add(new LiteralControl(string.Format(itemImgStart, tri.ToolTip)));
                }

                int endingColumn = startingColumn + tri.EndDate.Subtract(tri.StartDate).Days;
                if (endingColumn > DaysGenerated)
                {
                    endingColumn = DaysGenerated;
                }

                // render out this date.
                for (int i = 1; i < (endingColumn - startingColumn); i++)
                {
                    tr.Cells[startingColumn + i].Controls.Add(new LiteralControl(string.Format(itemImgMiddle, tri.ToolTip)));
                }

                if ((startingColumn + tri.EndDate.Subtract(tri.StartDate).Days) > DaysGenerated)
                {
                    tr.Cells[endingColumn].Controls.Add(new LiteralControl(string.Format(itemImgMiddle, tri.ToolTip)));
                }
                else
                {
                    tr.Cells[endingColumn].Controls.Add(new LiteralControl(string.Format(itemImgEnd, tri.ToolTip)));
                }
            }

            // write out the html for rendering
            System.IO.StringWriter sr  = new System.IO.StringWriter();
            HtmlTextWriter         htr = new HtmlTextWriter(sr);

            tr.RenderControl(htr);
            sb.Append(htr.InnerWriter.ToString());

            sb.ToString();
        }
Ejemplo n.º 2
0
        private string GenerateSchedule(DateTime startDate, DateTime endDate)
        {
            #region Correct the dates
            // Ensure that the first day is a monday.
            if (startDate.DayOfWeek != DayOfWeek.Monday)
            {
                while (startDate.DayOfWeek != DayOfWeek.Monday)
                {
                    startDate = startDate.AddDays(-1);
                }
            }

            // ensure that the end date is a sunday
            if (endDate.DayOfWeek != DayOfWeek.Sunday)
            {
                while (endDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    endDate = endDate.AddDays(1);
                }
            }

            ColumnStartDate = startDate;
            ColumnEndDate   = endDate;
            #endregion

            #region Generate The header Information
            // We need to know the number of weeks for this.
            int dayCount = ColumnEndDate.Subtract(ColumnStartDate).Days;
            int weeks    = dayCount / 7;
            int rem      = dayCount % 7;
            if (rem > 0)
            {
                weeks++;
            }

            DaysGenerated  = 7 * weeks;
            WeeksGenerated = weeks;
            HtmlTable tbl = new HtmlTable();


            StringBuilder sb = new StringBuilder();
            sb.Append(GenerateHeader());

            string tmp = string.Empty;

            for (int i = 0; i < weeks; i++)
            {
                // determine the date for eah of the weeks for display
                tmp = string.Format(headerWeekRow, startDate.AddDays(i * 7).ToString("dd/MM/yy"));
                sb.Append(tmp);
            }
            sb.Append("</tr>");
            sb.Append(headerDayRowBegin);

            string[] days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saaturday", "Sunday" };
            for (int i = 0; i < weeks; i++)
            {
                foreach (string day in days)
                {
                    tmp = string.Format(headerDayRowday, day, day.Substring(0, 1));
                    sb.Append(tmp);
                }
            }
            sb.Append(headerDayRowEnd);

            #endregion

            #region Create the Items

            TaskRow     taskRow      = null;
            TaskRowItem tri          = null;
            string      currentValue = string.Empty;
            foreach (DataRow dr in Data.Tables[0].Rows)
            {
                if (dr[GroupingField].ToString() != currentValue)
                {
                    if (taskRow != null)
                    {
                        CreateItem(taskRow, ref sb);
                    }

                    taskRow       = new TaskRow();
                    taskRow.Title = dr[TitleField].ToString();
                    if (TitleActionField != "")
                    {
                        taskRow.TitleAction = dr[TitleActionField].ToString();
                    }
                    currentValue = dr[GroupingField].ToString();
                }

                tri = new TaskRowItem();
                if (!string.IsNullOrEmpty(ToolTipField))
                {
                    tri.ToolTip = dr[ToolTipField].ToString();
                }

                tri.Action    = string.Empty;
                tri.StartDate = (DateTime)dr[StartDateField];
                tri.EndDate   = (DateTime)dr[EndDateField];
                taskRow.Items.Add(tri);
            }

            //string toolTip = "Holiday [ " + new DateTime(2007, 02, 02).ToString("dd/MM/yy") + " to " + new DateTime(2007, 01, 13).ToString("dd/MM/yy") + " ]";
            //TaskRow taskRow = new TaskRow("Greg Duffield", "#", toolTip, "#", new DateTime(2007, 02, 02), new DateTime(2007, 02, 05));
            //TaskRowItem tri = new TaskRowItem("#", "Working", new DateTime(2007, 01, 12), new DateTime(2007, 01, 13));
            //taskRow.Items.Add(tri);
            //CreateItem(taskRow, ref sb);

            //toolTip = "Testing";
            //taskRow = new TaskRow("A N Other", "#", toolTip, "#", new DateTime(2006, 12, 29), new DateTime(2007, 01, 10));
            //tri = new TaskRowItem("#", "Over the last day", new DateTime(2007, 01, 27), new DateTime(2007, 02, 12));
            //taskRow.Items.Add(tri);
            //CreateItem(taskRow, ref sb);

            #endregion

            #region Create the Footer

            sb.Append(headerTableFooterBegin);
            for (int i = 0; i < (7 * weeks) - 1; i++)
            {
                sb.Append(string.Format(headerTableFooterItem, ""));
            }

            sb.Append(headerTableFooterEnd);

            #endregion

            return(sb.ToString());
        }