コード例 #1
0
        public void UseTable_WithoutColumnDefinition_DefineOnce()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.DefineOnce);
            dynamic       row;

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            table.AddRow(row);

            row           = new ExpandoObject();
            row.FirstName = "Sarah";
            row.LastName  = "Meier";
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(3, table.Columns.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);

            row = table.Rows[1];
            Assert.AreEqual("Sarah", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(0, row.Age);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: lanicon/DynamicObjects
        static void Main(string[] args)
        {
            dynamic element = new ExpandoObject();

            element.FirstName = "John";
            element.LastName  = "Doe";
            element.Age       = 30;

            using (StreamWriter writer = new StreamWriter("test.csv"))
            {
                writer.Write(ExpandoObjectSerializer.AsCsv(element));
            }

            ImportElementCsvFile();



            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic       row;

            row           = new ExpandoObject();
            row.FirstName = "John";
            row.LastName  = "Doe";
            row.Age       = 30;
            table.AddRow(row);

            row           = new ExpandoObject();
            row.FirstName = "Jane";
            row.LastName  = "Doe";
            row.Street    = "Main street";
            table.AddRow(row);


            foreach (dynamic actualRow in table.Rows)
            {
                Console.WriteLine(
                    string.Format("{0} {1} is {2} years old.",
                                  actualRow.FirstName,
                                  actualRow.LastName,
                                  actualRow.Age));
            }


            using (StreamWriter writer = new StreamWriter("test.csv"))
            {
                writer.Write(table.AsCsv());
            }

            using (StreamWriter writer = new StreamWriter("test.xml"))
            {
                writer.Write(table.AsXml());
            }

            ImportTableCsvFile();

            Console.ReadKey();
        }
コード例 #3
0
        public void ExportAndImport_DataTable()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic       row;
            DataTable     data;

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            row.TimeStamp = new DateTime(2012, 12, 24, 1, 2, 3);
            table.AddRow(row);

            row          = new ExpandoObject();
            row.LastName = "Meier";
            row.Street   = "Main street";
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(5, table.Columns.Count);

            //export
            data = table.AsDataTable();

            //remove rows
            table.RemoveAllRows();
            Assert.AreEqual(0, table.Rows.Count);
            Assert.AreEqual(5, table.Columns.Count);

            //import
            table.FromDataTable(data);

            //compare
            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);

            Assert.AreEqual(2012, row.TimeStamp.Year);
            Assert.AreEqual(12, row.TimeStamp.Month);
            Assert.AreEqual(24, row.TimeStamp.Day);
            Assert.AreEqual(1, row.TimeStamp.Hour);
            Assert.AreEqual(2, row.TimeStamp.Minute);
            Assert.AreEqual(3, row.TimeStamp.Second);

            Assert.AreEqual(null, row.Street);

            row = table.Rows[1];
            Assert.AreEqual(null, row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(0, row.Age);
            Assert.AreEqual(0, row.TimeStamp.Ticks);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #4
0
        void ControlTreeDataLoader.LoadData()
        {
            CssClass = CssClass.ConcatenateWithSpace(CheckBoxListCssElementCreator.CssClass);

            var table = new DynamicTable {
                Caption = caption
            };

            if (includeSelectAndDeselectAllButtons)
            {
                table.AddActionLink(new ActionButtonSetup("Select All", new CustomButton(() => string.Format(@"toggleCheckBoxes( '{0}', true )", ClientID))));
                table.AddActionLink(new ActionButtonSetup("Deselect All", new CustomButton(() => string.Format(@"toggleCheckBoxes( '{0}', false )", ClientID))));
            }

            var itemsPerColumn = (int)Math.Ceiling((decimal)items.Count() / numberOfColumns);
            var cells          = new List <EwfTableCell>();

            for (byte i = 0; i < numberOfColumns; i += 1)
            {
                var maxIndex = Math.Min((i + 1) * itemsPerColumn, items.Count());
                var place    = new PlaceHolder();
                for (var j = i * itemsPerColumn; j < maxIndex; j += 1)
                {
                    var item     = items.ElementAt(j);
                    var checkBox = new BlockCheckBox(selectedItemIds.Contains(item.Id), label: item.Label, highlightWhenChecked: true, postBack: postBack);
                    place.Controls.Add(checkBox);
                    checkBoxesByItem.Add(item, checkBox);
                }
                cells.Add(place);
            }
            table.AddRow(cells.ToArray());
            Controls.Add(table);
        }
コード例 #5
0
        public void UseTable_PreDefinedColumns_Expandeable()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic       row;

            //set columns
            table.PreDefineColumns(
                new List <IDynamicTableColumn>()
            {
                new DynamicTableColumn <string>("FirstName", ""),
                new DynamicTableColumn <string>("LastName"),
                new DynamicTableColumn <int>("Age", -1)
            });

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            table.AddRow(row);

            row          = new ExpandoObject();
            row.LastName = "Meier";
            row.Street   = "Main street";
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(4, table.Columns.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);
            Assert.AreEqual(null, row.Street);

            row = table.Rows[1];
            Assert.AreEqual("", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(-1, row.Age);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #6
0
        public void UseTable_PreDefinedColumns_WellFormet()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.WellFormed);
            dynamic       row;

            //set columns
            table.PreDefineColumns(
                new List <IDynamicTableColumn>()
            {
                new DynamicTableColumn <string>("FirstName"),
                new DynamicTableColumn <string>("LastName"),
                new DynamicTableColumn <int>("Age", 100)
            });

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            table.AddRow(row);

            row           = new ExpandoObject();
            row.FirstName = "Sarah";
            row.LastName  = "Meier";
            row.Age       = 50;
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(3, table.Columns.Count);

            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);

            row = table.Rows[1];
            Assert.AreEqual("Sarah", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(50, row.Age);
        }
