Example #1
0
	void Awake ()
	{
		if (Instance != null && Instance != this)
		{
			Destroy(gameObject);
		}
		Instance = this;

		DontDestroyOnLoad(gameObject);

		startTime = Time.time;

		Tasks = Resources.Load<TasksResource>("Tasks");

		Grid = new GridDefinition();

		ClockGO = GameObject.Find("Time");
		ClockText = ClockGO.GetComponent<TextMesh>();
		DayGO = GameObject.Find("Day");
		DayText = DayGO.GetComponent<TextMesh>();
		TimeBarGO = GameObject.Find("TimeBar");

		scoreText = ScoreObject.GetComponent<UnityEngine.UI.Text>();
		highScoreText = HighScoreObject.GetComponent<UnityEngine.UI.Text>();
		completedTasksText = CompletedTasksObject.GetComponent<UnityEngine.UI.Text>();

		highScore = ReadHighScore();

		highScoreText.text = "High Score: " + highScore.ToString();

		lastSpawnTime = 0.0f;
	}
        public void if_no_explicit_sort_use_the_first_column_if_the_first_column_is_a_view_link()
        {
            var definition = new GridDefinition<Case>();
            definition.ShowViewLink(x => x.Condition);

            definition.SortBy.FieldName.ShouldEqual("Condition");
            definition.SortBy.IsAscending.ShouldBeTrue();
        }
        public void explicit_default_sort()
        {
            var definition = new GridDefinition<Case>();
            definition.ShowViewLink(x => x.Condition);
            definition.SortBy = SortRule<Case>.Descending(x => x.Created);

            definition.SortBy.FieldName.ShouldEqual("Created");
            definition.SortBy.IsAscending.ShouldBeFalse();
        }
        public void Case_03()
        {
            var grid = new GridDefinition
            {
                RowDefinitions = new List <RowDefinition>
                {
                    new RowDefinition {
                        HeightType = HeightType.Fixed, Height = 1
                    },
                    new RowDefinition {
                        HeightType = HeightType.Fixed, Height = 1
                    }
                },
                ColumnDefinitions = new List <ColumnDefinition>
                {
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    }
                },
                CellDefinitions = new List <CellDefinition>
                {
                    new CellDefinition
                    {
                        Row             = 0,
                        Column          = 0,
                        Value           = "Lorem Ipsum!",
                        HorizontalAlign = HorizontalAlign.Right,
                        Border          = BorderDefinition.Empty
                    },
                    new CellDefinition
                    {
                        Row             = 1,
                        Column          = 0,
                        Value           = "Dolor!",
                        HorizontalAlign = HorizontalAlign.Center,
                        Border          = BorderDefinition.Empty
                    },

                    new CellDefinition
                    {
                        Row             = 0,
                        Column          = 1,
                        Value           = "Lorem Ipsum!",
                        HorizontalAlign = HorizontalAlign.Right,
                        Border          = BorderDefinition.Empty
                    },
                    new CellDefinition
                    {
                        Row             = 1,
                        Column          = 1,
                        Value           = "Dolor!",
                        HorizontalAlign = HorizontalAlign.Center,
                        Border          = BorderDefinition.Empty
                    }
                }
            };

            var gridRender = new GridRender(grid);
            var actual     = gridRender.Render(40);

            var expected =
                "         Lorem Ipsum        Lorem Ipsum!" + Environment.NewLine +
                "       Dolor!              Dolor!       ";

            Assert.AreEqual(expected, actual);
        }
        public void Case_06()
        {
            var grid = new GridDefinition
            {
                RowDefinitions = new List <RowDefinition>
                {
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    }
                },
                ColumnDefinitions = new List <ColumnDefinition>
                {
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Fixed, Width = 8
                    }
                }
            };

            grid
            .AddCell("Produto", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Valor", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Qtd.", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Total", horizontalAlign: HorizontalAlign.Center);

            grid
            .AddCell("Refeição", horizontalAlign: HorizontalAlign.Right, verticalAlign: VerticalAlign.Middle)
            .AddCell("R$ 44,90")
            .AddCell("0,000 kg")
            .AddCell("R$ 167.008,89");

            grid
            .AddCell("Refrigerantes")
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            grid
            .AddCell("Sucos")
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            grid
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            var gridRender = new GridRender(grid);

            var actual = gridRender.Render(57);

            var expected =
                "+----------------------------+--------+--------+--------+" + Environment.NewLine +
                "|          Produto           | Valor  |  Qtd.  | Total  |" + Environment.NewLine +
                "+----------------------------+--------+--------+--------+" + Environment.NewLine +
                "|                            |R$ 44,90|0,000 kg|R$      |" + Environment.NewLine +
                "|                    Refeição|        |        |167.008,|" + Environment.NewLine +
                "|                            |        |        |89      |" + Environment.NewLine +
                "+----------------------------+--------+--------+--------+" + Environment.NewLine +
                "|Refrigerantes               |        |        |        |" + Environment.NewLine +
                "+----------------------------+--------+--------+--------+" + Environment.NewLine +
                "|Sucos                       |        |        |        |" + Environment.NewLine +
                "+----------------------------+--------+--------+--------+" + Environment.NewLine +
                "|                            |        |        |        |" + Environment.NewLine +
                "+----------------------------+--------+--------+--------+";

            Assert.AreEqual(expected, actual);
        }
        public void Case_04()
        {
            var grid = new GridDefinition
            {
                RowDefinitions = new List <RowDefinition>
                {
                    new RowDefinition {
                        HeightType = HeightType.Fixed, Height = 1
                    },
                    new RowDefinition {
                        HeightType = HeightType.Fixed, Height = 1
                    }
                },
                ColumnDefinitions = new List <ColumnDefinition>
                {
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    }
                },
                CellDefinitions = new List <CellDefinition>
                {
                    new CellDefinition
                    {
                        Row             = 0,
                        Column          = 0,
                        Value           = "Lorem Ipsum!",
                        HorizontalAlign = HorizontalAlign.Right
                    },
                    new CellDefinition
                    {
                        Row             = 1,
                        Column          = 0,
                        Value           = "Dolor!",
                        HorizontalAlign = HorizontalAlign.Center
                    },

                    new CellDefinition
                    {
                        Row             = 0,
                        Column          = 1,
                        Value           = "Lorem Ipsum!",
                        HorizontalAlign = HorizontalAlign.Right
                    },
                    new CellDefinition
                    {
                        Row             = 1,
                        Column          = 1,
                        Value           = "Dolor!",
                        HorizontalAlign = HorizontalAlign.Center
                    }
                }
            };

            var gridRender = new GridRender(grid);

            gridRender.AddStyle(new InsideBordersStyle());

            var actual = gridRender.Render(40);

            var expected =
                "        Lorem Ipsum!|       Lorem Ipsum!" + Environment.NewLine +
                "--------------------+-------------------" + Environment.NewLine +
                "       Dolor!       |      Dolor!       ";

            Assert.AreEqual(expected, actual);
        }
