Пример #1
0
        public void WebGridLinqTest2()
        {
            NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

            Collection <NorthwindEmployee> employees = employeedata.GetAllEmployeesCollection("", 0, 100);

            var list = from test in employees
                       where test.Region != "WA"
                       select new { test.EmployeeID, test.FirstName };

            Grid grid = new Grid();

            grid.DataSource = list;
            grid.ID         = "test";
            int            rows       = grid.Rows.Count; // Return 5 rows.
            StringBuilder  sb         = new StringBuilder();
            StringWriter   sw         = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);

            grid.RenderControl(gridwriter);
            Assert.Greater(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(rows, 4);
            foreach (WebGrid.Data.Row row in grid.Rows)
            {
                Assert.IsNotNull(row["EmployeeID"].Value);
                Assert.IsNotNull(row["FirstName"].Value);
                Assert.AreEqual(row["FirstName"].Value.GetType(), typeof(string));
                // WebGrid is using int64
                Assert.AreEqual(row["EmployeeID"].Value.GetType(), typeof(Int64));
            }
        }
Пример #2
0
        public void LoadGridWithNeedDataGridView()
        {
            NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

            List <NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);
            Grid grid = new Grid();

            grid.DataBind();
            grid.ID = "test";
            BeforeGetDataExecuted = 0;
            grid.BeforeGetData   += grid_BeforeGetData;
            grid.Columns["EmployeeID"].ColumnType         = WebGrid.Enums.ColumnType.Number;
            grid.Columns["EmployeeID"].Primarykey         = true;
            grid.Columns["FirstName"].ColumnType          = WebGrid.Enums.ColumnType.Text;
            grid.Columns["LastName"].ColumnType           = WebGrid.Enums.ColumnType.Text;
            grid.Columns["Address"].ColumnType            = WebGrid.Enums.ColumnType.Text;
            grid.Columns["BirthDay"].ColumnType           = WebGrid.Enums.ColumnType.DateTime;
            grid.Columns["CustomerType"].ColumnType       = WebGrid.Enums.ColumnType.Foreignkey;
            grid.Columns["CustomerType"].AllowEditInGrid  = true;
            grid.Columns["CustomerType2"].ColumnType      = WebGrid.Enums.ColumnType.Foreignkey;
            grid.Columns["CustomerType2"].AllowEditInGrid = true;
            ((WebGrid.Foreignkey)grid.Columns["CustomerType"]).ValueColumn = "title";
            StringBuilder  sb         = new StringBuilder();
            StringWriter   sw         = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);

            grid.RenderControl(gridwriter);
            Assert.AreEqual(BeforeGetDataExecuted, 1);
            Assert.AreEqual(grid.MasterTable.Rows.Count, employees.Count);
            Assert.AreEqual(((WebGrid.Foreignkey)grid.Columns["CustomerType"]).Table.Rows.Count, 3);
            Assert.AreEqual(((WebGrid.Foreignkey)grid.Columns["CustomerType2"]).Table.Rows.Count, 9);
            Assert.AreEqual(grid.SystemMessage.Count, 0);
        }
Пример #3
0
        public void LoadGridWithEmployeesGenericList()
        {
            NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

            List<NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);

            Grid grid = new Grid();
            grid.DataSource = employees;
            grid.ID = "test";
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.Rows.Count, employees.Count);
        }
Пример #4
0
        public void LoadGridWithEmployeesGenericCollection()
        {
            NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

            Collection <NorthwindEmployee> employees = employeedata.GetAllEmployeesCollection("", 0, 100);
            Grid grid = new Grid();

            grid.DataSource = employees;
            grid.ID         = "test";
            StringBuilder  sb         = new StringBuilder();
            StringWriter   sw         = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);

            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.Rows.Count, employees.Count);
        }
Пример #5
0
        void grid_BeforeGetData(object sender, WebGrid.Events.BeforeGetDataEventArgs e)
        {
            if (e.Table == ((Grid)sender).MasterTable)
            {
                BeforeGetDataExecuted++;
                NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

                List <NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);
                e.Table.DataSource = employees;
            }
            else if (e.Table == ((WebGrid.Foreignkey)((Grid)sender).Columns["CustomerType"]).Table)
            {
                e.Table.Columns["CustomerType"].ColumnType = WebGrid.Enums.ColumnType.Number;
                e.Table.Columns["Title"].ColumnType        = WebGrid.Enums.ColumnType.Text;

                WebGrid.Data.Row row = new WebGrid.Data.Row(e.Table);

                row["CustomerType"].Value = 1;
                row["Title"].Value        = "Title";
                e.Table.Rows.Add(row);

                row = new WebGrid.Data.Row(e.Table);
                row["CustomerType"].Value = 2;
                row["Title"].Value        = "Title";
                e.Table.Rows.Add(row);

                row = new WebGrid.Data.Row(e.Table);
                row["CustomerType"].Value = 3;
                row["Title"].Value        = "Title";
                e.Table.Rows.Add(row);
            }
            else if (e.Table == ((WebGrid.Foreignkey)((Grid)sender).Columns["CustomerType2"]).Table)
            {
                NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

                List <NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);
                e.Table.DataSource = employees;
            }
        }