コード例 #7
0
        private DynamicTable buildTree( string name, IEnumerable<MergeRow> emptyRowTree )
        {
            var singleRow = emptyRowTree.Single();

            var table = new DynamicTable( new EwfTableColumn( "Field name" ), new EwfTableColumn( "Description" ) ) { Caption = name };
            foreach( var field in singleRow.Values )
                table.AddTextRow( getFieldNameCellText( field ), field.GetDescription() );

            foreach( var child in singleRow.Children ) {
                var panel = new Panel();
                panel.Style.Add( HtmlTextWriterStyle.MarginLeft, "2em" );
                panel.Controls.Add( buildTree( child.NodeName, child.Rows ) );

                table.AddRow( panel.ToCell( new TableCellSetup( fieldSpan: 2 ) ) );
            }

            return table;
        }
コード例 #8
0
        /// <summary>
        /// Creates a check box list.
        /// </summary>
        public EwfCheckBoxList(
            IEnumerable <SelectListItem <ItemIdType> > items, IEnumerable <ItemIdType> selectedItemIds, string caption = "", bool includeSelectAndDeselectAllButtons = false,
            byte numberOfColumns = 1, FormAction action = null)
        {
            this.items      = items.ToArray();
            selectedItemIds = selectedItemIds.ToArray();

            CssClass = CssClass.ConcatenateWithSpace(CheckBoxListCssElementCreator.CssClass);

            var table = new DynamicTable {
                Caption = caption
            };

            if (includeSelectAndDeselectAllButtons)
            {
                table.AddActionLink(new ActionButtonSetup("Select All", new CustomButton(() => string.Format(@"toggleCheckBoxes( '{0}', true )", ClientID))));
                table.AddActionLink(new ActionButtonSetup("Deselect All", new CustomButton(() => string.Format(@"toggleCheckBoxes( '{0}', false )", ClientID))));
            }

            var itemsPerColumn = (int)Math.Ceiling((decimal)this.items.Count() / numberOfColumns);
            var cells          = new List <EwfTableCell>();

            for (byte i = 0; i < numberOfColumns; i += 1)
            {
                var maxIndex = Math.Min((i + 1) * itemsPerColumn, this.items.Count());
                var place    = new PlaceHolder();
                for (var j = i * itemsPerColumn; j < maxIndex; j += 1)
                {
                    var item     = this.items.ElementAt(j);
                    var checkBox = new BlockCheckBox(
                        selectedItemIds.Contains(item.Id),
                        (postBackValue, validator) => { },
                        label: item.Label,
                        setup: new BlockCheckBoxSetup(highlightedWhenChecked: true, action: action));
                    place.Controls.Add(checkBox);
                    checkBoxesByItem.Add(item, checkBox);
                }
                cells.Add(place);
            }
            table.AddRow(cells.ToArray());
            Controls.Add(table);
        }
