Пример #1
0
        public void NumberColumn()
        {
            Grid grid = new Grid();

            Number column = new Number("column", grid);

            column.Required   = true;
            column.Primarykey = true;

            Number column2 = new Number("column2", grid);
            Number column3 = new Number("column3", grid);
            Number column4 = new Number("column4", grid);
            Number column5 = new Number("column5", grid);
            Number column6 = new Number("column6", grid);
            Number column7 = new Number("column7", grid);
            Number column8 = new Number("column8", grid);

            grid.MasterTable.Columns.Add(column);
            grid.MasterTable.Columns.Add(column2);
            grid.MasterTable.Columns.Add(column3);
            grid.MasterTable.Columns.Add(column4);
            grid.MasterTable.Columns.Add(column5);
            grid.MasterTable.Columns.Add(column6);
            grid.MasterTable.Columns.Add(column7);
            grid.MasterTable.Columns.Add(column8);

            SetupGrid(grid);

            // Not allowed content
            grid.MasterTable.Rows[0]["column"].Value  = "";
            grid.MasterTable.Rows[0]["column2"].Value = "test";
            grid.MasterTable.Rows[0]["column3"].Value = "<'.3%&#'34,'5>";

            // Allowed Content
            grid.MasterTable.Rows[0]["column4"].Value = "05";
            grid.MasterTable.Rows[0]["column5"].Value = "34";
            grid.MasterTable.Rows[0]["column6"].Value = "1 035 000";
            grid.MasterTable.Rows[0]["column7"].Value = "1 000";
            grid.MasterTable.Rows[0]["column8"].Value = "123 000 000";

            Assert.AreEqual(grid.Mode, Mode.Edit);
            grid.RaisePostBackEvent("RecordUpdateClick!!False");

            Assert.AreSame("", grid.MasterTable.Rows[0]["column"].Value.ToString());
            Assert.AreSame("test", grid.MasterTable.Rows[0]["column2"].Value.ToString());
            Assert.AreSame("<'.3%&#'34,'5>", grid.MasterTable.Rows[0]["column3"].Value.ToString());

            Assert.AreEqual(grid.SystemMessage.Count, 3);
        }
Пример #2
0
        public void GetDataSourceDataTable()
        {
            //Setting up a standard OleDBDataAdapter datasource.
            OleDbConnection myConn = new OleDbConnection(ConnectionAccessOleDb);

            OleDbDataAdapter myCmd = new OleDbDataAdapter("SELECT * FROM [Employees]", myConn);
            DataTable        dt    = new DataTable();

            myCmd.Fill(dt);
            Grid grid = new Grid();

            grid.ID        = "test";
            grid.CurrentId = "3";
            grid.Mode      = Mode.Edit;

            WebGrid.Columns.Number column = new WebGrid.Columns.Number("EmployeeID", grid);
            column.Required   = true;
            column.Primarykey = true;
            grid.Columns.Add(column);
            grid.DataSource = dt;
            StringBuilder  sb         = new StringBuilder();
            StringWriter   sw         = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);

            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.DataSourceType, DataSourceControlType.EnumerableDataSource);
            Assert.AreEqual(grid.Primarykeys.Count, 1);
            Assert.Greater(grid.MasterTable.Columns.Count, 1);
            string content = sb.ToString();

            string[] triggerStrings = new[]
            {
                "test_3_HireDate_trigger",
                "calendar.gif",
                "class=\"wgeditfield\"  value=\"Ms.\"",
                "value=\"08/30/1963\"",
                "ob=true&amp;wgfilenameoption=2&amp;wgfilename=&amp;",
                "class=\"wgupdaterecord\""
            };
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1, part + Environment.NewLine + content);
            }
            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
        }
Пример #3
0
        public void GetDataSourceDataTable()
        {
            //Setting up a standard OleDBDataAdapter datasource.
            OleDbConnection myConn = new OleDbConnection(ConnectionAccessOleDb);

            OleDbDataAdapter myCmd = new OleDbDataAdapter("SELECT * FROM [Employees]", myConn);
            DataTable dt = new DataTable();

            myCmd.Fill(dt);
            Grid grid = new Grid();
            grid.ID = "test";
            grid.CurrentId = "3";
            grid.Mode = Mode.Edit;

            WebGrid.Columns.Number column = new WebGrid.Columns.Number("EmployeeID", grid);
            column.Required = true;
            column.Primarykey = true;
            grid.Columns.Add(column);
            grid.DataSource = dt;
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.DataSourceType, DataSourceControlType.EnumerableDataSource);
            Assert.AreEqual(grid.Primarykeys.Count, 1);
            Assert.Greater(grid.MasterTable.Columns.Count, 1);
            string content = sb.ToString();
            string[] triggerStrings = new[]
                                          {
                                              "test_3_HireDate_trigger",
                                              "calendar.gif",
                                              "class=\"wgeditfield\"  value=\"Ms.\"",
                                              "value=\"08/30/1963\"",
                                              "ob=true&amp;wgfilenameoption=2&amp;wgfilename=&amp;",
                                              "class=\"wgupdaterecord\""
                                          };
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1,part+Environment.NewLine+content);
            }
            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
        }
Пример #4
0
        public void NumberColumn()
        {
            Grid grid = new Grid();

            Number column = new Number("column", grid);
            column.Required = true;
            column.Primarykey = true;

            Number column2 = new Number("column2", grid);
            Number column3 = new Number("column3", grid);
            Number column4 = new Number("column4", grid);
            Number column5 = new Number("column5", grid);
            Number column6 = new Number("column6", grid);
            Number column7 = new Number("column7", grid);
            Number column8 = new Number("column8", grid);

            grid.MasterTable.Columns.Add(column);
            grid.MasterTable.Columns.Add(column2);
            grid.MasterTable.Columns.Add(column3);
            grid.MasterTable.Columns.Add(column4);
            grid.MasterTable.Columns.Add(column5);
            grid.MasterTable.Columns.Add(column6);
            grid.MasterTable.Columns.Add(column7);
            grid.MasterTable.Columns.Add(column8);

            SetupGrid(grid);

            // Not allowed content
            grid.MasterTable.Rows[0]["column"].Value = "";
            grid.MasterTable.Rows[0]["column2"].Value = "test";
            grid.MasterTable.Rows[0]["column3"].Value = "<'.3%&#'34,'5>";

            // Allowed Content
            grid.MasterTable.Rows[0]["column4"].Value = "05";
            grid.MasterTable.Rows[0]["column5"].Value = "34";
            grid.MasterTable.Rows[0]["column6"].Value = "1 035 000";
            grid.MasterTable.Rows[0]["column7"].Value = "1 000";
            grid.MasterTable.Rows[0]["column8"].Value = "123 000 000";

            Assert.AreEqual(grid.Mode, Mode.Edit);
            grid.RaisePostBackEvent("RecordUpdateClick!!False");

            Assert.AreSame("", grid.MasterTable.Rows[0]["column"].Value.ToString());
            Assert.AreSame("test", grid.MasterTable.Rows[0]["column2"].Value.ToString());
            Assert.AreSame("<'.3%&#'34,'5>", grid.MasterTable.Rows[0]["column3"].Value.ToString());

            Assert.AreEqual(grid.SystemMessage.Count, 3);
        }