Пример #6
0
        void grid_BeforeGetData(object sender, WebGrid.Events.BeforeGetDataEventArgs e)
        {
            if (e.Table == ((Grid)sender).MasterTable)
            {
                BeforeGetDataExecuted++;
                NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

                List<NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);
                e.Table.DataSource = employees;
            }
            else if (e.Table == ((WebGrid.Foreignkey)((Grid)sender).Columns["CustomerType"]).Table)
            {
                e.Table.Columns["CustomerType"].ColumnType = WebGrid.Enums.ColumnType.Number;
                e.Table.Columns["Title"].ColumnType = WebGrid.Enums.ColumnType.Text;

                WebGrid.Data.Row row = new WebGrid.Data.Row(e.Table);

                row["CustomerType"].Value = 1;
                row["Title"].Value = "Title";
                e.Table.Rows.Add(row);

                row = new WebGrid.Data.Row(e.Table);
                row["CustomerType"].Value = 2;
                row["Title"].Value = "Title";
                e.Table.Rows.Add(row);

                row = new WebGrid.Data.Row(e.Table);
                row["CustomerType"].Value = 3;
                row["Title"].Value = "Title";
                e.Table.Rows.Add(row);
            }
            else if (e.Table == ((WebGrid.Foreignkey)((Grid)sender).Columns["CustomerType2"]).Table)
            {
                NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

                List<NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);
                e.Table.DataSource = employees;
            }
        }
Пример #7
0
        public void WebGridLinqTest2()
        {
            NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

            Collection<NorthwindEmployee> employees = employeedata.GetAllEmployeesCollection("", 0, 100);

            var list = from test in employees
                       where test.Region != "WA"
                       select new { test.EmployeeID, test.FirstName };

            Grid grid = new Grid();
            grid.DataSource = list;
            grid.ID = "test";
            int rows = grid.Rows.Count; // Return 5 rows.
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.Greater(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(rows, 4);
            foreach (WebGrid.Data.Row row in grid.Rows)
            {
                Assert.IsNotNull(row["EmployeeID"].Value);
                Assert.IsNotNull(row["FirstName"].Value);
                Assert.AreEqual(row["FirstName"].Value.GetType(), typeof(string));
                // WebGrid is using int64
                Assert.AreEqual(row["EmployeeID"].Value.GetType(), typeof(Int64));
            }
        }
Пример #8
0
        public void LoadGridWithNeedDataGridView()
        {
            NorthwindEmployeeData employeedata = new NorthwindEmployeeData();

            List<NorthwindEmployee> employees = employeedata.GetAllEmployeesList("", 0, 100);
            Grid grid = new Grid();
            grid.DataBind();
            grid.ID = "test";
            BeforeGetDataExecuted = 0;
            grid.BeforeGetData += grid_BeforeGetData;
            grid.Columns["EmployeeID"].ColumnType = WebGrid.Enums.ColumnType.Number;
            grid.Columns["EmployeeID"].Primarykey = true;
            grid.Columns["FirstName"].ColumnType = WebGrid.Enums.ColumnType.Text;
            grid.Columns["LastName"].ColumnType = WebGrid.Enums.ColumnType.Text;
            grid.Columns["Address"].ColumnType = WebGrid.Enums.ColumnType.Text;
            grid.Columns["BirthDay"].ColumnType = WebGrid.Enums.ColumnType.DateTime;
            grid.Columns["CustomerType"].ColumnType = WebGrid.Enums.ColumnType.Foreignkey;
            grid.Columns["CustomerType"].AllowEditInGrid = true;
            grid.Columns["CustomerType2"].ColumnType = WebGrid.Enums.ColumnType.Foreignkey;
            grid.Columns["CustomerType2"].AllowEditInGrid = true;
            ((WebGrid.Foreignkey)grid.Columns["CustomerType"]).ValueColumn = "title";
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(BeforeGetDataExecuted, 1);
            Assert.AreEqual(grid.MasterTable.Rows.Count, employees.Count);
            Assert.AreEqual( ((WebGrid.Foreignkey)grid.Columns["CustomerType"]).Table.Rows.Count, 3);
            Assert.AreEqual(((WebGrid.Foreignkey)grid.Columns["CustomerType2"]).Table.Rows.Count, 9);
            Assert.AreEqual(grid.SystemMessage.Count, 0);
        }