Ejemplo n.º 1
0
        public void Dispose()
        {
            if (Refs > 0)
            {
                Refs--;
                return;
            }
            if (FDataSource != null)
            {
                FDataSource.Dispose();
            }
            if (Rows != null)
            {
                foreach (TOneRowValue r in Rows)
                {
                    if (r != null)
                    {
                        r.Dispose();
                    }
                }
            }

            if (Images != null)
            {
                Images.Dispose();
            }

            for (int i = 0; i < DetailBands.Count; i++)
            {
                TBand db = DetailBands[i];
                db.Dispose();
            }
            GC.SuppressFinalize(this);
        }
Ejemplo n.º 2
0
 internal TBand(TFlexCelDataSource aDataSource, TBand aMasterBand, TXlsCellRange aCellRange,
                string aName, TBandType aBandType, bool aDeleteLastRow, string aDataSourceName) :
     this(aDataSource, aMasterBand, aMasterBand, aCellRange, aName, aBandType, aDeleteLastRow, aDataSourceName)
 {
     //On an normal band, Searchband=Masterband. The only case this doesn't happen is on Sheet bands,
     //where we search on all other sheets but they are not in master/detail relationship.
 }
Ejemplo n.º 3
0
        internal override void Execute(ExcelFile Workbook, TWaitingCoords Coords, TBand Band)
        {
            int t, l, b, r;

            GetBounds(Coords, out t, out l, out b, out r);

            int fr = Math.Min(t, b);
            int fc = Math.Min(l, r);
            int lr = Math.Max(t, b);
            int lc = Math.Max(l, r);

            TValueAndXF val = new TValueAndXF();

            val.Workbook = Workbook;
            XFDef.Evaluate(0, 0, 0, 0, val);
            TConfigFormat fmt = FormatList.GetValue(FlxConvert.ToString(val.Value));

            if (fmt.ApplyFmt == null)
            {
                Workbook.SetCellFormat(fr, fc, lr, lc, fmt.XF);
            }
            else
            {
                Workbook.SetCellFormat(fr, fc, lr, lc, Workbook.GetFormat(fmt.XF), fmt.ApplyFmt, fmt.ExteriorBorders);
            }
        }
Ejemplo n.º 4
0
        internal override void Execute(ExcelFile Workbook, TWaitingCoords Coords, TBand Band)
        {
            int t, l, b, r;

            GetBounds(Coords, out t, out l, out b, out r);
            TXlsCellRange rangeToDelete = new TXlsCellRange(t, l, b, r);

            if (Sheet1 <= 0 || Sheet2 <= 0)
            {
                Workbook.DeleteRange(rangeToDelete, InsertMode);
            }
            else
            {
                Workbook.DeleteRange(Sheet1, Sheet2, rangeToDelete, InsertMode);
            }

            if (Sheet1 <= 0 || Sheet2 <= 0 || (Sheet1 <= Workbook.ActiveSheet && Sheet2 >= Workbook.ActiveSheet))
            {
                if (Band != null)
                {
                    if (InsertMode == TFlxInsertMode.ShiftRangeDown || InsertMode == TFlxInsertMode.ShiftRowDown)
                    {
                        Band.AddTmpExpandedRows(-rangeToDelete.RowCount, Left + Coords.ColOfs, Left + Coords.ColOfs + rangeToDelete.ColCount);
                        Band.TmpPartialRows += -rangeToDelete.RowCount;
                    }
                    else if (InsertMode == TFlxInsertMode.ShiftColRight || InsertMode == TFlxInsertMode.ShiftRangeRight)
                    {
                        Band.AddTmpExpandedCols(-rangeToDelete.ColCount, Top + Coords.RowOfs, Top + Coords.RowOfs + rangeToDelete.RowCount);
                        Band.TmpPartialCols += -rangeToDelete.ColCount;
                    }
                }
            }
        }
Ejemplo n.º 5
0
 internal TFormulaConvertTextWithTagsToInternal(ExcelFile aXls, string aFormulaText, TBand aCurrentBand, FlexCelReport afr, TStackData aStack) :
     base(aXls, aXls.ActiveSheet, false, aFormulaText, true)
 {
     MaxFormulaLen = 0xFFFF;
     CurrentBand   = aCurrentBand;
     fr            = afr;
     Stack         = aStack;
 }
Ejemplo n.º 6
0
        internal TRPNExpression(string Condition, ExcelFile Xls, TBand CurrentBand, FlexCelReport fr, TStackData Stack)
        {
            if (Condition != null && !Condition.StartsWith(TFormulaMessages.TokenString(TFormulaToken.fmStartFormula)))
            {
                Condition = TFormulaMessages.TokenString(TFormulaToken.fmStartFormula) + Condition;
            }

            TFormulaConvertTextWithTagsToInternal Parser = new TFormulaConvertTextWithTagsToInternal(Xls, Condition, CurrentBand, fr, Stack);

            wi = new TWorkbookInfo(Xls, Xls.ActiveSheet, 0, 0, 0, 0, 0, 0, false);
            Parser.Parse();
            Fmla = Parser.GetTokens();
        }