コード例 #9
0
        public void ExportAndImport_XML()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic       row;
            string        xmlExport;

            string fileName = _assemblyDirectory + @"\CsvTest.xml";

            //add values
            row           = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName  = "Mueller";
            row.Age       = 30;
            row.TimeStamp = new DateTime(2012, 12, 24, 1, 2, 3);
            table.AddRow(row);

            row          = new ExpandoObject();
            row.LastName = "Meier";
            row.Street   = "Main street";
            table.AddRow(row);

            //compare
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(5, table.Columns.Count);

            //export
            xmlExport = table.AsXml();

            using (StreamWriter writer = new StreamWriter(fileName))
            {
                writer.Write(xmlExport);
            }

            //remove rows
            table.RemoveAllRows();
            Assert.AreEqual(0, table.Rows.Count);
            Assert.AreEqual(5, table.Columns.Count);

            //import
            using (StreamReader reader = new StreamReader(fileName))
            {
                table.FromXml(ReadFile(reader));
            }

            //compare
            row = table.Rows[0];
            Assert.AreEqual("Hans", row.FirstName);
            Assert.AreEqual("Mueller", row.LastName);
            Assert.AreEqual(30, row.Age);

            Assert.AreEqual(2012, row.TimeStamp.Year);
            Assert.AreEqual(12, row.TimeStamp.Month);
            Assert.AreEqual(24, row.TimeStamp.Day);
            Assert.AreEqual(1, row.TimeStamp.Hour);
            Assert.AreEqual(2, row.TimeStamp.Minute);
            Assert.AreEqual(3, row.TimeStamp.Second);

            Assert.AreEqual("", row.Street);

            row = table.Rows[1];
            Assert.AreEqual("", row.FirstName);
            Assert.AreEqual("Meier", row.LastName);
            Assert.AreEqual(0, row.Age);
            Assert.AreEqual(0, row.TimeStamp.Ticks);
            Assert.AreEqual("Main street", row.Street);
        }
コード例 #10
0
        void ControlTreeDataLoader.LoadData()
        {
            var table = new DynamicTable { IsStandard = false };

            var controls = codeControls;
            if( HideIfEmpty && controls.Count == 0 ) {
                Visible = false;
                return;
            }
            var firstPassThroughRowLoop = true;
            for( var i = 0; i < controls.Count; i += NumberOfColumns ) {
                // spacer row
                if( !firstPassThroughRowLoop ) {
                    var spacerRowCount = SpacerCellSetup.RowSpacerCellCreator().Count;
                    for( var spacerRowIndex = 0; spacerRowIndex < spacerRowCount; spacerRowIndex += 1 ) {
                        var firstPassThroughSpacerRowColumnLoop = true;
                        var spacerRowCells = new List<EwfTableCell>();
                        for( var spacerRowColumnIndex = 0; spacerRowColumnIndex < NumberOfColumns; spacerRowColumnIndex += 1 ) {
                            if( !firstPassThroughSpacerRowColumnLoop )
                                spacerRowCells.AddRange( SpacerCellSetup.RowAndColumnSpacerCellCreator()[ spacerRowIndex ] );
                            spacerRowCells.Add( SpacerCellSetup.RowSpacerCellCreator()[ spacerRowIndex ] );
                            firstPassThroughSpacerRowColumnLoop = false;
                        }
                        table.AddRow( spacerRowCells.ToArray() );
                    }
                }

                // content row
                var firstPassThroughColumnLoop = true;
                var cells = new List<EwfTableCell>();
                for( var columnIndex = 0; columnIndex < NumberOfColumns; columnIndex += 1 ) {
                    // spacer cells
                    if( !firstPassThroughColumnLoop )
                        cells.AddRange( SpacerCellSetup.ColumnSpacerCellCreator() );

                    // content cell

                    if( firstPassThroughRowLoop && CaptionControl != null ) {
                        cells.Add( CaptionControl );
                        i -= NumberOfColumns;
                    }
                    else {
                        var controlIndex = i + columnIndex;
                        if( controlIndex < controls.Count )
                            cells.Add( controls[ controlIndex ] );
                        else
                            cells.Add( EmptyCellCreator() );
                    }
                    firstPassThroughColumnLoop = false;
                }
                table.AddRow( cells.ToArray() );

                firstPassThroughRowLoop = false;
            }

            Controls.Add( table );
        }
