예제 #1
0
        void InitSheet(WorkbookTracking w)
        {
            var t = queryReader.GetSchemaTable();

            if (t != null)
            {
                pts.CreateSheet(queryReader.CurrentResult
                                , w.SheetSubCount
                                , retrieveSheetName(queryReader.CurrentResult, w.SheetSubCount)
                                , queryReader.GetSchemaTable().Rows
                                );
                w.WorksheetOpen = true;
            }
        }
예제 #2
0
        void WriteARow(WorkbookTracking w)
        {
            if (w.RowCount > 0 && w.RowCount % runParameters.MaxRowsPerSheet == 0)
            {
                w.Status = WorkBookStatus.BreakWanted;
            }

            if (w.PreviousAndCurrentRowKeyColumns.PreviousDiffersFromCurrent)
            {
                if (w.Status == WorkBookStatus.BreakWanted)
                {
                    pts.CloseSheet();
                    w.SheetSubCount++;
                    w.WorksheetOpen = false;
                    w.RowCount      = 0;
                    InitSheet(w);
                    w.Status = WorkBookStatus.BreakCompleted;
                }
                else if (pts.FileSize >= runParameters.MaxWorkBookSize)
                {
                    w.Status = WorkBookStatus.OverSize;
                    return;
                }
                else
                {
                    w.Status = WorkBookStatus.Pending;
                }
            }
            else
            {
                w.Status = WorkBookStatus.Pending;
            }

            pts.WriteRow(queryReader, runParameters.DupeKeysToDelayStartingNewWorksheet);
            w.RowCount++;
        }
예제 #3
0
        void DetermineIfRowDependsOnPreviousRow(WorkbookTracking w)
        {
            w.PreviousAndCurrentRowKeyColumns.CurrentRowDupKey = pts.ReadKeyValues(queryReader, runParameters.DupeKeysToDelayStartingNewWorksheet);

            // first time through, set these values equal
            if (w.RowCount == 1)
            {
                w.PreviousAndCurrentRowKeyColumns.PrevDupKey = w.PreviousAndCurrentRowKeyColumns.CurrentRowDupKey;
            }
            // otherwise, if the values in the key columns are identical to previous row, then the desire is to keep them together
            // i.e., cannot split to another sheet or workbook between these rows
            if (w.PreviousAndCurrentRowKeyColumns.CurrentRowDupKey != null & w.PreviousAndCurrentRowKeyColumns.PrevDupKey != null)
            {
                for (int i = 0; i < w.PreviousAndCurrentRowKeyColumns.CurrentRowDupKey.Length; i++)
                {
                    if (string.Equals(w.PreviousAndCurrentRowKeyColumns.CurrentRowDupKey[i], w.PreviousAndCurrentRowKeyColumns.PrevDupKey[i], StringComparison.InvariantCulture))
                    {
                        w.PreviousAndCurrentRowKeyColumns.PreviousDiffersFromCurrent = false;
                    }
                    else
                    {
                        w.PreviousAndCurrentRowKeyColumns.PreviousDiffersFromCurrent = true;
                        break;
                    }
                }
            }
            else
            {
                w.PreviousAndCurrentRowKeyColumns.PreviousDiffersFromCurrent = true;
            }

            // set the prevDupKey for next cycle
            w.PreviousAndCurrentRowKeyColumns.PrevDupKey = w.PreviousAndCurrentRowKeyColumns.CurrentRowDupKey;

            //return w.keyColumnStatus;
        }
예제 #4
0
        /// <summary>
        /// Writes the results.
        /// </summary>
        /// <returns>The results.</returns>
        /// <param name="path">Path.</param>
        WorkBookStatus WriteResults(Stream path)
        {
            if (!queryRan)
            {
                throw new WorkbookNotStartedException();
            }

            switch (runParameters.BackendMethod)
            {
            case ExcelBackend.Xlsx:
                pts = new XlsxParts(path);
                break;

            // FIXME this isnt an xml backend
            case ExcelBackend.Xml:
                pts = new XlsxParts(path);
                break;

            default:
                pts = new XlsxParts(path);
                break;
            }

            WorkbookTracking w = new WorkbookTracking();

            // start to keep track of the result sets
            int resultSetTotal = 1;

            // loop through the result sets and write the results
            while (queryReader.MoveToNextResultSet())
            {
                // if this result set is over the max results per workbook, close this one and indicate a break has happened
                if (resultSetTotal > runParameters.MaximumResultSetsPerWorkbook)
                {
                    OnSave("Saving incremental result...");
                    pts.Close();
                    return(WorkBookStatus.BreakCompleted);
                }

                resultSetTotal++;

                // write empty columns if requested
                if (runParameters.WriteEmptyResultSetColumns)
                {
                    InitSheet(w);
                }

                // loop through all result sets
                while (queryReader.MoveNext())
                {
                    if (!w.WorksheetOpen)
                    {
                        InitSheet(w);
                    }
                    if (w.WorksheetOpen)
                    {
                        this.DetermineIfRowDependsOnPreviousRow(w);
                        queryReader.Reset();

                        // write the row, or determine why we couldn't write the row
                        WriteARow(w);

                        // if we're over-size, we must return now
                        // but keep the query open bc the caller may request to write the rest of the results
                        if (w.Status == WorkBookStatus.OverSize)
                        {
                            OnSave("Saving incremental result...");
                            if (w.WorksheetOpen)
                            {
                                pts.CloseSheet();
                            }
                            pts.Close();
                            return(w.Status);
                        }
                    }
                }

                if (w.WorksheetOpen)
                {
                    pts.CloseSheet();
                    w.WorksheetOpen = false;
                    w.RowCount      = 0;
                }
            }

            OnSave("Saving final result...");
            pts.Close();
            QueryClose();
            return(WorkBookStatus.Completed);
        }