Ejemplo n.º 7
0
        public void Dispose()
        {
            if (MainBand != null)
            {
                MainBand.Dispose();
            }
            if (Report != null)
            {
                Report.Unload();
#if (!COMPACTFRAMEWORK)
                ((IDisposable)Report).Dispose();
#endif
            }
            Report   = null;
            MainBand = null;

            GC.SuppressFinalize(this);
        }
Ejemplo n.º 8
0
        public TFlexCelDataSource(string dtName, VirtualDataTable aData, TRelationshipList ExtraRelations, TRelationshipList StaticRelations,
                                  TBand MasterBand, string Sort, IDataTableFinder TableFinder)
        {
            SplitLink = null;

            TBand band = MasterBand;
            TMasterDetailLinkList MasterDetailLinkList = new TMasterDetailLinkList();

            while (band != null)
            {
                if (band.DataSource != null)
                {
                    TRelation RelToMaster = band.DataSource.Data.GetRelationWith(aData);
                    if (RelToMaster != null)
                    {
                        MasterDetailLinkList.AddRelation(band.DataSource.DataState, RelToMaster);
                    }

                    //Create the splitlink.
                    TMasterSplitDataTableState SplitMaster = band.DataSource.DataState as TMasterSplitDataTableState;
                    if (SplitMaster != null && String.Equals(SplitMaster.DetailName, dtName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (SplitLink != null)
                        {
                            FlxMessages.ThrowException(FlxErr.ErrSplitNeedsOnlyOneMaster, dtName, SplitMaster.TableName, SplitLink.ParentDataSource.TableName);
                        }
                        SplitLink = new TSplitLink(SplitMaster, SplitMaster.SplitCount);
                    }

                    AddExtraRelationships(TableFinder, aData, ExtraRelations, band, MasterDetailLinkList);
                    AddExtraRelationships(TableFinder, aData, StaticRelations, band, MasterDetailLinkList);
                }
                band = band.MasterBand;
            }

            MasterDetailLinks = MasterDetailLinkList.ToArray();

            Data                 = aData;
            DataState            = aData.CreateState(Sort, MasterDetailLinks, SplitLink);
            DataState.FTableName = dtName;
            FName                = dtName;
        }
Ejemplo n.º 9
0
        private void DoPreload(TBand aParentBand, string aRange, string aFileName, TDataSourceInfoList aDsInfoList, int aNestedLevel, ExcelFile Result, MemoryStream MStream, FlexCelReport aParentReport)
        {
            Result.Open(MStream);
            Result.ActiveFileName = aFileName;

            TXlsNamedRange XlsRange = Result.GetNamedRange(aRange, -1);

            if (XlsRange == null)
            {
                FlxMessages.ThrowException(FlxErr.ErrCantFindNamedRange, aRange);
            }
            FRangeName = aRange;
            MainBand   = CreateStartingBand(XlsRange, aParentBand, aRange);
            Report     = new FlexCelReport(aNestedLevel, FTagText, aDsInfoList, aParentReport);
            if (!StaticInclude)
            {
                Report.PreLoad(Result, ref MainBand, XlsRange.SheetIndex, ref FData, out KeepRows, out KeepCols);
            }
            Result.ActiveSheet = XlsRange.SheetIndex;
        }
Ejemplo n.º 10
0
 internal TBand(TFlexCelDataSource aDataSource, TBand aMasterBand, TBand aSearchBand,
                TXlsCellRange aCellRange, string aName, TBandType aBandType, bool aDeleteLastRow, string aDataSourceName)
 {
     FDataSource  = aDataSource;
     FMasterBand  = aMasterBand;
     FSearchBand  = aSearchBand;
     FDetailBands = new TBandList();
     if (aCellRange != null)
     {
         FCellRange = (TXlsCellRange)aCellRange.Clone();
     }
     else
     {
         FCellRange = null;
     }
     FBandType       = aBandType;
     FName           = aName;
     FDataSourceName = aDataSourceName;
     FDeleteLastRow  = aDeleteLastRow;
 }
Ejemplo n.º 11
0
        internal static VirtualDataTable FindLinkedTable(TBand MasterBand, string Name, VirtualDataTable Table)
        {
            TBand band = MasterBand;

            while (band != null)
            {
                if (band.DataSource != null)
                {
                    VirtualDataTable vt = band.DataSource.GetDetail(Name, Table);
                    {
                        if (vt != null)
                        {
                            return(vt);
                        }
                    }
                }
                band = band.MasterBand;
            }
            return(Table);
        }
Ejemplo n.º 12
0
        internal TInclude(byte[] aData, string aRange, TBandType aBandType, TBand aParentBand,
                          string aTagText, int aNestedLevel, TDataSourceInfoList aDsInfoList, string aFileName, bool aStaticInclude, FlexCelReport aParentReport)
        {
            try
            {
                FData = new byte[aData.Length];
                Array.Copy(aData, 0, FData, 0, FData.Length);
                FBandType     = aBandType;
                FTagText      = aTagText;
                StaticInclude = aStaticInclude;

                //Preloading at read time has the advantage of fully checking the template on load,
                //so errors will be detected sooner. (If an include is conditional, might not be detected until much later)
                //For this same reason it is a little slower than preloading on demand, but it is worth.
                Preload(aParentBand, aRange, aFileName, aDsInfoList, aNestedLevel, aParentReport);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Ejemplo n.º 13
0
        private void Preload(TBand aParentBand, string aRange, string aFileName, TDataSourceInfoList aDsInfoList, int aNestedLevel, FlexCelReport aParentReport)
        {
            ExcelFile Result = new XlsAdapter.XlsFile();

            using (MemoryStream MStream = new MemoryStream(FData))
            {
                MStream.Position = 0;
                if (aNestedLevel > 1)
                {
                    DoPreload(aParentBand, aRange, aFileName, aDsInfoList, aNestedLevel, Result, MStream, aParentReport);
                }
                else
                {
                    try //We only catch a level 1 include. if not, we would end up with a nested message.
                    {
                        DoPreload(aParentBand, aRange, aFileName, aDsInfoList, aNestedLevel, Result, MStream, aParentReport);
                    }
                    catch (Exception e)
                    {
                        FlxMessages.ThrowException(e, FlxErr.ErrOnIncludeReport, FTagText, e.Message);
                    }
                }
            }
        }
Ejemplo n.º 14
0
 internal override void Execute(ExcelFile Workbook, TWaitingCoords Coords, TBand Band)
 {
     Workbook.DeleteRange(new TXlsCellRange(Top + Coords.RowOfs, Left + Coords.ColOfs, LastRow + Coords.RowOfs, Left + Coords.ColOfs), TFlxInsertMode.ShiftRangeRight);
     Band.AddTmpExpandedCols(-1, Top + Coords.RowOfs, LastRow + Coords.RowOfs);
     Band.TmpPartialCols -= 1;
 }
Ejemplo n.º 15
0
        internal override void Execute(ExcelFile Workbook, TWaitingCoords Coords, TBand Band)
        {
            ExcelFile IncludedReport = FInclude.Run();
            //Workbook.InsertAndCopyRange(IncludedReport.GetNamedRange(FInclude.RangeName, IncludedReport.ActiveSheet),
            //    Top+RowOfs, Left+ColOfs, 1, InsertMode , TRangeCopyMode.All,  IncludedReport, IncludedReport.ActiveSheet);

            //This is to avoid inserting one row more on the include.
            TXlsNamedRange range = IncludedReport.GetNamedRange(FInclude.RangeName, IncludedReport.ActiveSheet);

            //We don't want to copy he full range even if using "__". Just *insert* the full range
            //if (InsertMode == TFlxInsertMode.ShiftRowDown) {range.Left = 1; range.Right = FlxConsts.Max_Columns + 1;}
            //if (InsertMode == TFlxInsertMode.ShiftColRight) {range.Top = 1; range.Bottom = FlxConsts.Max_Rows + 1;}

            if (InsertMode == TFlxInsertMode.ShiftColRight || InsertMode == TFlxInsertMode.ShiftRangeRight)
            {
                TXlsCellRange rangeToInsert = new TXlsCellRange(range.Top, range.Left, range.Bottom, range.Right - 1);
                if (InsertMode == TFlxInsertMode.ShiftColRight)
                {
                    rangeToInsert.Top = 1; rangeToInsert.Bottom = FlxConsts.Max_Rows + 1;
                }

                if (range.Left > range.Right)
                {
                }  // not possible. Workbook.DeleteRange();
                else if (range.Left < range.Right)
                {
                    int CopyTop = Top + Coords.RowOfs;
                    if (InsertMode == TFlxInsertMode.ShiftColRight)
                    {
                        CopyTop = 1;
                    }

                    Workbook.InsertAndCopyRange(rangeToInsert, CopyTop, Left + Coords.ColOfs, 1, InsertMode, TRangeCopyMode.None);
                    if (Band != null)
                    {
                        Band.AddTmpExpandedCols(rangeToInsert.ColCount, Top + Coords.RowOfs, Top + Coords.RowOfs + rangeToInsert.RowCount);
                        Band.TmpPartialCols += rangeToInsert.ColCount;
                    }
                }

                CopyRowAndColFormat(Workbook, Coords, IncludedReport, range);

                if (range.Left <= range.Right)
                {
                    Workbook.InsertAndCopyRange(range, Top + Coords.RowOfs, Left + Coords.ColOfs, 1, TFlxInsertMode.NoneRight, TRangeCopyMode.AllIncludingDontMoveAndSizeObjects, IncludedReport, IncludedReport.ActiveSheet);
                }
            }
            else
            {
                TXlsCellRange rangeToInsert = new TXlsCellRange(range.Top, range.Left, range.Bottom - 1, range.Right);
                if (InsertMode == TFlxInsertMode.ShiftRowDown)
                {
                    rangeToInsert.Left = 1; rangeToInsert.Right = FlxConsts.Max_Columns + 1;
                }

                if (range.Top > range.Bottom)
                {
                }  // not possible. Workbook.DeleteRange();
                else if (range.Top < range.Bottom)
                {
                    int CopyLeft = Left + Coords.ColOfs;
                    if (InsertMode == TFlxInsertMode.ShiftRowDown)
                    {
                        CopyLeft = 1;
                    }

                    Workbook.InsertAndCopyRange(rangeToInsert, Top + Coords.RowOfs, CopyLeft, 1, InsertMode, TRangeCopyMode.None);
                    if (Band != null)
                    {
                        Band.AddTmpExpandedRows(rangeToInsert.RowCount, Left + Coords.ColOfs, Left + Coords.ColOfs + rangeToInsert.ColCount);
                        Band.TmpPartialRows += rangeToInsert.RowCount;
                    }
                }

                CopyRowAndColFormat(Workbook, Coords, IncludedReport, range);

                if (range.Top <= range.Bottom)
                {
                    Workbook.InsertAndCopyRange(range, Top + Coords.RowOfs, Left + Coords.ColOfs, 1, TFlxInsertMode.NoneDown, TRangeCopyMode.AllIncludingDontMoveAndSizeObjects, IncludedReport, IncludedReport.ActiveSheet);
                }
            }
        }
Ejemplo n.º 16
0
 internal abstract void Execute(ExcelFile Workbook, TWaitingCoords Coords, TBand Band);
Ejemplo n.º 17
0
 private static TBand CreateStartingBand(TXlsCellRange XlsRange, TBand aParentBand, string aRange)
 {
     return(new TBand(null, aParentBand, XlsRange, aRange, TBandType.Static, false, String.Empty));
 }
Ejemplo n.º 18
0
        private static void AddExtraRelationships(IDataTableFinder TableFinder, VirtualDataTable aData, TRelationshipList Relations, TBand band, TMasterDetailLinkList MasterDetailLinkList)
        {
            foreach (TRelationship tr in Relations)
            {
                TDataSourceInfo dParent = TableFinder.TryGetDataTable(tr.ParentTable);
                if (dParent == null || dParent.Table == null)
                {
                    FlxMessages.ThrowException(FlxErr.ErrInvalidManualRelationshipDatasetNull, tr.ParentTable);
                }

                TDataSourceInfo dChild = TableFinder.TryGetDataTable(tr.ChildTable);
                if (dChild == null || dChild.Table == null)
                {
                    FlxMessages.ThrowException(FlxErr.ErrInvalidManualRelationshipDatasetNull, tr.ChildTable);
                }

                if (SameTable(dChild.Table, aData) && SameTable(dParent.Table, band.DataSource.Data))
                {
                    GetColIndexes(dParent.Table, tr.ParentColumns, true); //we do it here so it checks all columns exist in the parent. They might not exist in our table, and that is ok if our table is a distinct for example)
                    GetColIndexes(dChild.Table, tr.ChildColumns, true);
                    int[] ChildCols  = GetColIndexes(aData, tr.ChildColumns, false);
                    int[] ParentCols = GetColIndexes(band.DataSource.Data, tr.ParentColumns, false);

                    if (ChildCols != null && ParentCols != null)
                    {
                        MasterDetailLinkList.AddRelation(band.DataSource.DataState,
                                                         new TRelation(band.DataSource.Data, aData, ParentCols,
                                                                       ChildCols));
                    }
                }
            }
        }
Ejemplo n.º 19
0
        internal TFlexCelDataSource CreateDataSource(TBand MasterBand, TRelationshipList ExtraRelations, TRelationshipList StaticRelations)
        {
            VirtualDataTable LinkedTable = FindLinkedTable(MasterBand, Name, FTable);

            return(new TFlexCelDataSource(LinkedTable.TableName, LinkedTable, ExtraRelations, StaticRelations, MasterBand, FSort, TableFinder));
        }
Ejemplo n.º 20
0
 internal void Add(TBand a)
 {
     FList.Add(a);
 }