Ejemplo n.º 1
0
        private static bool CreateDetailSheet(ISheet detailSheet, TwoLevelRequirementPointer <Zone, Space> requirementPointer)
        {
            try
            {
                var excelRow  = detailSheet.GetRow(0) ?? detailSheet.CreateRow(0);
                var excelCell = excelRow.GetCell(0) ?? excelRow.CreateCell(0);
                SetHeader(excelCell);
                excelCell.SetCellValue("Zone and spaces report");

                var rep = new TwoLevelDetailedGridReport <Zone, Space>(requirementPointer);
                rep.PrepareReport();


                var iRunningRow    = 2;
                var iRunningColumn = 0;
                excelRow = detailSheet.GetRow(iRunningRow++) ?? detailSheet.CreateRow(iRunningRow - 1);                                // prepares a row and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(@"Name:");                // writes cell and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(requirementPointer.Name); // writes cell and moves index forward

                iRunningColumn = 0;
                excelRow       = detailSheet.GetRow(iRunningRow++) ?? detailSheet.CreateRow(iRunningRow - 1);                                    // prepares a row and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(@"External system:");               // writes cell and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(requirementPointer.ExternalSystem); // writes cell and moves index forward

                iRunningColumn = 0;
                excelRow       = detailSheet.GetRow(iRunningRow++) ?? detailSheet.CreateRow(iRunningRow - 1);                                // prepares a row and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(@"External id:");               // writes cell and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(requirementPointer.ExternalId); // writes cell and moves index forward

                iRunningRow++;                                                                                                               // one empty row

                iRunningColumn = 0;
                excelRow       = detailSheet.GetRow(iRunningRow++) ?? detailSheet.CreateRow(iRunningRow - 1);                          // prepares a row and moves index forward
                (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(@"Matching categories:"); // writes cell and moves index forward

                foreach (var cat in rep.RequirementCategories)
                {
                    iRunningColumn = 0;
                    excelRow       = detailSheet.GetRow(iRunningRow++) ?? detailSheet.CreateRow(iRunningRow - 1);                     // prepares a row and moves index forward
                    (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(cat.Classification); // writes cell and moves index forward
                    (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(cat.Code);           // writes cell and moves index forward
                    (excelRow.GetCell(iRunningColumn++) ?? excelRow.CreateCell(iRunningColumn - 1)).SetCellValue(cat.Description);    // writes cell and moves index forward
                }

                iRunningRow++; // one empty row
                iRunningColumn = 0;

                var cellStyle = detailSheet.Workbook.CreateCellStyle();
                cellStyle.BorderBottom        = BorderStyle.Thick;
                cellStyle.BorderLeft          = BorderStyle.Thin;
                cellStyle.BorderRight         = BorderStyle.Thin;
                cellStyle.BorderTop           = BorderStyle.Thin;
                cellStyle.FillPattern         = FillPattern.SolidForeground;
                cellStyle.FillForegroundColor = IndexedColors.Grey50Percent.Index;

                var table = rep.AttributesGrid;

                excelRow = detailSheet.GetRow(iRunningRow) ?? detailSheet.CreateRow(iRunningRow);
                foreach (DataColumn tCol in table.Columns)
                {
                    if (tCol.AutoIncrement)
                    {
                        continue;
                    }
                    excelCell = excelRow.GetCell(iRunningColumn) ?? excelRow.CreateCell(iRunningColumn);
                    iRunningColumn++;
                    excelCell.SetCellValue(tCol.Caption);
                    excelCell.CellStyle = cellStyle;
                }
                iRunningRow++;

                var writer = new ExcelCellVisualValue(detailSheet.Workbook);
                foreach (DataRow row in table.Rows)
                {
                    excelRow = detailSheet.GetRow(iRunningRow) ?? detailSheet.CreateRow(iRunningRow);
                    iRunningRow++;

                    iRunningColumn = -1;
                    foreach (DataColumn tCol in table.Columns)
                    {
                        if (tCol.AutoIncrement)
                        {
                            continue;
                        }
                        iRunningColumn++;
                        if (row[tCol] == DBNull.Value)
                        {
                            continue;
                        }
                        excelCell = excelRow.GetCell(iRunningColumn) ?? excelRow.CreateCell(iRunningColumn);

                        // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
                        if (row[tCol] is IVisualValue)
                        {
                            writer.SetCell(excelCell, (IVisualValue)row[tCol]);
                        }
                        else
                        {
                            switch (tCol.DataType.Name)
                            {
                            case "String":
                                excelCell.SetCellValue((string)row[tCol]);
                                break;

                            case "Int32":
                                excelCell.SetCellValue(Convert.ToInt32(row[tCol]));
                                break;

                            default:
                                excelCell.SetCellValue((string)row[tCol]);
                                break;
                            }
                        }
                    }
                }

                //// sets all used columns to autosize
                //for (var irun = 0; irun < iRunningColumn; irun++)
                //{
                //    detailSheet.AutoSizeColumn(irun);
                //}

                return(true);
            }
            catch (Exception e)
            {
                //log the error
                Logger.Error("Failed to create detail Sheet", e);
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initialise the reporting class with an AssetTypeRequirementPointer
 /// </summary>
 internal TwoLevelDetailedGridReport(TwoLevelRequirementPointer <T, TSub> assetType)
 {
     _valideatedAssetType = assetType;
 }