Exemplo n.º 1
0
        private void postProcessData(string worksheetName)
        {
            foreach (TableDescriptionTableEntry descriptionEntry in getSortedDescriptionTable(worksheetName))
            {
                //if (descriptionEntry.Access_Column_Name != null && descriptionEntry.Access_Column_Name.Contains("V_Dash") && worksheetName == "V dash & Security 101") {
                // only for debugging purposes
                //Console.WriteLine("test...");
                //}

                if (descriptionEntry.SQL_Source_Query.NotEmpty())
                {
                    // lookup using the row header name because the table
                    // will be increased during the postprocessing step
                    // and the row numbers are not matching with
                    // the row number from the description table anymore
                    string   rowHeader = m_rowHeaderContainer.LookupRowHeader(descriptionEntry.Row_Number);
                    ExcelRow row       = m_reportTable.WorkSheets[worksheetName][rowHeader];

                    if (row != null)
                    {
                        // the registered index which was previously registered during requesting postprocessing data step
                        int registeredIndex = m_postprocessingReverseData[descriptionEntry.ID];
                        // dataset to be inserted in the postprocessing step
                        List <Dictionary <string, string> > dataset = getDataset(registeredIndex);
                        // +1 because next row should be targetted for inserting a new cell
                        // the current row is only a placeholder row and was marked with "DEL" to delete it later
                        int rowNumber      = row.Row + 1;
                        int rowNumberBegin = rowNumber;

                        foreach (Dictionary <string, string> record in dataset)
                        {
                            //if (descriptionEntry.Access_Column_Name != null && descriptionEntry.Access_Column_Name.Contains("V_Dash") && worksheetName == "V dash & Security 101" && (rowNumber - 3) == 1) {
                            // only for debugging purposes
                            //Console.WriteLine("test...");
                            //}

                            ExcelCell currentCell = row.Where(cell => cell.Column == descriptionEntry.Column_Number).FirstOrDefault();
                            if (currentCell != null &&
                                currentCell.Tag != null &&
                                ((string)currentCell.Tag) == "DEL" &&
                                rowNumber == rowNumberBegin)
                            {
                                // the current cell is the first cell of the column / the first row
                                // the current cell was marked with "DEL" so it is a placeholder cell
                                // the current cell will be overritten and the "DEL" mark will be removed
                                // from the cell
                                currentCell.Tag   = null;
                                currentCell.Value = record.Exists(descriptionEntry.Access_Column_Name) ? record[descriptionEntry.Access_Column_Name].NotEmpty() ? record[descriptionEntry.Access_Column_Name] : "" : "";
                            }
                            else
                            {
                                ExcelRow nextRow = m_reportTable.WorkSheets[worksheetName][rowNumber];
                                if (nextRow != null)
                                {
                                    if (nextRow.RowName.NotEmpty())
                                    {
                                        // the next row has already a row name aka random string
                                        // aka placeholder cell marked with "DEL" --> not marked anymore
                                        // but still begin of a new row / new dataset
                                        // therefore it needs to be added a new row at the specified index
                                        if (nextRow.Where(cell => cell.Column == descriptionEntry.Column_Number).FirstOrDefault() == null)
                                        {
                                            // the next row had already got a name but the cell in the next row is still available
                                            reusePreviousRow(worksheetName, descriptionEntry, record, rowNumber);
                                        }
                                        else
                                        {
                                            // the next row had already got a name and the cell is also not available anymore
                                            addNewRowBetween(worksheetName, descriptionEntry, record, rowNumber);
                                        }
                                    }
                                    else
                                    {
                                        // a writable new row was already created in a previous loop run, so reuse that row
                                        reusePreviousRow(worksheetName, descriptionEntry, record, rowNumber);
                                    }
                                }
                                else
                                {
                                    // the end of the table was reached
                                    // so create a new row to the table
                                    int rowCount = m_reportTable.WorkSheets[worksheetName].Count;
                                    // check if the rowCount of the created table is larger then the last row index of the cell to be created
                                    // check also if the rowCount is larger or equal to the dataset count
                                    //
                                    if (rowCount > rowNumber - 1 &&
                                        rowCount - row.Row >= dataset.Count)
                                    {
                                        reusePreviousRow(worksheetName, descriptionEntry, record, rowNumber);
                                    }
                                    else
                                    {
                                        addNewRowToTheEnd(worksheetName, descriptionEntry, record, rowNumber);
                                    }
                                }
                            }
                            // increase the row number
                            ++rowNumber;
                        }
                        //m_reportTable.Insert(new ExcelRow(new List<ExcelCell>() { new ExcelCell() }), row.Row);
                    }
                }
            }
        }