コード例 #11
0
        private void addFileRow( DynamicTable table, BlobFile file, ActionPostBack deletePb, List<Func<bool>> deleteModMethods )
        {
            var cells = new List<EwfTableCell>();

            var thumbnailControl = BlobFileOps.GetThumbnailControl( file, ThumbnailResourceInfoCreator );
            if( thumbnailControl != null )
                cells.Add( thumbnailControl );

            var fileIsUnread = fileIdsMarkedAsRead != null && !fileIdsMarkedAsRead.Contains( file.FileId );

            cells.Add(
                new PostBackButton(
                    PostBack.CreateFull(
                        id: PostBack.GetCompositeId( postBackIdBase, file.FileId.ToString() ),
                        firstModificationMethod: () => {
                            if( fileIsUnread && markFileAsReadMethod != null )
                                markFileAsReadMethod( file.FileId );
                        },
                        actionGetter: () => new PostBackAction( new SecondaryResponse( new BlobFileResponse( file.FileId, () => true ), false ) ) ),
                    new TextActionControlStyle( file.FileName ),
                    false ) { ToolTip = file.FileName } );

            cells.Add( file.UploadedDate.ToDayMonthYearString( false ) );
            cells.Add( ( fileIsUnread ? "New!" : "" ).ToCell( new TableCellSetup( classes: "ewfNewness".ToSingleElementArray() ) ) );

            var delete = false;
            var deleteCheckBox =
                FormItem.Create(
                    "",
                    new EwfCheckBox( false, postBack: deletePb ),
                    validationGetter: control => new EwfValidation( ( pbv, v ) => { delete = control.IsCheckedInPostBack( pbv ); }, deletePb ) ).ToControl();
            cells.Add( ReadOnly ? null : deleteCheckBox );
            deleteModMethods.Add(
                () => {
                    if( !delete )
                        return false;
                    BlobFileOps.SystemProvider.DeleteFile( file.FileId );
                    return true;
                } );

            table.AddRow( cells.ToArray() );
        }
