示例#1
0
        public static byte[] RenderChart(int projectId, int basePlanSlotId, bool generateDataXml, string styleFilePath, int portionX, int portionY, int itemsPerPage, int pageNumber)
        {
            GanttView gantt = CreateGanttView(projectId, HeaderItemHeight, ItemHeight);

            if (portionY >= 0)
            {
                #region Add data

                #region Load calendar

                int calendarId = -1;
                using (IDataReader reader = Project.GetProject(projectId))
                {
                    if (reader.Read())
                    {
                        calendarId = (int)reader["CalendarId"];
                    }
                }
                if (calendarId > 0)
                {
                    // Load rules by day of week
                    ArrayList days = new ArrayList();
                    for (byte i = 1; i <= 7; i++)
                    {
                        days.Add(i);
                    }
                    using (IDataReader reader = Mediachase.IBN.Business.Calendar.GetListWeekdayHours(calendarId))
                    {
                        while (reader.Read())
                        {
                            byte b = (byte)reader["DayOfWeek"];
                            days.Remove(b);
                        }
                    }
                    foreach (byte b in days)
                    {
                        gantt.CreateDayElement(ConvertDayOfWeek(b), true);
                    }

                    // Load exceptions
                    using (IDataReader reader = Mediachase.IBN.Business.Calendar.GetListExceptionHoursByCalendar(calendarId))
                    {
                        while (reader.Read())
                        {
                            DateTime fromDate = (DateTime)reader["FromDate"];
                            DateTime toDate   = (DateTime)reader["ToDate"];
                            bool     holiday  = (reader["FromTime"] == DBNull.Value && reader["ToTime"] == DBNull.Value);
                            for (DateTime date = fromDate.Date; date <= toDate.Date; date = date.AddDays(1))
                            {
                                gantt.CreateDateElement(date, holiday);
                            }
                        }
                    }
                }

                #endregion

                #region Load base plan

                Dictionary <int, DateTime> basePlanTaskHash = null;
                if (basePlanSlotId > 0)
                {
                    basePlanTaskHash = SpreadSheet.ProjectSpreadSheet.GetTaskHash(projectId, basePlanSlotId);
                }

                #endregion

                List <string> ids = new List <string>();

                #region Load tasks

                DataTable dt = Task.GetListTasksByProjectCollapsedDataTable(projectId);
                dt.AcceptChanges();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];

                    if (dr.RowState != DataRowState.Deleted)
                    {
                        Element spanElement = gantt.CreateSpanElement(null, null, null);

                        int    taskId = (int)dr["TaskId"];
                        string id     = taskId.ToString(CultureInfo.InvariantCulture);
                        ids.Add(id);
                        DateTime start       = (DateTime)dr["StartDate"];
                        bool     isMilestone = (bool)dr["IsMilestone"];
                        bool     isSummary   = (bool)dr["IsSummary"];
                        bool     isCompleted = (bool)dr["IsCompleted"];
                        string   type        = isSummary ? "Summary" : null;
                        string   tag         = isCompleted ? "Completed" : null;

                        if (isMilestone)
                        {
                            DateTime?basePlanDate = null;

                            if (basePlanTaskHash != null && basePlanTaskHash.ContainsKey(taskId))
                            {
                                basePlanDate = basePlanTaskHash[taskId];
                            }

                            AddMilestone(gantt, spanElement, start, basePlanDate, id, tag);
                        }
                        else
                        {
                            AddInterval(dr, gantt, spanElement, "StartDate", "FinishDate", id, type, tag);

                            if (!isSummary)
                            {
                                AddInterval(dr, gantt, spanElement, "ActualStartDate", "ActualFinishDate", null, "Actual", tag);

                                int progress = (int)dr["PercentCompleted"];
                                if (progress > 0)
                                {
                                    DateTime finish   = (DateTime)dr["FinishDate"];
                                    TimeSpan interval = finish - start;
                                    finish = start + new TimeSpan(interval.Ticks * progress / 100);
                                    AddInterval2(gantt, spanElement, start, finish, null, "Progress", tag);
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Load relations

                using (IDataReader reader = Project.GetListTaskLinksByProject(projectId))
                {
                    while (reader.Read())
                    {
                        //string linkId = reader["LinkId"].ToString();
                        string succId = reader["SuccId"].ToString();
                        string predId = reader["PredId"].ToString();

                        if (ids.Contains(succId) && ids.Contains(predId))
                        {
                            gantt.CreateRelationElement(null, null, null, predId, succId);
                        }
                    }
                }

                #endregion

                #endregion
            }

            return(Render(gantt, generateDataXml, styleFilePath, portionX, portionY, PortionWidth, PortionHeight, itemsPerPage, pageNumber));
        }