Example #7
0
 protected IndexGrid(GridDefinition def, GridIndexCell fillVal)
     : base(def, fillVal)
 {
 }
        public static void RegisterGrids()
        {
            ColumnDefaults colDefauls = new ColumnDefaults()
            {
                EnableSorting = true
            };

            MVCGridDefinitionTable.Add("TestGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .WithSorting(sorting: true, defaultSortColumn: "Id", defaultSortDirection: SortDirection.Dsc)
                .WithPaging(paging: true, itemsPerPage: 10, allowChangePageSize: true, maxItemsPerPage: 100)
                .WithAdditionalQueryOptionNames("search")
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>{Model.Id}</a>", false)
                        .WithPlainTextValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithVisibility(true, true)
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithVisibility(true, true)
                        .WithValueExpression(p => p.LastName);
                    cols.Add("FullName").WithHeaderText("Full Name")
                        .WithValueTemplate("{Model.FirstName} {Model.LastName}")
                        .WithVisibility(visible: false, allowChangeVisibility: true)
                        .WithSorting(false);
                    cols.Add("StartDate").WithHeaderText("Start Date")
                        .WithVisibility(visible: true, allowChangeVisibility: true)
                        .WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
                    cols.Add("Status")
                        .WithSortColumnData("Active")
                        .WithVisibility(visible: true, allowChangeVisibility: true)
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive")
                        .WithCellCssClassExpression(p => p.Active ? "success" : "danger");
                    cols.Add("Gender").WithValueExpression((p, c) => p.Gender)
                        .WithAllowChangeVisibility(true);
                    cols.Add("Email")
                        .WithVisibility(visible: false, allowChangeVisibility: true)
                        .WithValueExpression(p => p.Email);
                    cols.Add("Url").WithVisibility(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }));
                })
                //.WithAdditionalSetting(MVCGrid.Rendering.BootstrapRenderingEngine.SettingNameTableClass, "notreal") // Example of changing table css class
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string globalSearch = options.GetAdditionalQueryOptionString("search");

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords, globalSearch, options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("EmployeeGrid", new MVCGridBuilder<Person>()
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithRetrieveDataMethod((options) =>
                {
                    var result = new QueryResult<Person>();

                    using (var db = new SampleDatabaseEntities())
                    {
                        result.Items = db.People.Where(p => p.Employee).ToList();
                    }

                    return result;
                })
            );

            MVCGridDefinitionTable.Add("SortableGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithSorting(true, "LastName")
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;
                    var result = new QueryResult<Person>();

                    using (var db = new SampleDatabaseEntities())
                    {
                        var query = db.People.Where(p => p.Employee);

                        if (!String.IsNullOrWhiteSpace(options.SortColumnName))
                        {
                            switch (options.SortColumnName.ToLower())
                            {
                                case "firstname":
                                    query = query.OrderBy(p => p.FirstName, options.SortDirection);
                                    break;
                                case "lastname":
                                    query = query.OrderBy(p => p.LastName, options.SortDirection);
                                    break;
                            }
                        }

                        result.Items = query.ToList();
                    }

                    return result;
                })
            );

            MVCGridDefinitionTable.Add("PagingGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    var result = new QueryResult<Person>();

                    using (var db = new SampleDatabaseEntities())
                    {
                        var query = db.People.AsQueryable();

                        result.TotalRecords = query.Count();

                        if (!String.IsNullOrWhiteSpace(options.SortColumnName))
                        {
                            switch (options.SortColumnName.ToLower())
                            {
                                case "firstname":
                                    query = query.OrderBy(p => p.FirstName, options.SortDirection);
                                    break;
                                case "lastname":
                                    query = query.OrderBy(p => p.LastName, options.SortDirection);
                                    break;
                            }
                        }

                        if (options.GetLimitOffset().HasValue)
                        {
                            query = query.Skip(options.GetLimitOffset().Value).Take(options.GetLimitRowcount().Value);
                        }

                        result.Items = query.ToList();
                    }

                    return result;
                })
            );

            MVCGridDefinitionTable.Add("DIGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.SortColumnName, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("FormattingGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("StartDate").WithHeaderText("Start Date")
                        .WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
                    cols.Add("ViewLink").WithSorting(false)
                        .WithHeaderText("")
                        .WithHtmlEncoding(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>View</a>");
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.SortColumnName, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("StyledGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("StartDate").WithHeaderText("Start Date")
                        .WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive");
                    cols.Add("Gender").WithValueExpression(p => p.Gender)
                        .WithCellCssClassExpression(p => p.Gender == "Female" ? "danger" : "warning");
                    cols.Add().WithColumnName("ViewLink")
                        .WithSorting(false)
                        .WithHeaderText("")
                        .WithHtmlEncoding(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>View</a>");
                })
                .WithRowCssClassExpression(p => p.Active ? "success" : "")
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("Preloading", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithPreloadData(false)
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("CustomLoading", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName")
                        .WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithClientSideLoadingMessageFunctionName("showLoading")
                .WithClientSideLoadingCompleteFunctionName("hideLoading")
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);

                    // pause to test loading message
                    System.Threading.Thread.Sleep(1000);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("Filtering", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName)
                        .WithFiltering(true);
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName)
                        .WithFiltering(true);
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive")
                        .WithFiltering(true);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10, true, 100)
                .WithFiltering(true)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    bool? active = null;
                    string fa = options.GetFilterString("Status");
                    if (!String.IsNullOrWhiteSpace(fa))
                    {
                        active = (String.Compare(fa, "active", true) == 0);
                    }

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords,
                        options.GetFilterString("FirstName"),
                        options.GetFilterString("LastName"),
                        active,
                        options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("ExportGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add().WithColumnName("Id")
                        .WithSorting(false)
                        .WithHtmlEncoding(false)
                        .WithValueExpression((p, c) =>
                        {
                            return String.Format("<a href='{0}'>{1}</a>",
                                c.UrlHelper.Action("detail", "demo", new { id = p.Id }), p.Id);
                        })
                        .WithPlainTextValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive");
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithClientSideLoadingMessageFunctionName("showLoading")
                .WithClientSideLoadingCompleteFunctionName("hideLoading")
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords,
                        options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("Multiple1", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithHtmlEncoding(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>{Model.Id}</a>")
                        .WithPlainTextValueExpression((p, c) => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive");
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithQueryStringPrefix("grid1")
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords,
                        options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("Multiple2", new MVCGridBuilder<TestItem>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Col1").WithValueExpression(p => p.Col1);
                    cols.Add("Col2").WithValueExpression(p => p.Col2);
                    cols.Add("Col3").WithValueExpression(p => p.Col3);
                })
                .WithSorting(true, "Col1")
                .WithPaging(true, 10)
                .WithQueryStringPrefix("grid2")
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    TestItemRepository repo = new TestItemRepository();
                    int totalRecords;
                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(), options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<TestItem>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("CustomStyle", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithHtmlEncoding(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>{Model.Id}</a>")
                        .WithPlainTextValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive");
                })
                .WithRenderingEngine(typeof(CustomHtmlRenderingEngine))
                .WithSorting(true, "LastName")
                .WithPaging(true, 20)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords,
                        options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("CustomRazorView", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .WithRenderingMode(RenderingMode.Controller)
                .WithViewPath("~/Views/MVCGrid/_Custom.cshtml")
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithHtmlEncoding(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>{Model.Id}</a>")
                        .WithPlainTextValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive");
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 20)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords,
                        options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("ValueTemplate", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}'>{Model.Id}</a>", false)
                        .WithPlainTextValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("Edit").WithHtmlEncoding(false)
                        .WithSorting(false)
                        .WithHeaderText(" ")
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}' class='btn btn-primary' role='button'>Edit</a>");
                    cols.Add("Delete").WithHtmlEncoding(false)
                        .WithSorting(false)
                        .WithHeaderText(" ")
                        .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id }))
                        .WithValueTemplate("<a href='{Value}' class='btn btn-danger' role='button'>Delete</a>");
                    cols.Add("Example").WithHtmlEncoding(false)
                        .WithSorting(false)
                        .WithHeaderText("Example")
                        .WithValueExpression((p, c) => p.Active ? "label-success" : "label-danger")
                        .WithValueTemplate("You can access any of the item's properties: <strong>{Model.FirstName}</strong> <br />or the current column value: <span class='label {Value}'>{Model.Active}</span>");
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 20)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string sortColumn = options.GetSortColumnData<string>();

                    var items = repo.GetData(out totalRecords,
                        options.GetLimitOffset(), options.GetLimitRowcount(),
                        sortColumn, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );


            MVCGridDefinitionTable.Add("CustomErrorMessage", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithErrorMessageHtml(@"<div class=""alert alert-danger"" role=""alert"">OH NO!!!</div>")
                .WithSorting(true, "LastName")
                .WithPaging(true)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    var result = new QueryResult<Person>();

                    using (var db = new SampleDatabaseEntities())
                    {
                        var query = db.People.AsQueryable();

                        result.TotalRecords = query.Count();

                        if (!String.IsNullOrWhiteSpace(options.SortColumnName))
                        {
                            switch (options.SortColumnName.ToLower())
                            {
                                case "firstname":
                                    throw new Exception("Test exception");
                                case "lastname":
                                    query = query.OrderBy(p => p.LastName, options.SortDirection);
                                    break;
                            }
                        }

                        if (options.GetLimitOffset().HasValue)
                        {
                            query = query.Skip(options.GetLimitOffset().Value).Take(options.GetLimitRowcount().Value);
                        }

                        result.Items = query.ToList();
                    }

                    return result;
                })
            );

            MVCGridDefinitionTable.Add("UsageExample", new MVCGridBuilder<YourModelItem>()
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    // Add your columns here
                    cols.Add("UniqueColumnName").WithHeaderText("Any Header")
                        .WithValueExpression(i => i.YourProperty); // use the Value Expression to return the cell text for this column
                    cols.Add().WithColumnName("UrlExample")
                        .WithHeaderText("Edit")
                        .WithValueExpression((i, c) => c.UrlHelper.Action("detail", "demo", new { id = i.YourProperty }));
                })
                .WithRetrieveDataMethod((context) =>
                {
                    // Query your data here. Obey Ordering, paging and filtering paramters given in the context.QueryOptions.
                    // Use Entity Framwork, a module from your IoC Container, or any other method.
                    // Return QueryResult object containing IEnumerable<YouModelItem>

                    return new QueryResult<YourModelItem>()
                    {
                        Items = new List<YourModelItem>(),
                        TotalRecords = 0 // if paging is enabled, return the total number of records of all pages
                    };

                })
            );

            MVCGridDefinitionTable.Add("GlobalSearchGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithAdditionalQueryOptionNames("Search")
                .WithAdditionalSetting("RenderLoadingDiv", false)
                .WithSorting(true, "LastName")
                .WithPaging(true, 10, true, 100)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string globalSearch = options.GetAdditionalQueryOptionString("Search");

                    var items = repo.GetData(out totalRecords, globalSearch, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.SortColumnName, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("PageSizeGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10, true, 100)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.SortColumnName, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("ColumnVisibilityGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                    cols.Add("StartDate").WithHeaderText("Start Date")
                        .WithVisibility(false, true)
                        .WithValueExpression(p => p.StartDate.HasValue ? p.StartDate.Value.ToShortDateString() : "");
                    cols.Add("Status").WithSortColumnData("Active")
                        .WithHeaderText("Status")
                        .WithVisibility(false, true)
                        .WithValueExpression(p => p.Active ? "Active" : "Inactive")
                        .WithCellCssClassExpression((p, c) => p.Active ? "success" : "danger");
                    cols.Add("Gender")
                        .WithVisibility(false, true)
                        .WithValueExpression(p => p.Gender);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.SortColumnName, options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("NestedObjectTest", new MVCGridBuilder<Job>()
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .WithPaging(true)
                .AddColumns(cols =>
                {
                    cols.Add("Id", "Id", row => row.JobId.ToString());
                    cols.Add("Name", "Name", row => row.Name);

                    cols.Add("Contact")
                        .WithHeaderText("Contact")
                        .WithHtmlEncoding(false)
                        .WithSorting(true)
                        .WithValueExpression((p, c) => p.Contact != null ? c.UrlHelper.Action("Edit", "Contact", new { id = p.Contact.Id }) : "")
                        .WithValueTemplate("<a href='{Value}'>{Model.Contact.FullName}</a>").WithPlainTextValueExpression((p, c) => p.Contact != null ? p.Contact.FullName : "");
                })
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;
                    JobRepo repo = new JobRepo();
                    int totalRecords;
                    var data = repo.GetData(out totalRecords, null, options.GetLimitOffset(), options.GetLimitRowcount(), null, false);

                    return new QueryResult<Job>()
                    {
                        Items = data,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("PPGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .WithPageParameterNames("Active")
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithPreloadData(true)
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    string ppactive = options.GetPageParameterString("active");
                    bool filterActive = bool.Parse(ppactive);

                    var items = repo.GetData(out totalRecords, null,null, filterActive, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            MVCGridDefinitionTable.Add("QPLGrid", new MVCGridBuilder<Person>(colDefauls)
                .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                .WithQueryOnPageLoad(false)
                .WithPreloadData(false)
                .AddColumns(cols =>
                {
                    cols.Add("Id").WithSorting(false)
                        .WithValueExpression(p => p.Id.ToString());
                    cols.Add("FirstName").WithHeaderText("First Name")
                        .WithValueExpression(p => p.FirstName);
                    cols.Add("LastName").WithHeaderText("Last Name")
                        .WithValueExpression(p => p.LastName);
                })
                .WithSorting(true, "LastName")
                .WithPaging(true, 10)
                .WithRetrieveDataMethod((context) =>
                {
                    var options = context.QueryOptions;

                    int totalRecords;
                    var repo = DependencyResolver.Current.GetService<IPersonRepository>();

                    var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
                        options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc);

                    return new QueryResult<Person>()
                    {
                        Items = items,
                        TotalRecords = totalRecords
                    };
                })
            );

            //MVCGridDefinitionTable.Add DO NOT DELETE - Needed for demo code parsing


            GridDefinition<YourModelItem> def = new GridDefinition<YourModelItem>();

            GridColumn<YourModelItem> column = new GridColumn<YourModelItem>();
            column.ColumnName = "UniqueColumnName";
            column.HeaderText = "Any Header";
            column.ValueExpression = (i, c) => i.YourProperty;
            def.AddColumn(column);

            def.RetrieveData = (options) =>
            {
                return new QueryResult<YourModelItem>()
                    {
                        Items = new List<YourModelItem>(),
                        TotalRecords = 0
                    };
            };
            MVCGridDefinitionTable.Add("NonFluentUsageExample", def);

            GridDefaults defaultSet1 = new GridDefaults()
            {
                Paging = true,
                ItemsPerPage = 20,
                Sorting = true,
                NoResultsMessage = "Sorry, no results were found"
            };

            MVCGridDefinitionTable.Add("DefaultsExample",
                new MVCGridBuilder<YourModelItem>(defaultSet1) // pass in defauls object to ctor
                .AddColumns(cols =>
                {
                    // add columns
                })
                .WithDefaultSortColumn("Test")
                .WithRetrieveDataMethod((context) =>
                {
                    //get data
                    return new QueryResult<YourModelItem>();
                })
            );


            var docsReturnTypeColumn = new GridColumn<MethodDocItem>()
            {
                ColumnName = "ReturnType",
                HeaderText = "Return Type",
                HtmlEncode = false,
                ValueExpression = (p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Return))
            };
            var docsNameColumn = new GridColumn<MethodDocItem>()
            {
                ColumnName = "Name",
                HtmlEncode = false,
                ValueExpression = (p, c) => String.Format("<code>{0}</code>", HttpUtility.HtmlEncode(p.Name))
            };
            var docsDescriptionColumn = new GridColumn<MethodDocItem>()
            {
                ColumnName = "Description",
                ValueExpression = (p, c) => p.Description
            };

            Func<GridContext, QueryResult<MethodDocItem>> docsLoadData = (context) =>
            {
                var result = new QueryResult<MethodDocItem>();

                DocumentationRepository repo = new DocumentationRepository();
                result.Items = repo.GetData(context.GridName);

                return result;
            };

            MVCGridDefinitionTable.Add("GridDefinition", new MVCGridBuilder<MethodDocItem>()
                .AddColumn(docsNameColumn)
                .AddColumn(docsReturnTypeColumn)
                .AddColumn(docsDescriptionColumn)
                .WithRetrieveDataMethod(docsLoadData)
            );

            MVCGridDefinitionTable.Add("GridColumn", new MVCGridBuilder<MethodDocItem>()
                .AddColumn(docsNameColumn)
                .AddColumn(docsReturnTypeColumn)
                .AddColumn(docsDescriptionColumn)
                .WithRetrieveDataMethod(docsLoadData)
            );

            MVCGridDefinitionTable.Add("QueryOptions", new MVCGridBuilder<MethodDocItem>()
                .AddColumn(docsNameColumn)
                .AddColumn(docsReturnTypeColumn)
                .AddColumn(docsDescriptionColumn)
                .WithRetrieveDataMethod(docsLoadData)
            );

            MVCGridDefinitionTable.Add("ClientSide", new MVCGridBuilder<MethodDocItem>()
                .AddColumn(docsNameColumn)
                .AddColumn(docsDescriptionColumn)
                .WithRetrieveDataMethod(docsLoadData)
            );

        }
Example #9
0
        public void Case_01()
        {
            var grid = new GridDefinition
            {
                RowDefinitions = new List <RowDefinition>
                {
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    }
                },
                ColumnDefinitions = new List <ColumnDefinition>
                {
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    }
                }
            };

            grid
            .AddCell("Produto", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Valor", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Qtd.", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Total", horizontalAlign: HorizontalAlign.Center);

            grid
            .AddCell("Refeição")
            .AddCell("R$ 44,90")
            .AddCell("0,000 kg")
            .AddCell("R$ 8,89");

            grid
            .AddCell("Refrigerantes")
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            grid
            .AddCell("Sucos")
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            grid
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            var gridRender = new GridRender(grid);

            gridRender.AddStyle <InsideBordersStyle>();
            gridRender.AddStyle <HeaderBorderStyle>();

            var actual = gridRender.Render(57);

            var expected =
                "+-----------------------------+--------+--------+-------+" + Environment.NewLine +
                "|           Produto           | Valor  |  Qtd.  | Total |" + Environment.NewLine +
                "+-----------------------------+--------+--------+-------+" + Environment.NewLine +
                "Refeição                      |R$ 44,90|0,000 kg|R$ 8,89 " + Environment.NewLine +
                "------------------------------+--------+--------+--------" + Environment.NewLine +
                "Refrigerantes                 |        |        |        " + Environment.NewLine +
                "------------------------------+--------+--------+--------" + Environment.NewLine +
                "Sucos                         |        |        |        " + Environment.NewLine +
                "------------------------------+--------+--------+--------" + Environment.NewLine +
                "                              |        |        |        ";

            Assert.AreEqual(expected, actual);
        }
Example #10
0
 protected BasicGridRender(HtmlNode htmlNode, GridDefinition grid)
     : base(grid)
 {
     Styles.AddRange(htmlNode.BorderStyles());
 }
Example #11
0
 /// <summary>
 /// Loads the grid column definitions for a grid.
 /// </summary>
 /// <param name="gridDef">The GridDefinition object describing the grid.</param>
 /// <returns>A GridDictionaryInfo.ReadGridDictionaryInfo object describing the grid.</returns>
 /// <remarks>This method is not used by applications. It is reserved for component implementation.</remarks>
 public static async Task <GridDictionaryInfo.ReadGridDictionaryInfo> LoadGridColumnDefinitionsAsync(GridDefinition gridDef)
 {
     if (gridDef.CachedData == null)
     {
         gridDef.CachedData = await LoadGridColumnDefinitionsAsync(gridDef.RecordType);
     }
     return((GridDictionaryInfo.ReadGridDictionaryInfo)gridDef.CachedData);
 }
Example #12
0
        public void Apply(GridDefinition grid)
        {
            foreach (var cellDefinition in grid.CellDefinitions)
            {
                var border = cellDefinition.Border;

                border.Left   = VerticalSeparator;
                border.Top    = HorizontalSeparator;
                border.Right  = VerticalSeparator;
                border.Bottom = HorizontalSeparator;

                border.TopLeft     = CrossSeparator;
                border.TopRight    = CrossSeparator;
                border.BottomLeft  = CrossSeparator;
                border.BottomRight = CrossSeparator;

                var firstRow    = cellDefinition.Row == 0;
                var lastRow     = cellDefinition.Row == grid.RowDefinitions.Count - 1;
                var firstColumn = cellDefinition.Column == 0;
                var lastColumn  = cellDefinition.Column == grid.ColumnDefinitions.Count - 1;

                if (firstRow)
                {
                    border.Top = null;
                }

                if (lastRow)
                {
                    border.Bottom = null;
                }

                if (firstColumn)
                {
                    border.Left = null;
                }

                if (lastColumn)
                {
                    border.Right = null;
                }

                if (firstRow && firstColumn)
                {
                    border.TopLeft = null;
                }

                if (firstRow && lastColumn)
                {
                    border.TopRight = null;
                }

                if (lastRow && firstColumn)
                {
                    border.BottomLeft = null;
                }

                if (lastRow && lastColumn)
                {
                    border.BottomRight = null;
                }

                if (firstRow && !firstColumn)
                {
                    border.TopLeft = VerticalSeparator;
                }

                if (lastRow && !firstColumn)
                {
                    border.BottomLeft = VerticalSeparator;
                }

                if (firstColumn && !firstRow)
                {
                    border.TopLeft = HorizontalSeparator;
                }

                if (lastColumn && !firstRow)
                {
                    border.TopRight = HorizontalSeparator;
                }
            }
        }
 public GridUtils(GridDefinition definition) : this(definition.Size, definition.CellSize)
 {
 }
        public void Case_01()
        {
            var grid = new GridDefinition
            {
                RowDefinitions = new List <RowDefinition>
                {
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    }
                },
                ColumnDefinitions = new List <ColumnDefinition>
                {
                    new ColumnDefinition {
                        WidthType = WidthType.Star, Width = 1
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    },
                    new ColumnDefinition {
                        WidthType = WidthType.Auto
                    }
                }
            };

            grid
            .AddCell("Produto", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Valor", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Qtd.", horizontalAlign: HorizontalAlign.Center)
            .AddCell("Total", horizontalAlign: HorizontalAlign.Center);

            grid
            .AddCell("Refeição")
            .AddCell("R$ 44,90")
            .AddCell("0,000 kg")
            .AddCell("R$ 8,89");

            grid
            .AddCell("Refrigerantes")
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            grid
            .AddCell("Sucos")
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            grid
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty)
            .AddCell(string.Empty);

            var gridRender = new GridRender(grid);

            gridRender.AddStyle <WhiteSpaceVerticalBorderStyle>();

            var actual = gridRender.Render(57);

            var expected =
                "            Produto             Valor     Qtd.    Total  " + Environment.NewLine +
                " Refeição                      R$ 44,90 0,000 kg R$ 8,89 " + Environment.NewLine +
                " Refrigerantes                                           " + Environment.NewLine +
                " Sucos                                                   " + Environment.NewLine +
                "                                                         ";


            Assert.AreEqual(expected, actual);
        }
Example #15
0
 public GridRender(GridDefinition grid)
 {
     _grid  = grid;
     Styles = new List <IBorderStyle>();
 }
Example #16
0
        public void Only_Auto_With_Cells_Case_02()
        {
            var gridDefinition = new GridDefinition
            {
                RowDefinitions = new List <RowDefinition>
                {
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    },
                    new RowDefinition {
                        HeightType = HeightType.Auto
                    }
                },
                ColumnDefinitions = new List <ColumnDefinition>
                {
                    new ColumnDefinition(),
                    new ColumnDefinition(),
                    new ColumnDefinition()
                },
                CellDefinitions = new List <CellDefinition>
                {
                    new CellDefinition {
                        Row = 0, Column = 0, Value = "Lorem Ipsum is simply dummy text of the printing and typesetting industry", HorizontalAlign = HorizontalAlign.Justified
                    },
                    new CellDefinition {
                        Row = 0, Column = 1, Value = "Lorem Ipsum is simply dummy typesetting industry", HorizontalAlign = HorizontalAlign.Justified
                    },
                    new CellDefinition {
                        Row = 0, Column = 2, Value = "The printing and typesetting industry", HorizontalAlign = HorizontalAlign.Justified
                    },

                    new CellDefinition {
                        Row = 1, Column = 0, Value = "Lorem"
                    },
                    new CellDefinition {
                        Row = 1, Column = 1, Value = "Lorem Ipsum is simply dummy text of the printing and typesetting industry", HorizontalAlign = HorizontalAlign.Justified
                    },
                    new CellDefinition {
                        Row = 1, Column = 2, Value = "Ipsum is simply dummy text of the printing and typesetting industry", HorizontalAlign = HorizontalAlign.Justified
                    },

                    new CellDefinition {
                        Row = 2, Column = 0, Value = ""
                    },
                    new CellDefinition {
                        Row = 2, Column = 1, Value = "Lorem Ipsum is simply dummy text of the printing and typesetting industry", HorizontalAlign = HorizontalAlign.Justified
                    },
                    new CellDefinition {
                        Row = 2, Column = 2, Value = ""
                    }
                }
            };

            var columnsSize = new[] { 5, 10, 15 };

            var rowsSize = gridDefinition.RowsSize(columnsSize);

            Assert.AreEqual(3, rowsSize.Length);

            Assert.AreEqual(19, rowsSize[0]);
            Assert.AreEqual(9, rowsSize[1]);
            Assert.AreEqual(10, rowsSize[2]);
        }
Example #17
0
 private static void ApplyStyle(this GridDefinition grid, IBorderStyle borderStyle)
 {
     borderStyle?.Apply(grid);
 }