コード例 #12
0
        void ControlTreeDataLoader.LoadData()
        {
            CssClass = CssClass.ConcatenateWithSpace( "ewfStandardFileCollectionManager" );

            if( AppRequestState.Instance.Browser.IsInternetExplorer() ) {
                base.Controls.Add(
                    new HtmlGenericControl( "p" )
                        {
                            InnerText =
                                "Because you are using Internet Explorer, clicking on a file below will result in a yellow warning bar appearing near the top of the browser.  You will need to then click the warning bar and tell Internet Explorer you are sure you want to download the file."
                        } );
            }

            var columnSetups = new List<ColumnSetup>();
            if( ThumbnailResourceInfoCreator != null )
                columnSetups.Add( new ColumnSetup { Width = Unit.Percentage( 10 ) } );
            columnSetups.Add( new ColumnSetup { CssClassOnAllCells = "ewfOverflowedCell" } );
            columnSetups.Add( new ColumnSetup { Width = Unit.Percentage( 13 ) } );
            columnSetups.Add( new ColumnSetup { Width = Unit.Percentage( 7 ) } );
            columnSetups.Add( new ColumnSetup { Width = Unit.Percentage( 23 ), CssClassOnAllCells = "ewfRightAlignCell" } );

            var table = new DynamicTable( columnSetups.ToArray() ) { Caption = Caption };

            files = BlobFileOps.SystemProvider.GetFilesLinkedToFileCollection( fileCollectionId );
            files = ( sortByName ? files.OrderByName() : files.OrderByUploadedDateDescending() ).ToArray();

            var deletePb = PostBack.CreateFull( id: PostBack.GetCompositeId( postBackIdBase, "delete" ) );
            var deleteModMethods = new List<Func<bool>>();
            foreach( var file in files )
                addFileRow( table, file, deletePb, deleteModMethods );
            if( !ReadOnly ) {
                table.AddRow(
                    getUploadControlList().ToCell( new TableCellSetup( fieldSpan: ThumbnailResourceInfoCreator != null ? 3 : 2 ) ),
                    ( files.Any() ? new PostBackButton( deletePb, new ButtonActionControlStyle( "Delete Selected Files" ), usesSubmitBehavior: false ) : null ).ToCell(
                        new TableCellSetup( fieldSpan: 2, classes: "ewfRightAlignCell".ToSingleElementArray() ) ) );
            }
            deletePb.AddModificationMethod(
                () => {
                    if( deleteModMethods.Aggregate( false, ( deletesOccurred, method ) => method() || deletesOccurred ) )
                        EwfPage.AddStatusMessage( StatusMessageType.Info, "Selected files deleted successfully." );
                } );

            Controls.Add( table );

            if( ReadOnly && !files.Any() )
                Visible = false;
        }
コード例 #13
0
        private void buildNavigationBox()
        {
            var jumpList =
                SelectList.CreateDropDown(
                    from i in Enumerable.Range( -3, 7 ) select SelectListItem.Create( i, formatDateTimeForJumpList( adjustDateByNumberOfIntervals( date, i ) ) ),
                    0,
                    autoPostBack: true );
            jumpList.Width = JumpListWidth;
            var numIntervals = 0;
            EwfPage.Instance.DataUpdate.AddTopValidationMethod( ( pbv, validator ) => numIntervals = jumpList.ValidateAndGetSelectedItemIdInPostBack( pbv, validator ) );
            EwfPage.Instance.DataUpdate.AddModificationMethod( () => dateModificationMethod( adjustDateByNumberOfIntervals( date, numIntervals ) ) );

            var previousLink =
                new PostBackButton(
                    PostBack.CreateFull( id: "prev", firstModificationMethod: () => dateModificationMethod( adjustDateByNumberOfIntervals( date, -1 ) ) ),
                    PreviousButton,
                    usesSubmitBehavior: false );
            var todayLink = new PostBackButton(
                PostBack.CreateFull( id: "today", firstModificationMethod: () => dateModificationMethod( DateTime.Today ) ),
                CurrentDateButton,
                usesSubmitBehavior: false );
            var nextLink =
                new PostBackButton(
                    PostBack.CreateFull( id: "next", firstModificationMethod: () => dateModificationMethod( adjustDateByNumberOfIntervals( date, 1 ) ) ),
                    NextButton,
                    usesSubmitBehavior: false );

            var table = new DynamicTable { CssClass = "calendarViewHeader ewfNavigationBoxHeader", IsStandard = false };
            var navControls = new Panel();
            foreach( var postBackButton in new List<PostBackButton> { previousLink, todayLink, nextLink } )
                navControls.Controls.Add( postBackButton );

            table.AddRow( jumpList, navControls.ToCell( new TableCellSetup( classes: "calendarViewNavButtons".ToSingleElementArray() ) ) );
            Controls.Add( table );
        }