Пример #1
0
        public void AddPortlet(ContentItem projectDashboard, ContentItem portletTemplate, int position)
        {
            ContentItem newPortlet = null;

            if (portletTemplate.ContentType == ContentTypes.ProjectDashboardProjectionPortletTemplateContentType)
            {
                newPortlet = this.services.ContentManager.Create(ContentTypes.ProjectDashboardProjectionPortletContentType);
                ProjectionWithDynamicSortPart destinationProjectionPart = newPortlet.As <ProjectionWithDynamicSortPart>();
                ProjectionWithDynamicSortPart sourceProjectionPart      = portletTemplate.As <ProjectionWithDynamicSortPart>();
                CRMHelper.Copy(layoutRepository, sourceProjectionPart.Record, destinationProjectionPart.Record);
            }
            else if (portletTemplate.ContentType == ContentTypes.ProjectDashboardReportViewerPortletTemplateContentType)
            {
                newPortlet = this.services.ContentManager.Create(ContentTypes.ProjectDashboardReportViewerPortletContentType);
                DataReportViewerPart destinationReportViewerPart = newPortlet.As <DataReportViewerPart>();
                DataReportViewerPart sourceReportViewerPart      = portletTemplate.As <DataReportViewerPart>();
                CRMHelper.Copy(sourceReportViewerPart.Record, destinationReportViewerPart.Record);
            }
            else if (portletTemplate.ContentType == ContentTypes.ProjectLastActivityStreamTemplateContentType)
            {
                newPortlet = this.services.ContentManager.Create(ContentTypes.ProjectLastActivityStreamContentType);
                var sourceActivityStreamPart      = portletTemplate.As <ActivityStreamPart>();
                var destinationActivityStreamPart = newPortlet.As <ActivityStreamPart>();
                destinationActivityStreamPart.QueryId = sourceActivityStreamPart.QueryId;
            }
            else
            {
                throw new ArgumentOutOfRangeException("The ContentType of the portletTemplate is not supported.");
            }

            // store templateId
            newPortlet.As <InfosetPart>().Store <int>(FieldNames.ProjectDashboardPortletTemplateId, portletTemplate.Id);

            // copy Title
            TitlePart titlePart         = newPortlet.As <TitlePart>();
            TitlePart templateTitlePart = portletTemplate.As <TitlePart>();

            titlePart.Title = templateTitlePart.Title;

            ContainablePart containablePart = newPortlet.As <ContainablePart>();

            containablePart.Position = position;

            var projectDetailContainerPart = projectDashboard.As <ContainerPart>();
            var newPortletCommon           = newPortlet.As <CommonPart>();

            newPortletCommon.Container = projectDashboard;
            this.services.ContentManager.Publish(newPortlet);
        }
        public string GetCsv(DataReportViewerPart part)
        {
            var report = _reportRepository.Table.FirstOrDefault(c => c.Id == part.Record.Report.Id);

            if (report == null)
            {
                return(null);
            }
            IEnumerable <AggregationResult> reportData = null;

            if (string.IsNullOrWhiteSpace(report.GroupByCategory))
            {
                var multiColumn = part.Record.ChartType == ((int)ChartTypes.SimpleTable);
                reportData = RunHqlReport(report, part.ContentItem, multiColumn);
            }
            else
            {
                reportData = RunReport(report, part.ContentItem);
            }
            var rows = reportData.ToList();
            var sb   = new StringBuilder();
            var text = "";

            if (rows.Count > 0)
            {
                if (string.IsNullOrWhiteSpace(report.GroupByCategory) && rows[0].Other != null)
                {
                    // multi column hql report
                    foreach (var row in rows)
                    {
                        foreach (var col in (object[])(row.Other))
                        {
                            if (col != null)
                            {
                                switch (col.GetType().Name)
                                {
                                case "DateTime":
                                    sb.AppendFormat("{0:yyyy-MM-dd HH:mm:ss}", col);
                                    break;

                                case "Decimal":
                                case "Double":
                                case "Float":
                                    sb.Append(Convert.ToString(col, CultureInfo.InvariantCulture).Replace('.', ','));
                                    break;

                                default:
                                    text = Convert.ToString(col);
                                    if (text.Contains(';'))
                                    {
                                        text = string.Format("\"{0}\"", text);
                                    }
                                    sb.Append(text);
                                    break;
                                }
                            }
                            sb.Append(";"); // terminatore di campo
                        }
                        sb.Append("\r\n");  // terminatore di riga
                    }
                }
                else
                {
                    // standard report
                    foreach (var row in rows)
                    {
                        text = Convert.ToString(row.Label);
                        if (text.Contains(';'))
                        {
                            text = string.Format("\"{0}\"", text);
                        }
                        sb.AppendFormat("{0};{1}\r\n", text, row.AggregationValue);
                    }
                }
            }
            return(sb.ToString());
        }