コード例 #1
0
        public CftReport GetCftReport(int reportId = 0, int clientId = 0, bool withData = true)
        {
            var cftReport = new CftReport();

            if (reportId > 0)
            {
                var reportTemplate = _reportFactory.GetReportTemplate(reportId);
                if (withData)
                {
                    string source;
                    var    reportDataTable = _reportFactory.ExecuteReportQuery(reportTemplate, out source, clientId);



                    cftReport = GetGoogleReport(reportTemplate, reportDataTable);


                    cftReport.Filters = (from reportField in reportTemplate.ReportFields where reportField.Filter != null && (bool)reportField.Filter select new Filter()
                    {
                        FieldId = reportField.FieldId.Value, Name = reportField.DisplayName
                    }).ToArray();


                    switch (source)
                    {
                    case "Acturis":
                        cftReport.ClientList = _acturisFactory.GetClientList().ToArray();
                        break;

                    default:
                    case "CFT":

                        cftReport.ClientList = _reportFactory.GetClientList().ToArray();
                        break;
                    }
                }

                Array.Resize(ref cftReport.Colours, 5);
                cftReport.Name      = reportTemplate.Name;
                cftReport.ReportId  = reportTemplate.ReportID;
                cftReport.ChartType = reportTemplate.ReportType;



                cftReport.Colours[0]  = reportTemplate.Colour1 ?? "#ffffff";
                cftReport.Colours[1]  = reportTemplate.Colour2 ?? "#ffffff";
                cftReport.Colours[2]  = reportTemplate.Colour3 ?? "#ffffff";
                cftReport.Colours[3]  = reportTemplate.Colour4 ?? "#ffffff";
                cftReport.Colours[4]  = reportTemplate.Colour5 ?? "#ffffff";
                cftReport.HAxis       = reportTemplate.HAxis ?? "";
                cftReport.HAxisColour = reportTemplate.HAxisColour ?? "";

                cftReport.VAxis       = reportTemplate.VAxis ?? "";
                cftReport.VAxisColour = reportTemplate.VAxisColour ?? "";

                cftReport.ZAxis       = reportTemplate.ZAxis ?? "";
                cftReport.ZAxisColour = reportTemplate.ZAxisColour ?? "";
                cftReport.Description = reportTemplate.Description;
            }

            return(cftReport);
        }
コード例 #2
0
        public CftReport GetGoogleReport(ReportTemplate reportTemplate, DataTable reportDataTable)
        {
            var counter     = 0;
            var reportModel = new CftReport {
                GoogleDataTableColumns = new GoogleDataTableColumn[] { }
            };
            var reportFieldsCount = reportTemplate.ReportFields.Count();
            var reportRowCount    = reportDataTable.Rows.Count;

            Array.Resize(ref reportModel.GoogleDataTableColumns, reportFieldsCount);


            var reportFields = reportTemplate.ReportFields.OrderBy(m => m.FieldNumber);

            foreach (var reportField in reportFields)
            {
                var headerType = reportField.ClaimFieldTemplate.FieldType.GoogleColumnType;

                if (reportField.Func == "Count" || reportField.Func == "Sum")
                {
                    headerType = "number";
                }

                if (reportField.FieldId != null)
                {
                    var googleDataTableColumn = new GoogleDataTableColumn
                    {
                        Id    = "reportField" + reportField.FieldId.Value,
                        Label = reportField.DisplayName,
                        Type  = headerType
                    };
                    reportModel.GoogleDataTableColumns[counter] = googleDataTableColumn;
                }
                counter++;
            }


            Array.Resize(ref reportModel.GoogleDataTableRows, reportRowCount);
            var rowCounter = 0;

            foreach (DataRow row in reportDataTable.Rows)
            {
                var googleDataTableRow = new GoogleDataTableRow();
                Array.Resize(ref googleDataTableRow.GoogleDataRecords, reportFieldsCount);
                int columnCounter = 0;
                foreach (var column in reportModel.GoogleDataTableColumns)
                {
                    var googleDataRecord = new GoogleDataRecord();
                    switch (column.Type)
                    {
                    case "string":
                        var o = row[column.Label];
                        if (o != null)
                        {
                            googleDataRecord.StringValue = o.ToString();
                        }
                        break;

                    case "number":
                        googleDataRecord.IntegerValue =
                            ((row[column.Label] != null) && (!String.IsNullOrEmpty(row[column.Label].ToString()))) ?
                            Convert.ToInt32(row[column.Label]) : 0;
                        break;

                    case "date":
                    case "datetime":
                        googleDataRecord.DateTimeValue = ((row[column.Label] != null) ? Convert.ToDateTime(row[column.Label]) : new DateTime());

                        break;
                    }
                    googleDataTableRow.GoogleDataRecords[columnCounter] = googleDataRecord;
                    columnCounter++;
                }
                reportModel.GoogleDataTableRows[rowCounter] = googleDataTableRow;
                rowCounter++;
            }

            return(reportModel);
        }